From: Roland Haeder Date: Mon, 11 Apr 2016 14:31:40 +0000 (+0200) Subject: The method equals() is for object-equality, not if a country with given country code... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=624f57b84f94e6620e3a5d5ec9f5bfd3ecb9f641;p=jcountry-core.git The method equals() is for object-equality, not if a country with given country code or i18n key is already there. So with entities also the id number must be included. --- diff --git a/src/org/mxchange/jcountry/data/CountryData.java b/src/org/mxchange/jcountry/data/CountryData.java index 92020b9..28bdaa6 100644 --- a/src/org/mxchange/jcountry/data/CountryData.java +++ b/src/org/mxchange/jcountry/data/CountryData.java @@ -112,21 +112,33 @@ public class CountryData implements Country { @Override public boolean equals (final Object object) { - if (null == object) { + if (this == object) { + return true; + } else if (null == object) { return false; } else if (this.getClass() != object.getClass()) { return false; } - final CountryData other = (CountryData) object; + final Country other = (Country) object; - return Objects.equals(this.getCountryCode(), other.getCountryCode()); + if (!Objects.equals(this.getCountryCode(), other.getCountryCode())) { + return false; + } else if (!Objects.equals(this.getCountryI18nkey(), other.getCountryI18nkey())) { + return false; + } else if (!Objects.equals(this.getCountryId(), other.getCountryId())) { + return false; + } + + return true; } @Override public int hashCode () { - int hash = 5; - hash = 37 * hash + Objects.hashCode(this.getCountryCode()); + int hash = 7; + hash = 41 * hash + Objects.hashCode(this.getCountryCode()); + hash = 41 * hash + Objects.hashCode(this.getCountryI18nkey()); + hash = 41 * hash + Objects.hashCode(this.getCountryId()); return hash; }