2 * Copyright (C) 2017 - 2022 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 * Copy all fields from source object to this
38 * @param sourceNumber Source number object
39 * @param targetNumber Target number object
41 public static void copyLandLineNumberData (final DialableLandLineNumber sourceNumber, final DialableLandLineNumber targetNumber) {
43 if (null == sourceNumber) {
45 throw new NullPointerException("sourceNumber is null"); //NOI18N
46 } else if (null == targetNumber) {
48 throw new NullPointerException("targetNumber is null"); //NOI18N
49 } else if (Objects.equals(sourceNumber, targetNumber)) {
50 // Is exactly the same!
51 throw new IllegalArgumentException("sourcerNumber and targetNumber are the same."); //NOI18N
55 targetNumber.setPhoneAreaCode(sourceNumber.getPhoneAreaCode());
56 targetNumber.setPhoneCountry(sourceNumber.getPhoneCountry());
57 targetNumber.setPhoneId(sourceNumber.getPhoneId());
58 targetNumber.setPhoneNumber(sourceNumber.getPhoneNumber());
62 * Checks if both are the same
64 * @param landLineNumber First land-line number
65 * @param otherNumber Second land-line number
67 * @return Whether both are the same
69 public static boolean isSameLandLineNumber (final DialableLandLineNumber landLineNumber, final DialableLandLineNumber otherNumber) {
70 // Test object equality first
71 if (Objects.equals(landLineNumber, otherNumber)) {
72 // Both the same object (null/null or same object)
74 } else if (((null == landLineNumber) && (otherNumber instanceof DialableLandLineNumber)) || ((null == otherNumber) && (landLineNumber instanceof DialableLandLineNumber))) {
75 // One is null the other not
77 } else if (null == landLineNumber && null == otherNumber) {
79 throw new NullPointerException("Both landLineNumber and otherNumber are null"); //NOI18N
83 final boolean sameCountry = Objects.equals(landLineNumber.getPhoneCountry(), otherNumber.getPhoneCountry());
84 final boolean sameAreaCode = Objects.equals(landLineNumber.getPhoneAreaCode(), otherNumber.getPhoneAreaCode());
85 final boolean sameNumber = Objects.equals(landLineNumber.getPhoneNumber(), otherNumber.getPhoneNumber());
88 return sameCountry && sameAreaCode && sameNumber;
92 * No constructor for utilities classes
94 private LandLineNumberUtils () {