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

lib/jcountry-core.jar
src/org/mxchange/jphone/phonenumbers/cellphone/CellphoneNumber.java
src/org/mxchange/jphone/phonenumbers/cellphone/DialableCellphoneNumber.java
src/org/mxchange/jphone/phonenumbers/fax/DialableFaxNumber.java
src/org/mxchange/jphone/phonenumbers/fax/FaxNumber.java
src/org/mxchange/jphone/phonenumbers/landline/DialableLandLineNumber.java
src/org/mxchange/jphone/phonenumbers/landline/LandLineNumber.java
src/org/mxchange/jphone/phonenumbers/smsprovider/CellphoneProvider.java
src/org/mxchange/jphone/phonenumbers/smsprovider/SmsProvider.java

index 049ef5f9ea049cecb9bb874ec9b9c5518d6aec4c..7166776ede488c2c9e08be75ae1f7ff182548993 100644 (file)
Binary files a/lib/jcountry-core.jar and b/lib/jcountry-core.jar differ
index af396ba7824f4a8823f2d56976c5aca4f152f4a8..0e536ecda4b27278ac0eaa98005cb3d060797db0 100644 (file)
@@ -16,6 +16,7 @@
  */
 package org.mxchange.jphone.phonenumbers.cellphone;
 
+import java.util.Objects;
 import javax.persistence.Basic;
 import javax.persistence.Column;
 import javax.persistence.Entity;
@@ -83,6 +84,25 @@ public class CellphoneNumber implements DialableCellphoneNumber, Comparable<Dial
        protected CellphoneNumber () {
        }
 
