]> git.mxchange.org Git - jjobs-core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Thu, 19 Jan 2023 02:52:20 +0000 (03:52 +0100)
committerRoland Häder <roland@mxchange.org>
Thu, 19 Jan 2023 02:55:22 +0000 (03:55 +0100)
- implemented java.lang.Comparable<T> as this is later required for Primefaces
  to sort in p:dataTable tag
- added required jcore-utils project as JAR
- added utilities class for skills

lib/jcore-utils.jar [new file with mode: 0644]
nbproject/project.properties
src/org/mxchange/jjobs/model/jobskill/JobPositionSkill.java
src/org/mxchange/jjobs/model/jobskill/SkillableJobPosition.java
src/org/mxchange/jjobs/model/skill/JobSkill.java
src/org/mxchange/jjobs/model/skill/Skillable.java
src/org/mxchange/jjobs/model/user/skills/SkillableUser.java
src/org/mxchange/jjobs/model/user/skills/UserSkill.java
src/org/mxchange/jjobs/model/utils/SkillUtils.java [new file with mode: 0644]

diff --git a/lib/jcore-utils.jar b/lib/jcore-utils.jar
new file mode 100644 (file)
index 0000000..97e8674
Binary files /dev/null and b/lib/jcore-utils.jar differ
index 534590ae3319f319d03d561b7a98a097650fac48..d109a48d3ceb13afde91244c917373939173705b 100644 (file)
@@ -37,6 +37,7 @@ excludes=
 file.reference.jcontacts-business-core.jar=lib/jcontacts-business-core.jar
 file.reference.jcontacts-core.jar=lib/jcontacts-core.jar
 file.reference.jcore-logger-lib.jar=lib/jcore-logger-lib.jar
+file.reference.jcore-utils.jar=lib/jcore-utils.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
@@ -47,12 +48,14 @@ jar.compress=false
 jar.index=${jnlp.enabled}
 javac.classpath=\
     ${file.reference.jcoreee.jar}:\
+    ${file.reference.jcore-utils.jar}:\
     ${file.reference.jcore-logger-lib.jar}:\
     ${file.reference.jcountry-core.jar}:\
     ${file.reference.jphone-core.jar}:\
     ${file.reference.juser-core.jar}:\
     ${file.reference.jcontacts-core.jar}:\
     ${file.reference.jcontacts-business-core.jar}:\
+    ${libs.commons-lang3.classpath}:\
     ${libs.jpa20-persistence.classpath}:\
     ${libs.javaee-api-7.0.classpath}
 # Space-separated list of extra javac options
@@ -125,6 +128,7 @@ source.encoding=UTF-8
 source.reference.jcontacts-business-core.jar=../jcore-business-core/src/
 source.reference.jcontacts-core.jar=../jcontacts-core/src/
 source.reference.jcore-logger-lib.jar=../jcore-logger-lib/src/
+source.reference.jcore-utils.jar=../jcore-utils/src/
 source.reference.jcoreee.jar=../jcoreee/src/
 source.reference.jcountry-core.jar=../jcountry-core/src/
 source.reference.jphone-core.jar=../jphone-core/src/
index 410ae68680774c0d4a93c5d35056390f4376e066..adcc4a1e0bdc9eb8d280216f763ef16e99328ef1 100644 (file)
@@ -34,10 +34,15 @@ import javax.persistence.TemporalType;
 import javax.persistence.Transient;
 import org.mxchange.jcontactsbusiness.model.jobposition.EmployeePosition;
 import org.mxchange.jcontactsbusiness.model.jobposition.HireableJobPosition;
+import org.mxchange.jcontactsbusiness.model.utils.JobPositionUtils;
+import org.mxchange.jcoreutils.comparable.ComparableUtils;
+import org.mxchange.jcoreutils.number.SafeNumberUtils;
 import org.mxchange.jjobs.model.skill.JobSkill;
 import org.mxchange.jjobs.model.skill.Skillable;
+import org.mxchange.jjobs.model.utils.SkillUtils;
 import org.mxchange.jusercore.model.user.LoginUser;
 import org.mxchange.jusercore.model.user.User;
