]> git.mxchange.org Git - jphone-core.git/blobdiff - src/org/mxchange/jphone/model/phonenumbers/mobileprovider/CellphoneProvider.java
Updated copyright year
[jphone-core.git] / src / org / mxchange / jphone / model / phonenumbers / mobileprovider / CellphoneProvider.java
index ab39a7b821dbcecd57895d23119f40a938db0355..b97eafa694c4d9c35bdb05576e2b5d563961083c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2024 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -16,6 +16,7 @@
  */
 package org.mxchange.jphone.model.phonenumbers.mobileprovider;
 
+import java.text.MessageFormat;
 import java.util.Date;
 import java.util.Objects;
 import javax.persistence.Basic;
@@ -33,11 +34,15 @@ 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.comparable.ComparableUtils;
+import org.mxchange.jcoreutils.number.SafeNumberUtils;
 import org.mxchange.jcountry.model.data.Country;
 import org.mxchange.jcountry.model.data.CountryData;
+import org.mxchange.jcountry.model.utils.CountryUtils;
 
 /**
- * A POJO for cellphone providers
+ * A POJO for mobile providers
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
@@ -77,6 +82,13 @@ public class CellphoneProvider implements MobileProvider {
        @Column (name = "provider_entry_created", nullable = false, updatable = false)
        private Date providerEntryCreated;
 
+       /**
+        * Timestamp when this entry has been created
+        */
+       @Temporal (TemporalType.TIMESTAMP)
+       @Column (name = "provider_entry_updated", insertable = false)
+       private Date providerEntryUpdated;
+
        /**
         * Id number
         */
@@ -109,13 +121,43 @@ public class CellphoneProvider implements MobileProvider {
         * <p>
         * @param providerDialPrefix  Dial prefix
         * @param providerName        Name
-        * @param providerCountry     Country
+        * @param providerCountry     An instance of a Country class
         * @param providerMailPattern Pattern for email
         */
        public CellphoneProvider (final Long providerDialPrefix, final String providerName, final Country providerCountry, final String providerMailPattern) {
-               // Call default constructor
+               // Invoke default constructor
                this();
 
+               // Are all parameter set?
+               if (null == providerDialPrefix) {
+                       // Throw NPE
+                       throw new NullPointerException("providerDialPrefix is null"); //NOI18N
+               } else if (providerDialPrefix < 1) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("providerDialPrefix={0} is not valid.", providerDialPrefix)); //NOI18N
+               } else if (null == providerName) {
+                       // Throw NPE
+                       throw new NullPointerException("providerName is null"); //NOI18N
+               } else if (providerName.isEmpty()) {
+                       // Throw IAE
+                       throw new IllegalArgumentException("providerName is empty"); //NOI18N
+               } else if (null == providerCountry) {
+                       // Throw NPE
+                       throw new NullPointerException("providerCountry is null"); //NOI18N
+               } else if (null == providerCountry.getCountryId()) {
+                       // Throw NPE again
+                       throw new NullPointerException("providerCountry.countryId is null"); //NOI18N
+               } else if (providerCountry.getCountryId() < 1) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("providerCountry.countryId={0} is not valid", providerCountry.getCountryId())); //NOI18N
+               } else if (null == providerMailPattern) {
+                       // Throw NPE
+                       throw new NullPointerException("providerMailPattern is null"); //NOI18N
+               } else if (providerMailPattern.isEmpty()) {
+                       // Throw IAE
+                       throw new IllegalArgumentException("providerMailPattern is empty"); //NOI18N
+               }
+
                // Set all values
                this.providerDialPrefix = providerDialPrefix;
                this.providerName = providerName;
@@ -123,6 +165,36 @@ public class CellphoneProvider implements MobileProvider {
                this.providerMailPattern = providerMailPattern;
        }
 
