From ce727f68fdf2bb57096df11f43ed43984797ab74 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 16 Mar 2018 00:44:40 +0100 Subject: [PATCH] Continued: - added dependency jcoreee.jar - implemented compareTo() method, was a stub MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- nbproject/project.properties | 5 +++- .../jcountry/model/data/Countries.java | 2 +- .../jcountry/model/data/CountryData.java | 26 ++++++++++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/nbproject/project.properties b/nbproject/project.properties index 9b9c3f6..3a15f78 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -30,10 +30,12 @@ dist.jar=${dist.dir}/jcountry-core.jar dist.javadoc.dir=${dist.dir}/javadoc endorsed.classpath= excludes= +file.reference.jcoreee.jar=lib/jcoreee.jar includes=** jar.compress=false javac.classpath=\ - ${libs.jpa20-persistence.classpath} + ${libs.jpa20-persistence.classpath}:\ + ${file.reference.jcoreee.jar} # Space-separated list of extra javac options javac.compilerargs=-Xlint:unchecked -Xlint:deprecation javac.deprecation=true @@ -73,5 +75,6 @@ run.test.classpath=\ ${javac.test.classpath}:\ ${build.test.classes.dir} source.encoding=UTF-8 +source.reference.jcoreee.jar=../jcoreee/src/ src.dir=src test.src.dir=test diff --git a/src/org/mxchange/jcountry/model/data/Countries.java b/src/org/mxchange/jcountry/model/data/Countries.java index 8fd5d8e..15fdc95 100644 --- a/src/org/mxchange/jcountry/model/data/Countries.java +++ b/src/org/mxchange/jcountry/model/data/Countries.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Roland Häder + * Copyright (C) 2018 Free Software Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/org/mxchange/jcountry/model/data/CountryData.java b/src/org/mxchange/jcountry/model/data/CountryData.java index f851abb..75b7f82 100644 --- a/src/org/mxchange/jcountry/model/data/CountryData.java +++ b/src/org/mxchange/jcountry/model/data/CountryData.java @@ -30,6 +30,7 @@ import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Transient; +import org.mxchange.jcoreee.utils.Comparables; /** * A POJO for country data @@ -118,7 +119,30 @@ public class CountryData implements Country { @Override public int compareTo (final Country country) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + // For performance reasons + if (null == country) { + // Should not happen + throw new NullPointerException("country is null"); //NOI18N + } else if (Objects.equals(this, country)) { + // Same object + return 0; + } + + // Init comparators + final int comparators[] = { + // First check country code, clear indication ... + this.getCountryCode().compareTo(country.getCountryCode()), + // ... and phone code, too + this.getCountryPhoneCode().compareTo(country.getCountryPhoneCode()), + // ... then last i18n key + this.getCountryI18nKey().compareTo(country.getCountryI18nKey()) + }; + + // Check all values + final int comparison = Comparables.checkAll(comparators); + + // Return value + return comparison; } @Override -- 2.39.5