2 * Copyright (C) 2016 Roland Häder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.jphone.utils;
19 import java.io.Serializable;
20 import java.util.Objects;
21 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
22 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
23 import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
27 * @author Roland Häder<roland@mxchange.org>
29 public class PhoneUtils implements Serializable {
34 private static final long serialVersionUID = 183_598_328_176_450L;
37 * Checks if both are the same
39 * @param faxNumber First fax number
40 * @param otherNumber Second fax number
42 * @return Whether both are the same
44 public static boolean isSameFaxNumber (final DialableFaxNumber faxNumber, DialableFaxNumber otherNumber) {
45 // Test object equality first
46 if (Objects.equals(faxNumber, otherNumber)) {
47 // Both the same object (null/null or same object)
49 } else if (((null == faxNumber) && (otherNumber instanceof DialableFaxNumber)) || ((null == otherNumber) && (faxNumber instanceof DialableFaxNumber))) {
50 // One is null the other not
55 @SuppressWarnings ("null")
56 boolean sameCountry = Objects.equals(faxNumber.getPhoneCountry(), otherNumber.getPhoneCountry());
57 boolean sameAreaCode = Objects.equals(faxNumber.getPhoneAreaCode(), otherNumber.getPhoneAreaCode());
58 boolean sameNumber = Objects.equals(faxNumber.getPhoneNumber(), otherNumber.getPhoneNumber());
61 return (sameCountry && sameAreaCode && sameNumber);
65 * Checks if both are the same
67 * @param landLineNumber First land-line number
68 * @param otherNumber Second land-line number
70 * @return Whether both are the same
72 public static boolean isSameLandLineNumber (final DialableLandLineNumber landLineNumber, final DialableLandLineNumber otherNumber) {
73 // Test object equality first
74 if (Objects.equals(landLineNumber, otherNumber)) {
75 // Both the same object (null/null or same object)
77 } else if (((null == landLineNumber) && (otherNumber instanceof DialableLandLineNumber)) || ((null == otherNumber) && (landLineNumber instanceof DialableLandLineNumber))) {
78 // One is null the other not
83 @SuppressWarnings ("null")
84 boolean sameCountry = Objects.equals(landLineNumber.getPhoneCountry(), otherNumber.getPhoneCountry());
85 boolean sameAreaCode = Objects.equals(landLineNumber.getPhoneAreaCode(), otherNumber.getPhoneAreaCode());
86 boolean sameNumber = Objects.equals(landLineNumber.getPhoneNumber(), otherNumber.getPhoneNumber());
89 return (sameCountry && sameAreaCode && sameNumber);
93 * Checks if both are the same
95 * @param mobileNumber Mobile number 1
96 * @param otherNumber Mobile number 2
98 * @return Whether both are the same number
100 public static boolean isSameMobileNumber (final DialableMobileNumber mobileNumber, final DialableMobileNumber otherNumber) {
101 // Test object equality first
102 if (Objects.equals(mobileNumber, otherNumber)) {
103 // Both the same object (null/null or same object)
105 } else if (((null == mobileNumber) && (otherNumber instanceof DialableMobileNumber)) || ((null == otherNumber) && (mobileNumber instanceof DialableMobileNumber))) {
106 // One is null the other not
110 // Now compare deeper
111 @SuppressWarnings ("null")
112 boolean sameProvider = Objects.equals(mobileNumber.getMobileProvider(), otherNumber.getMobileProvider());
113 boolean sameNumber = Objects.equals(mobileNumber.getPhoneNumber(), otherNumber.getPhoneNumber());
116 return (sameProvider && sameNumber);
120 * Private constructor for utility classes
122 private PhoneUtils () {