]> git.mxchange.org Git - jcontacts-business-core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sun, 18 Mar 2018 22:09:43 +0000 (23:09 +0100)
committerRoland Häder <roland@mxchange.org>
Sun, 18 Mar 2018 22:14:24 +0000 (23:14 +0100)
- ops, need to compare basic data and contact employee of branch office before
  comparing the whole address
- branch office number being compared before contact employee is okay

Signed-off-by: Roland Häder <roland@mxchange.org>
src/org/mxchange/jcontactsbusiness/model/branchoffice/BranchOffices.java
src/org/mxchange/jcontactsbusiness/model/branchoffice/BusinessBranchOffice.java
src/org/mxchange/jcontactsbusiness/model/department/Departments.java
src/org/mxchange/jcontactsbusiness/model/employee/Employees.java
src/org/mxchange/jcontactsbusiness/model/headquarter/Headquarters.java
src/org/mxchange/jcontactsbusiness/model/jobposition/JobPositions.java

index 122752661ec5795cc85e4e114d0148a3de935442..e2be31f8c22156ecd6a416f5a26bee3c7252ddb5 100644 (file)
@@ -1,3 +1,4 @@
+
 /*
  * Copyright (C) 2017, 2018 Free Software Foundation
  *
@@ -39,8 +40,6 @@ public class BranchOffices implements Serializable {
         * @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
@@ -48,8 +47,8 @@ public class BranchOffices implements Serializable {
                        // 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;
index 7f3c91a2c075274514d7d32777fa600f0adf477a..12815f077453ebc589b4cea8a9450bf6d5f9a992 100644 (file)
@@ -41,6 +41,7 @@ import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
 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;
@@ -302,10 +303,12 @@ public class BusinessBranchOffice implements BranchOffice {
 
                // 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
index 7aa9a869deff872345dbd70fd2516e58f1769da4..e78550cc80c3f65a9723941cd9cbf49b894310a5 100644 (file)
@@ -42,8 +42,6 @@ public class Departments implements Serializable {
         * @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
@@ -51,8 +49,8 @@ public class Departments implements Serializable {
                        // 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;
index 9c642b6e06882c367849cfe72a271aa629769202..177da4fd32a07342b8a46c2efd4a58743aae41e4 100644 (file)
@@ -32,6 +32,32 @@ public class Employees implements Serializable {
         */
        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>
@@ -75,7 +101,7 @@ public class Employees implements Serializable {
                } 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)) {
@@ -120,7 +146,7 @@ public class Employees implements Serializable {
                } 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)) {
index 598290fee094b861fadf92c9f210300e807f7951..c6800043494dc1e25b823cf94fcc1165903e101e 100644 (file)
@@ -38,8 +38,6 @@ public class Headquarters implements Serializable {
         * @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
@@ -47,8 +45,8 @@ public class Headquarters implements Serializable {
                        // 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;
index 1b523a97a18d53ea98ee53676a27a3b367b3b3fe..a23be98391b6249af9e1216866a7c8b83135e9fa 100644 (file)
@@ -39,8 +39,6 @@ public class JobPositions implements Serializable {
         * @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
@@ -48,8 +46,8 @@ public class JobPositions implements Serializable {
                        // 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;