]> git.mxchange.org Git - jaddressbook-share-core.git/blobdiff - src/org/mxchange/jaddressbookshare/model/addressbook/shared/AddressbookShare.java
Continued:
[jaddressbook-share-core.git] / src / org / mxchange / jaddressbookshare / model / addressbook / shared / AddressbookShare.java
index adbdb658c5678b35b6c463a437d2066f3bedf800..5c9fda4bca9cd6c96984cbccc416eb950148a785 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2020 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
@@ -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.jcoreutils.Comparables;
 import org.mxchange.jusercore.model.user.LoginUser;
 import org.mxchange.jusercore.model.user.User;
 
@@ -79,8 +80,15 @@ public class AddressbookShare implements ShareableAddressbook {
         */
        @Basic (optional = false)
        @Temporal (TemporalType.TIMESTAMP)
-       @Column (name = "share_created", nullable = false, updatable = false)
-       private Date shareCreated;
+       @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
@@ -112,14 +120,14 @@ 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
+               // Invoke default constructor
                this();
 
                // Check all conditions
@@ -152,6 +160,33 @@ 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 (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 = Comparables.checkAll(comparators);
+
+               // Return value
+               return comparison;
+       }
+
        @Override
        public boolean equals (final Object object) {
                if (null == object) {
@@ -164,24 +199,17 @@ public class AddressbookShare implements ShareableAddressbook {
 
                if (!Objects.equals(this.getShareAddressbook(), other.getShareAddressbook())) {
                        return false;
-               } else if (!Objects.equals(this.getShareUserOwner(), other.getShareUserOwner())) {
+               } else if (!Objects.equals(this.getShareId(), other.getShareId())) {
                        return false;
                } else if (!Objects.equals(this.getShareUserOwner(), other.getShareUserOwner())) {
                        return false;
+               } else if (!Objects.equals(this.getShareUserSharee(), other.getShareUserSharee())) {
+                       return false;
                }
 
                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;
@@ -194,14 +222,26 @@ public class AddressbookShare implements ShareableAddressbook {
 
        @Override
        @SuppressWarnings ("ReturnOfDateField")
-       public Date getShareCreated () {
-               return this.shareCreated;
+       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 setShareCreated (final Date shareCreated) {
-               this.shareCreated = shareCreated;
+       public void setShareEntryUpdated (final Date shareEntryUpdated) {
+               this.shareEntryUpdated = shareEntryUpdated;
        }
 
        @Override
@@ -234,4 +274,16 @@ 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.getShareId());
+               hash = 19 * hash + Objects.hashCode(this.getShareUserOwner());
+               hash = 19 * hash + Objects.hashCode(this.getShareUserSharee());
+
+               return hash;
+       }
+
 }