From 2f9b9aac2f2cae5a27e23d0427644552bd3396b1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 12 Nov 2022 21:55:31 +0100 Subject: [PATCH] Continued: - if both instances are null, this indicates a bad idea? --- src/org/mxchange/jphone/model/utils/FaxNumberUtils.java | 5 +++++ src/org/mxchange/jphone/model/utils/LandLineNumberUtils.java | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/org/mxchange/jphone/model/utils/FaxNumberUtils.java b/src/org/mxchange/jphone/model/utils/FaxNumberUtils.java index 25b63f4..8337de6 100644 --- a/src/org/mxchange/jphone/model/utils/FaxNumberUtils.java +++ b/src/org/mxchange/jphone/model/utils/FaxNumberUtils.java @@ -74,11 +74,16 @@ public class FaxNumberUtils implements Serializable { } else if (((null == faxNumber) && (otherNumber instanceof DialableFaxNumber)) || ((null == otherNumber) && (faxNumber instanceof DialableFaxNumber))) { // One is null the other not return false; + } else if (null == faxNumber && null == otherNumber) { + // Throw NPE + throw new NullPointerException("Both faxNumber and otherNumber are null"); //NOI18N } + // 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; } diff --git a/src/org/mxchange/jphone/model/utils/LandLineNumberUtils.java b/src/org/mxchange/jphone/model/utils/LandLineNumberUtils.java index d7063ed..89fc25e 100644 --- a/src/org/mxchange/jphone/model/utils/LandLineNumberUtils.java +++ b/src/org/mxchange/jphone/model/utils/LandLineNumberUtils.java @@ -74,11 +74,16 @@ public class LandLineNumberUtils implements Serializable { } else if (((null == landLineNumber) && (otherNumber instanceof DialableLandLineNumber)) || ((null == otherNumber) && (landLineNumber instanceof DialableLandLineNumber))) { // One is null the other not return false; + } else if (null == landLineNumber && null == otherNumber) { + // Throw NPE + throw new NullPointerException("Both landLineNumber and otherNumber are null"); //NOI18N } + // 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; } -- 2.39.5