Skip to content

Instantly share code, notes, and snippets.

@rbe
Created September 26, 2012 08:53
Show Gist options
  • Save rbe/3786890 to your computer and use it in GitHub Desktop.
Save rbe/3786890 to your computer and use it in GitHub Desktop.
Entity bean with equals method
import java.util.Calendar;
public class User {
private Long id;
private Long version;
private Calendar lastModified;
private String username;
private String emailAddress;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getVersion() {
return version;
}
public void setVersion(Long version) {
this.version = version;
}
public Calendar getLastModified() {
return lastModified;
}
public void setLastModified(Calendar lastModified) {
this.lastModified = lastModified;
}
public void updateLastModified() {
setLastModified(Calendar.getInstance());
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getEmailAddress() {
return emailAddress;
}
public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
OdiseeUser that = (OdiseeUser) o;
if (id != null ? !id.equals(that.id) : that.id != null) return false;
if (emailAddress != null ? !emailAddress.equals(that.emailAddress) : that.emailAddress != null) return false;
if (!username.equals(that.username)) return false;
return true;
}
@Override
public int hashCode() {
int result = username.hashCode();
result = 31 * result + (emailAddress != null ? emailAddress.hashCode() : 0);
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment