HHH-10052 - documentation about hashCode and equals not up to date

This commit is contained in:
Vlad Mihalcea 2016-05-25 13:00:33 +03:00
parent 92dfd69937
commit 0834ab6b1d
2 changed files with 12 additions and 26 deletions

View File

@ -5,27 +5,20 @@ public class Person {
@GeneratedValue
private Integer id;
...
@Override
public int hashCode() {
return id != null ? id.hashCode() : 0;
return Objects.hash( id );
}
@Override
public boolean equals() {
public boolean equals(Object o) {
if ( this == o ) {
return true;
}
if ( !( o instanceof Person ) ) {
return false;
}
if ( id == null ) {
return false;
}
final Person other = ( Person ) o;
return id.equals( other.id );
Person person = (Person) o;
return Objects.equals( id, person.id );
}
}

View File

@ -9,35 +9,28 @@ public class Person {
private String ssn;
protected Person() {
// ctor for ORM
// Constructor for ORM
}
public Person( String ssn ) {
// ctor for app
// Constructor for app
this.ssn = ssn;
}
...
@Override
public int hashCode() {
assert ssn != null;
return ssn.hashCode();
return Objects.hash( ssn );
}
@Override
public boolean equals() {
public boolean equals(Object o) {
if ( this == o ) {
return true;
}
if ( !( o instanceof Person ) ) {
return false;
}
final Person other = ( Person ) o;
assert ssn != null;
assert other.ssn != null;
return ssn.equals( other.ssn );
Person person = (Person) o;
return Objects.equals( ssn, person.ssn );
}
}