+import org.mxchange.jusercore.model.utils.UserUtils;
 
 /**
  * A POJO entity for job position skills (linking job position and skill
@@ -157,6 +162,38 @@ public class JobPositionSkill implements SkillableJobPosition {
                this.skillImportance = skillImportance;
        }
 
+       @Override
+       public int compareTo (final SkillableJobPosition skillableJobPosition) {
+               // Checkparameter and return 0 if equal
+               if (null == skillableJobPosition) {
+                       // Should not happen
+                       throw new NullPointerException("Parameter 'skillableJobPosition' is null"); //NOI18N
+               } else if (Objects.equals(this, skillableJobPosition)) {
+                       // Same object
+                       return 0;
+               }
+
+               // Init comparitors
+               final int comparitors[] = {
+                       // First compare job position
+                       JobPositionUtils.compare(this.getJobPosition(), skillableJobPosition.getJobPosition()),
+                       // ... next skill
+                       SkillUtils.compare(this.getJobSkill(), skillableJobPosition.getJobSkill()),
+                       // next job importance
+                       SafeNumberUtils.compare(this.getSkillImportance(), skillableJobPosition.getSkillImportance()),
+                       // ... next user
+                       UserUtils.compare(this.getSkillAddedUser(), skillableJobPosition.getSkillAddedUser()),
+                       // ... next primary key
+                       SafeNumberUtils.compare(this.getJobPositionSkillId(), skillableJobPosition.getJobPositionSkillId())
+               };
+
+               // Check all values
+               final int comparison = ComparableUtils.checkAll(comparitors);
+
+               // Return value
+               return comparison;
+       }
+
        @Override
        public boolean equals (final Object object) {
                if (this == object) {
index 02878987e62decea45f29ba46df8a52e8d852f51..de28f035cdc11e839116c2f529bfff6cc1cc59d7 100644 (file)
@@ -27,7 +27,7 @@ import org.mxchange.jusercore.model.user.User;
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
-public interface SkillableJobPosition extends Serializable {
+public interface SkillableJobPosition extends Comparable<SkillableJobPosition>, Serializable {
 
        /**
         * Getter for job position skill id number
index 963b74402750e9d41880cd0fca28be3129d7b124..f479d10d209bac021de816ff6110430d06e3d41c 100644 (file)
@@ -30,6 +30,9 @@ import javax.persistence.Table;
 import javax.persistence.Temporal;
 import javax.persistence.TemporalType;
 import javax.persistence.Transient;
+import org.apache.commons.lang3.StringUtils;
+import org.mxchange.jcoreutils.comparable.ComparableUtils;
+import org.mxchange.jcoreutils.enums.EnumUtils;
 import org.mxchange.jjobs.model.skill.status.SkillStatus;
 
 /**
@@ -129,6 +132,32 @@ public class JobSkill implements Skillable {
                this.skillStatus = skillStatus;
        }
 
+       @Override
+       public int compareTo (final Skillable skill) {
+               // Checkparameter and return 0 if equal
+               if (null == skill) {
+                       // Should not happen
+                       throw new NullPointerException("Parameter 'skill' is null"); //NOI18N
+               } else if (Objects.equals(this, skill)) {
+                       // Same object
+                       return 0;
+               }
+
+               // Init comparitors
+               final int comparitors[] = {
+                       // First compare status
+                       EnumUtils.compare(this.getSkillStatus(), skill.getSkillStatus()),
+                       // ... next name
+                       StringUtils.compare(this.getSkillName(), skill.getSkillName())
+               };
+
+               // Check all values
+               final int comparison = ComparableUtils.checkAll(comparitors);
+
+               // Return value
+               return comparison;
+       }
+
        @Override
        public boolean equals (final Object object) {
                if (this == object) {
index 362856236a15321e5b69b9104ca859776e59a897..3ebc78055f9f2f6a74f508e26dc5a20140ab3a24 100644 (file)
  */
 package org.mxchange.jjobs.model.skill;
 
-import org.mxchange.jjobs.model.skill.status.SkillStatus;
 import java.io.Serializable;
 import java.util.Date;
