]> git.mxchange.org Git - jcontacts-core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sun, 18 Mar 2018 21:57:38 +0000 (22:57 +0100)
committerRoland Häder <roland@mxchange.org>
Sun, 18 Mar 2018 23:51:39 +0000 (00:51 +0100)
- 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.

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

index 357880401fb2fb4cac497b65eaa7993116696ea5..fcc03fd3e149ec94cb7fc9cded85d645edbf3764 100644 (file)
@@ -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
index 86d67dd2f648058f24e7f5b8947c9ce9a7cd4c5c..9210d41482f6a436b22b1d11359cc8d3524c2cfa 100644 (file)
@@ -47,8 +47,6 @@ public class Contacts implements Serializable {
         * @param contact2 Contact instance 2
         * <p>
         * @return Comparison value
-        * <p>
-        * @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
index 98a75d09703174eda9e0deeb53067f0265dd5d7d..1cb52c2096ad0025c76bdc74b23edb3e8fd1ca14 100644 (file)
@@ -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);