+
/*
* Copyright (C) 2017, 2018 Free Software Foundation
*
* @param branchOffice2 Branch office instance 2
* <p>
* @return Comparison value
- * <p>
- * @throws NullPointerException If first instance is null
*/
public static int compare (final BranchOffice branchOffice1, final BranchOffice branchOffice2) {
// Check euqality, then at least first must be given
// Both are same
return 0;
} else if (null == branchOffice1) {
- // First cannot be null
- throw new NullPointerException("branchOffice1 is null"); //NOI18N
+ // First is null
+ return -1;
} else if (null == branchOffice2) {
// Second is null
return 1;
import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
import org.mxchange.jcontactsbusiness.model.employee.BusinessEmployee;
import org.mxchange.jcontactsbusiness.model.employee.Employable;
+import org.mxchange.jcontactsbusiness.model.employee.Employees;
import org.mxchange.jcontactsbusiness.model.opening_time.BusinessOpeningTime;
import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime;
import org.mxchange.jcoreee.utils.Comparables;
// Init comparisons
final int[] comparators = {
- // A different branch number is a clear indication ...
+ // First compare basic data
+ this.getBranchCompany().compareTo(branchOffice.getBranchCompany()),
+ // ... branch office number
NumberUtils.compare(this.getBranchNumber(), branchOffice.getBranchNumber()),
- // ... same with id ...
- NumberUtils.compare(this.getBranchId(), branchOffice.getBranchId()),
+ // ... contact person
+ Employees.compare(this.getBranchContactEmployee(), branchOffice.getBranchContactEmployee()),
// ... then country
this.getBranchCountry().compareTo(branchOffice.getBranchCountry()),
// ... next city
* @param department2 Department instance 2
* <p>
* @return Comparison value
- * <p>
- * @throws NullPointerException If first instance is null
*/
public static int compare (final Department department1, final Department department2) {
// Check euqality, then at least first must be given
// Both are same
return 0;
} else if (null == department1) {
- // First cannot be null
- throw new NullPointerException("department1 is null"); //NOI18N
+ // First is null
+ return -1;
} else if (null == department2) {
// Second is null
return 1;
*/
private static final long serialVersionUID = 158_376_461_255_901L;
+ /**
+ * Compares both employee instances. This method returns -1 if second
+ * instance is null.
+ * <p>
+ * @param employable1 Employee instance 1
+ * @param employable2 Employee instance 2
+ * <p>
+ * @return Comparison value
+ */
+ public static int compare (final Employable employable1, final Employable employable2) {
+ // Check euqality, then at least first must be given
+ if (Objects.equals(employable1, employable2)) {
+ // Both are same
+ return 0;
+ } else if (null == employable1) {
+ // First is null
+ return -1;
+ } else if (null == employable2) {
+ // Second is null
+ return 1;
+ }
+
+ // Invoke compareTo() method
+ return employable1.compareTo(employable2);
+ }
+
/**
* Checks whether both employees are the same
* <p>
} else if (employee1.getEmployeeHeadquarter() != null && employee1.getEmployeeHeadquarter().getHeadquarterId() < 1) {
// Throw IAE
throw new IllegalArgumentException(MessageFormat.format("employee1.employeeHeadquarter.headquarterId={0} is invalid.", employee1.getEmployeeHeadquarter().getHeadquarterId())); //NOI18N
- } else if ((employee1.getEmployeePersonalData() == null) && (employee1.getEmployeeNumber()== null)) {
+ } else if ((employee1.getEmployeePersonalData() == null) && (employee1.getEmployeeNumber() == null)) {
// Both are null
throw new NullPointerException("employee1.employeePersonalData and employee1.employeeNumber are null"); //NOI18N
} else if ((employee1.getEmployeePersonalData() != null) && (employee1.getEmployeePersonalData().getContactId() == null)) {
} else if (employee2.getEmployeeHeadquarter() != null && employee2.getEmployeeHeadquarter().getHeadquarterId() < 1) {
// Throw IAE
throw new IllegalArgumentException(MessageFormat.format("employee2.employeeHeadquarter.headquarterId={0} is invalid.", employee2.getEmployeeHeadquarter().getHeadquarterId())); //NOI18N
- } else if ((employee2.getEmployeePersonalData() == null) && (employee2.getEmployeeNumber()== null)) {
+ } else if ((employee2.getEmployeePersonalData() == null) && (employee2.getEmployeeNumber() == null)) {
// Both are null
throw new NullPointerException("employee2.employeePersonalData and employee2.employeeNumber are null"); //NOI18N
} else if ((employee2.getEmployeePersonalData() != null) && (employee2.getEmployeePersonalData().getContactId() == null)) {
* @param headquarter2 Headquarter 2
* <p>
* @return Comparison value from invoking Comparable.compareTo()
- * <p>
- * @throws NullPointerException If first instance is null
*/
public static int compare (final Headquarter headquarter1, final Headquarter headquarter2) {
// Compare both
// Same headquarters
return 0;
} else if (null == headquarter1) {
- // First headquarter is null
- throw new NullPointerException("headquarter1 is null"); //NOI18N
+ // First is null
+ return -1;
} else if (null == headquarter2) {
// Second headquarter is null
return 1;
* @param jobPosition2 Job position instance 2
* <p>
* @return Comparison value
- * <p>
- * @throws NullPointerException If first instance is null
*/
public static int compare (final JobPosition jobPosition1, final JobPosition jobPosition2) {
// Check euqality, then at least first must be given
// Both are same
return 0;
} else if (null == jobPosition1) {
- // First cannot be null
- throw new NullPointerException("jobPosition1 is null"); //NOI18N
+ // First is null
+ return -1;
} else if (null == jobPosition2) {
// Second is null
return 1;