From ba4b9c17fba0ec883d197516d4b3d3260e8bdb96 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 22 Jan 2023 06:36:49 +0100 Subject: [PATCH] Continued: - moved entity class and interface into one lower package - event classes' constructors now check parameter (not null, valid primary keys) --- .../sharing/EndedAddressbookSharingEvent.java | 43 +++++++++++++++++- .../ObservableAddressbookSharingEvent.java | 7 +-- .../StartedAddressbookSharingEvent.java | 45 ++++++++++++++++++- .../events/sharing/type/SharingType.java | 5 ++- .../shared/AddressbookShare.java | 5 ++- .../shared/ShareableAddressbook.java | 2 +- 6 files changed, 96 insertions(+), 11 deletions(-) rename src/org/mxchange/jaddressbookshare/model/{addressbook => }/shared/AddressbookShare.java (99%) rename src/org/mxchange/jaddressbookshare/model/{addressbook => }/shared/ShareableAddressbook.java (97%) diff --git a/src/org/mxchange/jaddressbookshare/events/sharing/EndedAddressbookSharingEvent.java b/src/org/mxchange/jaddressbookshare/events/sharing/EndedAddressbookSharingEvent.java index cde4094..54eacf9 100644 --- a/src/org/mxchange/jaddressbookshare/events/sharing/EndedAddressbookSharingEvent.java +++ b/src/org/mxchange/jaddressbookshare/events/sharing/EndedAddressbookSharingEvent.java @@ -16,8 +16,9 @@ */ package org.mxchange.jaddressbookshare.events.sharing; +import java.text.MessageFormat; import org.mxchange.jaddressbookshare.events.sharing.type.SharingType; -import org.mxchange.jaddressbookshare.model.addressbook.shared.ShareableAddressbook; +import org.mxchange.jaddressbookshare.model.shared.ShareableAddressbook; /** * An event fired when a user ends sharing address books @@ -42,6 +43,46 @@ public class EndedAddressbookSharingEvent implements ObservableAddressbookSharin * @param share Address book share entry */ public EndedAddressbookSharingEvent (final ShareableAddressbook share) { + // Check parameter + if (null == share) { + // Throw NPE + throw new NullPointerException("Parameter 'share' is null"); //NOI18N + } else if (share.getShareId() == null) { + // Throw NPE again + throw new NullPointerException("share.shareId is null"); //NOI18N + } else if (share.getShareId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("share.shareId={0} is invalid", share.getShareId())); //NOI18N + } else if (share.getShareAddressbook() == null) { + // Throw NPE again + throw new NullPointerException("share.shareAddressbook is null"); //NOI18N + } else if (share.getShareAddressbook().getAddressbookId() == null) { + // ... and again + throw new NullPointerException("share.shareAddressbook.addressbookId is null"); //NOI18N + } else if (share.getShareAddressbook().getAddressbookId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("share.shareAddressbook.addressbookId={0} is invalid", share.getShareAddressbook().getAddressbookId())); //NOI18N + } else if (share.getShareUserOwner() == null) { + // Throw NPE again + throw new NullPointerException("share.shareUserOwner is null"); //NOI18N + } else if (share.getShareUserOwner().getUserId() == null) { + // ... and again + throw new NullPointerException("share.shareUserOwner.userId is null"); //NOI18N + } else if (share.getShareUserOwner().getUserId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("share.shareUserOwner.userId={0} is invalid", share.getShareUserOwner().getUserId())); //NOI18N + } else if (share.getShareUserSharee() == null) { + // Throw NPE again + throw new NullPointerException("share.shareUserSharee is null"); //NOI18N + } else if (share.getShareUserSharee().getUserId() == null) { + // ... and again + throw new NullPointerException("share.shareUserSharee.userId is null"); //NOI18N + } else if (share.getShareUserSharee().getUserId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("share.shareUserSharee.userId={0} is invalid", share.getShareUserSharee().getUserId())); //NOI18N + } + + // Set it in class this.shareableAddressbook = share; } diff --git a/src/org/mxchange/jaddressbookshare/events/sharing/ObservableAddressbookSharingEvent.java b/src/org/mxchange/jaddressbookshare/events/sharing/ObservableAddressbookSharingEvent.java index db8931b..8fb98fa 100644 --- a/src/org/mxchange/jaddressbookshare/events/sharing/ObservableAddressbookSharingEvent.java +++ b/src/org/mxchange/jaddressbookshare/events/sharing/ObservableAddressbookSharingEvent.java @@ -18,7 +18,7 @@ package org.mxchange.jaddressbookshare.events.sharing; import java.io.Serializable; import org.mxchange.jaddressbookshare.events.sharing.type.SharingType; -import org.mxchange.jaddressbookshare.model.addressbook.shared.ShareableAddressbook; +import org.mxchange.jaddressbookshare.model.shared.ShareableAddressbook; /** * An interface for address book sharing events @@ -35,9 +35,10 @@ public interface ObservableAddressbookSharingEvent extends Serializable { ShareableAddressbook getShareableAddressbook (); /** - * Getter for sharing type enum + * Getter for sharing type enumeration *

