]> git.mxchange.org Git - jcontacts-business-core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Thu, 15 Mar 2018 23:36:19 +0000 (00:36 +0100)
committerRoland Häder <roland@mxchange.org>
Sun, 18 Mar 2018 21:22:53 +0000 (22:22 +0100)
- added new dependency to jcoreee.jar
- implemented Comparable interface in all entities
- rewrote to use Comparables.checkAll()
- check for null-pointer reference
- documented thrown NPE
- added utils class for job positions

Signed-off-by: Roland Häder <roland@mxchange.org>
21 files changed:
nbproject/project.properties
src/org/mxchange/jcontactsbusiness/model/basicdata/BasicData.java
src/org/mxchange/jcontactsbusiness/model/basicdata/BusinessBasicData.java
src/org/mxchange/jcontactsbusiness/model/branchoffice/BranchOffices.java
src/org/mxchange/jcontactsbusiness/model/branchoffice/BusinessBranchOffice.java
src/org/mxchange/jcontactsbusiness/model/department/BusinessDepartment.java
src/org/mxchange/jcontactsbusiness/model/department/Department.java
src/org/mxchange/jcontactsbusiness/model/department/Departments.java
src/org/mxchange/jcontactsbusiness/model/employee/BusinessEmployee.java
src/org/mxchange/jcontactsbusiness/model/employee/Employable.java
src/org/mxchange/jcontactsbusiness/model/employee/Employees.java
src/org/mxchange/jcontactsbusiness/model/headquarter/BusinessHeadquarter.java
src/org/mxchange/jcontactsbusiness/model/headquarter/Headquarter.java
src/org/mxchange/jcontactsbusiness/model/headquarter/Headquarters.java
src/org/mxchange/jcontactsbusiness/model/jobposition/EmployeePosition.java
src/org/mxchange/jcontactsbusiness/model/jobposition/JobPosition.java
src/org/mxchange/jcontactsbusiness/model/jobposition/JobPositions.java [new file with mode: 0644]
src/org/mxchange/jcontactsbusiness/model/logo/BusinessLogo.java
src/org/mxchange/jcontactsbusiness/model/logo/Logo.java
src/org/mxchange/jcontactsbusiness/model/opening_time/BusinessOpeningTime.java
src/org/mxchange/jcontactsbusiness/model/opening_time/OpeningTime.java

index f3f37e132b0fed305144751b074b068b7b785ff2..f07f0a8305dd56c1272368ccecb40a692a0d563b 100644 (file)
@@ -31,6 +31,7 @@ dist.javadoc.dir=${dist.dir}/javadoc
 endorsed.classpath=
 excludes=
 file.reference.jcontacts-core.jar=lib/jcontacts-core.jar
+file.reference.jcoreee.jar=lib/jcoreee.jar
 file.reference.jcountry-core.jar=lib/jcountry-core.jar
 file.reference.jphone-core.jar=lib/jphone-core.jar
 file.reference.juser-core.jar=lib/juser-core.jar
@@ -43,6 +44,7 @@ javac.classpath=\
     ${file.reference.jcountry-core.jar}:\
     ${file.reference.jphone-core.jar}:\
     ${file.reference.juser-core.jar}:\
+    ${file.reference.jcoreee.jar}:\
     ${libs.jpa20-persistence.classpath}
 # Space-separated list of extra javac options
 javac.compilerargs=-Xlint:unchecked -Xlint:deprecation
@@ -97,7 +99,8 @@ run.test.classpath=\
     ${build.test.classes.dir}
 source.encoding=UTF-8
 source.reference.jcontacts-core.jar=../jcontacts-core/src/
-source.reference.jcountry-core.jar=../jcountry-code/src/
+source.reference.jcoreee.jar=../jcoreee/src/
+source.reference.jcountry-core.jar=../jcountry-core/src/
 source.reference.jphone-core.jar=../jphone-core/src/
 source.reference.juser-core.jar=../juser-core/src/
 src.dir=src
