2 * Copyright (C) 2017, 2018 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.jcontactsbusiness.model.headquarter;
19 import java.io.Serializable;
20 import java.util.Objects;
23 * An utilities class for headquarter
25 * @author Roland Häder<roland@mxchange.org>
27 public class Headquarters implements Serializable {
32 private static final long serialVersionUID = 69_537_867_224_651L;
35 * Compare null-reference-safe 2 headquarter instances with each other.
37 * @param headquarter1 Headquarter 1
38 * @param headquarter2 Headquarter 2
40 * @return Comparison value from invoking Comparable.compareTo()
42 public static int compare (final Headquarter headquarter1, final Headquarter headquarter2) {
44 if (Objects.equals(headquarter1, headquarter2)) {
47 } else if (null == headquarter1) {
50 } else if (null == headquarter2) {
51 // Second headquarter is null
55 // Now that both are not NULL, compare them
56 return headquarter1.compareTo(headquarter2);
60 * Checks if both headquarter have same address. This method will throw an
61 * {@code NullPointerException} if one of the instances is null.
63 * @param headquarter1 Headquarter 1
64 * @param headquarter2 Headquarter 2
66 * @return Whether both branch office addresses are the same
68 * @throws NullPointerException If one of the instances is null
70 public static boolean isSameAddress (final Headquarter headquarter1, final Headquarter headquarter2) {
71 // Check that both parameters are not null
72 if (null == headquarter1) {
74 throw new NullPointerException("headquarter1 is null"); //NOI18N
75 } else if (null == headquarter2) {
77 throw new NullPointerException("headquarter2 is null"); //NOI18N
80 // Default is the same
81 boolean isSameAddress = true;
83 // Compare both addresses
84 if (!Objects.equals(headquarter1.getHeadquarterCompanyName(), headquarter2.getHeadquarterCompanyName())) {
86 isSameAddress = false;
87 } else if (!Objects.equals(headquarter1.getHeadquarterCountry(), headquarter2.getHeadquarterCountry())) {
89 isSameAddress = false;
90 } else if (!Objects.equals(headquarter1.getHeadquarterCity(), headquarter2.getHeadquarterCity())) {
92 isSameAddress = false;
93 } else if (!Objects.equals(headquarter1.getHeadquarterZipCode(), headquarter2.getHeadquarterZipCode())) {
95 isSameAddress = false;
96 } else if (!Objects.equals(headquarter1.getHeadquarterStreet(), headquarter2.getHeadquarterStreet())) {
98 isSameAddress = false;
99 } else if (!Objects.equals(headquarter1.getHeadquarterHouseNumber(), headquarter2.getHeadquarterHouseNumber())) {
101 isSameAddress = false;
102 } else if (!Objects.equals(headquarter1.getHeadquarterHouseNumberExtension(), headquarter2.getHeadquarterHouseNumberExtension())) {
104 isSameAddress = false;
105 } else if (!Objects.equals(headquarter1.getHeadquarterStore(), headquarter2.getHeadquarterStore())) {
107 isSameAddress = false;
108 } else if (!Objects.equals(headquarter1.getHeadquarterSuiteNumber(), headquarter2.getHeadquarterSuiteNumber())) {
110 isSameAddress = false;
114 return isSameAddress;
118 * Private default constructor
120 private Headquarters () {
121 // Utilities don't have instances