- * @return Sharing type enum + * @return Sharing type enumeration */ SharingType getSharingType (); + } diff --git a/src/org/mxchange/jaddressbookshare/events/sharing/StartedAddressbookSharingEvent.java b/src/org/mxchange/jaddressbookshare/events/sharing/StartedAddressbookSharingEvent.java index 8748130..0b0419f 100644 --- a/src/org/mxchange/jaddressbookshare/events/sharing/StartedAddressbookSharingEvent.java +++ b/src/org/mxchange/jaddressbookshare/events/sharing/StartedAddressbookSharingEvent.java @@ -16,8 +16,9 @@ */ package org.mxchange.jaddressbookshare.events.sharing; +import java.text.MessageFormat; import org.mxchange.jaddressbookshare.events.sharing.type.SharingType; -import org.mxchange.jaddressbookshare.model.addressbook.shared.ShareableAddressbook; +import org.mxchange.jaddressbookshare.model.shared.ShareableAddressbook; /** * An event fired when a user starts sharing address books @@ -29,7 +30,7 @@ public class StartedAddressbookSharingEvent implements ObservableAddressbookShar /** * Serial number */ - private static final long serialVersionUID = 152_896_748_186_018_497L; + private static final long serialVersionUID = 152_896_748_186_018_498L; /** * Shared address book entry @@ -42,6 +43,46 @@ public class StartedAddressbookSharingEvent implements ObservableAddressbookShar * @param share Address book share entry */ public StartedAddressbookSharingEvent (final ShareableAddressbook share) { + // Check parameter + if (null == share) { + // Throw NPE + throw new NullPointerException("Parameter 'share' is null"); //NOI18N + } else if (share.getShareId() == null) { + // Throw NPE again + throw new NullPointerException("share.shareId is null"); //NOI18N + } else if (share.getShareId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("share.shareId={0} is invalid", share.getShareId())); //NOI18N + } else if (share.getShareAddressbook() == null) { + // Throw NPE again + throw new NullPointerException("share.shareAddressbook is null"); //NOI18N + } else if (share.getShareAddressbook().getAddressbookId() == null) { + // ... and again + throw new NullPointerException("share.shareAddressbook.addressbookId is null"); //NOI18N + } else if (share.getShareAddressbook().getAddressbookId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("share.shareAddressbook.addressbookId={0} is invalid", share.getShareAddressbook().getAddressbookId())); //NOI18N + } else if (share.getShareUserOwner() == null) { + // Throw NPE again + throw new NullPointerException("share.shareUserOwner is null"); //NOI18N + } else if (share.getShareUserOwner().getUserId() == null) { + // ... and again + throw new NullPointerException("share.shareUserOwner.userId is null"); //NOI18N + } else if (share.getShareUserOwner().getUserId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("share.shareUserOwner.userId={0} is invalid", share.getShareUserOwner().getUserId())); //NOI18N + } else if (share.getShareUserSharee() == null) { + // Throw NPE again + throw new NullPointerException("share.shareUserSharee is null"); //NOI18N + } else if (share.getShareUserSharee().getUserId() == null) { + // ... and again + throw new NullPointerException("share.shareUserSharee.userId is null"); //NOI18N + } else if (share.getShareUserSharee().getUserId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("share.shareUserSharee.userId={0} is invalid", share.getShareUserSharee().getUserId())); //NOI18N + } + + // Set it in class this.shareableAddressbook = share; } diff --git a/src/org/mxchange/jaddressbookshare/events/sharing/type/SharingType.java b/src/org/mxchange/jaddressbookshare/events/sharing/type/SharingType.java index 580209b..f1b7bbb 100644 --- a/src/org/mxchange/jaddressbookshare/events/sharing/type/SharingType.java +++ b/src/org/mxchange/jaddressbookshare/events/sharing/type/SharingType.java @@ -16,18 +16,19 @@ */ package org.mxchange.jaddressbookshare.events.sharing.type; +import java.io.Serializable; + /** * An enumeration for sharing types *

* @author Roland Häder */ -public enum SharingType { +public enum SharingType implements Serializable { /** * Sharing has been started */ STARTED, - /** * Sharing has been ended */ diff --git a/src/org/mxchange/jaddressbookshare/model/addressbook/shared/AddressbookShare.java b/src/org/mxchange/jaddressbookshare/model/shared/AddressbookShare.java similarity index 99% rename from src/org/mxchange/jaddressbookshare/model/addressbook/shared/AddressbookShare.java rename to src/org/mxchange/jaddressbookshare/model/shared/AddressbookShare.java index fc23f0c..e0c903d 100644 --- a/src/org/mxchange/jaddressbookshare/model/addressbook/shared/AddressbookShare.java +++ b/src/org/mxchange/jaddressbookshare/model/shared/AddressbookShare.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mxchange.jaddressbookshare.model.addressbook.shared; +package org.mxchange.jaddressbookshare.model.shared; import java.text.MessageFormat; import java.util.Date; @@ -178,7 +178,8 @@ public class AddressbookShare implements ShareableAddressbook { // ... next sharer this.getShareUserOwner().compareTo(shareableAddressbook.getShareUserOwner()), // ... next sharee - this.getShareUserSharee().compareTo(shareableAddressbook.getShareUserSharee()),}; + this.getShareUserSharee().compareTo(shareableAddressbook.getShareUserSharee()) + }; // Check all values final int comparison = ComparableUtils.checkAll(comparators); diff --git a/src/org/mxchange/jaddressbookshare/model/addressbook/shared/ShareableAddressbook.java b/src/org/mxchange/jaddressbookshare/model/shared/ShareableAddressbook.java similarity index 97% rename from src/org/mxchange/jaddressbookshare/model/addressbook/shared/ShareableAddressbook.java rename to src/org/mxchange/jaddressbookshare/model/shared/ShareableAddressbook.java index 6e74ac1..1ad7eb7 100644 --- a/src/org/mxchange/jaddressbookshare/model/addressbook/shared/ShareableAddressbook.java +++ b/src/org/mxchange/jaddressbookshare/model/shared/ShareableAddressbook.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mxchange.jaddressbookshare.model.addressbook.shared; +package org.mxchange.jaddressbookshare.model.shared; import java.io.Serializable; import java.util.Date; -- 2.39.5