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 * Copies all fields from source to target branch office instance
64 * @param sourceBranchOffice Source BranchOffice instance
65 * @param targetBranchOffice Target BranchOffice instance
67 public static void copyBranchOfficeData (final BranchOffice sourceBranchOffice, final BranchOffice targetBranchOffice) {
68 // Check that both parameters are not null
69 if (null == sourceBranchOffice) {
71 throw new NullPointerException("sourceBranchOffice is null"); //NOI18N
72 } else if (null == targetBranchOffice) {
74 throw new NullPointerException("targetBranchOffice is null"); //NOI18N
78 targetBranchOffice.setBranchCity(sourceBranchOffice.getBranchCity());
79 targetBranchOffice.setBranchCompany(sourceBranchOffice.getBranchCompany());
80 targetBranchOffice.setBranchContactEmployee(sourceBranchOffice.getBranchContactEmployee());
81 targetBranchOffice.setBranchCountry(sourceBranchOffice.getBranchCountry());
82 targetBranchOffice.setBranchEmailAddress(sourceBranchOffice.getBranchEmailAddress());
83 targetBranchOffice.setBranchEntryCreated(sourceBranchOffice.getBranchEntryCreated());
84 targetBranchOffice.setBranchEntryUpdated(sourceBranchOffice.getBranchEntryUpdated());
85 targetBranchOffice.setBranchFaxNumber(sourceBranchOffice.getBranchFaxNumber());
86 targetBranchOffice.setBranchHouseNumber(sourceBranchOffice.getBranchHouseNumber());
87 targetBranchOffice.setBranchHouseNumberExtension(sourceBranchOffice.getBranchHouseNumberExtension());
88 targetBranchOffice.setBranchId(sourceBranchOffice.getBranchId());
89 targetBranchOffice.setBranchLandLineNumber(sourceBranchOffice.getBranchLandLineNumber());
90 targetBranchOffice.setBranchLastHouseNumber(sourceBranchOffice.getBranchLastHouseNumber());
91 targetBranchOffice.setBranchNumber(sourceBranchOffice.getBranchNumber());
92 targetBranchOffice.setBranchOpeningTimes(sourceBranchOffice.getBranchOpeningTimes());
93 targetBranchOffice.setBranchOwnerEmployee(sourceBranchOffice.getBranchOwnerEmployee());
94 targetBranchOffice.setBranchStore(sourceBranchOffice.getBranchStore());
95 targetBranchOffice.setBranchStreet(sourceBranchOffice.getBranchStreet());
96 targetBranchOffice.setBranchSuiteNumber(sourceBranchOffice.getBranchSuiteNumber());
97 targetBranchOffice.setBranchUserOwner(sourceBranchOffice.getBranchUserOwner());
98 targetBranchOffice.setBranchZipCode(sourceBranchOffice.getBranchZipCode());
102 * Checks if both branch offices have same address. This method will throw
103 * an {@code NullPointerException} if one of the instances is null.
105 * @param branchOffice1 Branch office 1
106 * @param branchOffice2 Branch office 2
108 * @return Whether both branch office addresses are the same
110 * @throws NullPointerException If one of the instances is null
112 public static boolean isSameAddress (final BranchOffice branchOffice1, final BranchOffice branchOffice2) {
113 // Check that both parameters are not null
114 if (null == branchOffice1) {
116 throw new NullPointerException("branchOffice1 is null"); //NOI18N
117 } else if (null == branchOffice2) {
119 throw new NullPointerException("branchOffice2 is null"); //NOI18N
122 // Default is the same
123 boolean isSameAddress = true;
125 // Compare both addresses
126 if (!Objects.equals(branchOffice1.getBranchCompany(), branchOffice2.getBranchCompany())) {
128 isSameAddress = false;
129 } else if (!Objects.equals(branchOffice1.getBranchCountry(), branchOffice2.getBranchCountry())) {
131 isSameAddress = false;
132 } else if (!Objects.equals(branchOffice1.getBranchCity(), branchOffice2.getBranchCity())) {
134 isSameAddress = false;
135 } else if (!Objects.equals(branchOffice1.getBranchZipCode(), branchOffice2.getBranchZipCode())) {
137 isSameAddress = false;
138 } else if (!Objects.equals(branchOffice1.getBranchStreet(), branchOffice2.getBranchStreet())) {
140 isSameAddress = false;
141 } else if (!Objects.equals(branchOffice1.getBranchHouseNumber(), branchOffice2.getBranchHouseNumber())) {
143 isSameAddress = false;
144 } else if (!Objects.equals(branchOffice1.getBranchHouseNumberExtension(), branchOffice2.getBranchHouseNumberExtension())) {
146 isSameAddress = false;
147 } else if (!Objects.equals(branchOffice1.getBranchStore(), branchOffice2.getBranchStore())) {
149 isSameAddress = false;
150 } else if (!Objects.equals(branchOffice1.getBranchSuiteNumber(), branchOffice2.getBranchSuiteNumber())) {
152 isSameAddress = false;
156 return isSameAddress;
160 * Private default constructor
162 private BranchOffices () {
163 // Utilities don't have instances