]> git.mxchange.org Git - jphone-core.git/blob - src/org/mxchange/jphone/utils/PhoneUtils.java
updated own name and resources
[jphone-core.git] / src / org / mxchange / jphone / utils / PhoneUtils.java
1 /*
2  * Copyright (C) 2016 Roland Häder
3  *
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.
8  *
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.
13  *
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/>.
16  */
17 package org.mxchange.jphone.utils;
18
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;
24
25 /**
26  *
27  * @author Roland Häder<roland@mxchange.org>
28  */
29 public class PhoneUtils implements Serializable {
30
31         /**
32          * Serial number
33          */
34         private static final long serialVersionUID = 183_598_328_176_450L;
35
36         /**
37          * Checks if both are the same
38          * <p>
39          * @param faxNumber First fax number
40          * @param otherNumber Second fax number
41          * <p>
42          * @return Whether both are the same
43          */
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)
48                         return true;
49                 } else if (((null == faxNumber) && (otherNumber instanceof DialableFaxNumber)) || ((null == otherNumber) && (faxNumber instanceof DialableFaxNumber))) {
50                         // One is null the other not
51                         return false;
52                 }
53
54                 // Now compare deeper
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());
59
60                 // All are the same?
61                 return (sameCountry && sameAreaCode && sameNumber);
62         }
63
64         /**
65          * Checks if both are the same
66          * <p>
67          * @param landLineNumber First land-line number
68          * @param otherNumber Second land-line number
69          * <p>
70          * @return Whether both are the same
71          */
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)
76                         return true;
77                 } else if (((null == landLineNumber) && (otherNumber instanceof DialableLandLineNumber)) || ((null == otherNumber) && (landLineNumber instanceof DialableLandLineNumber))) {
78                         // One is null the other not
79                         return false;
80                 }
81
82                 // Now compare deeper
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());
87
88                 // All are the same?
89                 return (sameCountry && sameAreaCode && sameNumber);
90         }
91
92         /**
93          * Checks if both are the same
94          * <p>
95          * @param mobileNumber Mobile number 1
96          * @param otherNumber Mobile number 2
97          * <p>
98          * @return Whether both are the same number
99          */
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)
104                         return true;
105                 } else if (((null == mobileNumber) && (otherNumber instanceof DialableMobileNumber)) || ((null == otherNumber) && (mobileNumber instanceof DialableMobileNumber))) {
106                         // One is null the other not
107                         return false;
108                 }
109
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());
114
115                 // All are the same?
116                 return (sameProvider && sameNumber);
117         }
118
119         /**
120          * Private constructor for utility classes
121          */
122         private PhoneUtils () {
123         }
124
125 }