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.branchoffice;
19 import java.io.Serializable;
20 import java.util.Objects;
23 * An utilities class for branch offices
25 * @author Roland Häder<roland@mxchange.org>
27 public class BranchOffices implements Serializable {
32 private static final long serialVersionUID = 69_537_867_224_651L;
35 * Compares both branch office instances. This method returns -1 if second
38 * @param branchOffice1 Branch office instance 1
39 * @param branchOffice2 Branch office instance 2
41 * @return Comparison value
43 * @throws NullPointerException If first instance is null
45 public static int compare (final BranchOffice branchOffice1, final BranchOffice branchOffice2) {
46 // Check euqality, then at least first must be given
47 if (Objects.equals(branchOffice1, branchOffice2)) {
50 } else if (null == branchOffice1) {
51 // First cannot be null
52 throw new NullPointerException("branchOffice1 is null"); //NOI18N
53 } else if (null == branchOffice2) {
58 // Invoke compareTo() method
59 return branchOffice1.compareTo(branchOffice2);
63 * Checks if both branch offices have same address. This method will throw
64 * an {@code NullPointerException} if one of the instances is null.
66 * @param branchOffice1 Branch office 1
67 * @param branchOffice2 Branch office 2
69 * @return Whether both branch office addresses are the same
71 * @throws NullPointerException If one of the instances is null
73 public static boolean isSameAddress (final BranchOffice branchOffice1, final BranchOffice branchOffice2) {
74 // Check that both parameters are not null
75 if (null == branchOffice1) {
77 throw new NullPointerException("branchOffice1 is null"); //NOI18N
78 } else if (null == branchOffice2) {
80 throw new NullPointerException("branchOffice2 is null"); //NOI18N
83 // Default is the same
84 boolean isSameAddress = true;
86 // Compare both addresses
87 if (!Objects.equals(branchOffice1.getBranchCompany(), branchOffice2.getBranchCompany())) {
89 isSameAddress = false;
90 } else if (!Objects.equals(branchOffice1.getBranchCountry(), branchOffice2.getBranchCountry())) {
92 isSameAddress = false;
93 } else if (!Objects.equals(branchOffice1.getBranchCity(), branchOffice2.getBranchCity())) {
95 isSameAddress = false;
96 } else if (!Objects.equals(branchOffice1.getBranchZipCode(), branchOffice2.getBranchZipCode())) {
98 isSameAddress = false;
99 } else if (!Objects.equals(branchOffice1.getBranchStreet(), branchOffice2.getBranchStreet())) {
101 isSameAddress = false;
102 } else if (!Objects.equals(branchOffice1.getBranchHouseNumber(), branchOffice2.getBranchHouseNumber())) {
104 isSameAddress = false;
105 } else if (!Objects.equals(branchOffice1.getBranchHouseNumberExtension(), branchOffice2.getBranchHouseNumberExtension())) {
107 isSameAddress = false;
108 } else if (!Objects.equals(branchOffice1.getBranchStore(), branchOffice2.getBranchStore())) {
110 isSameAddress = false;
111 } else if (!Objects.equals(branchOffice1.getBranchSuiteNumber(), branchOffice2.getBranchSuiteNumber())) {
113 isSameAddress = false;
117 return isSameAddress;
121 * Private default constructor
123 private BranchOffices () {
124 // Utilities don't have instances