From b190be99c8a3aea2874377cd91dae870df8ecff7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 26 Apr 2020 19:51:37 +0200 Subject: [PATCH] Continued: - need to compare all entity properties in equals()/hashCode() methods MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../jcountry/model/data/CountryData.java | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/org/mxchange/jcountry/model/data/CountryData.java b/src/org/mxchange/jcountry/model/data/CountryData.java index c6591f8..39d8906 100644 --- a/src/org/mxchange/jcountry/model/data/CountryData.java +++ b/src/org/mxchange/jcountry/model/data/CountryData.java @@ -31,6 +31,7 @@ import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Transient; +import org.apache.commons.lang3.StringUtils; import org.mxchange.jcoreutils.Comparables; /** @@ -198,11 +199,15 @@ public class CountryData implements Country { // Init comparators final int comparators[] = { // First check country code, clear indication ... - this.getCountryCode().compareTo(country.getCountryCode()), + StringUtils.compare(this.getCountryCode(), country.getCountryCode()), // ... and phone code, too this.getCountryPhoneCode().compareTo(country.getCountryPhoneCode()), // ... then last i18n key - this.getCountryI18nKey().compareTo(country.getCountryI18nKey()) + StringUtils.compare(this.getCountryI18nKey(), country.getCountryI18nKey()), + // ... abroad dial prefix + StringUtils.compare(this.getCountryAbroadDialPrefix(), country.getCountryAbroadDialPrefix()), + // ... external dial prefix + StringUtils.compare(this.getCountryExternalDialPrefix(), country.getCountryExternalDialPrefix()) }; // Check all values @@ -225,18 +230,20 @@ public class CountryData implements Country { // @todo Maybe a bit unsafe cast? final Country country = (Country) object; - if (!Objects.equals(this.getCountryId(), country.getCountryId())) { + if (!Objects.equals(this.getCountryAbroadDialPrefix(), country.getCountryAbroadDialPrefix())) { return false; } else if (!Objects.equals(this.getCountryCode(), country.getCountryCode())) { return false; - } else if (!Objects.equals(this.getCountryAbroadDialPrefix(), country.getCountryAbroadDialPrefix())) { - return false; } else if (!Objects.equals(this.getCountryExternalDialPrefix(), country.getCountryExternalDialPrefix())) { return false; - } else if (!Objects.equals(this.getCountryPhoneCode(), country.getCountryPhoneCode())) { - return false; } else if (!Objects.equals(this.getCountryI18nKey(), country.getCountryI18nKey())) { return false; + } else if (!Objects.equals(this.getCountryId(), country.getCountryId())) { + return false; + } else if (!Objects.equals(this.getCountryIsLocalPrefixRequired(), country.getCountryIsLocalPrefixRequired())) { + return false; + } else if (!Objects.equals(this.getCountryPhoneCode(), country.getCountryPhoneCode())) { + return false; } return true; @@ -340,12 +347,13 @@ public class CountryData implements Country { public int hashCode () { int hash = 7; - hash = 41 * hash + Objects.hashCode(this.getCountryId()); - hash = 41 * hash + Objects.hashCode(this.getCountryCode()); hash = 41 * hash + Objects.hashCode(this.getCountryAbroadDialPrefix()); + hash = 41 * hash + Objects.hashCode(this.getCountryCode()); hash = 41 * hash + Objects.hashCode(this.getCountryExternalDialPrefix()); - hash = 41 * hash + Objects.hashCode(this.getCountryPhoneCode()); hash = 41 * hash + Objects.hashCode(this.getCountryI18nKey()); + hash = 41 * hash + Objects.hashCode(this.getCountryId()); + hash = 41 * hash + Objects.hashCode(this.getCountryIsLocalPrefixRequired()); + hash = 41 * hash + Objects.hashCode(this.getCountryPhoneCode()); return hash; } -- 2.39.5