From 0834ab6b1d31a768e87e33c4390ade40b5811f8e Mon Sep 17 00:00:00 2001 From: Vlad Mihalcea Date: Wed, 25 May 2016 13:00:33 +0300 Subject: [PATCH] HHH-10052 - documentation about hashCode and equals not up to date --- .../domain/extras/entity/listing6.java | 17 +++++---------- .../domain/extras/entity/listing9.java | 21 +++++++------------ 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/documentation/src/main/asciidoc/userguide/chapters/domain/extras/entity/listing6.java b/documentation/src/main/asciidoc/userguide/chapters/domain/extras/entity/listing6.java index fb7d40934a..6ef093c2f8 100644 --- a/documentation/src/main/asciidoc/userguide/chapters/domain/extras/entity/listing6.java +++ b/documentation/src/main/asciidoc/userguide/chapters/domain/extras/entity/listing6.java @@ -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 ) ) { + 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 ); } } \ No newline at end of file diff --git a/documentation/src/main/asciidoc/userguide/chapters/domain/extras/entity/listing9.java b/documentation/src/main/asciidoc/userguide/chapters/domain/extras/entity/listing9.java index 08d6bcc5ab..a0a296efb3 100644 --- a/documentation/src/main/asciidoc/userguide/chapters/domain/extras/entity/listing9.java +++ b/documentation/src/main/asciidoc/userguide/chapters/domain/extras/entity/listing9.java @@ -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 ) ) { + 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 ); } } \ No newline at end of file