From a869ce17e9696725e0ea1c287a81b50ec81005e9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 19 Jan 2023 03:52:20 +0100 Subject: [PATCH] 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 --- lib/jcore-utils.jar | Bin 0 -> 8416 bytes nbproject/project.properties | 4 ++ .../model/jobskill/JobPositionSkill.java | 37 +++++++++++ .../model/jobskill/SkillableJobPosition.java | 2 +- .../mxchange/jjobs/model/skill/JobSkill.java | 29 +++++++++ .../mxchange/jjobs/model/skill/Skillable.java | 4 +- .../model/user/skills/SkillableUser.java | 2 +- .../jjobs/model/user/skills/UserSkill.java | 32 ++++++++++ .../jjobs/model/utils/SkillUtils.java | 59 ++++++++++++++++++ 9 files changed, 165 insertions(+), 4 deletions(-) create mode 100644 lib/jcore-utils.jar create mode 100644 src/org/mxchange/jjobs/model/utils/SkillUtils.java diff --git a/lib/jcore-utils.jar b/lib/jcore-utils.jar new file mode 100644 index 0000000000000000000000000000000000000000..97e8674869d4b24ed517731010615099ef93c9f9 GIT binary patch literal 8416 zcmb_hO>7&-6@E*KqO_s>7um66TVBa_BFg*`Wye3VEQgY%n6@OVCgoHO&|pQ4sCCGt zx?I{;S~N(JL)rlCq3xk*l0y-+hZ-$cW6JYYE*J>&cmI2tXp0IeY4Sa;pkOSHzm3o5{?&Sj%MU8Ew>Qh!3a(s)z5t zJ5;JC-Sj0@2TGpu+cHXmJnLLx?$hdEuqa<>n6+q|5Vk&rcu+jtZK>9 zD;jP$xM$7nIjL<|>snDaHA}1;HQO@Q>bB4fThq<;bk))-z_GEdq5&F(rP*+7TUeEv zR^5;fFD$KSF9=gudRbepua%9WwqO*6SreL$ak-_oDb}^MZIxv^;Y?`4z!Z z09RW=t6J))ZZlv@t8Ve+;y}5rm9gGUxzx@Hd-Gb?3{!&MtZrc%o6v@d-8IT(ZB1zP zn%Jn96DlmAy_hRpy|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b1vIJrvL%7=kZ&CfB;*FaCS-Sb4kc#P$Z@^P&5D1n2QofBxc_w-bMAGLR<2?TaCJ5{r7g0;1$dKdVs alj`;rNMnQumW&WGd*~0~k5Bo~kNyumaqGVT literal 0 HcmV?d00001 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 () { + } +} -- 2.39.5