From: Roland Häder Date: Mon, 19 Mar 2018 01:05:59 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=fc66c91c40119ad2a1d53076f8f2dd439341f682;p=jcustomer-core.git Continued: - added method Customers.compare() which allows a null-safe comparison of the entity - updated commons-lang3 to 3.7 - updated commons-codec to 1.11 Signed-off-by: Roland Häder --- diff --git a/lib/nblibraries.properties b/lib/nblibraries.properties index 2f0bd14..b1c3713 100644 --- a/lib/nblibraries.properties +++ b/lib/nblibraries.properties @@ -1,11 +1,11 @@ libs.commons-codec.classpath=\ - ${base}/commons-codec/commons-codec-1.10.jar -libs.commons-codec.displayName=Commons Codec 1.10 + ${base}/commons-codec/commons-codec-1.11.jar +libs.commons-codec.displayName=Commons Codec 1.11 libs.commons-codec.javadoc=\ - https://commons.apache.org/proper/commons-codec/archives/1.10/apidocs/ + https://commons.apache.org/proper/commons-codec/archives/1.11/apidocs/ libs.commons-lang3.classpath=\ - ${base}/commons-lang3/commons-lang3-3.5.jar -libs.commons-lang3.displayName=Commons Lang3 3.5 + ${base}/commons-lang3/commons-lang3-3.7.jar +libs.commons-lang3.displayName=Commons Lang3 3.7 libs.commons-lang3.javadoc=\ https://commons.apache.org/proper/commons-lang/javadocs/api-release/ libs.CopyLibs.classpath=\ diff --git a/src/org/mxchange/jcustomercore/utils/Customers.java b/src/org/mxchange/jcustomercore/utils/Customers.java index 20ed6fd..866d871 100644 --- a/src/org/mxchange/jcustomercore/utils/Customers.java +++ b/src/org/mxchange/jcustomercore/utils/Customers.java @@ -18,6 +18,7 @@ package org.mxchange.jcustomercore.utils; import java.security.SecureRandom; import java.text.MessageFormat; +import java.util.Objects; import java.util.Random; import org.apache.commons.lang3.StringUtils; import org.mxchange.jcustomercore.model.customer.Customer; @@ -42,6 +43,32 @@ public class Customers { RANDOM_NUMBER_GENERATOR = new SecureRandom(); } + /** + * Compares both customer instances. This method returns -1 if second + * instance is null. + *

+ * @param customer1 Customer instance 1 + * @param customer2 Customer instance 2 + *

+ * @return Comparison value + */ + public static int compare (final Customer customer1, final Customer customer2) { + // Check euqality, then at least first must be given + if (Objects.equals(customer1, customer2)) { + // Both are same + return 0; + } else if (null == customer1) { + // First is null + return -1; + } else if (null == customer2) { + // Second is null + return 1; + } + + // Invoke compareTo() method + return customer1.compareTo(customer2); + } + /** * Copies all fields from source customer to target customer instance. *