From 2436eac936110e63d3f1d12711f6a0513a988564 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 18 Mar 2018 19:35:52 +0100 Subject: [PATCH] Continued: - added new dependency jcoreee - implemented Comparable interface MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- nbproject/project.properties | 3 ++ .../addressbook/shared/AddressbookShare.java | 53 +++++++++++++++---- .../shared/ShareableAddressbook.java | 2 +- 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/nbproject/project.properties b/nbproject/project.properties index b7f0a3c..639cb87 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -33,6 +33,7 @@ excludes= file.reference.jaddressbook-core.jar=lib/jaddressbook-core.jar file.reference.jcontacts-business-core.jar=lib/jcontacts-business-core.jar file.reference.jcontacts-core.jar=lib/jcontacts-core.jar +file.reference.jcoreee.jar=lib/jcoreee.jar file.reference.juser-core.jar=lib/juser-core.jar includes=** jar.archive.disabled=${jnlp.enabled} @@ -43,6 +44,7 @@ javac.classpath=\ ${file.reference.jcontacts-core.jar}:\ ${file.reference.jcontacts-business-core.jar}:\ ${file.reference.jaddressbook-core.jar}:\ + ${file.reference.jcoreee.jar}:\ ${libs.jpa20-persistence.classpath} # Space-separated list of extra javac options javac.compilerargs=-Xlint:unchecked -Xlint:deprecation @@ -103,6 +105,7 @@ source.encoding=UTF-8 source.reference.jaddressbook-core.jar=../jaddressbook-core/src/ source.reference.jcontacts-business-core.jar=../jcontacts-business-core/src/ source.reference.jcontacts-core.jar=../jcontacts-core/src/ +source.reference.jcoreee.jar=../jcoreee/src/ source.reference.juser-core.jar=../juser-core/src/ src.dir=src test.src.dir=test diff --git a/src/org/mxchange/jaddressbookshare/model/addressbook/shared/AddressbookShare.java b/src/org/mxchange/jaddressbookshare/model/addressbook/shared/AddressbookShare.java index cb9d2dd..23bc52f 100644 --- a/src/org/mxchange/jaddressbookshare/model/addressbook/shared/AddressbookShare.java +++ b/src/org/mxchange/jaddressbookshare/model/addressbook/shared/AddressbookShare.java @@ -36,6 +36,7 @@ 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.jcoreee.utils.Comparables; import org.mxchange.jusercore.model.user.LoginUser; import org.mxchange.jusercore.model.user.User; @@ -112,11 +113,11 @@ public class AddressbookShare implements ShareableAddressbook { /** * Constructor with address book and sharee instance. Both parameters must - * not be null, their id numbers must be set and the adress book's user + * 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. *

* @param addressbook Address book instance - * @param sharee User sharee instance + * @param sharee User sharee instance */ public AddressbookShare (final Addressbook addressbook, final User sharee) { // Call default constructor @@ -152,6 +153,34 @@ public class AddressbookShare implements ShareableAddressbook { 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 (Objects.equals(this, shareableAddressbook)) { + // 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 = Comparables.checkAll(comparators); + + // Return value + return comparison; + } + @Override public boolean equals (final Object object) { if (null == object) { @@ -173,15 +202,6 @@ public class AddressbookShare implements ShareableAddressbook { return Objects.equals(this.getShareUserSharee(), other.getShareUserSharee()); } - @Override - public int hashCode () { - int hash = 7; - hash = 19 * hash + Objects.hashCode(this.getShareAddressbook()); - hash = 19 * hash + Objects.hashCode(this.getShareUserOwner()); - hash = 19 * hash + Objects.hashCode(this.getShareUserSharee()); - return hash; - } - @Override public Addressbook getShareAddressbook () { return this.shareAddressbook; @@ -234,4 +254,15 @@ public class AddressbookShare implements ShareableAddressbook { this.shareUserSharee = shareUserSharee; } + @Override + public int hashCode () { + int hash = 7; + + hash = 19 * hash + Objects.hashCode(this.getShareAddressbook()); + hash = 19 * hash + Objects.hashCode(this.getShareUserOwner()); + hash = 19 * hash + Objects.hashCode(this.getShareUserSharee()); + + return hash; + } + } diff --git a/src/org/mxchange/jaddressbookshare/model/addressbook/shared/ShareableAddressbook.java b/src/org/mxchange/jaddressbookshare/model/addressbook/shared/ShareableAddressbook.java index ba9c602..2bf80df 100644 --- a/src/org/mxchange/jaddressbookshare/model/addressbook/shared/ShareableAddressbook.java +++ b/src/org/mxchange/jaddressbookshare/model/addressbook/shared/ShareableAddressbook.java @@ -26,7 +26,7 @@ import org.mxchange.jusercore.model.user.User; *

* @author Roland Häder */ -public interface ShareableAddressbook extends Serializable { +public interface ShareableAddressbook extends Comparable, Serializable { /** * Getter for shared address book instance -- 2.39.5