From 3396c324eafb819fc68c7ef14a29af3c84c8b0d0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 18 Mar 2018 17:30:34 +0100 Subject: [PATCH] Continued: - added new dependency jcoreee - implemented Comparable MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- nbproject/project.properties | 3 ++ .../jcontacts/model/contact/Contact.java | 2 +- .../jcontacts/model/contact/UserContact.java | 45 +++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) 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) { -- 2.39.5