+       @Override
+       public boolean equals (final Object object) {
+               if (object == null) {
+                       return false;
+               } else if (getClass() != object.getClass()) {
+                       return false;
+               }
+
+               final DialableCellphoneNumber other = (DialableCellphoneNumber) object;
+
+               if (!Objects.equals(this.getCellphoneProvider(), other.getCellphoneProvider())) {
+                       return false;
+               } else if (!Objects.equals(this.getPhoneNumber(), other.getPhoneNumber())) {
+                       return false;
+               }
+
+               return true;
+       }
+
        @Override
        @Deprecated
        public Country getPhoneCountry () {
@@ -141,4 +161,12 @@ public class CellphoneNumber implements DialableCellphoneNumber, Comparable<Dial
        public int compareTo (final DialableCellphoneNumber dialableCellphoneNumber) {
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
+
+       @Override
+       public int hashCode () {
+               int hash = 5;
+               hash = 97 * hash + Objects.hashCode(this.getCellphoneProvider());
+               hash = 97 * hash + Objects.hashCode(this.getPhoneNumber());
+               return hash;
+       }
 }
index 5fed9715dceb1dfc7ece4a526f134d88567ff45a..953c17a485fa64e541f229d6514958dd07e23ce5 100644 (file)
@@ -39,4 +39,10 @@ public interface DialableCellphoneNumber extends DialableNumber {
         * @param cellphoneProvider SMS provider instance
         */
        public void setCellphoneProvider (final SmsProvider cellphoneProvider);
+
+       @Override
+       public boolean equals (final Object object);
+
+       @Override
+       public int hashCode ();
 }
index 4e904e3f2ad4b77fe2e6bd45fba60bf25c731381..4cd57d28006c80976ac44d639abfd35f1828c274 100644 (file)
@@ -24,4 +24,10 @@ import org.mxchange.jphone.phonenumbers.DialableNumber;
  * @author Roland Haeder
  */
 public interface DialableFaxNumber extends DialableNumber {
+
+       @Override
+       public boolean equals (final Object object);
+
+       @Override
+       public int hashCode ();
 }
index 18520a798aba7b69c0cea73d513539572a2fc3d9..5e55e591d9e945036620645bf473c2bd959c3a07 100644 (file)
@@ -16,6 +16,7 @@
  */
 package org.mxchange.jphone.phonenumbers.fax;
 
+import java.util.Objects;
 import javax.persistence.Basic;
 import javax.persistence.Column;
 import javax.persistence.Entity;
@@ -69,7 +70,7 @@ public class FaxNumber implements DialableFaxNumber, Comparable<DialableFaxNumbe
         * Country instance ('s dial data)
         */
        @JoinColumn (name = "fax_country_id", nullable = false)
-       @OneToOne(targetEntity = CountryData.class, optional = false, fetch = FetchType.EAGER)
+       @OneToOne (targetEntity = CountryData.class, optional = false, fetch = FetchType.EAGER)
        private Country faxCountry;
 
        /**
@@ -91,6 +92,27 @@ public class FaxNumber implements DialableFaxNumber, Comparable<DialableFaxNumbe
        protected FaxNumber () {
        }
 
+       @Override
+       public boolean equals (final Object object) {
+               if (object == null) {
+                       return false;
+               } else if (getClass() != object.getClass()) {
+                       return false;
+               }
+
+               final DialableFaxNumber other = (DialableFaxNumber) object;
+
+               if (!Objects.equals(this.getPhoneNumber(), other.getPhoneNumber())) {
+                       return false;
+               } else if (!Objects.equals(this.getPhoneAreaCode(), other.getPhoneAreaCode())) {
+                       return false;
+               } else if (!Objects.equals(this.getPhoneCountry(), other.getPhoneCountry())) {
+                       return false;
+               }
+
+               return true;
+       }
+
        @Override
        public Long getPhoneId () {
                return this.phoneId;
@@ -136,4 +158,13 @@ public class FaxNumber implements DialableFaxNumber, Comparable<DialableFaxNumbe
                this.faxCountry = faxCountry;
        }
 
+       @Override
+       public int hashCode () {
+               int hash = 3;
+               hash = 23 * hash + Objects.hashCode(this.getPhoneNumber());
+               hash = 23 * hash + Objects.hashCode(this.getPhoneAreaCode());
+               hash = 23 * hash + Objects.hashCode(this.getPhoneCountry());
+               return hash;
+       }
+
 }
index 6d4589499b01d05a5c04b3727d73d7d74d3741c5..4a939979ff7cd286cad64fa9a0d7a1c9ca0d601f 100644 (file)
@@ -20,7 +20,14 @@ import org.mxchange.jphone.phonenumbers.DialableNumber;
 
 /**
  * A POJI for dialable land-line numbers
+ * <p>
  * @author Roland Haeder
  */
 public interface DialableLandLineNumber extends DialableNumber {
+
+       @Override
+       public boolean equals (final Object object);
+
+       @Override
+       public int hashCode ();
 }
index 70285f71ea1e5b55d6f6764b1b084a81680c76ae..aca8d08033ea900314194315f6a227068e8ba0f4 100644 (file)
@@ -16,6 +16,7 @@
  */
 package org.mxchange.jphone.phonenumbers.landline;
 
+import java.util.Objects;
 import javax.persistence.Basic;
 import javax.persistence.Column;
 import javax.persistence.Entity;
@@ -69,7 +70,7 @@ public class LandLineNumber implements DialableLandLineNumber, Comparable<Dialab
         * Connection to table "country_data"
         */
        @JoinColumn (name = "phone_country_id", nullable = false, updatable = false)
-       @OneToOne(targetEntity = CountryData.class, optional = false, fetch = FetchType.EAGER)
+       @OneToOne (targetEntity = CountryData.class, optional = false, fetch = FetchType.EAGER)
        private Country phoneCountry;
 
        /**
@@ -91,6 +92,27 @@ public class LandLineNumber implements DialableLandLineNumber, Comparable<Dialab
        protected LandLineNumber () {
        }
 
+       @Override
+       public boolean equals (Object object) {
+               if (object == null) {
+                       return false;
+               } else if (getClass() != object.getClass()) {
+                       return false;
+               }
+
+               final DialableLandLineNumber other = (DialableLandLineNumber) object;
+
+               if (!Objects.equals(this.getPhoneNumber(), other.getPhoneNumber())) {
+                       return false;
+               } else if (!Objects.equals(this.getPhoneAreaCode(), other.getPhoneAreaCode())) {
+                       return false;
+               } else if (!Objects.equals(this.getPhoneCountry(), other.getPhoneCountry())) {
+                       return false;
+               }
+
+               return true;
+       }
+
        @Override
        public Long getPhoneId () {
                return this.phoneId;
@@ -135,4 +157,13 @@ public class LandLineNumber implements DialableLandLineNumber, Comparable<Dialab
        public void setPhoneCountry (final Country phoneCountry) {
                this.phoneCountry = phoneCountry;
        }
+
+       @Override
+       public int hashCode () {
+               int hash = 7;
+               hash = 47 * hash + Objects.hashCode(this.getPhoneNumber());
+               hash = 47 * hash + Objects.hashCode(this.getPhoneAreaCode());
+               hash = 47 * hash + Objects.hashCode(this.getPhoneCountry());
+               return hash;
+       }
 }
index 26dae625bda742cc8cabf96cbb0f1554267b4ae9..1e3b360f6dcc8bcd4a4417eb97ad6e7c6a6c8ece 100644 (file)
@@ -16,6 +16,7 @@
  */
 package org.mxchange.jphone.phonenumbers.smsprovider;
 
+import java.util.Objects;
 import javax.persistence.Basic;
 import javax.persistence.Column;
 import javax.persistence.Entity;
@@ -41,7 +42,7 @@ import org.mxchange.jcountry.data.CountryData;
 @NamedQueries (
                @NamedQuery (name = "AllSmsProvider", query = "SELECT p FROM cellphone_provider AS p ORDER BY p.providerId ASC")
 )
-public class CellphoneProvider implements SmsProvider {
+public class CellphoneProvider implements SmsProvider, Comparable<SmsProvider> {
 
        /**
         * Serial number
@@ -74,9 +75,35 @@ public class CellphoneProvider implements SmsProvider {
         * Country instance ('s dial data)
         */
        @JoinColumn (name = "provider_country_id", nullable = false)
-       @OneToOne(targetEntity = CountryData.class, optional = false, fetch = FetchType.EAGER)
+       @OneToOne (targetEntity = CountryData.class, optional = false, fetch = FetchType.EAGER)
        private Country providerCountry;
 
+       @Override
+       public int compareTo (final SmsProvider provider) {
+               throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+       }
+
+       @Override
+       public boolean equals (final Object object) {
+               if (object == null) {
+                       return false;
+               } else if (getClass() != object.getClass()) {
+                       return false;
+               }
+
+               final SmsProvider other = (SmsProvider) object;
+
+               if (!Objects.equals(this.getProviderDialPrefix(), other.getProviderDialPrefix())) {
+                       return false;
+               } else if (!Objects.equals(this.getProviderName(), other.getProviderName())) {
+                       return false;
+               } else if (!Objects.equals(this.getProviderCountry(), other.getProviderCountry())) {
+                       return false;
+               }
+
+               return true;
+       }
+
        @Override
        public Long getProviderId () {
                return providerId;
@@ -117,4 +144,13 @@ public class CellphoneProvider implements SmsProvider {
                this.providerCountry = providerCountry;
        }
 
+       @Override
+       public int hashCode () {
+               int hash = 7;
+               hash = 19 * hash + Objects.hashCode(this.getProviderDialPrefix());
+               hash = 19 * hash + Objects.hashCode(this.getProviderName());
+               hash = 19 * hash + Objects.hashCode(this.getProviderCountry());
+               return hash;
+       }
+
 }
index 65354f97ca17beac340247c55b98df9ebb04187a..619a07c09833e2c1d4d5e4f880292cf56666487d 100644 (file)
@@ -81,4 +81,10 @@ public interface SmsProvider extends Serializable {
         * @param country Country instance
         */
        public void setProviderCountry (final Country country);
+
+       @Override
+       public boolean equals (final Object object);
+
+       @Override
+       public int hashCode ();
 }