Skip to content

Instantly share code, notes, and snippets.

@AgentKnopf
Last active September 5, 2017 14:10
Show Gist options
  • Save AgentKnopf/96c0a671d4475824c5d4ff37e9e48380 to your computer and use it in GitHub Desktop.
Save AgentKnopf/96c0a671d4475824c5d4ff37e9e48380 to your computer and use it in GitHub Desktop.
public final class User {
@NotNull
private final String email;
private final int age;
public User(@NotNull String email, int age) {
if (email == null) {
throw new RuntimeException("Email can't be null");
}
this.email = email;
this.age = age;
}
@NotNull
public final String getEmail() {
return this.email;
}
public final int getAge() {
return this.age;
}
public String toString() {
return "User(email=" + this.email + ", age=" + this.age + ")";
}
public int hashCode() {
return (this.email != null ? this.email.hashCode() : 0) * 31 + this.age;
}
@NotNull
public final User copy(@NotNull String email, int age) {
Intrinsics.checkParameterIsNotNull(email, "email");
return new User(email, age);
}
public boolean equals(Object otherObject) {
if (this != otherObject) {
if (otherObject instanceof User) {
User otherUser = (User) otherObject;
if (this.email.equals(otherUser.email) && this.age == otherUser.age) {
return true;
}
}
return false;
} else {
return true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment