From d07c91bb2e53df90e62de96c5aa610c129fb23ac Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 18 Mar 2018 22:57:38 +0100 Subject: [PATCH] Continued: - added new dependency to Apache Commons Lang3 - used their StringUtils class for null-safe comparison - but their NumberUtils class' compare() methods are not null-safe, so have to take own CoreNumberUtils class instead. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- nbproject/project.properties | 1 + .../jcontacts/model/contact/Contacts.java | 8 +++----- .../jcontacts/model/contact/UserContact.java | 15 ++++++++------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/nbproject/project.properties b/nbproject/project.properties index 3578804..fcc03fd 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -41,6 +41,7 @@ javac.classpath=\ ${file.reference.jcountry-core.jar}:\ ${file.reference.jphone-core.jar}:\ ${file.reference.jcoreee.jar}:\ + ${libs.commons-lang3.classpath}:\ ${libs.jpa20-persistence.classpath} # Space-separated list of extra javac options javac.compilerargs=-Xlint:unchecked -Xlint:deprecation diff --git a/src/org/mxchange/jcontacts/model/contact/Contacts.java b/src/org/mxchange/jcontacts/model/contact/Contacts.java index 86d67dd..9210d41 100644 --- a/src/org/mxchange/jcontacts/model/contact/Contacts.java +++ b/src/org/mxchange/jcontacts/model/contact/Contacts.java @@ -47,8 +47,6 @@ public class Contacts implements Serializable { * @param contact2 Contact instance 2 *

* @return Comparison value - *

- * @throws NullPointerException If first instance is null */ public static int compare (final Contact contact1, final Contact contact2) { // Check euqality, then at least first must be given @@ -56,11 +54,11 @@ public class Contacts implements Serializable { // Both are same return 0; } else if (null == contact1) { - // First cannot be null - throw new NullPointerException("contact1 is null"); //NOI18N + // First is null + return -1; } else if (null == contact2) { // Second is null - return -1; + return 1; } // Invoke compareTo() method diff --git a/src/org/mxchange/jcontacts/model/contact/UserContact.java b/src/org/mxchange/jcontacts/model/contact/UserContact.java index 98a75d0..1cb52c2 100644 --- a/src/org/mxchange/jcontacts/model/contact/UserContact.java +++ b/src/org/mxchange/jcontacts/model/contact/UserContact.java @@ -37,9 +37,10 @@ import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Transient; +import org.apache.commons.lang3.StringUtils; import org.mxchange.jcontacts.model.contact.title.PersonalTitle; import org.mxchange.jcoreee.utils.Comparables; -import org.mxchange.jcoreee.utils.StringUtils; +import org.mxchange.jcoreee.utils.CoreNumberUtils; import org.mxchange.jcountry.model.data.Country; import org.mxchange.jcountry.model.data.CountryData; import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; @@ -257,25 +258,25 @@ public class UserContact implements Contact { // First check country this.getContactCountry().compareTo(contact.getContactCountry()), // ... then ZIP code - Integer.compare(this.getContactZipCode(), contact.getContactZipCode()), + CoreNumberUtils.compare(this.getContactZipCode(), contact.getContactZipCode()), // ... and city this.getContactCity().compareTo(contact.getContactCity()), // ... street name - StringUtils.compareToIgnoreCase(this.getContactStreet(), contact.getContactStreet()), + StringUtils.compareIgnoreCase(this.getContactStreet(), contact.getContactStreet()), // ... house number - Integer.compare(this.getContactHouseNumber(), contact.getContactHouseNumber()), + CoreNumberUtils.compare(this.getContactHouseNumber(), contact.getContactHouseNumber()), // ... extension - StringUtils.compareToIgnoreCase(this.getContactHouseNumberExtension(), contact.getContactHouseNumberExtension()), + StringUtils.compareIgnoreCase(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()), + StringUtils.compareIgnoreCase(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()),}; + StringUtils.compareIgnoreCase(this.getContactEmailAddress(), contact.getContactEmailAddress()),}; // Check all values final int comparison = Comparables.checkAll(comparators); -- 2.39.5