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

Signed-off-by: Roland Häder <roland@mxchange.org>
nbproject/project.properties
src/org/mxchange/jcontacts/model/contact/Contact.java
src/org/mxchange/jcontacts/model/contact/UserContact.java

index a407659eabeb3ff0de84b19b3419656c1acf616e..357880401fb2fb4cac497b65eaa7993116696ea5 100644 (file)
@@ -30,6 +30,7 @@ dist.jar=${dist.dir}/jcontacts-core.jar
 dist.javadoc.dir=${dist.dir}/javadoc
 endorsed.classpath=
 excludes=
+file.reference.jcoreee.jar=lib/jcoreee.jar
 file.reference.jcountry-core.jar=lib/jcountry-core.jar
 file.reference.jphone-core.jar=lib/jphone-core.jar
 includes=**
@@ -39,6 +40,7 @@ jar.index=${jnlp.enabled}
 javac.classpath=\
     ${file.reference.jcountry-core.jar}:\
     ${file.reference.jphone-core.jar}:\
+    ${file.reference.jcoreee.jar}:\
     ${libs.jpa20-persistence.classpath}
 # Space-separated list of extra javac options
 javac.compilerargs=-Xlint:unchecked -Xlint:deprecation
@@ -92,6 +94,7 @@ run.test.classpath=\
     ${javac.test.classpath}:\
     ${build.test.classes.dir}
 source.encoding=UTF-8
+source.reference.jcoreee.jar=../jcoreee/src/
 source.reference.jcountry-core.jar=../jcountry-core/src/
 source.reference.jphone-core.jar=../jphone-core/src/
 src.dir=src
index f82cc43c59138691e2bc67a2df101577536f6281..89da0a7e6eee5aeb81b9aa8de840c17237134979 100644 (file)
@@ -29,7 +29,7 @@ import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
-public interface Contact extends Serializable {
+public interface Contact extends Comparable<Contact>, Serializable {
 
        /**
         * Birth day
index e61d4dfa2c57c9782f7eaf2948e815ad306bdadb..98a75d09703174eda9e0deeb53067f0265dd5d7d 100644 (file)
@@ -38,6 +38,8 @@ import javax.persistence.Temporal;
 import javax.persistence.TemporalType;
 import javax.persistence.Transient;
 import org.mxchange.jcontacts.model.contact.title.PersonalTitle;
+import org.mxchange.jcoreee.utils.Comparables;
+import org.mxchange.jcoreee.utils.StringUtils;
 import org.mxchange.jcountry.model.data.Country;
 import org.mxchange.jcountry.model.data.CountryData;
 import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
@@ -239,6 +241,49 @@ public class UserContact implements Contact {
                this.contactFamilyName = contactFamilyName;
        }
 
+       @Override
+       public int compareTo (final Contact contact) {
+               // Checkparameter and return 0 if equal
+               if (null == contact) {
+                       // Should not happen
+                       throw new NullPointerException("contact is null"); //NOI18N
+               } else if (Objects.equals(this, contact)) {
+                       // Same object
+                       return 0;
+               }
+
+               // Init comparators
+               final int comparators[] = {
+                       // First check country
+                       this.getContactCountry().compareTo(contact.getContactCountry()),
+                       // ... then ZIP code
+                       Integer.compare(this.getContactZipCode(), contact.getContactZipCode()),
+                       // ... and city
+                       this.getContactCity().compareTo(contact.getContactCity()),
+                       // ... street name
+                       StringUtils.compareToIgnoreCase(this.getContactStreet(), contact.getContactStreet()),
+                       // ... house number
+                       Integer.compare(this.getContactHouseNumber(), contact.getContactHouseNumber()),
+                       // ... extension
+                       StringUtils.compareToIgnoreCase(this.getContactHouseNumberExtension(), contact.getContactHouseNumberExtension()),
+                       // ... now it is sure that address is different/same, continue with personal title
+                       this.getContactPersonalTitle().compareTo(contact.getContactPersonalTitle()),
+                       // ... academical title
+                       StringUtils.compareToIgnoreCase(this.getContactTitle(), contact.getContactTitle()),
+                       // .. family name is next ...
+                       this.getContactFamilyName().compareToIgnoreCase(contact.getContactFamilyName()),
+                       // .. first name is second ...
+                       this.getContactFirstName().compareToIgnoreCase(contact.getContactFirstName()),
+                       // ... next is email address
+                       StringUtils.compareToIgnoreCase(this.getContactEmailAddress(), contact.getContactEmailAddress()),};
+
+               // Check all values
+               final int comparison = Comparables.checkAll(comparators);
+
+               // Return value
+               return comparison;
+       }
+
        @Override
        public boolean equals (final Object object) {
                if (this == object) {