*/
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
* @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;
}
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
ShareableAddressbook getShareableAddressbook ();
/**
- * Getter for sharing type enum
+ * Getter for sharing type enumeration
* <p>
- * @return Sharing type enum
+ * @return Sharing type enumeration
*/
SharingType getSharingType ();
+
}
*/
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
/**
* 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
* @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;
}
*/
package org.mxchange.jaddressbookshare.events.sharing.type;
+import java.io.Serializable;
+
/**
* An enumeration for sharing types
* <p>
* @author Roland Häder<roland@mxchange.org>
*/
-public enum SharingType {
+public enum SharingType implements Serializable {
/**
* Sharing has been started
*/
STARTED,
-
/**
* Sharing has been ended
*/
+++ /dev/null
-/*
- * 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
- * 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.jaddressbookshare.model.addressbook.shared;
-
-import java.text.MessageFormat;
-import java.util.Date;
-import java.util.Objects;
-import javax.persistence.Basic;
-import javax.persistence.CascadeType;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.NamedQueries;
-import javax.persistence.NamedQuery;
-import javax.persistence.OneToOne;
-import javax.persistence.Table;
-import javax.persistence.Temporal;
-import javax.persistence.TemporalType;
-import javax.persistence.Transient;
-import org.mxchange.jaddressbook.model.addressbook.Addressbook;
-import org.mxchange.jaddressbook.model.addressbook.UserAddressbook;
-import org.mxchange.jcoreutils.comparable.ComparableUtils;
-import org.mxchange.jusercore.model.user.LoginUser;
-import org.mxchange.jusercore.model.user.User;
-
-/**
- * A POJO for sharing address books with other users
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Entity (name = "addressbook_shares")
-@Table (name = "addressbook_shares")
-@NamedQueries (
- {
- @NamedQuery (
- name = "SearchUserSharedAddressbooks",
- query = "SELECT s FROM addressbook_shares AS s WHERE s.shareUserOwner = :user ORDER BY s.shareId ASC"
- ),
- @NamedQuery (
- name = "SearchShareeAddressbookShare",
- query = "SELECT s FROM addressbook_shares AS s WHERE s.shareAddressbook = :addressbook AND s.shareUserSharee = :sharee"
- )
- }
-)
-@SuppressWarnings ("PersistenceUnitPresent")
-public class AddressbookShare implements ShareableAddressbook {
-
- /**
- * Serial number
- */
- @Transient
- private static final long serialVersionUID = 167_889_678_177_691_690L;
-
- /**
- * Address book this share is for
- */
- @JoinColumn (name = "share_addressbook_id", nullable = false, updatable = false)
- @OneToOne (targetEntity = UserAddressbook.class, cascade = CascadeType.REFRESH, optional = false)
- private Addressbook shareAddressbook;
-
- /**
- * When this share has been created
- */
- @Basic (optional = false)
- @Temporal (TemporalType.TIMESTAMP)
- @Column (name = "share_entry_created", updatable = false, nullable = false)
- private Date shareEntryCreated;
-
- /**
- * When this share has been updated
- */
- @Temporal (TemporalType.TIMESTAMP)
- @Column (name = "share_entry_updated", insertable = false, nullable = false)
- private Date shareEntryUpdated;
-
- /**
- * Id number
- */
- @Id
- @GeneratedValue (strategy = GenerationType.IDENTITY)
- @Column (name = "share_id", nullable = false, updatable = false)
- private Long shareId;
-
- /**
- * User who is owning the share
- */
- @JoinColumn (name = "share_owner_id", nullable = false, updatable = false)
- @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH, optional = false)
- private User shareUserOwner;
-
- /**
- * User the address book is shared with
- */
- @JoinColumn (name = "share_sharee_id", nullable = false, updatable = false)
- @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH, optional = false)
- private User shareUserSharee;
-
- /**
- * Default constructor
- */
- public AddressbookShare () {
- }
-
- /**
- * Constructor with address book and sharee instance. Both parameters must
- * not be null, their id numbers must be set and the address book's user
- * instance must be set and have a valid id set.
- * <p>
- * @param addressbook Address book instance
- * @param sharee User sharee instance
- */
- public AddressbookShare (final Addressbook addressbook, final User sharee) {
- // Invoke default constructor
- this();
-
- // Check all conditions
- if (null == sharee) {
- // Throw NPE
- throw new NullPointerException("sharee is null"); //NOI18N
- } else if (sharee.getUserId() == null) {
- // Throw NPE again
- throw new NullPointerException("sharee.userId is null"); //NOI18N
- } else if (sharee.getUserId() < 1) {
- // Invalid id number
- throw new IllegalStateException(MessageFormat.format("sharee.userId={0} is invalid", sharee.getUserId())); //NOI18N
- } else if (null == addressbook) {
- // Throw NPE again
- throw new NullPointerException("addressbook is null"); //NOI18N
- } else if (addressbook.getAddressbookId() == null) {
- // Throw NPE again
- throw new NullPointerException("addressbook.addressbookId is null"); //NOI18N
- } else if (addressbook.getAddressbookId() < 1) {
- // Invalid id number
- throw new IllegalArgumentException(MessageFormat.format("addressbook.addressbookId={0} is invalid.", addressbook.getAddressbookId())); //NOI18N
- } else if (Objects.equals(addressbook.getAddressbookUser(), sharee)) {
- // Sharing with yourself!
- throw new IllegalStateException("User tries to share with himself."); //NOI18N
- }
-
- // Set all instances
- this.shareAddressbook = addressbook;
- this.shareUserOwner = addressbook.getAddressbookUser();
- this.shareUserSharee = sharee;
- }
-
- @Override
- public int compareTo (final ShareableAddressbook shareableAddressbook) {
- // Checkparameter and return 0 if equal
- if (null == shareableAddressbook) {
- // Should not happen
- throw new NullPointerException("shareableAddressbook is null"); //NOI18N
- } else if (shareableAddressbook.equals(this)) {
- // Same object
- return 0;
- }
-
- // All comparators
- final int comparators[] = {
- // First address book
- this.getShareAddressbook().compareTo(shareableAddressbook.getShareAddressbook()),
- // ... next sharer
- this.getShareUserOwner().compareTo(shareableAddressbook.getShareUserOwner()),
- // ... next sharee
- this.getShareUserSharee().compareTo(shareableAddressbook.getShareUserSharee()),};
-
- // Check all values
- final int comparison = ComparableUtils.checkAll(comparators);
-
- // Return value
- return comparison;
- }
-
- @Override
- public boolean equals (final Object object) {
- if (null == object) {
- return false;
- } else if (this.getClass() != object.getClass()) {
- return false;
- }
-
- final ShareableAddressbook shared = (ShareableAddressbook) object;
-
- if (!Objects.equals(this.getShareAddressbook(), shared.getShareAddressbook())) {
- return false;
- } else if (!Objects.equals(this.getShareId(), shared.getShareId())) {
- return false;
- } else if (!Objects.equals(this.getShareUserOwner(), shared.getShareUserOwner())) {
- return false;
- } else if (!Objects.equals(this.getShareUserSharee(), shared.getShareUserSharee())) {
- return false;
- }
-
- return Objects.equals(this.getShareUserSharee(), shared.getShareUserSharee());
- }
-
- @Override
- public Addressbook getShareAddressbook () {
- return this.shareAddressbook;
- }
-
- @Override
- public void setShareAddressbook (final Addressbook shareAddressbook) {
- this.shareAddressbook = shareAddressbook;
- }
-
- @Override
- @SuppressWarnings ("ReturnOfDateField")
- public Date getShareEntryCreated () {
- return this.shareEntryCreated;
- }
-
- @Override
- @SuppressWarnings ("AssignmentToDateFieldFromParameter")
- public void setShareEntryCreated (final Date shareEntryCreated) {
- this.shareEntryCreated = shareEntryCreated;
- }
-
- @Override
- @SuppressWarnings ("ReturnOfDateField")
- public Date getShareEntryUpdated () {
- return this.shareEntryUpdated;
- }
-
- @Override
- @SuppressWarnings ("AssignmentToDateFieldFromParameter")
- public void setShareEntryUpdated (final Date shareEntryUpdated) {
- this.shareEntryUpdated = shareEntryUpdated;
- }
-
- @Override
- public Long getShareId () {
- return this.shareId;
- }
-
- @Override
- public void setShareId (final Long shareId) {
- this.shareId = shareId;
- }
-
- @Override
- public User getShareUserOwner () {
- return this.shareUserOwner;
- }
-
- @Override
- public void setShareUserOwner (final User shareUserOwner) {
- this.shareUserOwner = shareUserOwner;
- }
-
- @Override
- public User getShareUserSharee () {
- return this.shareUserSharee;
- }
-
- @Override
- public void setShareUserSharee (final User shareUserSharee) {
- this.shareUserSharee = shareUserSharee;
- }
-
- @Override
- public int hashCode () {
- int hash = 7;
-
- hash = 19 * hash + Objects.hashCode(this.getShareAddressbook());
- hash = 19 * hash + Objects.hashCode(this.getShareId());
- hash = 19 * hash + Objects.hashCode(this.getShareUserOwner());
- hash = 19 * hash + Objects.hashCode(this.getShareUserSharee());
-
- return hash;
- }
-
-}
+++ /dev/null
-/*
- * 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
- * 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.jaddressbookshare.model.addressbook.shared;
-
-import java.io.Serializable;
-import java.util.Date;
-import org.mxchange.jaddressbook.model.addressbook.Addressbook;
-import org.mxchange.jusercore.model.user.User;
-
-/**
- * A POJI for shared address books
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public interface ShareableAddressbook extends Comparable<ShareableAddressbook>, Serializable {
-
- /**
- * Getter for shared address book instance
- * <p>
- * @return Shared address book instance
- */
- Addressbook getShareAddressbook ();
-
- /**
- * Setter for shared address book instance
- * <p>
- * @param shareAddressbook Shared address book instance
- */
- void setShareAddressbook (final Addressbook shareAddressbook);
-
- /**
- * Getter for id number
- * <p>
- * @return Id number
- */
- Long getShareId ();
-
- /**
- * Setter for id number
- * <p>
- * @param shareId Id number
- */
- void setShareId (final Long shareId);
-
- /**
- * Getter for address book owner instance
- * <p>
- * @return Address book owner instance
- */
- User getShareUserOwner ();
-
- /**
- * Setter for address book owner instance
- * <p>
- * @param shareUserOwner Address book owner instance
- */
- void setShareUserOwner (final User shareUserOwner);
-
- /**
- * Getter for address book sharee instance
- * <p>
- * @return Address book sharee instance
- */
- User getShareUserSharee ();
-
- /**
- * Setter for address book sharee instance
- * <p>
- * @param shareUserSharer Address book sharee instance
- */
- void setShareUserSharee (final User shareUserSharer);
-
- /**
- * Getter for share created timestamp
- * <p>
- * @return Share created timestamp
- */
- Date getShareEntryCreated ();
-
- /**
- * Setter for share created timestamp
- * <p>
- * @param shareCreated Share created timestamp
- */
- void setShareEntryCreated (final Date shareCreated);
-
- /**
- * Getter for share updated timestamp
- * <p>
- * @return Share updated timestamp
- */
- Date getShareEntryUpdated ();
-
- /**
- * Setter for share updated timestamp
- * <p>
- * @param shareUpdated Share updated timestamp
- */
- void setShareEntryUpdated (final Date shareUpdated);
-
- @Override
- boolean equals (final Object object);
-
- @Override
- int hashCode ();
-}
--- /dev/null
+/*
+ * 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
+ * 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.jaddressbookshare.model.shared;
+
+import java.text.MessageFormat;
+import java.util.Date;
+import java.util.Objects;
+import javax.persistence.Basic;
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.OneToOne;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.persistence.Transient;
+import org.mxchange.jaddressbook.model.addressbook.Addressbook;
+import org.mxchange.jaddressbook.model.addressbook.UserAddressbook;
+import org.mxchange.jcoreutils.comparable.ComparableUtils;
+import org.mxchange.jusercore.model.user.LoginUser;
+import org.mxchange.jusercore.model.user.User;
+
+/**
+ * A POJO for sharing address books with other users
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Entity (name = "addressbook_shares")
+@Table (name = "addressbook_shares")
+@NamedQueries (
+ {
+ @NamedQuery (
+ name = "SearchUserSharedAddressbooks",
+ query = "SELECT s FROM addressbook_shares AS s WHERE s.shareUserOwner = :user ORDER BY s.shareId ASC"
+ ),
+ @NamedQuery (
+ name = "SearchShareeAddressbookShare",
+ query = "SELECT s FROM addressbook_shares AS s WHERE s.shareAddressbook = :addressbook AND s.shareUserSharee = :sharee"
+ )
+ }
+)
+@SuppressWarnings ("PersistenceUnitPresent")
+public class AddressbookShare implements ShareableAddressbook {
+
+ /**
+ * Serial number
+ */
+ @Transient
+ private static final long serialVersionUID = 167_889_678_177_691_690L;
+
+ /**
+ * Address book this share is for
+ */
+ @JoinColumn (name = "share_addressbook_id", nullable = false, updatable = false)
+ @OneToOne (targetEntity = UserAddressbook.class, cascade = CascadeType.REFRESH, optional = false)
+ private Addressbook shareAddressbook;
+
+ /**
+ * When this share has been created
+ */
+ @Basic (optional = false)
+ @Temporal (TemporalType.TIMESTAMP)
+ @Column (name = "share_entry_created", updatable = false, nullable = false)
+ private Date shareEntryCreated;
+
+ /**
+ * When this share has been updated
+ */
+ @Temporal (TemporalType.TIMESTAMP)
+ @Column (name = "share_entry_updated", insertable = false, nullable = false)
+ private Date shareEntryUpdated;
+
+ /**
+ * Id number
+ */
+ @Id
+ @GeneratedValue (strategy = GenerationType.IDENTITY)
+ @Column (name = "share_id", nullable = false, updatable = false)
+ private Long shareId;
+
+ /**
+ * User who is owning the share
+ */
+ @JoinColumn (name = "share_owner_id", nullable = false, updatable = false)
+ @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH, optional = false)
+ private User shareUserOwner;
+
+ /**
+ * User the address book is shared with
+ */
+ @JoinColumn (name = "share_sharee_id", nullable = false, updatable = false)
+ @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH, optional = false)
+ private User shareUserSharee;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookShare () {
+ }
+
+ /**
+ * Constructor with address book and sharee instance. Both parameters must
+ * not be null, their id numbers must be set and the address book's user
+ * instance must be set and have a valid id set.
+ * <p>
+ * @param addressbook Address book instance
+ * @param sharee User sharee instance
+ */
+ public AddressbookShare (final Addressbook addressbook, final User sharee) {
+ // Invoke default constructor
+ this();
+
+ // Check all conditions
+ if (null == sharee) {
+ // Throw NPE
+ throw new NullPointerException("sharee is null"); //NOI18N
+ } else if (sharee.getUserId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("sharee.userId is null"); //NOI18N
+ } else if (sharee.getUserId() < 1) {
+ // Invalid id number
+ throw new IllegalStateException(MessageFormat.format("sharee.userId={0} is invalid", sharee.getUserId())); //NOI18N
+ } else if (null == addressbook) {
+ // Throw NPE again
+ throw new NullPointerException("addressbook is null"); //NOI18N
+ } else if (addressbook.getAddressbookId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("addressbook.addressbookId is null"); //NOI18N
+ } else if (addressbook.getAddressbookId() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("addressbook.addressbookId={0} is invalid.", addressbook.getAddressbookId())); //NOI18N
+ } else if (Objects.equals(addressbook.getAddressbookUser(), sharee)) {
+ // Sharing with yourself!
+ throw new IllegalStateException("User tries to share with himself."); //NOI18N
+ }
+
+ // Set all instances
+ this.shareAddressbook = addressbook;
+ this.shareUserOwner = addressbook.getAddressbookUser();
+ this.shareUserSharee = sharee;
+ }
+
+ @Override
+ public int compareTo (final ShareableAddressbook shareableAddressbook) {
+ // Checkparameter and return 0 if equal
+ if (null == shareableAddressbook) {
+ // Should not happen
+ throw new NullPointerException("shareableAddressbook is null"); //NOI18N
+ } else if (shareableAddressbook.equals(this)) {
+ // Same object
+ return 0;
+ }
+
+ // All comparators
+ final int comparators[] = {
+ // First address book
+ this.getShareAddressbook().compareTo(shareableAddressbook.getShareAddressbook()),
+ // ... next sharer
+ this.getShareUserOwner().compareTo(shareableAddressbook.getShareUserOwner()),
+ // ... next sharee
+ this.getShareUserSharee().compareTo(shareableAddressbook.getShareUserSharee())
+ };
+
+ // Check all values
+ final int comparison = ComparableUtils.checkAll(comparators);
+
+ // Return value
+ return comparison;
+ }
+
+ @Override
+ public boolean equals (final Object object) {
+ if (null == object) {
+ return false;
+ } else if (this.getClass() != object.getClass()) {
+ return false;
+ }
+
+ final ShareableAddressbook shared = (ShareableAddressbook) object;
+
+ if (!Objects.equals(this.getShareAddressbook(), shared.getShareAddressbook())) {
+ return false;
+ } else if (!Objects.equals(this.getShareId(), shared.getShareId())) {
+ return false;
+ } else if (!Objects.equals(this.getShareUserOwner(), shared.getShareUserOwner())) {
+ return false;
+ } else if (!Objects.equals(this.getShareUserSharee(), shared.getShareUserSharee())) {
+ return false;
+ }
+
+ return Objects.equals(this.getShareUserSharee(), shared.getShareUserSharee());
+ }
+
+ @Override
+ public Addressbook getShareAddressbook () {
+ return this.shareAddressbook;
+ }
+
+ @Override
+ public void setShareAddressbook (final Addressbook shareAddressbook) {
+ this.shareAddressbook = shareAddressbook;
+ }
+
+ @Override
+ @SuppressWarnings ("ReturnOfDateField")
+ public Date getShareEntryCreated () {
+ return this.shareEntryCreated;
+ }
+
+ @Override
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+ public void setShareEntryCreated (final Date shareEntryCreated) {
+ this.shareEntryCreated = shareEntryCreated;
+ }
+
+ @Override
+ @SuppressWarnings ("ReturnOfDateField")
+ public Date getShareEntryUpdated () {
+ return this.shareEntryUpdated;
+ }
+
+ @Override
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+ public void setShareEntryUpdated (final Date shareEntryUpdated) {
+ this.shareEntryUpdated = shareEntryUpdated;
+ }
+
+ @Override
+ public Long getShareId () {
+ return this.shareId;
+ }
+
+ @Override
+ public void setShareId (final Long shareId) {
+ this.shareId = shareId;
+ }
+
+ @Override
+ public User getShareUserOwner () {
+ return this.shareUserOwner;
+ }
+
+ @Override
+ public void setShareUserOwner (final User shareUserOwner) {
+ this.shareUserOwner = shareUserOwner;
+ }
+
+ @Override
+ public User getShareUserSharee () {
+ return this.shareUserSharee;
+ }
+
+ @Override
+ public void setShareUserSharee (final User shareUserSharee) {
+ this.shareUserSharee = shareUserSharee;
+ }
+
+ @Override
+ public int hashCode () {
+ int hash = 7;
+
+ hash = 19 * hash + Objects.hashCode(this.getShareAddressbook());
+ hash = 19 * hash + Objects.hashCode(this.getShareId());
+ hash = 19 * hash + Objects.hashCode(this.getShareUserOwner());
+ hash = 19 * hash + Objects.hashCode(this.getShareUserSharee());
+
+ return hash;
+ }
+
+}
--- /dev/null
+/*
+ * 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
+ * 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.jaddressbookshare.model.shared;
+
+import java.io.Serializable;
+import java.util.Date;
+import org.mxchange.jaddressbook.model.addressbook.Addressbook;
+import org.mxchange.jusercore.model.user.User;
+
+/**
+ * A POJI for shared address books
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface ShareableAddressbook extends Comparable<ShareableAddressbook>, Serializable {
+
+ /**
+ * Getter for shared address book instance
+ * <p>
+ * @return Shared address book instance
+ */
+ Addressbook getShareAddressbook ();
+
+ /**
+ * Setter for shared address book instance
+ * <p>
+ * @param shareAddressbook Shared address book instance
+ */
+ void setShareAddressbook (final Addressbook shareAddressbook);
+
+ /**
+ * Getter for id number
+ * <p>
+ * @return Id number
+ */
+ Long getShareId ();
+
+ /**
+ * Setter for id number
+ * <p>
+ * @param shareId Id number
+ */
+ void setShareId (final Long shareId);
+
+ /**
+ * Getter for address book owner instance
+ * <p>
+ * @return Address book owner instance
+ */
+ User getShareUserOwner ();
+
+ /**
+ * Setter for address book owner instance
+ * <p>
+ * @param shareUserOwner Address book owner instance
+ */
+ void setShareUserOwner (final User shareUserOwner);
+
+ /**
+ * Getter for address book sharee instance
+ * <p>
+ * @return Address book sharee instance
+ */
+ User getShareUserSharee ();
+
+ /**
+ * Setter for address book sharee instance
+ * <p>
+ * @param shareUserSharer Address book sharee instance
+ */
+ void setShareUserSharee (final User shareUserSharer);
+
+ /**
+ * Getter for share created timestamp
+ * <p>
+ * @return Share created timestamp
+ */
+ Date getShareEntryCreated ();
+
+ /**
+ * Setter for share created timestamp
+ * <p>
+ * @param shareCreated Share created timestamp
+ */
+ void setShareEntryCreated (final Date shareCreated);
+
+ /**
+ * Getter for share updated timestamp
+ * <p>
+ * @return Share updated timestamp
+ */
+ Date getShareEntryUpdated ();
+
+ /**
+ * Setter for share updated timestamp
+ * <p>
+ * @param shareUpdated Share updated timestamp
+ */
+ void setShareEntryUpdated (final Date shareUpdated);
+
+ @Override
+ boolean equals (final Object object);
+
+ @Override
+ int hashCode ();
+}