[Japi-cvs] SF.net SVN: japi: [273] libs/util/trunk/src/net/sf/japi/util/ LocaleComparator.java
Status: Beta
Brought to you by:
christianhujer
From: <chr...@us...> - 2007-01-07 16:06:36
|
Revision: 273 http://svn.sourceforge.net/japi/?rev=273&view=rev Author: christianhujer Date: 2007-01-07 08:06:35 -0800 (Sun, 07 Jan 2007) Log Message: ----------- Adding LocaleComparator. Added Paths: ----------- libs/util/trunk/src/net/sf/japi/util/LocaleComparator.java Added: libs/util/trunk/src/net/sf/japi/util/LocaleComparator.java =================================================================== --- libs/util/trunk/src/net/sf/japi/util/LocaleComparator.java (rev 0) +++ libs/util/trunk/src/net/sf/japi/util/LocaleComparator.java 2007-01-07 16:06:35 UTC (rev 273) @@ -0,0 +1,33 @@ +package net.sf.japi.util; + +import java.util.Comparator; +import java.util.Locale; +import java.text.Collator; + +/** Implementation of {@link Comparator} that is able to compare {@link Locale} instances by their names (allowing <code>null</code>). + * The Locale for sorting the Locales is determined at creation time. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public final class LocaleComparator implements Comparator<Locale> { + + /** Collator for comparing the names. */ + private final Collator collator = Collator.getInstance(); + + /** Create a LocaleComparator. */ + public LocaleComparator() { + } + + /** {@inheritDoc} */ + public int compare(final Locale o1, final Locale o2) { + if (o1 == null && o2 == null) { + return 0; + } else if (o1 == null) { + return -1; + } else if (o2 == null) { + return 1; + } else { + return collator.compare(o1.getDisplayName(), o2.getDisplayName()); + } + } + +} // class LocaleComparator Property changes on: libs/util/trunk/src/net/sf/japi/util/LocaleComparator.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |