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

Signed-off-by: Roland Häder <roland@mxchange.org>
nbproject/project.properties
src/org/mxchange/jaddressbook/model/addressbook/Addressbook.java
src/org/mxchange/jaddressbook/model/addressbook/UserAddressbook.java
src/org/mxchange/jaddressbook/model/addressbook/entry/AddressbookEntry.java
src/org/mxchange/jaddressbook/model/addressbook/entry/UserAddressbookEntry.java

index 6fdd9b2d65a0709334d5e7a0fc772e063f9aafef..e8c6002c8693680f5c15e370c76c5ed4106146b7 100644 (file)
@@ -32,6 +32,7 @@ endorsed.classpath=
 excludes=
 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}
@@ -39,8 +40,9 @@ jar.compress=false
 jar.index=${jnlp.enabled}
 javac.classpath=\
     ${file.reference.juser-core.jar}:\
-    ${file.reference.jcontacts-core.jar}:\
     ${file.reference.jcontacts-business-core.jar}:\
+    ${file.reference.jcontacts-core.jar}:\
+    ${file.reference.jcoreee.jar}:\
     ${libs.jpa20-persistence.classpath}
 # Space-separated list of extra javac options
 javac.compilerargs=-Xlint:unchecked -Xlint:deprecation
@@ -100,6 +102,7 @@ run.test.classpath=\
 source.encoding=UTF-8
 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 93bcf0558cfc240b5100b64595b7feb547816117..7ff705e8fbaf26edd466cb5f69757247ef6b1bc7 100644 (file)
