]> git.mxchange.org Git - jjobs-core.git/blobdiff - src/org/mxchange/jjobs/model/jobskill/JobPositionSkill.java
Continued:
[jjobs-core.git] / src / org / mxchange / jjobs / model / jobskill / JobPositionSkill.java
index d7607eed4f5bdec29133aa424fe5c38fdde0fb38..410ae68680774c0d4a93c5d35056390f4376e066 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016 - 2020 Free Software Foundation
+ * Copyright (C) 2016 - 2022 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
@@ -16,6 +16,7 @@
  */
 package org.mxchange.jjobs.model.jobskill;
 
+import java.text.MessageFormat;
 import java.util.Date;
 import java.util.Objects;
 import javax.persistence.Basic;
@@ -68,9 +69,9 @@ public class JobPositionSkill implements SkillableJobPosition {
         * When this entry has been created
         */
        @Basic (optional = false)
-       @Column (name = "skill_job_created", nullable = false, updatable = false)
+       @Column (name = "skill_job_entry_created", nullable = false, updatable = false)
        @Temporal (TemporalType.TIMESTAMP)
-       private Date jobPositionSkillCreated;
+       private Date jobPositionSkillEntryCreated;
 
        /**
         * Id number (primary key
@@ -90,13 +91,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 +109,54 @@ 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();
+
+               // Validate all parameter
+               if (null == jobPosition) {
+                       // ThroW NPE
+                       throw new NullPointerException("jobPosition is null"); //NOI18N
+               } else if (jobPosition.getJobPositionId() == null) {
+                       // Throw it again
+                       throw new NullPointerException("jobPosition.jobPositionId is null"); //NOI18N
+               } else if (jobPosition.getJobPositionId() < 1) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("jobPosition.jobPositionId={0} is invalid", jobPosition.getJobPositionId())); //NOI18N
+               } else if (null == jobSkill) {
+                       // Throw NPE
+                       throw new NullPointerException("jobSill is null"); //NOI18N
+               } else if (jobSkill.getSkillId() == null) {
+                       // Throw it again
+                       throw new NullPointerException("jobSill.skillId is null"); //NOI18N
+               } else if (jobSkill.getSkillId() < 1) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("jobSill.skillId={0} is invalid", jobSkill.getSkillId())); //NOI18N
+               } else if (null == skillImportance) {
+                       // Throw NPE
+                       throw new NullPointerException("skillImportance is null"); //NOI18N
+               }
+
+               // Set fields
+               this.jobPosition = jobPosition;
+               this.jobSkill = jobSkill;
+               this.skillImportance = skillImportance;
+       }
+
        @Override
        public boolean equals (final Object object) {
                if (this == object) {
@@ -119,14 +167,21 @@ public class JobPositionSkill implements SkillableJobPosition {
                        return false;
                }
 
-               final SkillableJobPosition other = (SkillableJobPosition) object;
+               // Cast to wanted type
+               final SkillableJobPosition position = (SkillableJobPosition) object;
 
-               if (!Objects.equals(this.getJobPositionSkillId(), other.getJobPositionSkillId())) {
+               // Check all false conditions
+               if (!Objects.equals(this.getSkillImportance(), position.getSkillImportance())) {
                        return false;
-               } else if (!Objects.equals(this.getSkillImportance(), other.getSkillImportance())) {
+               } else if (!Objects.equals(this.getJobPosition(), position.getJobPosition())) {
+                       return false;
+               } else if (!Objects.equals(this.getJobSkill(), position.getJobSkill())) {
+                       return false;
+               } else if (!Objects.equals(this.getJobPositionSkillId(), position.getJobPositionSkillId())) {
                        return false;
                }
 
+               // Okay, entities are matching (not objects)
                return true;
        }
 
@@ -142,14 +197,14 @@ public class JobPositionSkill implements SkillableJobPosition {
 
        @Override
        @SuppressWarnings ("ReturnOfDateField")
-       public Date getJobPositionSkillCreated () {
-               return this.jobPositionSkillCreated;
+       public Date getJobPositionSkillEntryCreated () {
+               return this.jobPositionSkillEntryCreated;
        }
 
        @Override
        @SuppressWarnings ("AssignmentToDateFieldFromParameter")
-       public void setJobPositionSkillCreated (final Date jobPositionSkillCreated) {
-               this.jobPositionSkillCreated = jobPositionSkillCreated;
+       public void setJobPositionSkillEntryCreated (final Date jobPositionSkillEntryCreated) {
+               this.jobPositionSkillEntryCreated = jobPositionSkillEntryCreated;
        }
 
        @Override
@@ -208,8 +263,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;
        }