]> git.mxchange.org Git - jjobs-core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Thu, 19 Jan 2023 07:00:12 +0000 (08:00 +0100)
committerRoland Häder <roland@mxchange.org>
Thu, 19 Jan 2023 07:00:12 +0000 (08:00 +0100)
- added new method SkillUtils.isSameSkill()
- added some constructors to exceptions

src/org/mxchange/jjobs/exceptions/SkillAlreadyAddedException.java
src/org/mxchange/jjobs/exceptions/SkillNotFoundException.java
src/org/mxchange/jjobs/model/utils/SkillUtils.java

index 1e63e920d97390b9651d59d812d8c734a1ac0197..7a0246864d96e4bc8e1fb41a95f16b1a4228a21c 100644 (file)
@@ -16,6 +16,9 @@
  */
 package org.mxchange.jjobs.exceptions;
 
+import java.text.MessageFormat;
+import org.mxchange.jjobs.model.skill.Skillable;
+
 /**
  * An exception being thrown when a skill instance has already been found
  * <p>
@@ -28,4 +31,14 @@ public class SkillAlreadyAddedException extends Exception {
         */
        private static final long serialVersionUID = 42_895_928_956_700_002L;
 
+       /**
+        * Constructor with a Skillable class
+        * <p>
+        * @param skill An instance of a Skillable class
+        */
+       public SkillAlreadyAddedException (final Skillable skill) {
+               // Construct message and invoke super
+               super(MessageFormat.format("Skill with id={0},name={1} already added", skill.getSkillId(), skill.getSkillName()));
+       }
+
 }
index 1cf8687ceb97c2a5bfd53f442d6b67485a8c5828..0dd46d44b5aeefa65df4674bffa1bab3c81831bb 100644 (file)
@@ -17,6 +17,7 @@
 package org.mxchange.jjobs.model.exceptions;
 
 import java.text.MessageFormat;
+import org.mxchange.jjobs.model.skill.Skillable;
 
 /**
  * An exception thrown when a Skillable instance wasn't found
@@ -39,4 +40,14 @@ public class SkillNotFoundException extends Exception {
                super(MessageFormat.format("Skill id {0} not found.", skillId)); //NOI18N
        }
 
+       /**
+        * Constructor with Skillable instance
+        * <p>
+        * @param skillable An instance of a Skillable class
+        */
+       public SkillNotFoundException (final Skillable skillable) {
+               // Construct message and invoke super
+               super(MessageFormat.format("Skill with name={0} not found.", skillable.getSkillName()));
+       }
+
 }
index 2a57e2ec270e0ae603fa43ee65e73cbb374d0ff5..4b42105e476d3c48d3825220b92c8baa638f7c58 100644 (file)
@@ -17,6 +17,7 @@
 package org.mxchange.jjobs.model.utils;
 
 import java.util.Objects;
+import org.apache.commons.lang3.StringUtils;
 import org.mxchange.jjobs.model.skill.Skillable;
 
 /**
@@ -78,6 +79,53 @@ public class SkillUtils {
                targetSkillable.setSkillStatus(sourceSkillable.getSkillStatus());
        }
 
+       /**
+        * Checks if both instances are the same
+        * <p>
+        * @param skillable1 First instance of a Skillable class
+        * @param skillable2 Second instance of a Skillable class
+        * <p>
+        * @return Whether they are the same
+        */
+       public static boolean isSameSkill (final Skillable skillable1, final Skillable skillable2) {
+               // Validate parameter
+               if (null == skillable1) {
+                       // Throw NPE
+                       throw new NullPointerException("Parameter 'skillable1' is null"); // NOI18N
+               } else if (null == skillable2) {
+                       // Throw it again
+                       throw new NullPointerException("Parameter 'skillable2' is null"); // NOI18N
+               } else if (Objects.equals(skillable1, skillable2)) {
+                       // Is the same
+                       return true;
+               } else if (skillable1.getSkillName() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("skillable1.skillName is null"); // NOI18N
+               } else if (skillable1.getSkillName().isEmpty()) {
+                       // Throw IAE
+                       throw new IllegalArgumentException("skillable1.skillName is empty"); // NOI18N
+               } else if (skillable2.getSkillName() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("skillable2.skillName is null"); // NOI18N
+               } else if (skillable2.getSkillName() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("skillable2.skillName is null"); // NOI18N
+               } else if (skillable2.getSkillName().isEmpty()) {
+                       // Throw IAE
+                       throw new IllegalArgumentException("skillable2.skillName is empty"); // NOI18N
+               } else if (skillable1.getSkillStatus() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("skillable1.skillStatus is null"); // NOI18N
+               } else if (skillable2.getSkillStatus() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("skillable2.skillStatus is null"); // NOI18N
+               }
+
+               // Now that all at least required fields are there, let's check them all
+               return ((StringUtils.equals(skillable1.getSkillName(), skillable2.getSkillName())) &&
+                               (skillable1.getSkillStatus().equals(skillable2.getSkillStatus())));
+       }
+
        /**
         * Utilities classes don't have constructors
         */