3 * Copyright (C) 2017, 2020 Free Software Foundation
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package org.mxchange.jcontactsbusiness.model.branchoffice;
20 import java.io.Serializable;
21 import java.util.Objects;
24 * An utilities class for branch offices
26 * @author Roland Häder<roland@mxchange.org>
28 public class BranchOffices implements Serializable {
33 private static final long serialVersionUID = 69_537_867_224_651L;
36 * Compares both branch office instances. This method returns -1 if second
39 * @param branchOffice1 Branch office instance 1
40 * @param branchOffice2 Branch office instance 2
42 * @return Comparison value
44 public static int compare (final BranchOffice branchOffice1, final BranchOffice branchOffice2) {
45 // Check euqality, then at least first must be given
46 if (Objects.equals(branchOffice1, branchOffice2)) {
49 } else if (null == branchOffice1) {
52 } else if (null == branchOffice2) {
57 // Invoke compareTo() method
58 return branchOffice1.compareTo(branchOffice2);
62 * Checks if both branch offices have same address. This method will throw
63 * an {@code NullPointerException} if one of the instances is null.
65 * @param branchOffice1 Branch office 1
66 * @param branchOffice2 Branch office 2
68 * @return Whether both branch office addresses are the same
70 * @throws NullPointerException If one of the instances is null
72 public static boolean isSameAddress (final BranchOffice branchOffice1, final BranchOffice branchOffice2) {
73 // Check that both parameters are not null
74 if (null == branchOffice1) {
76 throw new NullPointerException("branchOffice1 is null"); //NOI18N
77 } else if (null == branchOffice2) {
79 throw new NullPointerException("branchOffice2 is null"); //NOI18N
82 // Default is the same
83 boolean isSameAddress = true;
85 // Compare both addresses
86 if (!Objects.equals(branchOffice1.getBranchCompany(), branchOffice2.getBranchCompany())) {
88 isSameAddress = false;
89 } else if (!Objects.equals(branchOffice1.getBranchCountry(), branchOffice2.getBranchCountry())) {
91 isSameAddress = false;
92 } else if (!Objects.equals(branchOffice1.getBranchCity(), branchOffice2.getBranchCity())) {
94 isSameAddress = false;
95 } else if (!Objects.equals(branchOffice1.getBranchZipCode(), branchOffice2.getBranchZipCode())) {
97 isSameAddress = false;
98 } else if (!Objects.equals(branchOffice1.getBranchStreet(), branchOffice2.getBranchStreet())) {
100 isSameAddress = false;
101 } else if (!Objects.equals(branchOffice1.getBranchHouseNumber(), branchOffice2.getBranchHouseNumber())) {
103 isSameAddress = false;
104 } else if (!Objects.equals(branchOffice1.getBranchHouseNumberExtension(), branchOffice2.getBranchHouseNumberExtension())) {
106 isSameAddress = false;
107 } else if (!Objects.equals(branchOffice1.getBranchStore(), branchOffice2.getBranchStore())) {
109 isSameAddress = false;
110 } else if (!Objects.equals(branchOffice1.getBranchSuiteNumber(), branchOffice2.getBranchSuiteNumber())) {
112 isSameAddress = false;
116 return isSameAddress;
120 * Private default constructor
122 private BranchOffices () {
123 // Utilities don't have instances