]> git.mxchange.org Git - jcountry-core.git/commitdiff
Added equals() hashCode() for easy comparison
authorRoland Haeder <roland@mxchange.org>
Tue, 13 Oct 2015 12:30:40 +0000 (14:30 +0200)
committerRoland Haeder <roland@mxchange.org>
Tue, 13 Oct 2015 12:30:40 +0000 (14:30 +0200)
Signed-off-by:Roland Häder <roland@mxchange.org>

src/org/mxchange/jcountry/data/Country.java
src/org/mxchange/jcountry/data/CountryData.java

index 2578a2c13850aa512bfe9ae375bee2de2c566bb5..8a399d0b1a5932a4888572015d0821d77c5e6a08 100644 (file)
@@ -123,4 +123,10 @@ public interface Country extends Serializable {
         * required
         */
        public void setCountryIsLocalPrefixRequired (final Boolean countryIsLocalPrefixRequired);
+
+       @Override
+       public boolean equals (final Object object);
+
+       @Override
+       public int hashCode ();
 }
index 6bfb42f19ead8e7a90222daa2613db1f91642033..b286d7135bb9c47f5a100f70198705f1ef55a625 100644 (file)
@@ -16,6 +16,7 @@
  */
 package org.mxchange.jcountry.data;
 
+import java.util.Objects;
 import javax.persistence.Basic;
 import javax.persistence.Column;
 import javax.persistence.Entity;
@@ -98,6 +99,19 @@ public class CountryData implements Country, Comparable<Country> {
        @Column (name = "country_is_local_prefix_required", nullable = false)
        private Boolean countryIsLocalPrefixRequired;
 
+       @Override
+       public boolean equals (final Object object) {
+               if (object == null) {
+                       return false;
+               } else if (getClass() != object.getClass()) {
+                       return false;
+               }
+
+               final CountryData other = (CountryData) object;
+
+               return Objects.equals(this.getCountryCode(), other.getCountryCode());
+       }
+
        @Override
        public Short getCountryPhoneCode () {
                return this.countryPhoneCode;
@@ -172,4 +186,11 @@ public class CountryData implements Country, Comparable<Country> {
        public void setCountryIsLocalPrefixRequired (final Boolean countryIsLocalPrefixRequired) {
                this.countryIsLocalPrefixRequired = countryIsLocalPrefixRequired;
        }
+
+       @Override
+       public int hashCode () {
+               int hash = 5;
+               hash = 37 * hash + Objects.hashCode(this.getCountryCode());
+               return hash;
+       }
 }