From 4d7296715685ccacf770b3ba64a27363289d9684 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 6 Oct 2022 15:59:58 +0200 Subject: [PATCH] Continued: - renamed utility classes *s to *Utils - moved them in their own package (all in one) --- .../model/phonenumbers/fax/FaxNumber.java | 15 ++++++------ .../phonenumbers/mobile/MobileNumber.java | 6 +++-- .../mobileprovider/CellphoneProvider.java | 24 +++++++++++-------- .../FaxNumberUtils.java} | 7 +++--- .../LandLineNumberUtils.java} | 7 +++--- .../MobileNumberUtils.java} | 14 ++++++++--- .../MobileProviderUtils.java} | 15 ++++++++---- 7 files changed, 55 insertions(+), 33 deletions(-) rename src/org/mxchange/jphone/model/{phonenumbers/fax/FaxNumbers.java => utils/FaxNumberUtils.java} (94%) rename src/org/mxchange/jphone/model/{phonenumbers/landline/LandLineNumbers.java => utils/LandLineNumberUtils.java} (93%) rename src/org/mxchange/jphone/model/{phonenumbers/mobile/MobileNumbers.java => utils/MobileNumberUtils.java} (87%) rename src/org/mxchange/jphone/model/{phonenumbers/mobileprovider/MobileProviders.java => utils/MobileProviderUtils.java} (78%) diff --git a/src/org/mxchange/jphone/model/phonenumbers/fax/FaxNumber.java b/src/org/mxchange/jphone/model/phonenumbers/fax/FaxNumber.java index 0adc735..431caef 100644 --- a/src/org/mxchange/jphone/model/phonenumbers/fax/FaxNumber.java +++ b/src/org/mxchange/jphone/model/phonenumbers/fax/FaxNumber.java @@ -37,6 +37,7 @@ import javax.persistence.Transient; import org.mxchange.jcoreutils.Comparables; import org.mxchange.jcountry.model.data.Country; import org.mxchange.jcountry.model.data.CountryData; +import org.mxchange.jcountry.model.utils.CountryUtils; /** * A POJO for dialable fax numbers @@ -151,12 +152,12 @@ public class FaxNumber implements DialableFaxNumber { } @Override - public int compareTo (final DialableFaxNumber otherNumber) { + public int compareTo (final DialableFaxNumber faxNumber) { // Is the parameter given? - if (null == otherNumber) { + if (null == faxNumber) { // Throw NPE - throw new NullPointerException("otherNumber is null"); //NOI18N - } else if (otherNumber.equals(this)) { + throw new NullPointerException("faxNumber is null"); //NOI18N + } else if (Objects.equals(this, faxNumber)) { // Same object return 0; } @@ -164,11 +165,11 @@ public class FaxNumber implements DialableFaxNumber { // Init comparisons final int[] comparators = { // First country - this.getPhoneCountry().compareTo(otherNumber.getPhoneCountry()), + CountryUtils.compare(this.getPhoneCountry(), faxNumber.getPhoneCountry()), // Next area code - this.getPhoneAreaCode().compareTo(otherNumber.getPhoneAreaCode()), + this.getPhoneAreaCode().compareTo(faxNumber.getPhoneAreaCode()), // Last number - this.getPhoneNumber().compareTo(otherNumber.getPhoneNumber()) + this.getPhoneNumber().compareTo(faxNumber.getPhoneNumber()) }; // Check all values diff --git a/src/org/mxchange/jphone/model/phonenumbers/mobile/MobileNumber.java b/src/org/mxchange/jphone/model/phonenumbers/mobile/MobileNumber.java index 1aa1c51..eb369b6 100644 --- a/src/org/mxchange/jphone/model/phonenumbers/mobile/MobileNumber.java +++ b/src/org/mxchange/jphone/model/phonenumbers/mobile/MobileNumber.java @@ -35,8 +35,10 @@ import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Transient; import org.mxchange.jcoreutils.Comparables; +import org.mxchange.jcoreutils.SafeNumberUtils; import org.mxchange.jphone.model.phonenumbers.mobileprovider.CellphoneProvider; import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider; +import org.mxchange.jphone.model.utils.MobileProviderUtils; /** * A POJO for dialable mobile numbers @@ -149,9 +151,9 @@ public class MobileNumber implements DialableMobileNumber { // Init comparisons final int[] comparators = { // First compare provider - this.getMobileProvider().compareTo(otherNumber.getMobileProvider()), + MobileProviderUtils.compare(this.getMobileProvider(), otherNumber.getMobileProvider()), // Last number - this.getMobileNumber().compareTo(otherNumber.getMobileNumber()) + SafeNumberUtils.compare(this.getMobileNumber(), otherNumber.getMobileNumber()) }; // Check all values diff --git a/src/org/mxchange/jphone/model/phonenumbers/mobileprovider/CellphoneProvider.java b/src/org/mxchange/jphone/model/phonenumbers/mobileprovider/CellphoneProvider.java index 5b26389..e58d2d7 100644 --- a/src/org/mxchange/jphone/model/phonenumbers/mobileprovider/CellphoneProvider.java +++ b/src/org/mxchange/jphone/model/phonenumbers/mobileprovider/CellphoneProvider.java @@ -36,8 +36,10 @@ import javax.persistence.TemporalType; import javax.persistence.Transient; import org.apache.commons.lang3.StringUtils; import org.mxchange.jcoreutils.Comparables; +import org.mxchange.jcoreutils.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 mobile providers @@ -164,24 +166,26 @@ public class CellphoneProvider implements MobileProvider { } @Override - public int compareTo (final MobileProvider otherProvider) { + public int compareTo (final MobileProvider provider) { // Is the parameter given? - if (null == otherProvider) { + if (null == provider) { // Throw NPE - throw new NullPointerException("otherProvider is null"); //NOI18N - } else if (otherProvider.equals(this)) { + throw new NullPointerException("Parameter 'provider' is null"); //NOI18N + } else if (provider.equals(this)) { // Same object return 0; } // Init comparisons final int[] comparators = { - // First provider - this.getProviderCountry().compareTo(otherProvider.getProviderCountry()), - // Next is name - StringUtils.compare(this.getProviderName(), otherProvider.getProviderName()), - // Last is dial prefix - this.getProviderDialPrefix().compareTo(otherProvider.getProviderDialPrefix()) + // 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 diff --git a/src/org/mxchange/jphone/model/phonenumbers/fax/FaxNumbers.java b/src/org/mxchange/jphone/model/utils/FaxNumberUtils.java similarity index 94% rename from src/org/mxchange/jphone/model/phonenumbers/fax/FaxNumbers.java rename to src/org/mxchange/jphone/model/utils/FaxNumberUtils.java index 2998512..25b63f4 100644 --- a/src/org/mxchange/jphone/model/phonenumbers/fax/FaxNumbers.java +++ b/src/org/mxchange/jphone/model/utils/FaxNumberUtils.java @@ -14,17 +14,18 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mxchange.jphone.model.phonenumbers.fax; +package org.mxchange.jphone.model.utils; import java.io.Serializable; import java.util.Objects; +import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; /** * An utilities class for fax numbers *

* @author Roland Häder */ -public class FaxNumbers implements Serializable { +public class FaxNumberUtils implements Serializable { /** * Serial number @@ -85,7 +86,7 @@ public class FaxNumbers implements Serializable { /** * No constructor for utilities classes */ - private FaxNumbers () { + private FaxNumberUtils () { } } diff --git a/src/org/mxchange/jphone/model/phonenumbers/landline/LandLineNumbers.java b/src/org/mxchange/jphone/model/utils/LandLineNumberUtils.java similarity index 93% rename from src/org/mxchange/jphone/model/phonenumbers/landline/LandLineNumbers.java rename to src/org/mxchange/jphone/model/utils/LandLineNumberUtils.java index 769069d..d7063ed 100644 --- a/src/org/mxchange/jphone/model/phonenumbers/landline/LandLineNumbers.java +++ b/src/org/mxchange/jphone/model/utils/LandLineNumberUtils.java @@ -14,17 +14,18 @@ * You should have received a copy of the GNU General Public License * along with targetNumber program. If not, see . */ -package org.mxchange.jphone.model.phonenumbers.landline; +package org.mxchange.jphone.model.utils; import java.io.Serializable; import java.util.Objects; +import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber; /** * An utilities class for land-line numbers *

* @author Roland Häder */ -public class LandLineNumbers implements Serializable { +public class LandLineNumberUtils implements Serializable { /** * Serial number @@ -85,7 +86,7 @@ public class LandLineNumbers implements Serializable { /** * No constructor for utilities classes */ - private LandLineNumbers () { + private LandLineNumberUtils () { } } diff --git a/src/org/mxchange/jphone/model/phonenumbers/mobile/MobileNumbers.java b/src/org/mxchange/jphone/model/utils/MobileNumberUtils.java similarity index 87% rename from src/org/mxchange/jphone/model/phonenumbers/mobile/MobileNumbers.java rename to src/org/mxchange/jphone/model/utils/MobileNumberUtils.java index 1e139b6..805f0c1 100644 --- a/src/org/mxchange/jphone/model/phonenumbers/mobile/MobileNumbers.java +++ b/src/org/mxchange/jphone/model/utils/MobileNumberUtils.java @@ -14,17 +14,18 @@ * You should have received a copy of the GNU General Public License * along with targetNumber program. If not, see . */ -package org.mxchange.jphone.model.phonenumbers.mobile; +package org.mxchange.jphone.model.utils; import java.io.Serializable; import java.util.Objects; +import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; /** * An utilities class for mobile numbers *

* @author Roland Häder */ -public class MobileNumbers implements Serializable { +public class MobileNumberUtils implements Serializable { /** * Serial number @@ -63,6 +64,8 @@ public class MobileNumbers implements Serializable { * @param otherNumber Mobile number 2 *

* @return Whether both are the same number + *

+ * @throws NullPointerException If both instances are null */ public static boolean isSameMobileNumber (final DialableMobileNumber mobileNumber, final DialableMobileNumber otherNumber) { // Test object equality first @@ -72,10 +75,15 @@ public class MobileNumbers implements Serializable { } else if (((null == mobileNumber) && (otherNumber instanceof DialableMobileNumber)) || ((null == otherNumber) && (mobileNumber instanceof DialableMobileNumber))) { // One is null the other not return false; + } else if (null == mobileNumber && null == otherNumber) { + // Throw NPE + throw new NullPointerException("Both mobileNumber and otherNumber are null"); //NOI18N } + // Now compare deeper final boolean sameProvider = Objects.equals(mobileNumber.getMobileProvider(), otherNumber.getMobileProvider()); final boolean sameNumber = Objects.equals(mobileNumber.getMobileNumber(), otherNumber.getMobileNumber()); + // All are the same? return sameProvider && sameNumber; } @@ -83,7 +91,7 @@ public class MobileNumbers implements Serializable { /** * No constructor for utilities classes */ - private MobileNumbers () { + private MobileNumberUtils () { } } diff --git a/src/org/mxchange/jphone/model/phonenumbers/mobileprovider/MobileProviders.java b/src/org/mxchange/jphone/model/utils/MobileProviderUtils.java similarity index 78% rename from src/org/mxchange/jphone/model/phonenumbers/mobileprovider/MobileProviders.java rename to src/org/mxchange/jphone/model/utils/MobileProviderUtils.java index 10164bd..c403a47 100644 --- a/src/org/mxchange/jphone/model/phonenumbers/mobileprovider/MobileProviders.java +++ b/src/org/mxchange/jphone/model/utils/MobileProviderUtils.java @@ -14,24 +14,29 @@ * You should have received a copy of the GNU General Public License * along with targetMobileProvider program. If not, see . */ -package org.mxchange.jphone.model.phonenumbers.mobileprovider; +package org.mxchange.jphone.model.utils; import java.io.Serializable; import java.util.Objects; -import org.mxchange.jcountry.model.data.Countries; +import org.mxchange.jcountry.model.utils.CountryUtils; +import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider; /** * An utilities class for mobile providers *

* @author Roland Häder */ -public class MobileProviders implements Serializable { +public class MobileProviderUtils implements Serializable { /** * Serial number */ private static final long serialVersionUID = 15_468_608_721_651L; + public static int compare (MobileProvider mobileProvider, MobileProvider mobileProvider0) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + /** * Copies all values from source mobile provider to this *

@@ -52,7 +57,7 @@ public class MobileProviders implements Serializable { } // Copy all values - Countries.copyCountryData(sourceMobileProvider.getProviderCountry(), targetMobileProvider.getProviderCountry()); + CountryUtils.copyCountryData(sourceMobileProvider.getProviderCountry(), targetMobileProvider.getProviderCountry()); targetMobileProvider.setProviderDialPrefix(sourceMobileProvider.getProviderDialPrefix()); targetMobileProvider.setProviderId(sourceMobileProvider.getProviderId()); targetMobileProvider.setProviderMailPattern(sourceMobileProvider.getProviderMailPattern()); @@ -63,7 +68,7 @@ public class MobileProviders implements Serializable { * Private constructor, because there is no need for an instance of * targetMobileProvider class. */ - private MobileProviders () { + private MobileProviderUtils () { } } -- 2.39.5