From: Roland Häder Date: Sun, 18 Mar 2018 16:30:34 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=3396c324eafb819fc68c7ef14a29af3c84c8b0d0;p=jcontacts-core.git Continued: - added new dependency jcoreee - implemented Comparable Signed-off-by: Roland Häder --- diff --git a/nbproject/project.properties b/nbproject/project.properties index a407659..3578804 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -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 diff --git a/src/org/mxchange/jcontacts/model/contact/Contact.java b/src/org/mxchange/jcontacts/model/contact/Contact.java index f82cc43..89da0a7 100644 --- a/src/org/mxchange/jcontacts/model/contact/Contact.java +++ b/src/org/mxchange/jcontacts/model/contact/Contact.java @@ -29,7 +29,7 @@ import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; *

* @author Roland Häder */ -public interface Contact extends Serializable { +public interface Contact extends Comparable, Serializable { /** * Birth day diff --git a/src/org/mxchange/jcontacts/model/contact/UserContact.java b/src/org/mxchange/jcontacts/model/contact/UserContact.java index e61d4df..98a75d0 100644 --- a/src/org/mxchange/jcontacts/model/contact/UserContact.java +++ b/src/org/mxchange/jcontacts/model/contact/UserContact.java @@ -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) {