@@ -26,7 +26,7 @@ import org.mxchange.jusercore.model.user.User;
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
-public interface Addressbook extends Serializable {
+public interface Addressbook extends Comparable<Addressbook>, Serializable {
 
        /**
         * Getter for id number
index b920cd1b3e3165c8d5c03690d82c4a2b2deead01..0b85b7c3aa2276eec514367c8ff5388c7b1929d8 100644 (file)
@@ -37,11 +37,12 @@ import javax.persistence.Temporal;
 import javax.persistence.TemporalType;
 import javax.persistence.Transient;
 import org.mxchange.jaddressbook.model.addressbook.status.AddressbokStatus;
+import org.mxchange.jcoreee.utils.Comparables;
 import org.mxchange.jusercore.model.user.LoginUser;
 import org.mxchange.jusercore.model.user.User;
 
 /**
- * A POJO for user addressbooks
+ * A POJO for user address books
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
@@ -49,8 +50,9 @@ import org.mxchange.jusercore.model.user.User;
 @Table (name = "addressbooks")
 @NamedQueries (
                {
+                       @NamedQuery (name = "AllAddressbooks", query = "SELECT a FROM addressbooks AS a ORDER BY a.addressbookId ASC"),
                        @NamedQuery (name = "AllUsersAddressbooks", query = "SELECT a FROM addressbooks AS a WHERE a.addressbookUser = :param ORDER BY a.addressbookId ASC"),
-                       @NamedQuery (name = "SearchUserAddressbookName", query = "SELECT a FROM addressbooks AS a WHERE a.addressbookUser = :user AND LOWER(a.addressbookName) LIKE LOWER(:name)"),
+                       @NamedQuery (name = "SearchUserAddressbookName", query = "SELECT a FROM addressbooks AS a WHERE a.addressbookUser = :user AND LOWER(a.addressbookName) LIKE LOWER(:name)")
                }
 )
 @SuppressWarnings ("PersistenceUnitPresent")
@@ -100,7 +102,7 @@ public class UserAddressbook implements Addressbook {
        private String addressbookName;
 
        /**
-        * Adress book status
+        * Address book status
         */
        @Basic (optional = false)
        @Enumerated (EnumType.STRING)
@@ -133,8 +135,34 @@ public class UserAddressbook implements Addressbook {
         * Default constructor
         */
        public UserAddressbook () {
-               // Set status to UNLOCKED
-               this.addressbookStatus = AddressbokStatus.UNLOCKED;
+       }
+
+       @Override
+       public int compareTo (final Addressbook addressbook) {
+               // Checkparameter and return 0 if equal
+               if (null == addressbook) {
+                       // Should not happen
+                       throw new NullPointerException("addressbook is null"); //NOI18N
+               } else if (Objects.equals(this, addressbook)) {
+                       // Same object
+                       return 0;
+               }
+
+               // All comparators
+               final int comparators[] = {
+                       // First name ...
+                       this.getAddressbookName().compareToIgnoreCase(addressbook.getAddressbookName()),
+                       // ... status
+                       this.getAddressbookStatus().compareTo(addressbook.getAddressbookStatus()),
+                       // .. then user
+                       this.getAddressbookUser().compareTo(addressbook.getAddressbookUser())
+               };
+
+               // Check all values
+               final int comparison = Comparables.checkAll(comparators);
+
+               // Return value
+               return comparison;
        }
 
        @Override
@@ -157,19 +185,13 @@ public class UserAddressbook implements Addressbook {
        }
 
        @Override
-       public int hashCode () {
-               int hash = 7;
-               hash = 59 * hash + Objects.hashCode(this.getAddressbookName());
-               hash = 59 * hash + Objects.hashCode(this.getAddressbookUser());
-               return hash;
-       }
-
-       @Override
+       @SuppressWarnings ("ReturnOfDateField")
        public Date getAddressbookCreated () {
                return this.addressbookCreated;
        }
 
        @Override
+       @SuppressWarnings ("AssignmentToDateFieldFromParameter")
        public void setAddressbookCreated (final Date addressbookCreated) {
                this.addressbookCreated = addressbookCreated;
        }
@@ -185,11 +207,13 @@ public class UserAddressbook implements Addressbook {
        }
 
        @Override
+       @SuppressWarnings ("ReturnOfDateField")
        public Date getAddressbookLastLocked () {
                return this.addressbookLastLocked;
        }
 
        @Override
+       @SuppressWarnings ("AssignmentToDateFieldFromParameter")
        public void setAddressbookLastLocked (final Date addressbookLastLocked) {
                this.addressbookLastLocked = addressbookLastLocked;
        }
@@ -234,4 +258,14 @@ public class UserAddressbook implements Addressbook {
                this.addressbookUser = addressbookUser;
        }
 
+       @Override
+       public int hashCode () {
+               int hash = 7;
+
+               hash = 59 * hash + Objects.hashCode(this.getAddressbookName());
+               hash = 59 * hash + Objects.hashCode(this.getAddressbookUser());
+
+               return hash;
+       }
+
 }
index 8ab784340265b7e0adab58c538eae978616fffa3..7768cbe714337fb6875d734eabb5eb757071caf7 100644 (file)
@@ -27,7 +27,7 @@ import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
-public interface AddressbookEntry extends Serializable {
+public interface AddressbookEntry extends Comparable<AddressbookEntry>, Serializable {
 
        /**
         * Getter for id number
@@ -48,14 +48,14 @@ public interface AddressbookEntry extends Serializable {
         * <p>
         * @return Business contact
         */
-       BasicData getAddressbookEntryBusinessContact ();
+       BasicData getAddressbookEntryBusinessBasicData ();
 
        /**
         * Setter for business contact
         * <p>
         * @param addressbookEntryBusinessContact Business contact
         */
-       void setAddressbookEntryBusinessContact (final BasicData addressbookEntryBusinessContact);
+       void setAddressbookEntryBusinessBasicData (final BasicData addressbookEntryBusinessContact);
 
        /**
         * Getter for entry created timestamp
@@ -90,14 +90,14 @@ public interface AddressbookEntry extends Serializable {
         * <p>
         * @return Address book
         */
-       Addressbook getAddressbookId ();
+       Addressbook getEntryAddressbook ();
 
        /**
         * Setter for address book
         * <p>
         * @param addressbookId Address book
         */
-       void setAddressbookId (final Addressbook addressbookId);
+       void setEntryAddressbook (final Addressbook addressbookId);
 
        @Override
        boolean equals (final Object object);
index 86345400f599ed239fcc13add60ab70564dd2685..c2ee460809a734034ce4f4071ddb5be8768370c1 100644 (file)
@@ -39,6 +39,7 @@ import org.mxchange.jcontacts.model.contact.Contact;
 import org.mxchange.jcontacts.model.contact.UserContact;
 import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
 import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
+import org.mxchange.jcoreee.utils.Comparables;
 
 /**
  * A POJO for address book entries
@@ -49,10 +50,7 @@ import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
 @Table (name = "addressbook_entries")
 @NamedQueries (
                {
-                       @NamedQuery (
-                                       name = "SearchUsersAddressbookEntries",
-                                       query = "SELECT e FROM addressbook_entries AS e INNER JOIN addressbooks AS a ON e.addressbookId = a WHERE e.addressbookId = :addressbook AND a.addressbookUser = :owner ORDER BY e.addressbookEntryId ASC"
-                       )
+                       @NamedQuery (name = "AllAddressBookEntries", query = "SELECT e FROM addressbook_entries AS e ORDER BY e.addressbookEntryId ASC")
                }
 )
 @SuppressWarnings ("PersistenceUnitPresent")
@@ -69,7 +67,7 @@ public class UserAddressbookEntry implements AddressbookEntry {
         */
        @JoinColumn (name = "entry_business_contact_id", updatable = false)
        @OneToOne (targetEntity = BusinessBasicData.class, cascade = CascadeType.REFRESH)
-       private BasicData addressbookEntryBusinessContact;
+       private BasicData addressbookEntryBusinessBasicData;
 
        /**
         * When this address book entry has been created
@@ -95,11 +93,39 @@ public class UserAddressbookEntry implements AddressbookEntry {
        private Contact addressbookEntryPrivateContact;
 
        /**
-        * Connection to table "addressbooks"
+        * Connection to table "address books"
         */
        @JoinColumn (name = "entry_addressbook_id", nullable = false, updatable = false)
        @OneToOne (targetEntity = UserAddressbook.class, cascade = CascadeType.REFRESH, optional = false)
-       private Addressbook addressbookId;
+       private Addressbook entryAddressbook;
+
+       @Override
+       public int compareTo (final AddressbookEntry addressbookEntry) {
+               // For performance reasons
+               if (null == addressbookEntry) {
+                       // Should not happen
+                       throw new NullPointerException("addressbookEntry is null"); //NOI18N
+               } else if (Objects.equals(this, addressbookEntry)) {
+                       // Same object
+                       return 0;
+               }
+
+               // Init comparitors
+               final int comparitors[] = {
+                       // First compare address books
+                       this.getEntryAddressbook().compareTo(addressbookEntry.getEntryAddressbook()),
+                       // ... then business address
+                       this.getAddressbookEntryBusinessBasicData().compareTo(addressbookEntry.getAddressbookEntryBusinessBasicData()),
+                       // ... then private contact
+                       this.getAddressbookEntryPrivateContact().compareTo(addressbookEntry.getAddressbookEntryPrivateContact())
+               };
+
+               // Check all vaules
+               final int comparison = Comparables.checkAll(comparitors);
+
+               // Return value
+               return comparison;
+       }
 
        @Override
        public boolean equals (final Object object) {
@@ -111,11 +137,11 @@ public class UserAddressbookEntry implements AddressbookEntry {
 
                final AddressbookEntry other = (AddressbookEntry) object;
 
-               if (!Objects.equals(this.getAddressbookEntryBusinessContact(), other.getAddressbookEntryBusinessContact())) {
+               if (!Objects.equals(this.getAddressbookEntryBusinessBasicData(), other.getAddressbookEntryBusinessBasicData())) {
                        return false;
                } else if (!Objects.equals(this.getAddressbookEntryPrivateContact(), other.getAddressbookEntryPrivateContact())) {
                        return false;
-               } else if (!Objects.equals(this.getAddressbookId(), other.getAddressbookId())) {
+               } else if (!Objects.equals(this.getEntryAddressbook(), other.getEntryAddressbook())) {
                        return false;
                }
 
@@ -123,24 +149,13 @@ public class UserAddressbookEntry implements AddressbookEntry {
        }
 
        @Override
-       public int hashCode () {
-               int hash = 3;
-
-               hash = 19 * hash + Objects.hashCode(this.getAddressbookEntryBusinessContact());
-               hash = 19 * hash + Objects.hashCode(this.getAddressbookEntryPrivateContact());
-               hash = 19 * hash + Objects.hashCode(this.getAddressbookId());
-
-               return hash;
+       public BasicData getAddressbookEntryBusinessBasicData () {
+               return this.addressbookEntryBusinessBasicData;
        }
 
        @Override
-       public BasicData getAddressbookEntryBusinessContact () {
-               return this.addressbookEntryBusinessContact;
-       }
-
-       @Override
-       public void setAddressbookEntryBusinessContact (final BasicData addressbookEntryBusinessContact) {
-               this.addressbookEntryBusinessContact = addressbookEntryBusinessContact;
+       public void setAddressbookEntryBusinessBasicData (final BasicData addressbookEntryBusinessBasicData) {
+               this.addressbookEntryBusinessBasicData = addressbookEntryBusinessBasicData;
        }
 
        @Override
@@ -176,13 +191,24 @@ public class UserAddressbookEntry implements AddressbookEntry {
        }
 
        @Override
-       public Addressbook getAddressbookId () {
-               return this.addressbookId;
+       public Addressbook getEntryAddressbook () {
+               return this.entryAddressbook;
+       }
+
+       @Override
+       public void setEntryAddressbook (final Addressbook entryAddressbook) {
+               this.entryAddressbook = entryAddressbook;
        }
 
        @Override
-       public void setAddressbookId (final Addressbook addressbookId) {
-               this.addressbookId = addressbookId;
+       public int hashCode () {
+               int hash = 3;
+
+               hash = 19 * hash + Objects.hashCode(this.getAddressbookEntryBusinessBasicData());
+               hash = 19 * hash + Objects.hashCode(this.getAddressbookEntryPrivateContact());
+               hash = 19 * hash + Objects.hashCode(this.getEntryAddressbook());
+
+               return hash;
        }
 
 }