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