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 this 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.fax.DialableFaxNumber;
24 * An utilities class for fax numbers
26 * @author Roland Häder<roland@mxchange.org>
28 public class FaxNumberUtils implements Serializable {
33 private static final long serialVersionUID = 1_948_653_672_761L;
36 * Compares two fax number instances with each other
38 * @param faxNumber1 First instance of a DialableFaxNumber class
39 * @param faxNumber2 Second instance of a DialableFaxNumber class
41 * @return Comparison value
43 public static int compare (final DialableFaxNumber faxNumber1, final DialableFaxNumber faxNumber2) {
44 // Check equality, then at least first must be given
45 if (Objects.equals(faxNumber1, faxNumber2)) {
48 } else if (null == faxNumber1) {
51 } else if (null == faxNumber2) {
56 // Invoke compareTo() method
57 return faxNumber1.compareTo(faxNumber2);
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 copyFaxNumberData (final DialableFaxNumber sourceNumber, final DialableFaxNumber 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 faxNumber First fax number
90 * @param otherNumber Second fax number
92 * @return Whether both are the same
94 public static boolean isSameFaxNumber (final DialableFaxNumber faxNumber, DialableFaxNumber otherNumber) {
95 // Test object equality first
96 if (Objects.equals(faxNumber, otherNumber)) {
97 // Both the same object (null/null or same object)
99 } else if (((null == faxNumber) && (otherNumber instanceof DialableFaxNumber)) || ((null == otherNumber) && (faxNumber instanceof DialableFaxNumber))) {
100 // One is null the other not
102 } else if (null == faxNumber && null == otherNumber) {
104 throw new NullPointerException("Both faxNumber and otherNumber are null"); //NOI18N
107 // Now compare deeper
108 final boolean sameCountry = Objects.equals(faxNumber.getPhoneCountry(), otherNumber.getPhoneCountry());
109 final boolean sameAreaCode = Objects.equals(faxNumber.getPhoneAreaCode(), otherNumber.getPhoneAreaCode());
110 final boolean sameNumber = Objects.equals(faxNumber.getPhoneNumber(), otherNumber.getPhoneNumber());
113 return sameCountry && sameAreaCode && sameNumber;
117 * No constructor for utilities classes
119 private FaxNumberUtils () {