+import org.mxchange.jjobs.model.skill.status.SkillStatus;
 
 /**
  * A POJI for skills (hard and soft)
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
-public interface Skillable extends Serializable {
+public interface Skillable extends Comparable<Skillable>, Serializable {
 
        /**
         * Getter for skill id
index 3f2116f2afe1df2fc975fbc3f6ba959ba1906975..00512f3abdb0254c2f08f8911a7522f6c0d9c637 100644 (file)
@@ -26,7 +26,7 @@ import org.mxchange.jusercore.model.user.User;
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
-public interface SkillableUser extends Serializable {
+public interface SkillableUser extends Comparable<SkillableUser>, Serializable {
 
        /**
         * Getter for user skill id number
index aa089b3bdfe5e8dfc0de0db4feeedc86d518b9c8..87d37ccb3eb3dd98e7a5c85921586a45912ca5dd 100644 (file)
@@ -31,10 +31,14 @@ import javax.persistence.OneToOne;
 import javax.persistence.Table;
 import javax.persistence.Temporal;
 import javax.persistence.TemporalType;
+import org.mxchange.jcoreutils.comparable.ComparableUtils;
+import org.mxchange.jcoreutils.number.SafeNumberUtils;
 import org.mxchange.jjobs.model.skill.JobSkill;
 import org.mxchange.jjobs.model.skill.Skillable;
+import org.mxchange.jjobs.model.utils.SkillUtils;
 import org.mxchange.jusercore.model.user.LoginUser;
 import org.mxchange.jusercore.model.user.User;
+import org.mxchange.jusercore.model.utils.UserUtils;
 
 /**
  * A POJO entity for user skills
@@ -133,6 +137,34 @@ public class UserSkill implements SkillableUser {
                this.skillUser = skillUser;
        }
 
+       @Override
+       public int compareTo (final SkillableUser user) {
+               // Checkparameter and return 0 if equal
+               if (null == user) {
+                       // Should not happen
+                       throw new NullPointerException("Parameter 'user' is null"); //NOI18N
+               } else if (Objects.equals(this, user)) {
+                       // Same object
+                       return 0;
+               }
+
+               // Init comparitors
+               final int comparitors[] = {
+                       // First compare user
+                       UserUtils.compare(this.getSkillUser(), user.getSkillUser()),
+                       // Next skill
+                       SkillUtils.compare(this.getJobSkill(), user.getJobSkill()),
+                       // Primary key
+                       SafeNumberUtils.compare(this.getUserSkillId(), user.getUserSkillId())
+               };
+
+               // Check all values
+               final int comparison = ComparableUtils.checkAll(comparitors);
+
+               // Return value
+               return comparison;
+       }
+
        @Override
        public boolean equals (final Object object) {
                if (this == object) {
diff --git a/src/org/mxchange/jjobs/model/utils/SkillUtils.java b/src/org/mxchange/jjobs/model/utils/SkillUtils.java
new file mode 100644 (file)
index 0000000..0549b65
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2023 Roland Häder<roland@mxchange.org>
+ *
+ * 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.jjobs.model.utils;
+
+import java.util.Objects;
+import org.mxchange.jjobs.model.skill.Skillable;
+
+/**
+ * Utilities class for skills to learn and practice
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public class SkillUtils {
+
+       /**
+        * Compares two skills with each other
+        * <p>
+        * @param skill1 Skill instance 1
+        * @param skill2 Skill instance 2
+        * <p>
+        * @return Comparison value
+        */
+       public static int compare (final Skillable skill1, final Skillable skill2) {
+               // Check equality, then at least first must be given
+               if (Objects.equals(skill1, skill2)) {
+                       // Both are same
+                       return 0;
+               } else if (null == skill1) {
+                       // First is null
+                       return -1;
+               } else if (null == skill2) {
+                       // Second is null
+                       return 1;
+               }
+
+               // Invoke compare() method
+               return skill1.compareTo(skill2);
+       }
+
+       /**
+        * Utilities classes don't have constructors
+        */
+       private SkillUtils () {
+       }
+}