index 554cb84f394c1d60a5878557499f14e7c10907bc..834aad7306c9f805da31f6df2598ec4f5621fb49 100644 (file)
@@ -32,7 +32,7 @@ import org.mxchange.jusercore.model.user.User;
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
-public interface BasicData extends Serializable {
+public interface BasicData extends Comparable<BasicData>, Serializable {
 
        /**
         * Getter for branches list
index dd3ab39538058eb694d534b3d1b252212351fa95..1efd780901fa15e389d916ada0219376b6365088 100644 (file)
@@ -40,8 +40,11 @@ import org.mxchange.jcontactsbusiness.model.employee.BusinessEmployee;
 import org.mxchange.jcontactsbusiness.model.employee.Employable;
 import org.mxchange.jcontactsbusiness.model.headquarter.BusinessHeadquarter;
 import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter;
+import org.mxchange.jcontactsbusiness.model.headquarter.Headquarters;
 import org.mxchange.jcontactsbusiness.model.logo.BusinessLogo;
 import org.mxchange.jcontactsbusiness.model.logo.Logo;
+import org.mxchange.jcoreee.utils.Comparables;
+import org.mxchange.jcoreee.utils.StringUtils;
 import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
 import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber;
 import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
@@ -198,6 +201,36 @@ public class BusinessBasicData implements BasicData {
                this.companyName = companyName;
        }
 
+       @Override
+       public int compareTo (final BasicData basicData) {
+               // For performance reasons
+               if (null == basicData) {
+                       // Should not happen
+                       throw new NullPointerException("basicData is null"); //NOI18N
+               } else if (Objects.equals(this, basicData)) {
+                       // Same object
+                       return 0;
+               }
+
+               // Init comparators
+               final int comparators[] = {
+                       // First compare company name
+                       this.getCompanyName().compareToIgnoreCase(basicData.getCompanyName()),
+                       // ... next tax number
+                       StringUtils.compareToIgnoreCase(this.getCompanyTaxNumber(), basicData.getCompanyTaxNumber()),
+                       // ... and email address
+                       StringUtils.compareToIgnoreCase(this.getCompanyEmailAddress(), basicData.getCompanyEmailAddress()),
+                       // ... head quarter data
+                       Headquarters.compare(this.getCompanyHeadquarterData(), basicData.getCompanyHeadquarterData())
+               };
+
+               // Check all values
+               final int comparison = Comparables.checkAll(comparators);
+
+               // Return value
+               return comparison;
+       }
+
        @Override
        public boolean equals (final Object object) {
                if (null == object) {
index 284d0976602eb40cc452990e564c945eb3042c87..7054e4b2387050afc41685df96e57e9f477c9d39 100644 (file)
@@ -31,6 +31,34 @@ public class BranchOffices implements Serializable {
         */
        private static final long serialVersionUID = 69_537_867_224_651L;
 
+       /**
+        * Compares both branch office instances. This method returns -1 if second
+        * instance is null.
+        * <p>
+        * @param branchOffice1 Branch office instance 1
+        * @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
+               if (Objects.equals(branchOffice1, branchOffice2)) {
+                       // Both are same
+                       return 0;
+               } else if (null == branchOffice1) {
+                       // First cannot be null
+                       throw new NullPointerException("branchOffice1 is null"); //NOI18N
+               } else if (null == branchOffice2) {
+                       // Second is null
+                       return -1;
+               }
+
+               // Invoke compareTo() method
+               return branchOffice1.compareTo(branchOffice2);
+       }
+
        /**
         * Checks if both branch offices have same address. This method will throw
         * an {@code NullPointerException} if one of the instances is null.
index 1c327872d99da89c88415e1214c432dfdbe539e8..9619c546473d6f40f1956e224568a405ff26eb72 100644 (file)
@@ -43,6 +43,7 @@ import org.mxchange.jcontactsbusiness.model.employee.BusinessEmployee;
 import org.mxchange.jcontactsbusiness.model.employee.Employable;
 import org.mxchange.jcontactsbusiness.model.opening_time.BusinessOpeningTime;
 import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime;
+import org.mxchange.jcoreee.utils.Comparables;
 import org.mxchange.jcoreee.utils.StringUtils;
 import org.mxchange.jcountry.model.data.Country;
 import org.mxchange.jcountry.model.data.CountryData;
@@ -290,16 +291,16 @@ public class BusinessBranchOffice implements BranchOffice {
        @Override
        public int compareTo (final BranchOffice branchOffice) {
                // For performance reasons
-               if (Objects.equals(this, branchOffice)) {
+               if (null == branchOffice) {
+                       // Should not happen
+                       throw new NullPointerException("branchOffice is null"); //NOI18N
+               } else if (Objects.equals(this, branchOffice)) {
                        // Same object
                        return 0;
                }
 
-               // Init check array (I could repeat myself here, but no)
+               // Init comparisons
                final int[] comparators = {
-                       // A different branch number is a clear indication ...
-                       // A different branch number is a clear indication ...
-                       // A different branch number is a clear indication ...
                        // A different branch number is a clear indication ...
                        Long.compare(this.getBranchNumber(), branchOffice.getBranchNumber()),
                        // ... same with id ...
@@ -314,31 +315,21 @@ public class BusinessBranchOffice implements BranchOffice {
                        this.getBranchStreet().compareToIgnoreCase(branchOffice.getBranchStreet()),
                        // ... and house number
                        this.getBranchHouseNumber().compareTo(branchOffice.getBranchHouseNumber()),
-                       // ... and last house number
+                       // ... and house number
                        Short.compare(this.getBranchLastHouseNumber(), branchOffice.getBranchLastHouseNumber()),
-                       StringUtils.comareToIgnoreCase(this.getBranchHouseNumberExtension(), branchOffice.getBranchHouseNumberExtension()),
+                       // ... and extension
+                       StringUtils.compareToIgnoreCase(this.getBranchHouseNumberExtension(), branchOffice.getBranchHouseNumberExtension()),
                        // ... store ...
                        Short.compare(this.getBranchStore(), branchOffice.getBranchStore()),
                        // ... suite number ...
                        Short.compare(this.getBranchSuiteNumber(), branchOffice.getBranchSuiteNumber())
                };
 
-               // Loop through all
-               for (int i = 0; i < comparators.length; i++) {
-
-                       // Is it smaller or bigger?
-                       if (comparators[i] < 0) {
-                               return -1;
-                       } else if (comparators[i] > 0) {
-                               return 1;
-                       }
-               }
-
-               // Verify that compareTo() is constistent with equals()
-               assert Objects.equals(this, branchOffice) : "compareTo inconsistent with equals()"; //NOI18N
+               // Check all values
+               final int comparison = Comparables.checkAll(comparators);
 
-               // Assume euqality
-               return 0;
+               // Return value
+               return comparison;
        }
 
        @Override
index 611e0e48642cb8f91d3146e045fad89b803a9a61..edde1cce4eb2b74f412e2c4e20c8e5a4289af58f 100644 (file)
@@ -37,11 +37,14 @@ import javax.persistence.Transient;
 import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
 import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
 import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
+import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffices;
 import org.mxchange.jcontactsbusiness.model.branchoffice.BusinessBranchOffice;
 import org.mxchange.jcontactsbusiness.model.employee.BusinessEmployee;
 import org.mxchange.jcontactsbusiness.model.employee.Employable;
 import org.mxchange.jcontactsbusiness.model.headquarter.BusinessHeadquarter;
 import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter;
+import org.mxchange.jcontactsbusiness.model.headquarter.Headquarters;
+import org.mxchange.jcoreee.utils.Comparables;
 import org.mxchange.jusercore.model.user.LoginUser;
 import org.mxchange.jusercore.model.user.User;
 
@@ -157,6 +160,36 @@ public class BusinessDepartment implements Department {
                this.departmentI18nKey = departmentName;
        }
 
+       @Override
+       public int compareTo (final Department department) {
+               // For performance reasons
+               if (null == department) {
+                       // Should not happen
+                       throw new NullPointerException("department is null"); //NOI18N
+               } else if (Objects.equals(this, department)) {
+                       // Same object
+                       return 0;
+               }
+
+               // Init comparisons
+               final int[] comparators = {
+                       // First department's company (BasicData) ...
+                       this.getDepartmentCompany().compareTo(department.getDepartmentCompany()),
+                       // ... then headquarters
+                       Headquarters.compare(this.getDepartmentHeadquarter(), department.getDepartmentHeadquarter()),
+                       // ... branch office
+                       BranchOffices.compare(this.getDepartmentBranchOffice(), department.getDepartmentBranchOffice()),
+                       // ... finally department's i18n key
+                       this.getDepartmentI18nKey().compareTo(department.getDepartmentI18nKey())
+               };
+
+               // Check all values
+               final int comparison = Comparables.checkAll(comparators);
+
+               // Return value
+               return comparison;
+       }
+
        @Override
        public boolean equals (final Object object) {
                if (null == object) {
index eeb92267b1ce32fe066feca5750750a7998af04d..2cb07714705e07a686984cc8735fbba9693302ae 100644 (file)
@@ -18,18 +18,18 @@ package org.mxchange.jcontactsbusiness.model.department;
 
 import java.io.Serializable;
 import java.util.Date;
+import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
 import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
-import org.mxchange.jusercore.model.user.User;
 import org.mxchange.jcontactsbusiness.model.employee.Employable;
-import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
 import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter;
+import org.mxchange.jusercore.model.user.User;
 
 /**
  * A POJI for company departments
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
-public interface Department extends Serializable {
+public interface Department extends Comparable<Department>, Serializable {
 
        /**
         * Getter for connection to business contact
index b1664a8c79509b01abbb25e1f8fb841fb71e5ba8..7786af356f1909f1646dd48fe325a4634b17ed7c 100644 (file)
@@ -34,6 +34,34 @@ public class Departments implements Serializable {
         */
        private static final long serialVersionUID = 20_154_686_786_561L;
 
+       /**
+        * Compares both department instances. This method returns -1 if second
+        * instance is null.
+        * <p>
+        * @param department1 Department instance 1
+        * @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
+               if (Objects.equals(department1, department2)) {
+                       // Both are same
+                       return 0;
+               } else if (null == department1) {
+                       // First cannot be null
+                       throw new NullPointerException("department1 is null"); //NOI18N
+               } else if (null == department2) {
+                       // Second is null
+                       return -1;
+               }
+
+               // Invoke compareTo() method
+               return department1.compareTo(department2);
+       }
+
        /**
         * Checks if both departments are the same (entity) or if at least basic
         * company data and department name are matching.
index 8e349f6331ad6bc14e343d896c5070d5dfd46d36..cf87e934774919401979e29b8ec96853328cb67d 100644 (file)
@@ -34,17 +34,24 @@ import javax.persistence.Temporal;
 import javax.persistence.TemporalType;
 import javax.persistence.Transient;
 import org.mxchange.jcontacts.model.contact.Contact;
+import org.mxchange.jcontacts.model.contact.Contacts;
 import org.mxchange.jcontacts.model.contact.UserContact;
 import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
 import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
 import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
+import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffices;
 import org.mxchange.jcontactsbusiness.model.branchoffice.BusinessBranchOffice;
 import org.mxchange.jcontactsbusiness.model.department.BusinessDepartment;
 import org.mxchange.jcontactsbusiness.model.department.Department;
+import org.mxchange.jcontactsbusiness.model.department.Departments;
 import org.mxchange.jcontactsbusiness.model.headquarter.BusinessHeadquarter;
 import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter;
+import org.mxchange.jcontactsbusiness.model.headquarter.Headquarters;
 import org.mxchange.jcontactsbusiness.model.jobposition.EmployeePosition;
 import org.mxchange.jcontactsbusiness.model.jobposition.JobPosition;
+import org.mxchange.jcontactsbusiness.model.jobposition.JobPositions;
+import org.mxchange.jcoreee.utils.Comparables;
+import org.mxchange.jcoreee.utils.StringUtils;
 import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
 import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber;
 import org.mxchange.jusercore.model.user.LoginUser;
@@ -70,6 +77,13 @@ public class BusinessEmployee implements Employable {
        @Transient
        private static final long serialVersionUID = 48_959_819_859_812_076L;
 
+       /**
+        * Company the employee is working at
+        */
+       @JoinColumn (name = "employee_company_id", nullable = false, updatable = false)
+       @OneToOne (targetEntity = BusinessBasicData.class, cascade = CascadeType.REFRESH, optional = false)
+       private BasicData employeeBasicData;
+
        /**
         * Branch office (if the employee works there)
         */
@@ -77,13 +91,6 @@ public class BusinessEmployee implements Employable {
        @OneToOne (targetEntity = BusinessBranchOffice.class, cascade = CascadeType.REFRESH)
        private BranchOffice employeeBranchOffice;
 
-       /**
-        * Company the employee is working at
-        */
-       @JoinColumn (name = "employee_company_id", nullable = false, updatable = false)
-       @OneToOne (targetEntity = BusinessBasicData.class, cascade = CascadeType.REFRESH, optional = false)
-       private BasicData employeeCompany;
-
        /**
         * Timestamp when this entry has been created
         */
@@ -100,7 +107,7 @@ public class BusinessEmployee implements Employable {
        private Department employeeDepartment;
 
        /**
-        * Employable's email address
+        * Employee's email address
         */
        @Column (name = "employee_email_address", length = 30)
        private String employeeEmailAddress;
@@ -121,38 +128,38 @@ public class BusinessEmployee implements Employable {
        private Long employeeId;
 
        /**
-        * Employable's business mobile number
+        * Employee's position (example: CEO)
+        */
+       @JoinColumn (name = "employee_position_id")
+       @OneToOne (targetEntity = EmployeePosition.class, cascade = CascadeType.REFRESH)
+       private JobPosition employeeJobPosition;
+
+       /**
+        * Employee's business mobile number
         */
        @JoinColumn (name = "employee_mobile_number_id")
        @OneToOne (targetEntity = MobileNumber.class, cascade = CascadeType.REFRESH)
        private DialableMobileNumber employeeMobileNumber;
 
        /**
-        * Employable's staff number
+        * Employee's staff number
         */
        @Column (name = "employee_staff_number", length = 20)
        private String employeeNumber;
 
        /**
-        * Employable's personal data
+        * Employee's personal data
         */
        @JoinColumn (name = "employee_personal_data_id")
        @OneToOne (targetEntity = UserContact.class, cascade = CascadeType.REFRESH)
        private Contact employeePersonalData;
 
        /**
-        * Employable's phone extension (or number if different)
+        * Employee's phone extension (or number if different)
         */
        @Column (name = "employee_phone_extension", length = 10)
        private Integer employeePhoneExtension;
 
-       /**
-        * Employable's position (example: CEO)
-        */
-       @JoinColumn (name = "employee_position_id")
-       @OneToOne (targetEntity = EmployeePosition.class, cascade = CascadeType.REFRESH)
-       private JobPosition employeePosition;
-
        /**
         * User owner instance
         */
@@ -188,11 +195,49 @@ public class BusinessEmployee implements Employable {
                }
 
                // Set all fields
-               this.employeeCompany = employeeCompany;
+               this.employeeBasicData = employeeCompany;
                this.employeeNumber = employeeNumber;
                this.employeePersonalData = employeePersonalData;
        }
 
+       @Override
+       public int compareTo (final Employable employable) {
+               // For performance reasons
+               if (null == employable) {
+                       // Should not happen
+                       throw new NullPointerException("employable is null"); //NOI18N
+               } else if (Objects.equals(this, employable)) {
+                       // Same object
+                       return 0;
+               }
+
+               // Init comparisons
+               final int[] comparators = {
+                       // First check company data (BasicData)
+                       this.getEmployeeBasicData().compareTo(employable.getEmployeeBasicData()),
+                       // ... next headquarters
+                       Headquarters.compare(this.getEmployeeHeadquarter(), employable.getEmployeeHeadquarter()),
+                       // ... branch office
+                       BranchOffices.compare(this.getEmployeeBranchOffice(), employable.getEmployeeBranchOffice()),
+                       // ... department
+                       Departments.compare(this.getEmployeeDepartment(), employable.getEmployeeDepartment()),
+                       // ... job position
+                       JobPositions.compare(this.getEmployeeJobPosition(), employable.getEmployeeJobPosition()),
+                       // ... employee's number
+                       StringUtils.compareToIgnoreCase(this.getEmployeeNumber(), employable.getEmployeeNumber()),
+                       // ... employee's email address
+                       StringUtils.compareToIgnoreCase(this.getEmployeeEmailAddress(), employable.getEmployeeEmailAddress()),
+                       // ... finally contact data
+                       Contacts.compare(this.getEmployeePersonalData(), employable.getEmployeePersonalData())
+               };
+
+               // Check all values
+               final int comparison = Comparables.checkAll(comparators);
+
+               // Return value
+               return comparison;
+       }
+
        @Override
        public boolean equals (final Object object) {
                if (null == object) {
@@ -205,7 +250,7 @@ public class BusinessEmployee implements Employable {
 
                if (!Objects.equals(this.getEmployeeId(), employee.getEmployeeId())) {
                        return false;
-               } else if (!Objects.equals(this.getEmployeeCompany(), employee.getEmployeeCompany())) {
+               } else if (!Objects.equals(this.getEmployeeBasicData(), employee.getEmployeeBasicData())) {
                        return false;
                } else if (!Objects.equals(this.getEmployeeNumber(), employee.getEmployeeNumber())) {
                        return false;
@@ -217,23 +262,23 @@ public class BusinessEmployee implements Employable {
        }
 
        @Override
-       public BranchOffice getEmployeeBranchOffice () {
-               return this.employeeBranchOffice;
+       public BasicData getEmployeeBasicData () {
+               return this.employeeBasicData;
        }
 
        @Override
-       public void setEmployeeBranchOffice (final BranchOffice employeeBranchOffice) {
-               this.employeeBranchOffice = employeeBranchOffice;
+       public void setEmployeeBasicData (final BasicData employeeBasicData) {
+               this.employeeBasicData = employeeBasicData;
        }
 
        @Override
-       public BasicData getEmployeeCompany () {
-               return this.employeeCompany;
+       public BranchOffice getEmployeeBranchOffice () {
+               return this.employeeBranchOffice;
        }
 
        @Override
-       public void setEmployeeCompany (final BasicData employeeCompany) {
-               this.employeeCompany = employeeCompany;
+       public void setEmployeeBranchOffice (final BranchOffice employeeBranchOffice) {
+               this.employeeBranchOffice = employeeBranchOffice;
        }
 
        @Override
@@ -288,6 +333,16 @@ public class BusinessEmployee implements Employable {
                this.employeeId = employeeId;
        }
 
+       @Override
+       public JobPosition getEmployeeJobPosition () {
+               return this.employeeJobPosition;
+       }
+
+       @Override
+       public void setEmployeeJobPosition (final JobPosition employeeJobPosition) {
+               this.employeeJobPosition = employeeJobPosition;
+       }
+
        @Override
        public DialableMobileNumber getEmployeeMobileNumber () {
                return this.employeeMobileNumber;
@@ -328,16 +383,6 @@ public class BusinessEmployee implements Employable {
                this.employeePhoneExtension = employeePhoneExtension;
        }
 
-       @Override
-       public JobPosition getEmployeePosition () {
-               return this.employeePosition;
-       }
-
-       @Override
-       public void setEmployeePosition (final JobPosition employeePosition) {
-               this.employeePosition = employeePosition;
-       }
-
        @Override
        public User getEmployeeUserOwner () {
                return this.employeeUserOwner;
@@ -353,7 +398,7 @@ public class BusinessEmployee implements Employable {
                int hash = 3;
 
                hash = 97 * hash + Objects.hashCode(this.getEmployeeId());
-               hash = 97 * hash + Objects.hashCode(this.getEmployeeCompany());
+               hash = 97 * hash + Objects.hashCode(this.getEmployeeBasicData());
                hash = 97 * hash + Objects.hashCode(this.getEmployeeNumber());
                hash = 97 * hash + Objects.hashCode(this.getEmployeePersonalData());
 
index faac46437660a934ee187e9dfab93591b526b289..1eec65b9cff750648b1f6b17a27353918b184c17 100644 (file)
@@ -32,7 +32,7 @@ import org.mxchange.jusercore.model.user.User;
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
-public interface Employable extends Serializable {
+public interface Employable extends Comparable<Employable>, Serializable {
 
        /**
         * Getter for employee's branch office
@@ -53,14 +53,14 @@ public interface Employable extends Serializable {
         * <p>
         * @return Company instance
         */
-       BasicData getEmployeeCompany ();
+       BasicData getEmployeeBasicData ();
 
        /**
         * Setter for employee's company
         * <p>
         * @param employeeCompany Company instance
         */
-       void setEmployeeCompany (final BasicData employeeCompany);
+       void setEmployeeBasicData (final BasicData employeeCompany);
 
        /**
         * Getter for employee's department
@@ -179,14 +179,14 @@ public interface Employable extends Serializable {
         * <p>
         * @return Employable's position
         */
-       JobPosition getEmployeePosition ();
+       JobPosition getEmployeeJobPosition ();
 
        /**
         * Setter for employee's position
         * <p>
         * @param employeePosition Employable's position
         */
-       void setEmployeePosition (final JobPosition employeePosition);
+       void setEmployeeJobPosition (final JobPosition employeePosition);
 
        /**
         * Getter for user owner instance
index 50fec03737e629997def3a34cb691ea41d370298..9c642b6e06882c367849cfe72a271aa629769202 100644 (file)
@@ -45,15 +45,15 @@ public class Employees implements Serializable {
                if (null == employee1) {
                        // Throw NPE
                        throw new NullPointerException("employee1 is null"); //NOI18N
-               } else if (employee1.getEmployeeCompany() == null) {
+               } else if (employee1.getEmployeeBasicData() == null) {
                        // Throw it again
                        throw new NullPointerException("employee1.employeeCompany is null"); //NOI18N
-               } else if (employee1.getEmployeeCompany().getBasicDataId() == null) {
+               } else if (employee1.getEmployeeBasicData().getBasicDataId() == null) {
                        // Throw it again
                        throw new NullPointerException("employee1.employeeCompany.basicDataId is null"); //NOI18N
-               } else if (employee1.getEmployeeCompany().getBasicDataId() < 1) {
+               } else if (employee1.getEmployeeBasicData().getBasicDataId() < 1) {
                        // Throw IAE
-                       throw new IllegalArgumentException(MessageFormat.format("employee1.employeeCompany.basicDataId={0} is invalid.", employee1.getEmployeeCompany().getBasicDataId())); //NOI18N
+                       throw new IllegalArgumentException(MessageFormat.format("employee1.employeeCompany.basicDataId={0} is invalid.", employee1.getEmployeeBasicData().getBasicDataId())); //NOI18N
                } else if (employee1.getEmployeeBranchOffice() == null && employee1.getEmployeeDepartment() == null && employee1.getEmployeeHeadquarter() == null) {
                        // At least one must be set
                        throw new NullPointerException("employee1.employeeBranchOffice, employee1.employeeDepartment and employee1.employeeHeadquarter is null"); //NOI18N
@@ -90,15 +90,15 @@ public class Employees implements Serializable {
                } else if (null == employee2) {
                        // Throw NPE
                        throw new NullPointerException("employee2 is null"); //NOI18N
-               } else if (employee2.getEmployeeCompany() == null) {
+               } else if (employee2.getEmployeeBasicData() == null) {
                        // Throw it again
                        throw new NullPointerException("employee2.employeeCompany is null"); //NOI18N
-               } else if (employee2.getEmployeeCompany().getBasicDataId() == null) {
+               } else if (employee2.getEmployeeBasicData().getBasicDataId() == null) {
                        // Throw it again
                        throw new NullPointerException("employee2.employeeCompany.basicDataId is null"); //NOI18N
-               } else if (employee2.getEmployeeCompany().getBasicDataId() < 1) {
+               } else if (employee2.getEmployeeBasicData().getBasicDataId() < 1) {
                        // Throw IAE
-                       throw new IllegalArgumentException(MessageFormat.format("employee2.employeeCompany.basicDataId={0} is invalid.", employee2.getEmployeeCompany().getBasicDataId())); //NOI18N
+                       throw new IllegalArgumentException(MessageFormat.format("employee2.employeeCompany.basicDataId={0} is invalid.", employee2.getEmployeeBasicData().getBasicDataId())); //NOI18N
                } else if (employee2.getEmployeeBranchOffice() == null && employee2.getEmployeeDepartment() == null && employee2.getEmployeeHeadquarter() == null) {
                        // At least one must be set
                        throw new NullPointerException("employee2.employeeBranchOffice, employee2.employeeDepartment and employee2.employeeHeadquarter is null"); //NOI18N
@@ -138,7 +138,7 @@ public class Employees implements Serializable {
                }
 
                // Same data found?
-               if (!Objects.equals(employee1.getEmployeeCompany(), employee2.getEmployeeCompany())) {
+               if (!Objects.equals(employee1.getEmployeeBasicData(), employee2.getEmployeeBasicData())) {
                        // Not the same companies
                        return false;
                } else if (!Objects.equals(employee1.getEmployeeNumber(), employee2.getEmployeeNumber())) {
index f6a35e1517df3a480eb6b2ed3bac41e22fdd65e6..6391d47aa04b3f275b17614683d05ba082082101 100644 (file)
@@ -41,6 +41,8 @@ import org.mxchange.jcontactsbusiness.model.employee.BusinessEmployee;
 import org.mxchange.jcontactsbusiness.model.employee.Employable;
 import org.mxchange.jcontactsbusiness.model.opening_time.BusinessOpeningTime;
 import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime;
+import org.mxchange.jcoreee.utils.Comparables;
+import org.mxchange.jcoreee.utils.StringUtils;
 import org.mxchange.jcountry.model.data.Country;
 import org.mxchange.jcountry.model.data.CountryData;
 import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
@@ -267,6 +269,50 @@ public class BusinessHeadquarter implements Headquarter {
                this.headquarterZipCode = headquarterZipCode;
        }
 
+       @Override
+       public int compareTo (final Headquarter headquarter) {
+               // For performance reasons
+               if (null == headquarter) {
+                       // Should not happen
+                       throw new NullPointerException("headquarter is null"); //NOI18N
+               } else if (Objects.equals(this, headquarter)) {
+                       // Same object
+                       return 0;
+               }
+
+               // Init comparators
+               final int comparators[] = {
+                       // First check company name
+                       this.getHeadquarterCompanyName().compareTo(headquarter.getHeadquarterCompanyName()),
+                       // ... next country
+                       this.getHeadquarterCountry().compareTo(headquarter.getHeadquarterCountry()),
+                       // ... then ZIP code
+                       Integer.compare(this.getHeadquarterZipCode(), headquarter.getHeadquarterZipCode()),
+                       // ... and city
+                       this.getHeadquarterCity().compareTo(headquarter.getHeadquarterCity()),
+                       // ... street name
+                       StringUtils.compareToIgnoreCase(this.getHeadquarterStreet(), headquarter.getHeadquarterStreet()),
+                       // ... house number
+                       Integer.compare(this.getHeadquarterHouseNumber(), headquarter.getHeadquarterHouseNumber()),
+                       // ... last house number
+                       Integer.compare(this.getHeadquarterLastHouseNumber(), headquarter.getHeadquarterLastHouseNumber()),
+                       // ... extension
+                       StringUtils.compareToIgnoreCase(this.getHeadquarterHouseNumberExtension(), headquarter.getHeadquarterHouseNumberExtension()),
+                       // ... store number
+                       Integer.compare(this.getHeadquarterStore(), headquarter.getHeadquarterStore()),
+                       // ... suite number
+                       Integer.compare(this.getHeadquarterSuiteNumber(), headquarter.getHeadquarterSuiteNumber()),
+                       // ... last email address
+                       StringUtils.compareToIgnoreCase(this.getHeadquarterEmailAddress(), headquarter.getHeadquarterEmailAddress())
+               };
+
+               // Check all values
+               final int comparison = Comparables.checkAll(comparators);
+
+               // Return value
+               return comparison;
+       }
+
        @Override
        public boolean equals (final Object object) {
                if (null == object) {
index 92c7535e2f4eb8d292fea947b7a42dcc3b50a4bf..6e62e75e4891479f5f53800bbea03cebb8b714ce 100644 (file)
@@ -31,7 +31,7 @@ import org.mxchange.jusercore.model.user.User;
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
-public interface Headquarter extends Serializable {
+public interface Headquarter extends Comparable<Headquarter>, Serializable {
 
        /**
         * Getter for headquarter's city name
index d43189a1bb840584b444d2f84b0f2dea9f523f03..2d847b9e04d88f9ad75be3165e2b792396fd2805 100644 (file)
@@ -32,8 +32,35 @@ public class Headquarters implements Serializable {
        private static final long serialVersionUID = 69_537_867_224_651L;
 
        /**
-        * Checks if both headquarter have same address. This method will throw
-        * an {@code NullPointerException} if one of the instances is null.
+        * Compare null-reference-safe 2 headquarter instances with each other.
+        * <p>
+        * @param headquarter1 Headquarter 1
+        * @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
+               if (Objects.equals(headquarter1, headquarter2)) {
+                       // Same headquarters
+                       return 0;
+               } else if (null == headquarter1) {
+                       // First headquarter is null
+                       throw new NullPointerException("headquarter1 is null"); //NOI18N
+               } else if (null == headquarter2) {
+                       // Second headquarter is null
+                       return -1;
+               }
+
+               // Now that both are not NULL, compare them
+               return headquarter1.compareTo(headquarter2);
+       }
+
+       /**
+        * Checks if both headquarter have same address. This method will throw an
+        * {@code NullPointerException} if one of the instances is null.
         * <p>
         * @param headquarter1 Headquarter 1
         * @param headquarter2 Headquarter 2
index 592d0783892e5c4da829939309bc09983a70b8ee..c77c72a2b7a2bc009435fa022a066dc46d468ca2 100644 (file)
@@ -28,6 +28,7 @@ import javax.persistence.Table;
 import javax.persistence.Temporal;
 import javax.persistence.TemporalType;
 import javax.persistence.Transient;
+import org.mxchange.jcoreee.utils.Comparables;
 
 /**
  * A POJO for job positions
@@ -77,6 +78,30 @@ public class EmployeePosition implements JobPosition {
        @Column (name = "job_position_updated", insertable = false)
        private Date jobPositionUpdated;
 
+       @Override
+       public int compareTo (final JobPosition jobPosition) {
+               // For performance reasons
+               if (null == jobPosition) {
+                       // Should not happen
+                       throw new NullPointerException("jobPosition is null"); //NOI18N
+               } else if (Objects.equals(this, jobPosition)) {
+                       // Same object
+                       return 0;
+               }
+
+               // Init comparisons
+               final int[] comparators = {
+                       // First position name ...
+                       this.getJobPositionName().compareToIgnoreCase(jobPosition.getJobPositionName())
+               };
+
+               // Check all values
+               final int comparison = Comparables.checkAll(comparators);
+
+               // Return value
+               return comparison;
+       }
+
        @Override
        public boolean equals (final Object object) {
                if (this == object) {
index e9ee4178bf4852ff7b7e6da638db739ddfe4daed..01e2335c457a87ac80912050083e53820185fb36 100644 (file)
@@ -24,7 +24,7 @@ import java.util.Date;
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
-public interface JobPosition extends Serializable {
+public interface JobPosition extends Comparable<JobPosition>, Serializable {
 
        /**
         * Getter for id number
diff --git a/src/org/mxchange/jcontactsbusiness/model/jobposition/JobPositions.java b/src/org/mxchange/jcontactsbusiness/model/jobposition/JobPositions.java
new file mode 100644 (file)
index 0000000..b94b6f2
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2018 Free Software Foundation
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jcontactsbusiness.model.jobposition;
+
+import java.io.Serializable;
+import java.util.Objects;
+
+/**
+ * Utilities class for job positions
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public class JobPositions implements Serializable {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 157_986_766_142_309L;
+
+       /**
+        * Compares both job position instances. This method returns -1 if second
+        * instance is null.
+        * <p>
+        * @param jobPosition1 Job position instance 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
+               if (Objects.equals(jobPosition1, jobPosition2)) {
+                       // Both are same
+                       return 0;
+               } else if (null == jobPosition1) {
+                       // First cannot be null
+                       throw new NullPointerException("jobPosition1 is null"); //NOI18N
+               } else if (null == jobPosition2) {
+                       // Second is null
+                       return -1;
+               }
+
+               // Invoke compareTo() method
+               return jobPosition1.compareTo(jobPosition2);
+       }
+
+       /**
+        * Private constructor
+        */
+       private JobPositions () {
+               // No instance should be creatable
+       }
+
+}
index 07604b1f8b389360024566e00a0d1e33da90e23e..26c56428ffd39128fe2574f85a25f054934c791d 100644 (file)
@@ -31,6 +31,7 @@ import javax.persistence.Table;
 import javax.persistence.Temporal;
 import javax.persistence.TemporalType;
 import javax.persistence.Transient;
+import org.mxchange.jcoreee.utils.Comparables;
 import org.mxchange.jusercore.model.user.LoginUser;
 import org.mxchange.jusercore.model.user.User;
 
@@ -80,6 +81,32 @@ public class BusinessLogo implements Logo {
        @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH, optional = false)
        private User logoUploader;
 
+       @Override
+       public int compareTo (final Logo logo) {
+               // For performance reasons
+               if (null == logo) {
+                       // Should not happen
+                       throw new NullPointerException("logo is null"); //NOI18N
+               } else if (Objects.equals(this, logo)) {
+                       // Same object
+                       return 0;
+               }
+
+               // Init comparisons
+               final int[] comparators = {
+                       // First file name ...
+                       this.getLogoFileName().compareToIgnoreCase(logo.getLogoFileName()),
+                       // ... then uploader instance
+                       this.getLogoUploader().compareTo(logo.getLogoUploader())
+               };
+
+               // Check all values
+               final int comparison = Comparables.checkAll(comparators);
+
+               // Return value
+               return comparison;
+       }
+
        @Override
        public boolean equals (final Object object) {
                if (null == object) {
index dda0532282a1a63199219418f2392ddb1273a16b..37940fc292206a016e374a54df279ce2df7d18fd 100644 (file)
@@ -25,7 +25,7 @@ import org.mxchange.jusercore.model.user.User;
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
-public interface Logo extends Serializable {
+public interface Logo extends Comparable<Logo>, Serializable {
 
        /**
         * Getter for logo's local file name
index c9397f52ffcb2254b1822c2d54e3164c79200a2c..c84f8b47172cbb63c595dcaafcf5f09306369a97 100644 (file)
@@ -33,6 +33,7 @@ import javax.persistence.Temporal;
 import javax.persistence.TemporalType;
 import javax.persistence.Transient;
 import org.mxchange.jcontactsbusiness.model.opening_time.dayofweek.DayOfTheWeek;
+import org.mxchange.jcoreee.utils.Comparables;
 
 /**
  * A POJO for business opening hours
@@ -43,7 +44,7 @@ import org.mxchange.jcontactsbusiness.model.opening_time.dayofweek.DayOfTheWeek;
 @Table (name = "company_opening_times")
 @NamedQueries (
                {
-                       @NamedQuery (name = "AllOpeningTimes", query = "SELECT ot FROM company_opening_times AS ot ORDER BY ot.openingId ASC"),
+                       @NamedQuery (name = "AllOpeningTimes", query = "SELECT ot FROM company_opening_times AS ot ORDER BY ot.openingId ASC")
                }
 )
 @SuppressWarnings ("PersistenceUnitPresent")
@@ -58,8 +59,8 @@ public class BusinessOpeningTime implements OpeningTime {
        /**
         * When this opening time was created
         */
-       @Basic(optional = false)
-       @Column(name = "opening_times_created", nullable = false, updatable = false)
+       @Basic (optional = false)
+       @Column (name = "opening_times_created", nullable = false, updatable = false)
        @Temporal (TemporalType.TIMESTAMP)
        private Date openingCreated;
 
@@ -125,6 +126,33 @@ public class BusinessOpeningTime implements OpeningTime {
                this.openingStartTime = openingStartTime;
        }
 
+       @Override
+       public int compareTo (final OpeningTime openingTime) {
+               // For performance reasons
+               if (null == openingTime) {
+                       // Should not happen
+                       throw new NullPointerException("openingTime is null"); //NOI18N
+               } else if (Objects.equals(this, openingTime)) {
+                       // Same object
+                       return 0;
+               }
+
+               // Init comparisons
+               // @TODO Also compare start and end timestamps (java.util.Date)
+               final int[] comparators = {
+                       // First starting day of the week
+                       this.getOpeningStartDay().compareTo(openingTime.getOpeningStartDay()),
+                       // ... and end day of the week
+                       this.getOpeningEndDay().compareTo(openingTime.getOpeningEndDay())
+               };
+
+               // Check all values
+               final int comparison = Comparables.checkAll(comparators);
+
+               // Return value
+               return comparison;
+       }
+
        @Override
        public boolean equals (final Object obj) {
                if (this == obj) {
index 130add04419f7997a2f59b37ba49058afdabaa2c..a52d76b006b9d1b209b35dfc8f0469238288f9f5 100644 (file)
@@ -25,7 +25,7 @@ import org.mxchange.jcontactsbusiness.model.opening_time.dayofweek.DayOfTheWeek;
  *
  * @author Roland Häder<roland@mxchange.org>
  */
-public interface OpeningTime extends Serializable {
+public interface OpeningTime extends Comparable<OpeningTime>, Serializable {
 
        /**
         * Getter for opening time created timestamp