From: Roland Häder Date: Thu, 6 Oct 2022 13:59:58 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=4d7296715685ccacf770b3ba64a27363289d9684;p=jphone-core.git Continued: - renamed utility classes *s to *Utils - moved them in their own package (all in one) --- 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/fax/FaxNumbers.java b/src/org/mxchange/jphone/model/phonenumbers/fax/FaxNumbers.java deleted file mode 100644 index 2998512..0000000 --- a/src/org/mxchange/jphone/model/phonenumbers/fax/FaxNumbers.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2017 - 2022 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 - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * 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; - -import java.io.Serializable; -import java.util.Objects; - -/** - * An utilities class for fax numbers - *

- * @author Roland Häder - */ -public class FaxNumbers implements Serializable { - - /** - * Serial number - */ - private static final long serialVersionUID = 1_948_653_672_761L; - - /** - * Copy all fields from source object to this - *

- * @param sourceNumber Source number object - * @param targetNumber Target number object - */ - public static void copyFaxNumberData (final DialableFaxNumber sourceNumber, final DialableFaxNumber targetNumber) { - // Validate instance - if (null == sourceNumber) { - // Throw NPE - throw new NullPointerException("sourceNumber is null"); //NOI18N - } else if (null == targetNumber) { - // Throw NPE - throw new NullPointerException("targetNumber is null"); //NOI18N - } else if (Objects.equals(sourceNumber, targetNumber)) { - // Is exactly the same! - throw new IllegalArgumentException("sourcerNumber and targetNumber are the same."); //NOI18N - } - - // Copy all - targetNumber.setPhoneAreaCode(sourceNumber.getPhoneAreaCode()); - targetNumber.setPhoneCountry(sourceNumber.getPhoneCountry()); - targetNumber.setPhoneId(sourceNumber.getPhoneId()); - targetNumber.setPhoneNumber(sourceNumber.getPhoneNumber()); - } - - /** - * Checks if both are the same - *

- * @param faxNumber First fax number - * @param otherNumber Second fax number - *

- * @return Whether both are the same - */ - public static boolean isSameFaxNumber (final DialableFaxNumber faxNumber, DialableFaxNumber otherNumber) { - // Test object equality first - if (Objects.equals(faxNumber, otherNumber)) { - // Both the same object (null/null or same object) - return true; - } else if (((null == faxNumber) && (otherNumber instanceof DialableFaxNumber)) || ((null == otherNumber) && (faxNumber instanceof DialableFaxNumber))) { - // One is null the other not - return false; - } - // Now compare deeper - final boolean sameCountry = Objects.equals(faxNumber.getPhoneCountry(), otherNumber.getPhoneCountry()); - final boolean sameAreaCode = Objects.equals(faxNumber.getPhoneAreaCode(), otherNumber.getPhoneAreaCode()); - final boolean sameNumber = Objects.equals(faxNumber.getPhoneNumber(), otherNumber.getPhoneNumber()); - // All are the same? - return sameCountry && sameAreaCode && sameNumber; - } - - /** - * No constructor for utilities classes - */ - private FaxNumbers () { - } - -} diff --git a/src/org/mxchange/jphone/model/phonenumbers/landline/LandLineNumbers.java b/src/org/mxchange/jphone/model/phonenumbers/landline/LandLineNumbers.java deleted file mode 100644 index 769069d..0000000 --- a/src/org/mxchange/jphone/model/phonenumbers/landline/LandLineNumbers.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2017 - 2022 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 - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * 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; - -import java.io.Serializable; -import java.util.Objects; - -/** - * An utilities class for land-line numbers - *

- * @author Roland Häder - */ -public class LandLineNumbers implements Serializable { - - /** - * Serial number - */ - private static final long serialVersionUID = 18_698_467_372_167_561L; - - /** - * Copy all fields from source object to this - *

- * @param sourceNumber Source number object - * @param targetNumber Target number object - */ - public static void copyLandLineNumberData (final DialableLandLineNumber sourceNumber, final DialableLandLineNumber targetNumber) { - // Validate instance - if (null == sourceNumber) { - // Throw NPE - throw new NullPointerException("sourceNumber is null"); //NOI18N - } else if (null == targetNumber) { - // Throw NPE - throw new NullPointerException("targetNumber is null"); //NOI18N - } else if (Objects.equals(sourceNumber, targetNumber)) { - // Is exactly the same! - throw new IllegalArgumentException("sourcerNumber and targetNumber are the same."); //NOI18N - } - - // Copy all - targetNumber.setPhoneAreaCode(sourceNumber.getPhoneAreaCode()); - targetNumber.setPhoneCountry(sourceNumber.getPhoneCountry()); - targetNumber.setPhoneId(sourceNumber.getPhoneId()); - targetNumber.setPhoneNumber(sourceNumber.getPhoneNumber()); - } - - /** - * Checks if both are the same - *

- * @param landLineNumber First land-line number - * @param otherNumber Second land-line number - *

- * @return Whether both are the same - */ - public static boolean isSameLandLineNumber (final DialableLandLineNumber landLineNumber, final DialableLandLineNumber otherNumber) { - // Test object equality first - if (Objects.equals(landLineNumber, otherNumber)) { - // Both the same object (null/null or same object) - return true; - } else if (((null == landLineNumber) && (otherNumber instanceof DialableLandLineNumber)) || ((null == otherNumber) && (landLineNumber instanceof DialableLandLineNumber))) { - // One is null the other not - return false; - } - // Now compare deeper - final boolean sameCountry = Objects.equals(landLineNumber.getPhoneCountry(), otherNumber.getPhoneCountry()); - final boolean sameAreaCode = Objects.equals(landLineNumber.getPhoneAreaCode(), otherNumber.getPhoneAreaCode()); - final boolean sameNumber = Objects.equals(landLineNumber.getPhoneNumber(), otherNumber.getPhoneNumber()); - // All are the same? - return sameCountry && sameAreaCode && sameNumber; - } - - /** - * No constructor for utilities classes - */ - private LandLineNumbers () { - } - -} 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/mobile/MobileNumbers.java b/src/org/mxchange/jphone/model/phonenumbers/mobile/MobileNumbers.java deleted file mode 100644 index 1e139b6..0000000 --- a/src/org/mxchange/jphone/model/phonenumbers/mobile/MobileNumbers.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) 2017 - 2022 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 - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * 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; - -import java.io.Serializable; -import java.util.Objects; - -/** - * An utilities class for mobile numbers - *

- * @author Roland Häder - */ -public class MobileNumbers implements Serializable { - - /** - * Serial number - */ - private static final long serialVersionUID = 291_608_496_882_761L; - - /** - * Copy all fields from source object to this - *

- * @param sourceNumber Source number object - * @param targetNumber Target number object - */ - public static void copyMobileNumberData (final DialableMobileNumber sourceNumber, final DialableMobileNumber targetNumber) { - // Validate instance - if (null == sourceNumber) { - // Throw NPE - throw new NullPointerException("sourceNumber is null"); //NOI18N - } else if (null == targetNumber) { - // Throw NPE - throw new NullPointerException("targetNumber is null"); //NOI18N - } else if (Objects.equals(sourceNumber, targetNumber)) { - // Is exactly the same! - throw new IllegalArgumentException("sourcerNumber and targetNumber are the same."); //NOI18N - } - - // Copy all fields - targetNumber.setMobileProvider(sourceNumber.getMobileProvider()); - targetNumber.setMobileId(sourceNumber.getMobileId()); - targetNumber.setMobileNumber(sourceNumber.getMobileNumber()); - } - - /** - * Checks if both are the same - *

- * @param mobileNumber Mobile number 1 - * @param otherNumber Mobile number 2 - *

- * @return Whether both are the same number - */ - public static boolean isSameMobileNumber (final DialableMobileNumber mobileNumber, final DialableMobileNumber otherNumber) { - // Test object equality first - if (Objects.equals(mobileNumber, otherNumber)) { - // Both the same object (null/null or same object) - return true; - } else if (((null == mobileNumber) && (otherNumber instanceof DialableMobileNumber)) || ((null == otherNumber) && (mobileNumber instanceof DialableMobileNumber))) { - // One is null the other not - return false; - } - // 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; - } - - /** - * No constructor for utilities classes - */ - private MobileNumbers () { - } - -} 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/mobileprovider/MobileProviders.java b/src/org/mxchange/jphone/model/phonenumbers/mobileprovider/MobileProviders.java deleted file mode 100644 index 10164bd..0000000 --- a/src/org/mxchange/jphone/model/phonenumbers/mobileprovider/MobileProviders.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2017 - 2022 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 - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * 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; - -import java.io.Serializable; -import java.util.Objects; -import org.mxchange.jcountry.model.data.Countries; - -/** - * An utilities class for mobile providers - *

- * @author Roland Häder - */ -public class MobileProviders implements Serializable { - - /** - * Serial number - */ - private static final long serialVersionUID = 15_468_608_721_651L; - - /** - * Copies all values from source mobile provider to this - *

- * @param sourceMobileProvider Source mobile provider - * @param targetMobileProvider Target mobile provider - */ - public static void copyMobileProviderData (final MobileProvider sourceMobileProvider, final MobileProvider targetMobileProvider) { - // Parameter should not be null - if (null == sourceMobileProvider) { - // Throw NPE - throw new NullPointerException("sourceMobileProvider is null"); //NOI18N - } else if (null == targetMobileProvider) { - // Throw NPE - throw new NullPointerException("targetMobileProvider is null"); //NOI18N - } else if (Objects.equals(sourceMobileProvider, targetMobileProvider)) { - // Is same mobile provider - throw new IllegalArgumentException("Source and target mobile provider are the same."); //NOI18N - } - - // Copy all values - Countries.copyCountryData(sourceMobileProvider.getProviderCountry(), targetMobileProvider.getProviderCountry()); - targetMobileProvider.setProviderDialPrefix(sourceMobileProvider.getProviderDialPrefix()); - targetMobileProvider.setProviderId(sourceMobileProvider.getProviderId()); - targetMobileProvider.setProviderMailPattern(sourceMobileProvider.getProviderMailPattern()); - targetMobileProvider.setProviderName(sourceMobileProvider.getProviderName()); - } - - /** - * Private constructor, because there is no need for an instance of - * targetMobileProvider class. - */ - private MobileProviders () { - } - -} diff --git a/src/org/mxchange/jphone/model/utils/FaxNumberUtils.java b/src/org/mxchange/jphone/model/utils/FaxNumberUtils.java new file mode 100644 index 0000000..25b63f4 --- /dev/null +++ b/src/org/mxchange/jphone/model/utils/FaxNumberUtils.java @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2017 - 2022 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +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 FaxNumberUtils implements Serializable { + + /** + * Serial number + */ + private static final long serialVersionUID = 1_948_653_672_761L; + + /** + * Copy all fields from source object to this + *

+ * @param sourceNumber Source number object + * @param targetNumber Target number object + */ + public static void copyFaxNumberData (final DialableFaxNumber sourceNumber, final DialableFaxNumber targetNumber) { + // Validate instance + if (null == sourceNumber) { + // Throw NPE + throw new NullPointerException("sourceNumber is null"); //NOI18N + } else if (null == targetNumber) { + // Throw NPE + throw new NullPointerException("targetNumber is null"); //NOI18N + } else if (Objects.equals(sourceNumber, targetNumber)) { + // Is exactly the same! + throw new IllegalArgumentException("sourcerNumber and targetNumber are the same."); //NOI18N + } + + // Copy all + targetNumber.setPhoneAreaCode(sourceNumber.getPhoneAreaCode()); + targetNumber.setPhoneCountry(sourceNumber.getPhoneCountry()); + targetNumber.setPhoneId(sourceNumber.getPhoneId()); + targetNumber.setPhoneNumber(sourceNumber.getPhoneNumber()); + } + + /** + * Checks if both are the same + *

+ * @param faxNumber First fax number + * @param otherNumber Second fax number + *

+ * @return Whether both are the same + */ + public static boolean isSameFaxNumber (final DialableFaxNumber faxNumber, DialableFaxNumber otherNumber) { + // Test object equality first + if (Objects.equals(faxNumber, otherNumber)) { + // Both the same object (null/null or same object) + return true; + } else if (((null == faxNumber) && (otherNumber instanceof DialableFaxNumber)) || ((null == otherNumber) && (faxNumber instanceof DialableFaxNumber))) { + // One is null the other not + return false; + } + // Now compare deeper + final boolean sameCountry = Objects.equals(faxNumber.getPhoneCountry(), otherNumber.getPhoneCountry()); + final boolean sameAreaCode = Objects.equals(faxNumber.getPhoneAreaCode(), otherNumber.getPhoneAreaCode()); + final boolean sameNumber = Objects.equals(faxNumber.getPhoneNumber(), otherNumber.getPhoneNumber()); + // All are the same? + return sameCountry && sameAreaCode && sameNumber; + } + + /** + * No constructor for utilities classes + */ + private FaxNumberUtils () { + } + +} diff --git a/src/org/mxchange/jphone/model/utils/LandLineNumberUtils.java b/src/org/mxchange/jphone/model/utils/LandLineNumberUtils.java new file mode 100644 index 0000000..d7063ed --- /dev/null +++ b/src/org/mxchange/jphone/model/utils/LandLineNumberUtils.java @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2017 - 2022 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with targetNumber program. If not, see . + */ +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 LandLineNumberUtils implements Serializable { + + /** + * Serial number + */ + private static final long serialVersionUID = 18_698_467_372_167_561L; + + /** + * Copy all fields from source object to this + *

+ * @param sourceNumber Source number object + * @param targetNumber Target number object + */ + public static void copyLandLineNumberData (final DialableLandLineNumber sourceNumber, final DialableLandLineNumber targetNumber) { + // Validate instance + if (null == sourceNumber) { + // Throw NPE + throw new NullPointerException("sourceNumber is null"); //NOI18N + } else if (null == targetNumber) { + // Throw NPE + throw new NullPointerException("targetNumber is null"); //NOI18N + } else if (Objects.equals(sourceNumber, targetNumber)) { + // Is exactly the same! + throw new IllegalArgumentException("sourcerNumber and targetNumber are the same."); //NOI18N + } + + // Copy all + targetNumber.setPhoneAreaCode(sourceNumber.getPhoneAreaCode()); + targetNumber.setPhoneCountry(sourceNumber.getPhoneCountry()); + targetNumber.setPhoneId(sourceNumber.getPhoneId()); + targetNumber.setPhoneNumber(sourceNumber.getPhoneNumber()); + } + + /** + * Checks if both are the same + *

+ * @param landLineNumber First land-line number + * @param otherNumber Second land-line number + *

+ * @return Whether both are the same + */ + public static boolean isSameLandLineNumber (final DialableLandLineNumber landLineNumber, final DialableLandLineNumber otherNumber) { + // Test object equality first + if (Objects.equals(landLineNumber, otherNumber)) { + // Both the same object (null/null or same object) + return true; + } else if (((null == landLineNumber) && (otherNumber instanceof DialableLandLineNumber)) || ((null == otherNumber) && (landLineNumber instanceof DialableLandLineNumber))) { + // One is null the other not + return false; + } + // Now compare deeper + final boolean sameCountry = Objects.equals(landLineNumber.getPhoneCountry(), otherNumber.getPhoneCountry()); + final boolean sameAreaCode = Objects.equals(landLineNumber.getPhoneAreaCode(), otherNumber.getPhoneAreaCode()); + final boolean sameNumber = Objects.equals(landLineNumber.getPhoneNumber(), otherNumber.getPhoneNumber()); + // All are the same? + return sameCountry && sameAreaCode && sameNumber; + } + + /** + * No constructor for utilities classes + */ + private LandLineNumberUtils () { + } + +} diff --git a/src/org/mxchange/jphone/model/utils/MobileNumberUtils.java b/src/org/mxchange/jphone/model/utils/MobileNumberUtils.java new file mode 100644 index 0000000..805f0c1 --- /dev/null +++ b/src/org/mxchange/jphone/model/utils/MobileNumberUtils.java @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2017 - 2022 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with targetNumber program. If not, see . + */ +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 MobileNumberUtils implements Serializable { + + /** + * Serial number + */ + private static final long serialVersionUID = 291_608_496_882_761L; + + /** + * Copy all fields from source object to this + *

+ * @param sourceNumber Source number object + * @param targetNumber Target number object + */ + public static void copyMobileNumberData (final DialableMobileNumber sourceNumber, final DialableMobileNumber targetNumber) { + // Validate instance + if (null == sourceNumber) { + // Throw NPE + throw new NullPointerException("sourceNumber is null"); //NOI18N + } else if (null == targetNumber) { + // Throw NPE + throw new NullPointerException("targetNumber is null"); //NOI18N + } else if (Objects.equals(sourceNumber, targetNumber)) { + // Is exactly the same! + throw new IllegalArgumentException("sourcerNumber and targetNumber are the same."); //NOI18N + } + + // Copy all fields + targetNumber.setMobileProvider(sourceNumber.getMobileProvider()); + targetNumber.setMobileId(sourceNumber.getMobileId()); + targetNumber.setMobileNumber(sourceNumber.getMobileNumber()); + } + + /** + * Checks if both are the same + *

+ * @param mobileNumber Mobile number 1 + * @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 + if (Objects.equals(mobileNumber, otherNumber)) { + // Both the same object (null/null or same object) + return true; + } 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; + } + + /** + * No constructor for utilities classes + */ + private MobileNumberUtils () { + } + +} diff --git a/src/org/mxchange/jphone/model/utils/MobileProviderUtils.java b/src/org/mxchange/jphone/model/utils/MobileProviderUtils.java new file mode 100644 index 0000000..c403a47 --- /dev/null +++ b/src/org/mxchange/jphone/model/utils/MobileProviderUtils.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2017 - 2022 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with targetMobileProvider program. If not, see . + */ +package org.mxchange.jphone.model.utils; + +import java.io.Serializable; +import java.util.Objects; +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 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 + *

+ * @param sourceMobileProvider Source mobile provider + * @param targetMobileProvider Target mobile provider + */ + public static void copyMobileProviderData (final MobileProvider sourceMobileProvider, final MobileProvider targetMobileProvider) { + // Parameter should not be null + if (null == sourceMobileProvider) { + // Throw NPE + throw new NullPointerException("sourceMobileProvider is null"); //NOI18N + } else if (null == targetMobileProvider) { + // Throw NPE + throw new NullPointerException("targetMobileProvider is null"); //NOI18N + } else if (Objects.equals(sourceMobileProvider, targetMobileProvider)) { + // Is same mobile provider + throw new IllegalArgumentException("Source and target mobile provider are the same."); //NOI18N + } + + // Copy all values + CountryUtils.copyCountryData(sourceMobileProvider.getProviderCountry(), targetMobileProvider.getProviderCountry()); + targetMobileProvider.setProviderDialPrefix(sourceMobileProvider.getProviderDialPrefix()); + targetMobileProvider.setProviderId(sourceMobileProvider.getProviderId()); + targetMobileProvider.setProviderMailPattern(sourceMobileProvider.getProviderMailPattern()); + targetMobileProvider.setProviderName(sourceMobileProvider.getProviderName()); + } + + /** + * Private constructor, because there is no need for an instance of + * targetMobileProvider class. + */ + private MobileProviderUtils () { + } + +}