]> git.mxchange.org Git - jaddressbook-share-core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sun, 18 Mar 2018 18:35:52 +0000 (19:35 +0100)
committerRoland Häder <roland@mxchange.org>
Sun, 18 Mar 2018 18:44:28 +0000 (19:44 +0100)
- added new dependency jcoreee
- implemented Comparable interface

Signed-off-by: Roland Häder <roland@mxchange.org>
nbproject/project.properties
src/org/mxchange/jaddressbookshare/model/addressbook/shared/AddressbookShare.java
src/org/mxchange/jaddressbookshare/model/addressbook/shared/ShareableAddressbook.java

index b7f0a3c063655cec92fde0fdefa834125cc4356a..639cb87bec8fbcc0c0fae08cebeffb897ae58a45 100644 (file)
@@ -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
index cb9d2dd19007b280384cff2ee68a03132435a833..23bc52fdaee321b5a03e1541a2d176dc4711822e 100644 (file)
@@ -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.
         * <p>
         * @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;
+       }
+
 }
index ba9c602cac7a799b3be4db34e665ab96b91ad039..2bf80df40acf589d60b4c636b1224c3310192444 100644 (file)
@@ -26,7 +26,7 @@ import org.mxchange.jusercore.model.user.User;
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
-public interface ShareableAddressbook extends Serializable {
+public interface ShareableAddressbook extends Comparable<ShareableAddressbook>, Serializable {
 
        /**
         * Getter for shared address book instance