2 * Copyright (C) 2017 - 2024 Free Software Foundation
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 targetNumber program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.jphone.model.utils;
19 import java.io.Serializable;
20 import java.util.Objects;
21 import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
24 * An utilities class for land-line numbers
26 * @author Roland Häder<roland@mxchange.org>
28 public class LandLineNumberUtils implements Serializable {
33 private static final long serialVersionUID = 18_698_467_372_167_561L;
36 * Compares two mobile number instances with each other
38 * @param landLineNumber1 First instance of a DialableLandLineNumber class
39 * @param landLineNumber2 Second instance of a DialableLandLineNumber class
41 * @return Comparison value
43 public static int compare (final DialableLandLineNumber landLineNumber1, final DialableLandLineNumber landLineNumber2) {
44 // Check equality, then at least first must be given
45 if (Objects.equals(landLineNumber1, landLineNumber2)) {
48 } else if (null == landLineNumber1) {
51 } else if (null == landLineNumber2) {
56 // Invoke compareTo() method
57 return landLineNumber1.compareTo(landLineNumber2);
61 * Copy all fields from source object to this
63 * @param sourceNumber Source number object
64 * @param targetNumber Target number object
66 public static void copyLandLineNumberData (final DialableLandLineNumber sourceNumber, final DialableLandLineNumber targetNumber) {
68 if (null == sourceNumber) {
70 throw new NullPointerException("sourceNumber is null"); //NOI18N
71 } else if (null == targetNumber) {
73 throw new NullPointerException("targetNumber is null"); //NOI18N
74 } else if (Objects.equals(sourceNumber, targetNumber)) {
75 // Is exactly the same!
76 throw new IllegalArgumentException("sourcerNumber and targetNumber are the same."); //NOI18N
80 targetNumber.setPhoneAreaCode(sourceNumber.getPhoneAreaCode());
81 targetNumber.setPhoneCountry(sourceNumber.getPhoneCountry());
82 targetNumber.setPhoneId(sourceNumber.getPhoneId());
83 targetNumber.setPhoneNumber(sourceNumber.getPhoneNumber());
87 * Checks if both are the same
89 * @param landLineNumber First land-line number
90 * @param otherNumber Second land-line number
92 * @return Whether both are the same
94 public static boolean isSameLandLineNumber (final DialableLandLineNumber landLineNumber, final DialableLandLineNumber otherNumber) {
95 // Test object equality first
96 if (Objects.equals(landLineNumber, otherNumber)) {
97 // Both the same object (null/null or same object)
99 } else if (((null == landLineNumber) && (otherNumber instanceof DialableLandLineNumber)) || ((null == otherNumber) && (landLineNumber instanceof DialableLandLineNumber))) {
100 // One is null the other not
102 } else if (null == landLineNumber && null == otherNumber) {
104 throw new NullPointerException("Both landLineNumber and otherNumber are null"); //NOI18N
107 // Now compare deeper
108 final boolean sameCountry = Objects.equals(landLineNumber.getPhoneCountry(), otherNumber.getPhoneCountry());
109 final boolean sameAreaCode = Objects.equals(landLineNumber.getPhoneAreaCode(), otherNumber.getPhoneAreaCode());
110 final boolean sameNumber = Objects.equals(landLineNumber.getPhoneNumber(), otherNumber.getPhoneNumber());
113 return sameCountry && sameAreaCode && sameNumber;
117 * No constructor for utilities classes
119 private LandLineNumberUtils () {