+       @Override
+       public int compareTo (final MobileProvider provider) {
+               // Is the parameter given?
+               if (null == provider) {
+                       // Throw NPE
+                       throw new NullPointerException("Parameter 'provider' is null"); //NOI18N
+               } else if (Objects.equals(this, provider)) {
+                       // Same object
+                       return 0;
+               }
+
+               // Init comparisons
+               final int[] comparators = {
+                       // First provider country
+                       CountryUtils.compare(this.getProviderCountry(), provider.getProviderCountry()),
+                       // ... provider name
+                       StringUtils.compare(this.getProviderName(), provider.getProviderName()),
+                       // ... dial prefix
+                       SafeNumberUtils.compare(this.getProviderDialPrefix(), provider.getProviderDialPrefix()),
+                       // ... mail pattern
+                       StringUtils.compare(this.getProviderMailPattern(), provider.getProviderMailPattern())
+               };
+
+               // Check all values
+               final int comparison = ComparableUtils.checkAll(comparators);
+
+               // Return value
+               return comparison;
+       }
+
        @Override
        public boolean equals (final Object object) {
                if (null == object) {
@@ -131,28 +203,23 @@ public class CellphoneProvider implements MobileProvider {
                        return false;
                }
 
-               final MobileProvider other = (MobileProvider) object;
+               final MobileProvider mobileProvider = (MobileProvider) object;
 
-               if (!Objects.equals(this.getProviderDialPrefix(), other.getProviderDialPrefix())) {
+               if (!Objects.equals(this.getProviderDialPrefix(), mobileProvider.getProviderDialPrefix())) {
                        return false;
-               } else if (!Objects.equals(this.getProviderName(), other.getProviderName())) {
+               } else if (!Objects.equals(this.getProviderId(), mobileProvider.getProviderId())) {
                        return false;
-               } else if (!Objects.equals(this.getProviderCountry(), other.getProviderCountry())) {
+               } else if (!Objects.equals(this.getProviderMailPattern(), mobileProvider.getProviderMailPattern())) {
+                       return false;
+               } else if (!Objects.equals(this.getProviderName(), mobileProvider.getProviderName())) {
+                       return false;
+               } else if (!Objects.equals(this.getProviderCountry(), mobileProvider.getProviderCountry())) {
                        return false;
                }
 
                return true;
        }
 
-       @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;
-       }
-
        @Override
        public Country getProviderCountry () {
                return this.providerCountry;
@@ -185,6 +252,18 @@ public class CellphoneProvider implements MobileProvider {
                this.providerEntryCreated = providerEntryCreated;
        }
 
+       @Override
+       @SuppressWarnings ("ReturnOfDateField")
+       public Date getProviderEntryUpdated () {
+               return this.providerEntryUpdated;
+       }
+
+       @Override
+       @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+       public void setProviderEntryUpdated (final Date providerEntryUpdated) {
+               this.providerEntryUpdated = providerEntryUpdated;
+       }
+
        @Override
        public Long getProviderId () {
                return this.providerId;
@@ -195,6 +274,16 @@ public class CellphoneProvider implements MobileProvider {
                this.providerId = providerId;
        }
 
+       @Override
+       public String getProviderMailPattern () {
+               return this.providerMailPattern;
+       }
+
+       @Override
+       public void setProviderMailPattern (final String providerMailPattern) {
+               this.providerMailPattern = providerMailPattern;
+       }
+
        @Override
        public String getProviderName () {
                return this.providerName;
@@ -206,13 +295,16 @@ public class CellphoneProvider implements MobileProvider {
        }
 
        @Override
-       public String getProviderMailPattern () {
-               return this.providerMailPattern;
-       }
+       public int hashCode () {
+               int hash = 7;
 
-       @Override
-       public void setProviderMailPattern (final String providerMailPattern) {
-               this.providerMailPattern = providerMailPattern;
+               hash = 19 * hash + Objects.hashCode(this.getProviderDialPrefix());
+               hash = 19 * hash + Objects.hashCode(this.getProviderId());
+               hash = 19 * hash + Objects.hashCode(this.getProviderMailPattern());
+               hash = 19 * hash + Objects.hashCode(this.getProviderName());
+               hash = 19 * hash + Objects.hashCode(this.getProviderCountry());
+
+               return hash;
        }
 
 }