From f5f988d341edca874aec2554f3f37de019bc58dd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 21 Jan 2023 19:04:44 +0100 Subject: [PATCH] Continued: - added missing compare() methods to utilities classes - added primary key and mail address pattern to equals()/hashCode() --- .../mobileprovider/CellphoneProvider.java | 6 +++++ .../jphone/model/utils/FaxNumberUtils.java | 25 +++++++++++++++++++ .../model/utils/LandLineNumberUtils.java | 25 +++++++++++++++++++ .../jphone/model/utils/MobileNumberUtils.java | 25 +++++++++++++++++++ .../model/utils/MobileProviderUtils.java | 25 +++++++++++++++++-- 5 files changed, 104 insertions(+), 2 deletions(-) diff --git a/src/org/mxchange/jphone/model/phonenumbers/mobileprovider/CellphoneProvider.java b/src/org/mxchange/jphone/model/phonenumbers/mobileprovider/CellphoneProvider.java index 8efb8f8..da3a8f7 100644 --- a/src/org/mxchange/jphone/model/phonenumbers/mobileprovider/CellphoneProvider.java +++ b/src/org/mxchange/jphone/model/phonenumbers/mobileprovider/CellphoneProvider.java @@ -207,6 +207,10 @@ public class CellphoneProvider implements MobileProvider { if (!Objects.equals(this.getProviderDialPrefix(), mobileProvider.getProviderDialPrefix())) { return false; + } else if (!Objects.equals(this.getProviderId(), mobileProvider.getProviderId())) { + return false; + } 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())) { @@ -295,6 +299,8 @@ public class CellphoneProvider implements MobileProvider { int hash = 7; 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()); diff --git a/src/org/mxchange/jphone/model/utils/FaxNumberUtils.java b/src/org/mxchange/jphone/model/utils/FaxNumberUtils.java index 8337de6..21bc095 100644 --- a/src/org/mxchange/jphone/model/utils/FaxNumberUtils.java +++ b/src/org/mxchange/jphone/model/utils/FaxNumberUtils.java @@ -32,6 +32,31 @@ public class FaxNumberUtils implements Serializable { */ private static final long serialVersionUID = 1_948_653_672_761L; + /** + * Compares two fax number instances with each other + *

+ * @param faxNumber1 First instance of a DialableFaxNumber class + * @param faxNumber2 Second instance of a DialableFaxNumber class + *

+ * @return Comparison value + */ + public static int compare (final DialableFaxNumber faxNumber1, final DialableFaxNumber faxNumber2) { + // Check equality, then at least first must be given + if (Objects.equals(faxNumber1, faxNumber2)) { + // Both are same + return 0; + } else if (null == faxNumber1) { + // First is null + return -1; + } else if (null == faxNumber2) { + // Second is null + return 1; + } + + // Invoke compareTo() method + return faxNumber1.compareTo(faxNumber2); + } + /** * Copy all fields from source object to this *

diff --git a/src/org/mxchange/jphone/model/utils/LandLineNumberUtils.java b/src/org/mxchange/jphone/model/utils/LandLineNumberUtils.java index 89fc25e..d9fbe81 100644 --- a/src/org/mxchange/jphone/model/utils/LandLineNumberUtils.java +++ b/src/org/mxchange/jphone/model/utils/LandLineNumberUtils.java @@ -32,6 +32,31 @@ public class LandLineNumberUtils implements Serializable { */ private static final long serialVersionUID = 18_698_467_372_167_561L; + /** + * Compares two mobile number instances with each other + *

+ * @param landLineNumber1 First instance of a DialableLandLineNumber class + * @param landLineNumber2 Second instance of a DialableLandLineNumber class + *

+ * @return Comparison value + */ + public static int compare (final DialableLandLineNumber landLineNumber1, final DialableLandLineNumber landLineNumber2) { + // Check equality, then at least first must be given + if (Objects.equals(landLineNumber1, landLineNumber2)) { + // Both are same + return 0; + } else if (null == landLineNumber1) { + // First is null + return -1; + } else if (null == landLineNumber2) { + // Second is null + return 1; + } + + // Invoke compareTo() method + return landLineNumber1.compareTo(landLineNumber2); + } + /** * Copy all fields from source object to this *

diff --git a/src/org/mxchange/jphone/model/utils/MobileNumberUtils.java b/src/org/mxchange/jphone/model/utils/MobileNumberUtils.java index 805f0c1..5bef495 100644 --- a/src/org/mxchange/jphone/model/utils/MobileNumberUtils.java +++ b/src/org/mxchange/jphone/model/utils/MobileNumberUtils.java @@ -32,6 +32,31 @@ public class MobileNumberUtils implements Serializable { */ private static final long serialVersionUID = 291_608_496_882_761L; + /** + * Compares two mobile number instances with each other + *

+ * @param mobileNumber1 First instance of a DialableMobileNumber class + * @param mobileNumber2 Second instance of a DialableMobileNumber class + *

+ * @return Comparison value + */ + public static int compare (final DialableMobileNumber mobileNumber1, final DialableMobileNumber mobileNumber2) { + // Check equality, then at least first must be given + if (Objects.equals(mobileNumber1, mobileNumber2)) { + // Both are same + return 0; + } else if (null == mobileNumber1) { + // First is null + return -1; + } else if (null == mobileNumber2) { + // Second is null + return 1; + } + + // Invoke compareTo() method + return mobileNumber1.compareTo(mobileNumber2); + } + /** * Copy all fields from source object to this *

diff --git a/src/org/mxchange/jphone/model/utils/MobileProviderUtils.java b/src/org/mxchange/jphone/model/utils/MobileProviderUtils.java index c403a47..37b7891 100644 --- a/src/org/mxchange/jphone/model/utils/MobileProviderUtils.java +++ b/src/org/mxchange/jphone/model/utils/MobileProviderUtils.java @@ -33,8 +33,29 @@ public class MobileProviderUtils implements Serializable { */ 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. + /** + * Compares two mobile provider instances with each other + *

+ * @param mobileProvider1 First instance of a MobileProvider class + * @param mobileProvider2 Second instance of a MobileProvider class + *

+ * @return Comparison value + */ + public static int compare (final MobileProvider mobileProvider1, final MobileProvider mobileProvider2) { + // Check equality, then at least first must be given + if (Objects.equals(mobileProvider1, mobileProvider2)) { + // Both are same + return 0; + } else if (null == mobileProvider1) { + // First is null + return -1; + } else if (null == mobileProvider2) { + // Second is null + return 1; + } + + // Invoke compareTo() method + return mobileProvider1.compareTo(mobileProvider2); } /** -- 2.39.5