]> 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                 }
76
77                 // Copy all fields
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());
99         }
100
101         /**
102          * Checks if both branch offices have same address. This method will throw
103          * an {@code NullPointerException} if one of the instances is null.
104          * <p>
105          * @param branchOffice1 Branch office 1
106          * @param branchOffice2 Branch office 2
107          * <p>
108          * @return Whether both branch office addresses are the same
109          * <p>
110          * @throws NullPointerException If one of the instances is null
111          */
112         public static boolean isSameAddress (final BranchOffice branchOffice1, final BranchOffice branchOffice2) {
113                 // Check that both parameters are not null
114                 if (null == branchOffice1) {
115                         // Throw NPE
116                         throw new NullPointerException("branchOffice1 is null"); //NOI18N
117                 } else if (null == branchOffice2) {
118                         // Throw NPE
119                         throw new NullPointerException("branchOffice2 is null"); //NOI18N
120                 }
121
122                 // Default is the same
123                 boolean isSameAddress = true;
124
125                 // Compare both addresses
126                 if (!Objects.equals(branchOffice1.getBranchCompany(), branchOffice2.getBranchCompany())) {
127                         // Not the same
128                         isSameAddress = false;
129                 } else if (!Objects.equals(branchOffice1.getBranchCountry(), branchOffice2.getBranchCountry())) {
130                         // Not the same
131                         isSameAddress = false;
132                 } else if (!Objects.equals(branchOffice1.getBranchCity(), branchOffice2.getBranchCity())) {
133                         // Not the same
134                         isSameAddress = false;
135                 } else if (!Objects.equals(branchOffice1.getBranchZipCode(), branchOffice2.getBranchZipCode())) {
136                         // Not the same
137                         isSameAddress = false;
138                 } else if (!Objects.equals(branchOffice1.getBranchStreet(), branchOffice2.getBranchStreet())) {
139                         // Not the same
140                         isSameAddress = false;
141                 } else if (!Objects.equals(branchOffice1.getBranchHouseNumber(), branchOffice2.getBranchHouseNumber())) {
142                         // Not the same
143                         isSameAddress = false;
144                 } else if (!Objects.equals(branchOffice1.getBranchHouseNumberExtension(), branchOffice2.getBranchHouseNumberExtension())) {
145                         // Not the same
146                         isSameAddress = false;
147                 } else if (!Objects.equals(branchOffice1.getBranchStore(), branchOffice2.getBranchStore())) {
148                         // Not the same
149                         isSameAddress = false;
150                 } else if (!Objects.equals(branchOffice1.getBranchSuiteNumber(), branchOffice2.getBranchSuiteNumber())) {
151                         // Not the same
152                         isSameAddress = false;
153                 }
154
155                 // Return flag
156                 return isSameAddress;
157         }
158
159         /**
160          * Private default constructor
161          */
162         private BranchOffices () {
163                 // Utilities don't have instances
164         }
165
166 }