]> git.mxchange.org Git - jcontacts-business-core.git/blob - src/org/mxchange/jcontactsbusiness/model/employee/Employees.java
Continued:
[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          * Checks whether both employees are the same
37          * <p>
38          * @param employee1 Employee 1
39          * @param employee2 Employee 2
40          * <p>
41          * @return Whether both are the same
42          */
43         public static boolean isSameEmployeeFound (final Employable employee1, final Employable employee2) {
44                 // Validate parameter
45                 if (null == employee1) {
46                         // Throw NPE
47                         throw new NullPointerException("employee1 is null"); //NOI18N
48                 } else if (employee1.getEmployeeBasicData() == null) {
49                         // Throw it again
50                         throw new NullPointerException("employee1.employeeCompany is null"); //NOI18N
51                 } else if (employee1.getEmployeeBasicData().getBasicDataId() == null) {
52                         // Throw it again
53                         throw new NullPointerException("employee1.employeeCompany.basicDataId is null"); //NOI18N
54                 } else if (employee1.getEmployeeBasicData().getBasicDataId() < 1) {
55                         // Throw IAE
56                         throw new IllegalArgumentException(MessageFormat.format("employee1.employeeCompany.basicDataId={0} is invalid.", employee1.getEmployeeBasicData().getBasicDataId())); //NOI18N
57                 } else if (employee1.getEmployeeBranchOffice() == null && employee1.getEmployeeDepartment() == null && employee1.getEmployeeHeadquarter() == null) {
58                         // At least one must be set
59                         throw new NullPointerException("employee1.employeeBranchOffice, employee1.employeeDepartment and employee1.employeeHeadquarter is null"); //NOI18N
60                 } else if (employee1.getEmployeeBranchOffice() != null && employee1.getEmployeeBranchOffice().getBranchId() == null) {
61                         // Throw NPE
62                         throw new NullPointerException("employee1.employeeBranchOffice.branchId is null"); //NOI18N
63                 } else if (employee1.getEmployeeBranchOffice() != null && employee1.getEmployeeBranchOffice().getBranchId() < 1) {
64                         // Throw IAE
65                         throw new IllegalArgumentException(MessageFormat.format("employee1.employeeBranchOffice.branchId={0} is invalid.", employee1.getEmployeeBranchOffice().getBranchId())); //NOI18N
66                 } else if (employee1.getEmployeeDepartment() != null && employee1.getEmployeeDepartment().getDepartmentId() == null) {
67                         // Throw NPE
68                         throw new NullPointerException("employee1.employeeDepartment.departmentId is null"); //NOI18N
69                 } else if (employee1.getEmployeeDepartment() != null && employee1.getEmployeeDepartment().getDepartmentId() < 1) {
70                         // Throw IAE
71                         throw new IllegalArgumentException(MessageFormat.format("employee1.employeeDepartment.departmentId={0} is invalid.", employee1.getEmployeeDepartment().getDepartmentId())); //NOI18N
72                 } else if (employee1.getEmployeeHeadquarter() != null && employee1.getEmployeeHeadquarter().getHeadquarterId() == null) {
73                         // Throw NPE
74                         throw new NullPointerException("employee1.employeeHeadquarter.headquarterId is null"); //NOI18N
75                 } else if (employee1.getEmployeeHeadquarter() != null && employee1.getEmployeeHeadquarter().getHeadquarterId() < 1) {
76                         // Throw IAE
77                         throw new IllegalArgumentException(MessageFormat.format("employee1.employeeHeadquarter.headquarterId={0} is invalid.", employee1.getEmployeeHeadquarter().getHeadquarterId())); //NOI18N
78                 } else if ((employee1.getEmployeePersonalData() == null) && (employee1.getEmployeeNumber()== null)) {
79                         // Both are null
80                         throw new NullPointerException("employee1.employeePersonalData and employee1.employeeNumber are null"); //NOI18N
81                 } else if ((employee1.getEmployeePersonalData() != null) && (employee1.getEmployeePersonalData().getContactId() == null)) {
82                         // Throw NPE
83                         throw new NullPointerException("employee1.employeePersonalData.contactId is null"); //NOI18N
84                 } else if ((employee1.getEmployeePersonalData() != null) && (employee1.getEmployeePersonalData().getContactId() < 1)) {
85                         // Throw IAE
86                         throw new IllegalArgumentException(MessageFormat.format("employee1.employeePersonalData.contactId={0} is invalid.", employee1.getEmployeePersonalData().getContactId())); //NOI18N
87                 } else if ((employee1.getEmployeeNumber() != null) && (employee1.getEmployeeNumber().isEmpty())) {
88                         // Throw it again
89                         throw new IllegalArgumentException("employee1.employeeNumber is empty"); //NOI18N
90                 } else if (null == employee2) {
91                         // Throw NPE
92                         throw new NullPointerException("employee2 is null"); //NOI18N
93                 } else if (employee2.getEmployeeBasicData() == null) {
94                         // Throw it again
95                         throw new NullPointerException("employee2.employeeCompany is null"); //NOI18N
96                 } else if (employee2.getEmployeeBasicData().getBasicDataId() == null) {
97                         // Throw it again
98                         throw new NullPointerException("employee2.employeeCompany.basicDataId is null"); //NOI18N
99                 } else if (employee2.getEmployeeBasicData().getBasicDataId() < 1) {
100                         // Throw IAE
101                         throw new IllegalArgumentException(MessageFormat.format("employee2.employeeCompany.basicDataId={0} is invalid.", employee2.getEmployeeBasicData().getBasicDataId())); //NOI18N
102                 } else if (employee2.getEmployeeBranchOffice() == null && employee2.getEmployeeDepartment() == null && employee2.getEmployeeHeadquarter() == null) {
103                         // At least one must be set
104                         throw new NullPointerException("employee2.employeeBranchOffice, employee2.employeeDepartment and employee2.employeeHeadquarter is null"); //NOI18N
105                 } else if (employee2.getEmployeeBranchOffice() != null && employee2.getEmployeeBranchOffice().getBranchId() == null) {
106                         // Throw NPE
107                         throw new NullPointerException("employee2.employeeBranchOffice.branchId is null"); //NOI18N
108                 } else if (employee2.getEmployeeBranchOffice() != null && employee2.getEmployeeBranchOffice().getBranchId() < 1) {
109                         // Throw IAE
110                         throw new IllegalArgumentException(MessageFormat.format("employee2.employeeBranchOffice.branchId={0} is invalid.", employee2.getEmployeeBranchOffice().getBranchId())); //NOI18N
111                 } else if (employee2.getEmployeeDepartment() != null && employee2.getEmployeeDepartment().getDepartmentId() == null) {
112                         // Throw NPE
113                         throw new NullPointerException("employee2.employeeDepartment.departmentId is null"); //NOI18N
114                 } else if (employee2.getEmployeeDepartment() != null && employee2.getEmployeeDepartment().getDepartmentId() < 1) {
115                         // Throw IAE
116                         throw new IllegalArgumentException(MessageFormat.format("employee2.employeeDepartment.departmentId={0} is invalid.", employee2.getEmployeeDepartment().getDepartmentId())); //NOI18N
117                 } else if (employee2.getEmployeeHeadquarter() != null && employee2.getEmployeeHeadquarter().getHeadquarterId() == null) {
118                         // Throw NPE
119                         throw new NullPointerException("employee2.employeeHeadquarter.headquarterId is null"); //NOI18N
120                 } else if (employee2.getEmployeeHeadquarter() != null && employee2.getEmployeeHeadquarter().getHeadquarterId() < 1) {
121                         // Throw IAE
122                         throw new IllegalArgumentException(MessageFormat.format("employee2.employeeHeadquarter.headquarterId={0} is invalid.", employee2.getEmployeeHeadquarter().getHeadquarterId())); //NOI18N
123                 } else if ((employee2.getEmployeePersonalData() == null) && (employee2.getEmployeeNumber()== null)) {
124                         // Both are null
125                         throw new NullPointerException("employee2.employeePersonalData and employee2.employeeNumber are null"); //NOI18N
126                 } else if ((employee2.getEmployeePersonalData() != null) && (employee2.getEmployeePersonalData().getContactId() == null)) {
127                         // Throw NPE
128                         throw new NullPointerException("employee2.employeePersonalData.contactId is null"); //NOI18N
129                 } else if ((employee2.getEmployeePersonalData() != null) && (employee2.getEmployeePersonalData().getContactId() < 1)) {
130                         // Throw IAE
131                         throw new IllegalArgumentException(MessageFormat.format("employee2.employeePersonalData.contactId={0} is invalid.", employee2.getEmployeePersonalData().getContactId())); //NOI18N
132                 } else if ((employee2.getEmployeeNumber() != null) && (employee2.getEmployeeNumber().isEmpty())) {
133                         // Throw it again
134                         throw new IllegalArgumentException("employee2.employeeNumber is empty"); //NOI18N
135                 } else if (Objects.equals(employee1, employee2)) {
136                         // Found equal entity
137                         return true;
138                 }
139
140                 // Same data found?
141                 if (!Objects.equals(employee1.getEmployeeBasicData(), employee2.getEmployeeBasicData())) {
142                         // Not the same companies
143                         return false;
144                 } else if (!Objects.equals(employee1.getEmployeeNumber(), employee2.getEmployeeNumber())) {
145                         // Not same number
146                         return false;
147                 } else if (!Objects.equals(employee1.getEmployeePersonalData(), employee2.getEmployeePersonalData())) {
148                         // Not same personal data
149                         return false;
150                 }
151
152                 // Is same employee
153                 return true;
154         }
155
156         /**
157          * Private constructor
158          */
159         private Employees () {
160                 // No instances from utilities
161         }
162
163 }