Package org.apache.wiki.util.comparators
Class CollatorComparator
- java.lang.Object
-
- org.apache.wiki.util.comparators.CollatorComparator
-
- All Implemented Interfaces:
java.util.Comparator<java.lang.String>
- Direct Known Subclasses:
LocaleComparator
public class CollatorComparator extends java.lang.Object implements java.util.Comparator<java.lang.String>
A comparator that sorts Strings using a Collator. This class is needed because, even though Collator implementsComparator<Object>
and the requiredcompare(String, String)
method, you can't safely cast Collator toComparator<String>
.
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.Comparator<java.lang.String>
DEFAULT_LOCALE_COMPARATOR
protected java.text.Collator
m_collator
-
Constructor Summary
Constructors Constructor Description CollatorComparator()
Default constructor uses the current locale's collator.CollatorComparator(java.text.Collator collator)
Construct with a specific collator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compare(java.lang.String str1, java.lang.String str2)
void
setCollator(java.text.Collator collator)
Specify a new collator.
-
-
-
Field Detail
-
DEFAULT_LOCALE_COMPARATOR
public static final java.util.Comparator<java.lang.String> DEFAULT_LOCALE_COMPARATOR
-
m_collator
protected java.text.Collator m_collator
-
-
Constructor Detail
-
CollatorComparator
public CollatorComparator()
Default constructor uses the current locale's collator.
-
CollatorComparator
public CollatorComparator(java.text.Collator collator)
Construct with a specific collator.- Parameters:
collator
- the collator to be used for comparisons
-
-
Method Detail
-
compare
public int compare(java.lang.String str1, java.lang.String str2)
- Specified by:
compare
in interfacejava.util.Comparator<java.lang.String>
-
setCollator
public void setCollator(java.text.Collator collator)
Specify a new collator.- Parameters:
collator
- the collator to be used from now on
-
-