]> git.mxchange.org Git - jcontacts-business-core.git/blob - src/org/mxchange/jcontactsbusiness/model/employee/Employees.java
Updated jar(s)
[jcontacts-business-core.git] / src / org / mxchange / jcontactsbusiness / model / employee / Employees.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.employee;
18
19 import java.io.Serializable;
20 import java.text.MessageFormat;
21 import java.util.Objects;
22
23 /**
24  * Utilities class for employees
25  * <p>
26  * @author Roland Häder<roland@mxchange.org>
27  */
28 public class Employees implements Serializable {
29
30         /**
31          * Serial number
32          */
33         private static final long serialVersionUID = 158_376_461_255_901L;
34
35         /**
36          * Compares both employee instances. This method returns -1 if second
37          * instance is null.
38          * <p>
39          * @param employable1 Employee instance 1
40          * @param employable2 Employee instance 2
41          * <p>
42          * @return Comparison value
43          */
44         public static int compare (final Employable employable1, final Employable employable2) {
45                 // Check euqality, then at least first must be given
46                 if (Objects.equals(employable1, employable2)) {
47                         // Both are same
48                         return 0;
49                 } else if (null == employable1) {
50                         // First is null
51                         return -1;
52                 } else if (null == employable2) {
53                         // Second is null
54                         return 1;
55                 }
56
57                 // Invoke compareTo() method
58                 return employable1.compareTo(employable2);
59         }
60
61         /**
62          * Checks whether both employees are the same
63          * <p>
64          * @param employee1 Employee 1
65          * @param employee2 Employee 2
66          * <p>
67          * @return Whether both are the same
68          */
69         public static boolean isSameEmployeeFound (final Employable employee1, final Employable employee2) {
70                 // Validate parameter
71                 if (null == employee1) {
72                         // Throw NPE
73                         throw new NullPointerException("employee1 is null"); //NOI18N
74                 } else if (employee1.getEmployeeBasicData() == null) {
75                         // Throw it again
76                         throw new NullPointerException("employee1.employeeCompany is null"); //NOI18N
77                 } else if (employee1.getEmployeeBasicData().getBasicDataId() == null) {
78                         // Throw it again
79                         throw new NullPointerException("employee1.employeeCompany.basicDataId is null"); //NOI18N
80                 } else if (employee1.getEmployeeBasicData().getBasicDataId() < 1) {
81                         // Throw IAE
82                         throw new IllegalArgumentException(MessageFormat.format("employee1.employeeCompany.basicDataId={0} is invalid.", employee1.getEmployeeBasicData().getBasicDataId())); //NOI18N
83                 } else if (employee1.getEmployeeBranchOffice() == null && employee1.getEmployeeDepartment() == null && employee1.getEmployeeHeadquarter() == null) {
84                         // At least one must be set
85                         throw new NullPointerException("employee1.employeeBranchOffice, employee1.employeeDepartment and employee1.employeeHeadquarter is null"); //NOI18N
86                 } else if (employee1.getEmployeeBranchOffice() != null && employee1.getEmployeeBranchOffice().getBranchId() == null) {
87                         // Throw NPE
88                         throw new NullPointerException("employee1.employeeBranchOffice.branchId is null"); //NOI18N
89                 } else if (employee1.getEmployeeBranchOffice() != null && employee1.getEmployeeBranchOffice().getBranchId() < 1) {
90                         // Throw IAE
91                         throw new IllegalArgumentException(MessageFormat.format("employee1.employeeBranchOffice.branchId={0} is invalid.", employee1.getEmployeeBranchOffice().getBranchId())); //NOI18N
92                 } else if (employee1.getEmployeeDepartment() != null && employee1.getEmployeeDepartment().getDepartmentId() == null) {
93                         // Throw NPE
94                         throw new NullPointerException("employee1.employeeDepartment.departmentId is null"); //NOI18N
95                 } else if (employee1.getEmployeeDepartment() != null && employee1.getEmployeeDepartment().getDepartmentId() < 1) {
96                         // Throw IAE
97                         throw new IllegalArgumentException(MessageFormat.format("employee1.employeeDepartment.departmentId={0} is invalid.", employee1.getEmployeeDepartment().getDepartmentId())); //NOI18N
98                 } else if (employee1.getEmployeeHeadquarter() != null && employee1.getEmployeeHeadquarter().getHeadquarterId() == null) {
99                         // Throw NPE
100                         throw new NullPointerException("employee1.employeeHeadquarter.headquarterId is null"); //NOI18N
101                 } else if (employee1.getEmployeeHeadquarter() != null && employee1.getEmployeeHeadquarter().getHeadquarterId() < 1) {
102                         // Throw IAE
103                         throw new IllegalArgumentException(MessageFormat.format("employee1.employeeHeadquarter.headquarterId={0} is invalid.", employee1.getEmployeeHeadquarter().getHeadquarterId())); //NOI18N
104                 } else if ((employee1.getEmployeePersonalData() == null) && (employee1.getEmployeeBranchOffice() == null) && (employee1.getEmployeeHeadquarter() == null) && (employee1.getEmployeeNumber() == null)) {
105                         // All are null
106                         throw new NullPointerException("employee1.employeePersonalData, employee1.employeeBranchOffice, employee1.employeeHeadquarter and employee1.employeeNumber are null"); //NOI18N
107                 } else if ((employee1.getEmployeePersonalData() != null) && (employee1.getEmployeePersonalData().getContactId() == null)) {
108                         // Throw NPE
109                         throw new NullPointerException("employee1.employeePersonalData.contactId is null"); //NOI18N
110                 } else if ((employee1.getEmployeePersonalData() != null) && (employee1.getEmployeePersonalData().getContactId() < 1)) {
111                         // Throw IAE
112                         throw new IllegalArgumentException(MessageFormat.format("employee1.employeePersonalData.contactId={0} is invalid.", employee1.getEmployeePersonalData().getContactId())); //NOI18N
113                 } else if ((employee1.getEmployeeNumber() != null) && (employee1.getEmployeeNumber().isEmpty())) {
114                         // Throw it again
115                         throw new IllegalArgumentException("employee1.employeeNumber is empty"); //NOI18N
116                 } else if (null == employee2) {
117                         // Throw NPE
118                         throw new NullPointerException("employee2 is null"); //NOI18N
119                 } else if (employee2.getEmployeeBasicData() == null) {
120                         // Throw it again
121                         throw new NullPointerException("employee2.employeeCompany is null"); //NOI18N
122                 } else if (employee2.getEmployeeBasicData().getBasicDataId() == null) {
123                         // Throw it again
124                         throw new NullPointerException("employee2.employeeCompany.basicDataId is null"); //NOI18N
125                 } else if (employee2.getEmployeeBasicData().getBasicDataId() < 1) {
126                         // Throw IAE
127                         throw new IllegalArgumentException(MessageFormat.format("employee2.employeeCompany.basicDataId={0} is invalid.", employee2.getEmployeeBasicData().getBasicDataId())); //NOI18N
128                 } else if (employee2.getEmployeeBranchOffice() == null && employee2.getEmployeeDepartment() == null && employee2.getEmployeeHeadquarter() == null) {
129                         // At least one must be set
130                         throw new NullPointerException("employee2.employeeBranchOffice, employee2.employeeDepartment and employee2.employeeHeadquarter is null"); //NOI18N
131                 } else if (employee2.getEmployeeBranchOffice() != null && employee2.getEmployeeBranchOffice().getBranchId() == null) {
132                         // Throw NPE
133                         throw new NullPointerException("employee2.employeeBranchOffice.branchId is null"); //NOI18N
134                 } else if (employee2.getEmployeeBranchOffice() != null && employee2.getEmployeeBranchOffice().getBranchId() < 1) {
135                         // Throw IAE
136                         throw new IllegalArgumentException(MessageFormat.format("employee2.employeeBranchOffice.branchId={0} is invalid.", employee2.getEmployeeBranchOffice().getBranchId())); //NOI18N
137                 } else if (employee2.getEmployeeDepartment() != null && employee2.getEmployeeDepartment().getDepartmentId() == null) {
138                         // Throw NPE
139                         throw new NullPointerException("employee2.employeeDepartment.departmentId is null"); //NOI18N
140                 } else if (employee2.getEmployeeDepartment() != null && employee2.getEmployeeDepartment().getDepartmentId() < 1) {
141                         // Throw IAE
142                         throw new IllegalArgumentException(MessageFormat.format("employee2.employeeDepartment.departmentId={0} is invalid.", employee2.getEmployeeDepartment().getDepartmentId())); //NOI18N
143                 } else if (employee2.getEmployeeHeadquarter() != null && employee2.getEmployeeHeadquarter().getHeadquarterId() == null) {
144                         // Throw NPE
145                         throw new NullPointerException("employee2.employeeHeadquarter.headquarterId is null"); //NOI18N
146                 } else if (employee2.getEmployeeHeadquarter() != null && employee2.getEmployeeHeadquarter().getHeadquarterId() < 1) {
147                         // Throw IAE
148                         throw new IllegalArgumentException(MessageFormat.format("employee2.employeeHeadquarter.headquarterId={0} is invalid.", employee2.getEmployeeHeadquarter().getHeadquarterId())); //NOI18N
149                 } else if ((employee2.getEmployeePersonalData() == null) && (employee2.getEmployeeBranchOffice() == null) && (employee2.getEmployeeHeadquarter() == null) && (employee2.getEmployeeNumber() == null)) {
150                         // All are null
151                         throw new NullPointerException("employee2.employeePersonalData, employee2.employeeBranchOffice, employee2.employeeHeadquarter and employee2.employeeNumber are null"); //NOI18N
152                 } else if ((employee2.getEmployeePersonalData() != null) && (employee2.getEmployeePersonalData().getContactId() == null)) {
153                         // Throw NPE
154                         throw new NullPointerException("employee2.employeePersonalData.contactId is null"); //NOI18N
155                 } else if ((employee2.getEmployeePersonalData() != null) && (employee2.getEmployeePersonalData().getContactId() < 1)) {
156                         // Throw IAE
157                         throw new IllegalArgumentException(MessageFormat.format("employee2.employeePersonalData.contactId={0} is invalid.", employee2.getEmployeePersonalData().getContactId())); //NOI18N
158                 } else if ((employee2.getEmployeeNumber() != null) && (employee2.getEmployeeNumber().isEmpty())) {
159                         // Throw it again
160                         throw new IllegalArgumentException("employee2.employeeNumber is empty"); //NOI18N
161                 } else if (Objects.equals(employee1, employee2)) {
162                         // Found equal entity
163                         return true;
164                 }
165
166                 // Same data found?
167                 if (!Objects.equals(employee1.getEmployeeBasicData(), employee2.getEmployeeBasicData())) {
168                         // Not the same companies
169                         return false;
170                 } else if (!Objects.equals(employee1.getEmployeeNumber(), employee2.getEmployeeNumber())) {
171                         // Not same number
172                         return false;
173                 } else if (!Objects.equals(employee1.getEmployeePersonalData(), employee2.getEmployeePersonalData())) {
174                         // Not same personal data
175                         return false;
176                 }
177
178                 // Is same employee
179                 return true;
180         }
181
182         /**
183          * Private constructor
184          */
185         private Employees () {
186                 // No instances from utilities
187         }
188
189 }