]> git.mxchange.org Git - jjobs-core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Thu, 19 Jan 2023 06:25:40 +0000 (07:25 +0100)
committerRoland Häder <roland@mxchange.org>
Thu, 19 Jan 2023 06:25:40 +0000 (07:25 +0100)
- added event class/interface for when an administrator has updated a skill
- added exception when a skill has already been found
- added missing utilities method SkillUtils.copySkillData()

src/org/mxchange/jjobs/events/skill/add/AdminAddedSkillEvent.java
src/org/mxchange/jjobs/events/skill/update/AdminUpdatedSkillEvent.java [new file with mode: 0644]
src/org/mxchange/jjobs/events/skill/update/ObservableAdminUpdatedSkillEvent.java [new file with mode: 0644]
src/org/mxchange/jjobs/exceptions/SkillAlreadyAddedException.java [new file with mode: 0644]
src/org/mxchange/jjobs/model/utils/SkillUtils.java

index d36462784ee9eec6407f37a97ae1bc89e18b854a..b2953257a5f2b919707167255664f555331335a1 100644 (file)
@@ -37,7 +37,7 @@ public class AdminAddedSkillEvent implements ObservableAdminAddedSkillEvent {
        private final Skillable skillable;
 
        /**
-        * Constrcutor with skill instance
+        * Constructor with skill instance
         * <p>
         * @param skillable An instance of a Skillable class
         */
diff --git a/src/org/mxchange/jjobs/events/skill/update/AdminUpdatedSkillEvent.java b/src/org/mxchange/jjobs/events/skill/update/AdminUpdatedSkillEvent.java
new file mode 100644 (file)
index 0000000..96ea965
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2023 Roland Häder<roland@mxchange.org>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jjobs.events.skill.update;
+
+import java.text.MessageFormat;
+import org.mxchange.jjobs.model.skill.Skillable;
+
+/**
+ * An event being fired when an administrator has added a new skill
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public class AdminUpdatedSkillEvent implements ObservableAdminUpdatedSkillEvent {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 14_785_787_174_600_002L;
+
+       /**
+        * Instance of added skillable
+        */
+       private final Skillable skillable;
+
+       /**
+        * Constructor with skill instance
+        * <p>
+        * @param skillable An instance of a Skillable class
+        */
+       public AdminUpdatedSkillEvent (final Skillable skillable) {
+               // Validate parameter
+               if (null == skillable) {
+                       // Throw NPE
+                       throw new NullPointerException("Parameter 'skillable' is null"); //NOI18N
+               } else if (skillable.getSkillId() == null) {
+                       // Throw it again
+                       throw new NullPointerException("skillable.skillId is null"); //NOI18N
+               } else if (skillable.getSkillId() < 1) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("skillable.skillId={0} is invalid", skillable.getSkillId())); //NOI18N
+               }
+
+               // Set it here
+               this.skillable = skillable;
+       }
+
+       @Override
+       public Skillable getSkillable () {
+               return this.skillable;
+       }
+}
diff --git a/src/org/mxchange/jjobs/events/skill/update/ObservableAdminUpdatedSkillEvent.java b/src/org/mxchange/jjobs/events/skill/update/ObservableAdminUpdatedSkillEvent.java
new file mode 100644 (file)
index 0000000..90aa217
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2023 Roland Häder<roland@mxchange.org>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jjobs.events.skill.update;
+
+import java.io.Serializable;
+import org.mxchange.jjobs.model.skill.Skillable;
+
+/**
+ * An interface for events being fired when an administrator has added a skill
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface ObservableAdminUpdatedSkillEvent extends Serializable {
+
+       /**
+        * Getter for Skillable class field
+        * <p>
+        * @return An instance of a Skillable class
+        */
+       Skillable getSkillable ();
+
+}
diff --git a/src/org/mxchange/jjobs/exceptions/SkillAlreadyAddedException.java b/src/org/mxchange/jjobs/exceptions/SkillAlreadyAddedException.java
new file mode 100644 (file)
index 0000000..1e63e92
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2023 Roland Häder<roland@mxchange.org>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jjobs.exceptions;
+
+/**
+ * An exception being thrown when a skill instance has already been found
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public class SkillAlreadyAddedException extends Exception {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 42_895_928_956_700_002L;
+
+}
index 0549b65857317348e1acaee7d615b78a4159aa5a..2a57e2ec270e0ae603fa43ee65e73cbb374d0ff5 100644 (file)
@@ -51,6 +51,33 @@ public class SkillUtils {
                return skill1.compareTo(skill2);
        }
 
+       /**
+        * Copies all fields exception created/updated timestamps from source
+        * Skillable instance to target instance all fields.
+        * <p>
+        * @param sourceSkillable Source instance of a Skillable class
+        * @param targetSkillable Target instance of a Skillable class
+        */
+       public static void copySkillData (final Skillable sourceSkillable, final Skillable targetSkillable) {
+               // Check that both parameters are not null
+               if (null == sourceSkillable) {
+                       // Throw NPE
+                       throw new NullPointerException("sourceSkillable is null"); //NOI18N
+               } else if (null == targetSkillable) {
+                       // Throw NPE
+                       throw new NullPointerException("targetSkillable is null"); //NOI18N
+               } else if (Objects.equals(sourceSkillable, targetSkillable)) {
+                       // Throw IAE
+                       throw new IllegalArgumentException("sourceSkillable and targetSkillable are the same"); //NOI18N
+               }
+
+               // Copy all fields
+               targetSkillable.setSkillId(sourceSkillable.getSkillId());
+               targetSkillable.setSkillLastLocked(sourceSkillable.getSkillLastLocked());
+               targetSkillable.setSkillName(sourceSkillable.getSkillName());
+               targetSkillable.setSkillStatus(sourceSkillable.getSkillStatus());
+       }
+
        /**
         * Utilities classes don't have constructors
         */