2 * Copyright (C) 2016 Roland Haeder
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.cellphone.DialableCellphoneNumber;
22 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
23 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
27 * @author Roland Haeder<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 cellphoneNumber Cellphone number 1
40 * @param otherNumber Cellphone number 2
42 * @return Whether both are the same number
44 public static boolean isSameCellphoneNumber (final DialableCellphoneNumber cellphoneNumber, final DialableCellphoneNumber otherNumber) {
45 // Test object equality first
46 if (Objects.equals(cellphoneNumber, otherNumber)) {
47 // Both the same object (null/null or same object)
49 } else if (((null == cellphoneNumber) && (otherNumber instanceof DialableCellphoneNumber)) || ((null == otherNumber) && (cellphoneNumber instanceof DialableCellphoneNumber))) {
50 // One is null the other not
55 @SuppressWarnings ("null")
56 boolean sameProvider = Objects.equals(cellphoneNumber.getCellphoneProvider(), otherNumber.getCellphoneProvider());
57 boolean sameNumber = Objects.equals(cellphoneNumber.getPhoneNumber(), otherNumber.getPhoneNumber());
60 return (sameProvider && sameNumber);
64 * Checks if both are the same
66 * @param faxNumber First fax number
67 * @param otherNumber Second fax number
69 * @return Whether both are the same
71 public static boolean isSameFaxNumber (final DialableFaxNumber faxNumber, DialableFaxNumber otherNumber) {
72 // Test object equality first
73 if (Objects.equals(faxNumber, otherNumber)) {
74 // Both the same object (null/null or same object)
76 } else if (((null == faxNumber) && (otherNumber instanceof DialableFaxNumber)) || ((null == otherNumber) && (faxNumber instanceof DialableFaxNumber))) {
77 // One is null the other not
82 @SuppressWarnings ("null")
83 boolean sameCountry = Objects.equals(faxNumber.getPhoneCountry(), otherNumber.getPhoneCountry());
84 boolean sameAreaCode = Objects.equals(faxNumber.getPhoneAreaCode(), otherNumber.getPhoneAreaCode());
85 boolean sameNumber = Objects.equals(faxNumber.getPhoneNumber(), otherNumber.getPhoneNumber());
88 return (sameCountry && sameAreaCode && sameNumber);
92 * Checks if both are the same
94 * @param landLineNumber First land-line number
95 * @param otherNumber Second land-line number
97 * @return Whether both are the same
99 public static boolean isSameLandLineNumber (final DialableLandLineNumber landLineNumber, final DialableLandLineNumber otherNumber) {
100 // Test object equality first
101 if (Objects.equals(landLineNumber, otherNumber)) {
102 // Both the same object (null/null or same object)
104 } else if (((null == landLineNumber) && (otherNumber instanceof DialableLandLineNumber)) || ((null == otherNumber) && (landLineNumber instanceof DialableLandLineNumber))) {
105 // One is null the other not
109 // Now compare deeper
110 @SuppressWarnings ("null")
111 boolean sameCountry = Objects.equals(landLineNumber.getPhoneCountry(), otherNumber.getPhoneCountry());
112 boolean sameAreaCode = Objects.equals(landLineNumber.getPhoneAreaCode(), otherNumber.getPhoneAreaCode());
113 boolean sameNumber = Objects.equals(landLineNumber.getPhoneNumber(), otherNumber.getPhoneNumber());
116 return (sameCountry && sameAreaCode && sameNumber);
120 * Private constructor for utility classes
122 private PhoneUtils () {