]> git.mxchange.org Git - jphone-core.git/blob - src/org/mxchange/jphone/model/phonenumbers/landline/LandLineNumbers.java
Continued:
[jphone-core.git] / src / org / mxchange / jphone / model / phonenumbers / landline / LandLineNumbers.java
1 /*
2  * Copyright (C) 2017 - 2020 Free Software Foundation
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 targetNumber program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.jphone.model.phonenumbers.landline;
18
19 import java.io.Serializable;
20 import java.util.Objects;
21
22 /**
23  * An utilities class for land-line numbers
24  * <p>
25  * @author Roland Häder<roland@mxchange.org>
26  */
27 public class LandLineNumbers implements Serializable {
28
29         /**
30          * Serial number
31          */
32         private static final long serialVersionUID = 18_698_467_372_167_561L;
33
34         /**
35          * Copy all fields from source object to this
36          * <p>
37          * @param sourceNumber Source number object
38          * @param targetNumber Target number object
39          */
40         public static void copyLandLineNumber (final DialableLandLineNumber sourceNumber, final DialableLandLineNumber targetNumber) {
41                 // Validate instance
42                 if (null == sourceNumber) {
43                         // Throw NPE
44                         throw new NullPointerException("sourceNumber is null"); //NOI18N
45                 } else if (null == targetNumber) {
46                         // Throw NPE
47                         throw new NullPointerException("targetNumber is null"); //NOI18N
48                 }
49
50                 // Copy all
51                 targetNumber.setPhoneAreaCode(sourceNumber.getPhoneAreaCode());
52                 targetNumber.setPhoneCountry(sourceNumber.getPhoneCountry());
53                 targetNumber.setPhoneEntryCreated(sourceNumber.getPhoneEntryCreated());
54                 targetNumber.setPhoneId(sourceNumber.getPhoneId());
55                 targetNumber.setPhoneNumber(sourceNumber.getPhoneNumber());
56         }
57
58         /**
59          * Checks if both are the same
60          * <p>
61          * @param landLineNumber First land-line number
62          * @param otherNumber    Second land-line number
63          * <p>
64          * @return Whether both are the same
65          */
66         public static boolean isSameLandLineNumber (final DialableLandLineNumber landLineNumber, final DialableLandLineNumber otherNumber) {
67                 // Test object equality first
68                 if (Objects.equals(landLineNumber, otherNumber)) {
69                         // Both the same object (null/null or same object)
70                         return true;
71                 } else if (((null == landLineNumber) && (otherNumber instanceof DialableLandLineNumber)) || ((null == otherNumber) && (landLineNumber instanceof DialableLandLineNumber))) {
72                         // One is null the other not
73                         return false;
74                 }
75                 // Now compare deeper
76                 final boolean sameCountry = Objects.equals(landLineNumber.getPhoneCountry(), otherNumber.getPhoneCountry());
77                 final boolean sameAreaCode = Objects.equals(landLineNumber.getPhoneAreaCode(), otherNumber.getPhoneAreaCode());
78                 final boolean sameNumber = Objects.equals(landLineNumber.getPhoneNumber(), otherNumber.getPhoneNumber());
79                 // All are the same?
80                 return sameCountry && sameAreaCode && sameNumber;
81         }
82
83         /**
84          * No constructor for utilities classes
85          */
86         private LandLineNumbers () {
87         }
88
89 }