From 6b0db45cc89a9f75d3b641e749d4b1ccf3e793d8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 19 Jan 2023 07:25:40 +0100 Subject: [PATCH] Continued: - 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() --- .../skill/add/AdminAddedSkillEvent.java | 2 +- .../skill/update/AdminUpdatedSkillEvent.java | 65 +++++++++++++++++++ .../ObservableAdminUpdatedSkillEvent.java | 36 ++++++++++ .../SkillAlreadyAddedException.java | 31 +++++++++ .../jjobs/model/utils/SkillUtils.java | 27 ++++++++ 5 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 src/org/mxchange/jjobs/events/skill/update/AdminUpdatedSkillEvent.java create mode 100644 src/org/mxchange/jjobs/events/skill/update/ObservableAdminUpdatedSkillEvent.java create mode 100644 src/org/mxchange/jjobs/exceptions/SkillAlreadyAddedException.java diff --git a/src/org/mxchange/jjobs/events/skill/add/AdminAddedSkillEvent.java b/src/org/mxchange/jjobs/events/skill/add/AdminAddedSkillEvent.java index d364627..b295325 100644 --- a/src/org/mxchange/jjobs/events/skill/add/AdminAddedSkillEvent.java +++ b/src/org/mxchange/jjobs/events/skill/add/AdminAddedSkillEvent.java @@ -37,7 +37,7 @@ public class AdminAddedSkillEvent implements ObservableAdminAddedSkillEvent { private final Skillable skillable; /** - * Constrcutor with skill instance + * Constructor with skill instance *

* @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 index 0000000..96ea965 --- /dev/null +++ b/src/org/mxchange/jjobs/events/skill/update/AdminUpdatedSkillEvent.java @@ -0,0 +1,65 @@ +/* + * 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.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 + *

+ * @author Roland Häder + */ +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 + *

+ * @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 index 0000000..90aa217 --- /dev/null +++ b/src/org/mxchange/jjobs/events/skill/update/ObservableAdminUpdatedSkillEvent.java @@ -0,0 +1,36 @@ +/* + * 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.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 + *

+ * @author Roland Häder + */ +public interface ObservableAdminUpdatedSkillEvent extends Serializable { + + /** + * Getter for Skillable class field + *

+ * @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 index 0000000..1e63e92 --- /dev/null +++ b/src/org/mxchange/jjobs/exceptions/SkillAlreadyAddedException.java @@ -0,0 +1,31 @@ +/* + * 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.exceptions; + +/** + * An exception being thrown when a skill instance has already been found + *

+ * @author Roland Häder + */ +public class SkillAlreadyAddedException extends Exception { + + /** + * Serial number + */ + private static final long serialVersionUID = 42_895_928_956_700_002L; + +} diff --git a/src/org/mxchange/jjobs/model/utils/SkillUtils.java b/src/org/mxchange/jjobs/model/utils/SkillUtils.java index 0549b65..2a57e2e 100644 --- a/src/org/mxchange/jjobs/model/utils/SkillUtils.java +++ b/src/org/mxchange/jjobs/model/utils/SkillUtils.java @@ -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. + *

+ * @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 */ -- 2.39.5