--- /dev/null
+/*
+ * Copyright (C) 2016 Roland Haeder
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jphone.utils;
+
+import java.io.Serializable;
+import java.util.Objects;
+import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
+import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
+import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
+
+/**
+ *
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+public class PhoneUtils implements Serializable {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 183_598_328_176_450L;
+
+ /**
+ * Checks if both are the same
+ * <p>
+ * @param cellphoneNumber Cellphone number 1
+ * @param otherNumber Cellphone number 2
+ * <p>
+ * @return Whether both are the same number
+ */
+ public static boolean isSameCellphoneNumber (final DialableCellphoneNumber cellphoneNumber, final DialableCellphoneNumber otherNumber) {
+ // Test object equality first
+ if (Objects.equals(cellphoneNumber, otherNumber)) {
+ // Both the same object (null/null or same object)
+ return true;
+ } else if (((null == cellphoneNumber) && (otherNumber instanceof DialableCellphoneNumber)) || ((null == otherNumber) && (cellphoneNumber instanceof DialableCellphoneNumber))) {
+ // One is null the other not
+ return false;
+ }
+
+ // Now compare deeper
+ @SuppressWarnings ("null")
+ boolean sameProvider = Objects.equals(cellphoneNumber.getCellphoneProvider(), otherNumber.getCellphoneProvider());
+ boolean sameNumber = Objects.equals(cellphoneNumber.getPhoneNumber(), otherNumber.getPhoneNumber());
+
+ // All are the same?
+ return (sameProvider && sameNumber);
+ }
+
+ /**
+ * Checks if both are the same
+ * <p>
+ * @param faxNumber First fax number
+ * @param otherNumber Second fax number
+ * <p>
+ * @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
+ @SuppressWarnings ("null")
+ boolean sameCountry = Objects.equals(faxNumber.getPhoneCountry(), otherNumber.getPhoneCountry());
+ boolean sameAreaCode = Objects.equals(faxNumber.getPhoneAreaCode(), otherNumber.getPhoneAreaCode());
+ boolean sameNumber = Objects.equals(faxNumber.getPhoneNumber(), otherNumber.getPhoneNumber());
+
+ // All are the same?
+ return (sameCountry && sameAreaCode && sameNumber);
+ }
+
+ /**
+ * Checks if both are the same
+ * <p>
+ * @param landLineNumber First land-line number
+ * @param otherNumber Second land-line number
+ * <p>
+ * @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
+ @SuppressWarnings ("null")
+ boolean sameCountry = Objects.equals(landLineNumber.getPhoneCountry(), otherNumber.getPhoneCountry());
+ boolean sameAreaCode = Objects.equals(landLineNumber.getPhoneAreaCode(), otherNumber.getPhoneAreaCode());
+ boolean sameNumber = Objects.equals(landLineNumber.getPhoneNumber(), otherNumber.getPhoneNumber());
+
+ // All are the same?
+ return (sameCountry && sameAreaCode && sameNumber);
+ }
+
+ /**
+ * Private constructor for utility classes
+ */
+ private PhoneUtils () {
+ }
+
+}