From 12faad5115ebfb768e753bcfc38ac861d1d0a3bd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 18 Mar 2018 22:05:28 +0100 Subject: [PATCH] Continued: - renamed ContactUtils -> Contacts - added public method Contacts.compare() for comparing two contact instances MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../{ContactUtils.java => Contacts.java} | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) rename src/org/mxchange/jcontacts/model/contact/{ContactUtils.java => Contacts.java} (92%) diff --git a/src/org/mxchange/jcontacts/model/contact/ContactUtils.java b/src/org/mxchange/jcontacts/model/contact/Contacts.java similarity index 92% rename from src/org/mxchange/jcontacts/model/contact/ContactUtils.java rename to src/org/mxchange/jcontacts/model/contact/Contacts.java index d39444c..86d67dd 100644 --- a/src/org/mxchange/jcontacts/model/contact/ContactUtils.java +++ b/src/org/mxchange/jcontacts/model/contact/Contacts.java @@ -32,13 +32,41 @@ import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider; *

* @author Roland Häder */ -public class ContactUtils implements Serializable { +public class Contacts implements Serializable { /** * Serial number */ private static final long serialVersionUID = 26_785_734_719_670L; + /** + * Compares both contact instances. This method returns -1 if second + * instance is null. + *

+ * @param contact1 Contact instance 1 + * @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 + if (Objects.equals(contact1, contact2)) { + // Both are same + return 0; + } else if (null == contact1) { + // First cannot be null + throw new NullPointerException("contact1 is null"); //NOI18N + } else if (null == contact2) { + // Second is null + return -1; + } + + // Invoke compareTo() method + return contact1.compareTo(contact2); + } + /** * Copies all attributes from other contact object to this *

@@ -268,7 +296,7 @@ public class ContactUtils implements Serializable { /** * Private constructor for utilities */ - private ContactUtils () { + private Contacts () { } } -- 2.39.5