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