From 73eae6cf27106e04b4a12334896388d09823f4c5 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 13 Oct 2015 14:30:40 +0200 Subject: [PATCH] =?utf8?q?Added=20equals()=20hashCode()=20for=20easy=20com?= =?utf8?q?parison=20Signed-off-by:Roland=20H=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/org/mxchange/jcountry/data/Country.java | 6 ++++++ .../mxchange/jcountry/data/CountryData.java | 21 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/org/mxchange/jcountry/data/Country.java b/src/org/mxchange/jcountry/data/Country.java index 2578a2c..8a399d0 100644 --- a/src/org/mxchange/jcountry/data/Country.java +++ b/src/org/mxchange/jcountry/data/Country.java @@ -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 (); } diff --git a/src/org/mxchange/jcountry/data/CountryData.java b/src/org/mxchange/jcountry/data/CountryData.java index 6bfb42f..b286d71 100644 --- a/src/org/mxchange/jcountry/data/CountryData.java +++ b/src/org/mxchange/jcountry/data/CountryData.java @@ -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 { @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 { 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; + } } -- 2.39.5