]> 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  * Copyright (C) 2017, 2018 Free Software Foundation
3  *
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.
8  *
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.
13  *
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/>.
16  */
17 package org.mxchange.jcontactsbusiness.model.branchoffice;
18
19 import java.io.Serializable;
20 import java.util.Objects;
21
22 /**
23  * An utilities class for branch offices
24  *
25  * @author Roland Häder<roland@mxchange.org>
26  */
27 public class BranchOffices implements Serializable {
28
29         /**
30          * Serial number
31          */
32         private static final long serialVersionUID = 69_537_867_224_651L;
33
34         /**
35          * Compares both branch office instances. This method returns -1 if second
36          * instance is null.
37          * <p>
38          * @param branchOffice1 Branch office instance 1
39          * @param branchOffice2 Branch office instance 2
40          * <p>
41          * @return Comparison value
42          * <p>
43          * @throws NullPointerException If first instance is null
44          */
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)) {
48                         // Both are same
49                         return 0;
50                 } else if (null == branchOffice1) {
51                         // First cannot be null
52                         throw new NullPointerException("branchOffice1 is null"); //NOI18N
53                 } else if (null == branchOffice2) {
54                         // Second is null
55                         return -1;
56                 }
57
58                 // Invoke compareTo() method
59                 return branchOffice1.compareTo(branchOffice2);
60         }
61
62         /**
63          * Checks if both branch offices have same address. This method will throw
64          * an {@code NullPointerException} if one of the instances is null.
65          * <p>
66          * @param branchOffice1 Branch office 1
67          * @param branchOffice2 Branch office 2
68          * <p>
69          * @return Whether both branch office addresses are the same
70          * <p>
71          * @throws NullPointerException If one of the instances is null
72          */
73         public static boolean isSameAddress (final BranchOffice branchOffice1, final BranchOffice branchOffice2) {
74                 // Check that both parameters are not null
75                 if (null == branchOffice1) {
76                         // Throw NPE
77                         throw new NullPointerException("branchOffice1 is null"); //NOI18N
78                 } else if (null == branchOffice2) {
79                         // Throw NPE
80                         throw new NullPointerException("branchOffice2 is null"); //NOI18N
81                 }
82
83                 // Default is the same
84                 boolean isSameAddress = true;
85
86                 // Compare both addresses
87                 if (!Objects.equals(branchOffice1.getBranchCompany(), branchOffice2.getBranchCompany())) {
88                         // Not the same
89                         isSameAddress = false;
90                 } else if (!Objects.equals(branchOffice1.getBranchCountry(), branchOffice2.getBranchCountry())) {
91                         // Not the same
92                         isSameAddress = false;
93                 } else if (!Objects.equals(branchOffice1.getBranchCity(), branchOffice2.getBranchCity())) {
94                         // Not the same
95                         isSameAddress = false;
96                 } else if (!Objects.equals(branchOffice1.getBranchZipCode(), branchOffice2.getBranchZipCode())) {
97                         // Not the same
98                         isSameAddress = false;
99                 } else if (!Objects.equals(branchOffice1.getBranchStreet(), branchOffice2.getBranchStreet())) {
100                         // Not the same
101                         isSameAddress = false;
102                 } else if (!Objects.equals(branchOffice1.getBranchHouseNumber(), branchOffice2.getBranchHouseNumber())) {
103                         // Not the same
104                         isSameAddress = false;
105                 } else if (!Objects.equals(branchOffice1.getBranchHouseNumberExtension(), branchOffice2.getBranchHouseNumberExtension())) {
106                         // Not the same
107                         isSameAddress = false;
108                 } else if (!Objects.equals(branchOffice1.getBranchStore(), branchOffice2.getBranchStore())) {
109                         // Not the same
110                         isSameAddress = false;
111                 } else if (!Objects.equals(branchOffice1.getBranchSuiteNumber(), branchOffice2.getBranchSuiteNumber())) {
112                         // Not the same
113                         isSameAddress = false;
114                 }
115
116                 // Return flag
117                 return isSameAddress;
118         }
119
120         /**
121          * Private default constructor
122          */
123         private BranchOffices () {
124                 // Utilities don't have instances
125         }
126
127 }