From: Roland Häder Date: Thu, 19 Jan 2023 02:52:20 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=a869ce17e9696725e0ea1c287a81b50ec81005e9;p=jjobs-core.git Continued: - implemented java.lang.Comparable 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 --- diff --git a/lib/jcore-utils.jar b/lib/jcore-utils.jar new file mode 100644 index 0000000..97e8674 Binary files /dev/null and b/lib/jcore-utils.jar differ diff --git a/nbproject/project.properties b/nbproject/project.properties index 534590a..d109a48 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -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/ diff --git a/src/org/mxchange/jjobs/model/jobskill/JobPositionSkill.java b/src/org/mxchange/jjobs/model/jobskill/JobPositionSkill.java index 410ae68..adcc4a1 100644 --- a/src/org/mxchange/jjobs/model/jobskill/JobPositionSkill.java +++ b/src/org/mxchange/jjobs/model/jobskill/JobPositionSkill.java @@ -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) { diff --git a/src/org/mxchange/jjobs/model/jobskill/SkillableJobPosition.java b/src/org/mxchange/jjobs/model/jobskill/SkillableJobPosition.java index 0287898..de28f03 100644 --- a/src/org/mxchange/jjobs/model/jobskill/SkillableJobPosition.java +++ b/src/org/mxchange/jjobs/model/jobskill/SkillableJobPosition.java @@ -27,7 +27,7 @@ import org.mxchange.jusercore.model.user.User; *

* @author Roland Häder */ -public interface SkillableJobPosition extends Serializable { +public interface SkillableJobPosition extends Comparable, Serializable { /** * Getter for job position skill id number diff --git a/src/org/mxchange/jjobs/model/skill/JobSkill.java b/src/org/mxchange/jjobs/model/skill/JobSkill.java index 963b744..f479d10 100644 --- a/src/org/mxchange/jjobs/model/skill/JobSkill.java +++ b/src/org/mxchange/jjobs/model/skill/JobSkill.java @@ -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) { diff --git a/src/org/mxchange/jjobs/model/skill/Skillable.java b/src/org/mxchange/jjobs/model/skill/Skillable.java index 3628562..3ebc780 100644 --- a/src/org/mxchange/jjobs/model/skill/Skillable.java +++ b/src/org/mxchange/jjobs/model/skill/Skillable.java @@ -16,16 +16,16 @@ */ 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) *

* @author Roland Häder */ -public interface Skillable extends Serializable { +public interface Skillable extends Comparable, Serializable { /** * Getter for skill id diff --git a/src/org/mxchange/jjobs/model/user/skills/SkillableUser.java b/src/org/mxchange/jjobs/model/user/skills/SkillableUser.java index 3f2116f..00512f3 100644 --- a/src/org/mxchange/jjobs/model/user/skills/SkillableUser.java +++ b/src/org/mxchange/jjobs/model/user/skills/SkillableUser.java @@ -26,7 +26,7 @@ import org.mxchange.jusercore.model.user.User; *

* @author Roland Häder */ -public interface SkillableUser extends Serializable { +public interface SkillableUser extends Comparable, Serializable { /** * Getter for user skill id number diff --git a/src/org/mxchange/jjobs/model/user/skills/UserSkill.java b/src/org/mxchange/jjobs/model/user/skills/UserSkill.java index aa089b3..87d37cc 100644 --- a/src/org/mxchange/jjobs/model/user/skills/UserSkill.java +++ b/src/org/mxchange/jjobs/model/user/skills/UserSkill.java @@ -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 index 0000000..0549b65 --- /dev/null +++ b/src/org/mxchange/jjobs/model/utils/SkillUtils.java @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2023 Roland Häder + * + * 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 . + */ +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 + *

+ * @author Roland Häder + */ +public class SkillUtils { + + /** + * Compares two skills with each other + *

+ * @param skill1 Skill instance 1 + * @param skill2 Skill instance 2 + *

+ * @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 () { + } +}