From: Roland Häder Date: Sun, 18 Mar 2018 16:31:12 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=9fdbccaf7dfa0001c078fc6158ec4ca7402715c6;p=jaddressbook-core.git Continued: - added new dependency jcoreee - implemented interface Comparable Signed-off-by: Roland Häder --- diff --git a/nbproject/project.properties b/nbproject/project.properties index 6fdd9b2..e8c6002 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -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 diff --git a/src/org/mxchange/jaddressbook/model/addressbook/Addressbook.java b/src/org/mxchange/jaddressbook/model/addressbook/Addressbook.java index 93bcf05..7ff705e 100644 --- a/src/org/mxchange/jaddressbook/model/addressbook/Addressbook.java +++ b/src/org/mxchange/jaddressbook/model/addressbook/Addressbook.java @@ -26,7 +26,7 @@ import org.mxchange.jusercore.model.user.User; *

* @author Roland Häder */ -public interface Addressbook extends Serializable { +public interface Addressbook extends Comparable, Serializable { /** * Getter for id number diff --git a/src/org/mxchange/jaddressbook/model/addressbook/UserAddressbook.java b/src/org/mxchange/jaddressbook/model/addressbook/UserAddressbook.java index b920cd1..0b85b7c 100644 --- a/src/org/mxchange/jaddressbook/model/addressbook/UserAddressbook.java +++ b/src/org/mxchange/jaddressbook/model/addressbook/UserAddressbook.java @@ -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 *

* @author Roland Häder */ @@ -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; + } + } diff --git a/src/org/mxchange/jaddressbook/model/addressbook/entry/AddressbookEntry.java b/src/org/mxchange/jaddressbook/model/addressbook/entry/AddressbookEntry.java index 8ab7843..7768cbe 100644 --- a/src/org/mxchange/jaddressbook/model/addressbook/entry/AddressbookEntry.java +++ b/src/org/mxchange/jaddressbook/model/addressbook/entry/AddressbookEntry.java @@ -27,7 +27,7 @@ import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; *

* @author Roland Häder */ -public interface AddressbookEntry extends Serializable { +public interface AddressbookEntry extends Comparable, Serializable { /** * Getter for id number @@ -48,14 +48,14 @@ public interface AddressbookEntry extends Serializable { *

* @return Business contact */ - BasicData getAddressbookEntryBusinessContact (); + BasicData getAddressbookEntryBusinessBasicData (); /** * Setter for business contact *

* @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 { *

* @return Address book */ - Addressbook getAddressbookId (); + Addressbook getEntryAddressbook (); /** * Setter for address book *

* @param addressbookId Address book */ - void setAddressbookId (final Addressbook addressbookId); + void setEntryAddressbook (final Addressbook addressbookId); @Override boolean equals (final Object object); diff --git a/src/org/mxchange/jaddressbook/model/addressbook/entry/UserAddressbookEntry.java b/src/org/mxchange/jaddressbook/model/addressbook/entry/UserAddressbookEntry.java index 8634540..c2ee460 100644 --- a/src/org/mxchange/jaddressbook/model/addressbook/entry/UserAddressbookEntry.java +++ b/src/org/mxchange/jaddressbook/model/addressbook/entry/UserAddressbookEntry.java @@ -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; } }