]> git.mxchange.org Git - jjobs-core.git/commitdiff
Please cherry-pick:
authorRoland Häder <haeder@ambroox.de>
Tue, 11 Feb 2020 15:09:19 +0000 (16:09 +0100)
committerRoland Häder <roland@mxchange.org>
Fri, 14 Feb 2020 23:12:56 +0000 (00:12 +0100)
- added default construtors
- added constructors with required entity properties
- added missing equals()/hashCode() methods (ALWAYS implement both!)

src/org/mxchange/jjobs/model/jobskill/JobPositionSkill.java
src/org/mxchange/jjobs/model/skill/JobSkill.java
src/org/mxchange/jjobs/model/user/skills/UserSkill.java

index d7607eed4f5bdec29133aa424fe5c38fdde0fb38..872a383bcd84853bf60b8e979a4c5c88c9e5c206 100644 (file)
@@ -90,13 +90,12 @@ public class JobPositionSkill implements SkillableJobPosition {
        /**
         * Link to skill entity
         */
-       @JoinColumn(name = "skill_job_skill_id", nullable = false,updatable = false, referencedColumnName = "skill_id")
+       @JoinColumn (name = "skill_job_skill_id", nullable = false, updatable = false, referencedColumnName = "skill_id")
        @OneToOne (cascade = CascadeType.REFRESH, targetEntity = JobSkill.class)
        private Skillable jobSkill;
 
        /**
-        * User added this skill (optional as administrators can add skills,
-        * too)
+        * User added this skill (optional as administrators can add skills, too)
         */
        @JoinColumn (name = "skill_job_user_id", referencedColumnName = "user_id")
        @OneToOne (cascade = CascadeType.REFRESH, targetEntity = LoginUser.class)
@@ -109,6 +108,30 @@ public class JobPositionSkill implements SkillableJobPosition {
        @Column (name = "skill_job_importance", nullable = false)
        private Short skillImportance;
 
+       /**
+        * Default constructor, required for the JPA.
+        */
+       public JobPositionSkill () {
+               // Nothing to do here
+       }
+
+       /**
+        * Constructor with all required entity properties
+        * <p>
+        * @param jobPosition An instance of a HireableJobPosition class
+        * @param jobSkill An instance of a Skillable class
+        * @param skillImportance Importance level
+        */
+       public JobPositionSkill (final HireableJobPosition jobPosition, final Skillable jobSkill, final Short skillImportance) {
+               // Invoke default constructor
+               this();
+
+               // Set fields
+               this.jobPosition = jobPosition;
+               this.jobSkill = jobSkill;
+               this.skillImportance = skillImportance;
+       }
+
        @Override
        public boolean equals (final Object object) {
                if (this == object) {
@@ -119,11 +142,15 @@ public class JobPositionSkill implements SkillableJobPosition {
                        return false;
                }
 
-               final SkillableJobPosition other = (SkillableJobPosition) object;
+               final SkillableJobPosition jobPosition = (SkillableJobPosition) object;
 
-               if (!Objects.equals(this.getJobPositionSkillId(), other.getJobPositionSkillId())) {
+               if (!Objects.equals(this.getSkillImportance(), jobPosition.getSkillImportance())) {
                        return false;
-               } else if (!Objects.equals(this.getSkillImportance(), other.getSkillImportance())) {
+               } else if (!Objects.equals(this.getJobPosition(), jobPosition.getJobPosition())) {
+                       return false;
+               } else if (!Objects.equals(this.getJobSkill(), jobPosition.getJobSkill())) {
+                       return false;
+               } else if (!Objects.equals(this.getJobPositionSkillId(), jobPosition.getJobPositionSkillId())) {
                        return false;
                }
 
@@ -208,8 +235,10 @@ public class JobPositionSkill implements SkillableJobPosition {
        public int hashCode () {
                int hash = 5;
 
-               hash = 41 * hash + Objects.hashCode(this.getJobPositionSkillId());
+               hash = 41 * hash + Objects.hashCode(this.getJobPosition());
+               hash = 41 * hash + Objects.hashCode(this.getJobSkill());
                hash = 41 * hash + Objects.hashCode(this.getSkillImportance());
+               hash = 41 * hash + Objects.hashCode(this.getJobPositionSkillId());
 
                return hash;
        }
index f1dda2c74d9e72b37d393a56512daf1fcfe72715..f3774ba1f2df4d72ab38c45a6feb383f6beaa25a 100644 (file)
@@ -95,6 +95,40 @@ public class JobSkill implements Skillable {
        @Temporal (TemporalType.TIMESTAMP)
        private Date skillUpdated;
 
+       /**
+        * Default constructor, required for the JPA.
+        */
+       public JobSkill () {
+               // Nothing to do here
+       }
+
+       /**
+        * Constructor with required fields
+        * <p>
+        * @param skillName Name of skill
+        * @param skillStatus Status
+        */
+       public JobSkill (final String skillName, final SkillStatus skillStatus) {
+               // Call default constructor (always and regardless)
+               this();
+
+               // Validate parameter
+               if (null == skillName) {
+                       // Throw NPE
+                       throw new NullPointerException("skillName is null"); //NOI18N
+               } else if (skillName.isEmpty()) {
+                       // Throw IAE
+                       throw new IllegalArgumentException("skillName is empty"); //NOI18N
+               } else if (null == skillStatus) {
+                       // Throw NPE
+                       throw new NullPointerException("skillStatus is null"); //NOI18N
+               }
+
+               // Set fields
+               this.skillName = skillName;
+               this.skillStatus = skillStatus;
+       }
+
        @Override
        public boolean equals (final Object object) {
                if (this == object) {
@@ -105,11 +139,13 @@ public class JobSkill implements Skillable {
                        return false;
                }
 
-               final Skillable other = (Skillable) object;
+               final Skillable skill = (Skillable) object;
 
-               if (!Objects.equals(this.getSkillName(), other.getSkillName())) {
+               if (!Objects.equals(this.getSkillStatus(), skill.getSkillStatus())) {
+                       return false;
+               } else if (!Objects.equals(this.getSkillName(), skill.getSkillName())) {
                        return false;
-               } else if (!Objects.equals(this.getSkillId(), other.getSkillId())) {
+               } else if (!Objects.equals(this.getSkillId(), skill.getSkillId())) {
                        return false;
                }
 
@@ -188,6 +224,7 @@ public class JobSkill implements Skillable {
 
                hash = 97 * hash + Objects.hashCode(this.getSkillId());
                hash = 97 * hash + Objects.hashCode(this.getSkillName());
+               hash = 97 * hash + Objects.hashCode(this.getSkillStatus());
 
                return hash;
        }
index 326dd825337d8887d036a49f94af6cf202bf8c23..b4b61c613a42173b9f7b1a85d5398899bfb59f7f 100644 (file)
@@ -19,6 +19,7 @@ package org.mxchange.jjobs.model.user.skills;
 import org.mxchange.jjobs.model.skill.JobSkill;
 import org.mxchange.jjobs.model.skill.Skillable;
 import java.util.Date;
+import java.util.Objects;
 import javax.persistence.Basic;
 import javax.persistence.CascadeType;
 import javax.persistence.Column;
@@ -88,6 +89,71 @@ public class UserSkill implements SkillableUser {
        @Temporal (TemporalType.TIMESTAMP)
        private Date userSkillUpdated;
 
+       /**
+        * Default constructor, required for the EJB
+        */
+       public UserSkill () {
+               // Empty by default
+       }
+
+       /**
+        * Constructor with all required entity properties
+        * <p>
+        * @param jobSkill An instance of a Skillable class
+        * @param skillUser An instance of a User class
+        */
+       public UserSkill (final Skillable jobSkill, final User skillUser) {
+               // Invoke default constructor
+               this();
+
+               // Validate parameter
+               if (null == jobSkill) {
+                       // Throw NPE
+                       throw new NullPointerException("jobSkill is null"); //NOI18N
+               } else if (null == skillUser) {
+                       // Throw NPE
+                       throw new NullPointerException("skillUser is null"); //NOI18N
+               }
+
+               // Set fields
+               this.jobSkill = jobSkill;
+               this.skillUser = skillUser;
+       }
+
+       @Override
+       public boolean equals (final Object object) {
+               if (this == object) {
+                       return true;
+               } else if (object == null) {
+                       return false;
+               } else if (getClass() != object.getClass()) {
+                       return false;
+               }
+
+               final SkillableUser skillableUser = (SkillableUser) object;
+
+               if (!Objects.equals(this.getJobSkill(), skillableUser.getJobSkill())) {
+                       return false;
+               } else if (!Objects.equals(this.getSkillUser(), skillableUser.getSkillUser())) {
+                       return false;
+               } else if (!Objects.equals(this.getUserSkillId(), skillableUser.getUserSkillId())) {
+                       return false;
+               }
+
+               return true;
+       }
+
+       @Override
+       public int hashCode () {
+               int hash = 7;
+
+               hash = 17 * hash + Objects.hashCode(this.getJobSkill());
+               hash = 17 * hash + Objects.hashCode(this.getSkillUser());
+               hash = 17 * hash + Objects.hashCode(this.getUserSkillId());
+
+               return hash;
+       }
+
        @Override
        public Skillable getJobSkill () {
                return this.jobSkill;