From e6285ceb313d6fdd50688a97fef1fef9ff218d6d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 6 Oct 2022 15:09:07 +0200 Subject: [PATCH] Continued: - added utilities method Countries.compare() - renamed class Countries to CountryUtils --- .../{Countries.java => CountryUtils.java} | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) rename src/org/mxchange/jcountry/model/data/{Countries.java => CountryUtils.java} (78%) diff --git a/src/org/mxchange/jcountry/model/data/Countries.java b/src/org/mxchange/jcountry/model/data/CountryUtils.java similarity index 78% rename from src/org/mxchange/jcountry/model/data/Countries.java rename to src/org/mxchange/jcountry/model/data/CountryUtils.java index 825ec11..7086765 100644 --- a/src/org/mxchange/jcountry/model/data/Countries.java +++ b/src/org/mxchange/jcountry/model/data/CountryUtils.java @@ -24,13 +24,38 @@ import java.util.Objects; *

* @author Roland Häder */ -public class Countries implements Serializable { +public class CountryUtils implements Serializable { /** * Serial number */ private static final long serialVersionUID = 286_956_737_410L; + /** + * Compares two instances of Country with each other + *

+ * @param country1 First instance of Country + * @param country2 Second instance of Country + *

+ * @return See Comparable.compareTo() + */ + public static int compare (final Country country1, final Country country2) { + // Check equality, then at least first must be given + if (Objects.equals(country1, country2)) { + // Both are same + return 0; + } else if (null == country1) { + // First is null + return -1; + } else if (null == country2) { + // Second is null + return 1; + } + + // Invoke compareTo() method + return country1.compareTo(country2); + } + /** * Copies data from sourceCountry to targetCountry. *

@@ -69,7 +94,7 @@ public class Countries implements Serializable { /** * Utility classes should not have instances */ - private Countries () { + private CountryUtils () { } } -- 2.39.5