]> git.mxchange.org Git - jcontacts-business-core.git/blob - src/org/mxchange/jcontactsbusiness/model/branchoffice/BranchOffices.java
Continued:
[jcontacts-business-core.git] / src / org / mxchange / jcontactsbusiness / model / branchoffice / BranchOffices.java
1
2 /*
3  * Copyright (C) 2017 - 2020 Free Software Foundation
4  *
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.
9  *
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.
14  *
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/>.
17  */
18 package org.mxchange.jcontactsbusiness.model.branchoffice;
19
20 import java.io.Serializable;
21 import java.util.Objects;
22
23 /**
24  * An utilities class for branch offices
25  *
26  * @author Roland Häder<roland@mxchange.org>
27  */
28 public class BranchOffices implements Serializable {
29
30         /**
31          * Serial number
32          */
33         private static final long serialVersionUID = 69_537_867_224_651L;
34
35         /**
36          * Compares both branch office instances. This method returns -1 if second
37          * instance is null.
38          * <p>
39          * @param branchOffice1 Branch office instance 1
40          * @param branchOffice2 Branch office instance 2
41          * <p>
42          * @return Comparison value
43          */
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)) {
47                         // Both are same
48                         return 0;
49                 } else if (null == branchOffice1) {
50                         // First is null
51                         return -1;
52                 } else if (null == branchOffice2) {
53                         // Second is null
54                         return 1;
55                 }
56
57                 // Invoke compareTo() method
58                 return branchOffice1.compareTo(branchOffice2);
59         }
60
61         /**
62          * Copies all fields from source to target branch office instance
63          * <p>
64          * @param sourceBranchOffice Source BranchOffice instance
65          * @param targetBranchOffice Target BranchOffice instance
66          */
67         public static void copyBranchOfficeData (final BranchOffice sourceBranchOffice, final BranchOffice targetBranchOffice) {
68                 // Check that both parameters are not null
69                 if (null == sourceBranchOffice) {
70                         // Throw NPE
71                         throw new NullPointerException("sourceBranchOffice is null"); //NOI18N
72                 } else if (null == targetBranchOffice) {
73                         // Throw NPE
74                         throw new NullPointerException("targetBranchOffice is null"); //NOI18N
75                 } else if (Objects.equals(sourceBranchOffice, targetBranchOffice)) {
76                         // Throw IAE
77                         throw new IllegalArgumentException("sourceBranchOffice and targetBranchOffice are the same"); //NOI18N
78                 }
79
80                 // Copy all fields
81                 targetBranchOffice.setBranchCity(sourceBranchOffice.getBranchCity());
82                 targetBranchOffice.setBranchCompany(sourceBranchOffice.getBranchCompany());
83                 targetBranchOffice.setBranchContactEmployee(sourceBranchOffice.getBranchContactEmployee());
84                 targetBranchOffice.setBranchCountry(sourceBranchOffice.getBranchCountry());
85                 targetBranchOffice.setBranchEmailAddress(sourceBranchOffice.getBranchEmailAddress());
86                 targetBranchOffice.setBranchFaxNumber(sourceBranchOffice.getBranchFaxNumber());
87                 targetBranchOffice.setBranchHouseNumber(sourceBranchOffice.getBranchHouseNumber());
88                 targetBranchOffice.setBranchHouseNumberExtension(sourceBranchOffice.getBranchHouseNumberExtension());
89                 targetBranchOffice.setBranchId(sourceBranchOffice.getBranchId());
90                 targetBranchOffice.setBranchLandLineNumber(sourceBranchOffice.getBranchLandLineNumber());
91                 targetBranchOffice.setBranchLastHouseNumber(sourceBranchOffice.getBranchLastHouseNumber());
92                 targetBranchOffice.setBranchNumber(sourceBranchOffice.getBranchNumber());
93                 targetBranchOffice.setBranchOpeningTimes(sourceBranchOffice.getBranchOpeningTimes());
94                 targetBranchOffice.setBranchOwnerEmployee(sourceBranchOffice.getBranchOwnerEmployee());
95                 targetBranchOffice.setBranchStore(sourceBranchOffice.getBranchStore());
96                 targetBranchOffice.setBranchStreet(sourceBranchOffice.getBranchStreet());
97                 targetBranchOffice.setBranchSuiteNumber(sourceBranchOffice.getBranchSuiteNumber());
98                 targetBranchOffice.setBranchUserOwner(sourceBranchOffice.getBranchUserOwner());
99                 targetBranchOffice.setBranchZipCode(sourceBranchOffice.getBranchZipCode());
100         }
101
102         /**
103          * Checks if both branch offices have same address. This method will throw
104          * an {@code NullPointerException} if one of the instances is null.
105          * <p>
106          * @param branchOffice1 Branch office 1
107          * @param branchOffice2 Branch office 2
108          * <p>
109          * @return Whether both branch office addresses are the same
110          * <p>
111          * @throws NullPointerException If one of the instances is null
112          */
113         public static boolean isSameAddress (final BranchOffice branchOffice1, final BranchOffice branchOffice2) {
114                 // Check that both parameters are not null
115                 if (null == branchOffice1) {
116                         // Throw NPE
117                         throw new NullPointerException("branchOffice1 is null"); //NOI18N
118                 } else if (null == branchOffice2) {
119                         // Throw NPE
120                         throw new NullPointerException("branchOffice2 is null"); //NOI18N
121                 }
122
123                 // Default is the same
124                 boolean isSameAddress = true;
125
126                 // Compare both addresses
127                 if (!Objects.equals(branchOffice1.getBranchCompany(), branchOffice2.getBranchCompany())) {
128                         // Not the same
129                         isSameAddress = false;
130                 } else if (!Objects.equals(branchOffice1.getBranchCountry(), branchOffice2.getBranchCountry())) {
131                         // Not the same
132                         isSameAddress = false;
133                 } else if (!Objects.equals(branchOffice1.getBranchCity(), branchOffice2.getBranchCity())) {
134                         // Not the same
135                         isSameAddress = false;
136                 } else if (!Objects.equals(branchOffice1.getBranchZipCode(), branchOffice2.getBranchZipCode())) {
137                         // Not the same
138                         isSameAddress = false;
139                 } else if (!Objects.equals(branchOffice1.getBranchStreet(), branchOffice2.getBranchStreet())) {
140                         // Not the same
141                         isSameAddress = false;
142                 } else if (!Objects.equals(branchOffice1.getBranchHouseNumber(), branchOffice2.getBranchHouseNumber())) {
143                         // Not the same
144                         isSameAddress = false;
145                 } else if (!Objects.equals(branchOffice1.getBranchHouseNumberExtension(), branchOffice2.getBranchHouseNumberExtension())) {
146                         // Not the same
147                         isSameAddress = false;
148                 } else if (!Objects.equals(branchOffice1.getBranchStore(), branchOffice2.getBranchStore())) {
149                         // Not the same
150                         isSameAddress = false;
151                 } else if (!Objects.equals(branchOffice1.getBranchSuiteNumber(), branchOffice2.getBranchSuiteNumber())) {
152                         // Not the same
153                         isSameAddress = false;
154                 }
155
156                 // Return flag
157                 return isSameAddress;
158         }
159
160         /**
161          * Private default constructor
162          */
163         private BranchOffices () {
164                 // Utilities don't have instances
165         }
166
167 }