]> git.mxchange.org Git - jcountry-core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sun, 26 Apr 2020 17:51:37 +0000 (19:51 +0200)
committerRoland Häder <roland@mxchange.org>
Sun, 26 Apr 2020 17:51:37 +0000 (19:51 +0200)
- need to compare all entity properties in equals()/hashCode() methods

Signed-off-by: Roland Häder <roland@mxchange.org>
src/org/mxchange/jcountry/model/data/CountryData.java

index c6591f86fb976b71ad7c1a2478f66dd17e9b127d..39d8906b1a0a7197c758fd62d29d6ddadf0f6ce0 100644 (file)
@@ -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;
        }