From: Roland Häder Date: Thu, 15 Mar 2018 23:44:40 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=ce727f68fdf2bb57096df11f43ed43984797ab74;p=jcountry-core.git Continued: - added dependency jcoreee.jar - implemented compareTo() method, was a stub Signed-off-by: Roland Häder --- 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