Package org.apache.wiki.util.comparators

# Class CollatorComparator

java.lang.Object
org.apache.wiki.util.comparators.CollatorComparator

All Implemented Interfaces:
  `Comparator<String>`

Direct Known Subclasses:
  `LocaleComparator`

public class CollatorComparator extends Object implements Comparator<String>
A comparator that sorts Strings using a Collator. This class is needed because, even though Collator implements `Comparator<Object>` and the required `compare(String, String)` method, you can't safely cast Collator to `Comparator<String>`.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final Comparator<String>`
`DEFAULT_LOCALE_COMPARATOR`
`protected Collator`
`m_collator`

## Constructor Summary

Constructors
Constructor
Description
`CollatorComparator()`
Default constructor uses the current locale's collator.
`CollatorComparator(Collator collator)`
Construct with a specific collator.

## Method Summary

Modifier and Type
Method
Description
`int`
`compare(String str1, String str2)`
`void`
`setCollator(Collator collator)`
Specify a new collator.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface java.util.Comparator

`equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong`

## Field Details

### DEFAULT_LOCALE_COMPARATOR

public static final Comparator<String> DEFAULT_LOCALE_COMPARATOR

### m_collator

protected Collator m_collator

## Constructor Details

### CollatorComparator

public CollatorComparator()
Default constructor uses the current locale's collator.

### CollatorComparator

public CollatorComparator(Collator collator)
Construct with a specific collator.

Parameters:
  `collator` - the collator to be used for comparisons

## Method Details

### compare

public int compare(String str1, String str2)

Specified by:
  `compare` in interface `Comparator<String>`

### setCollator

public void setCollator(Collator collator)
Specify a new collator.

Parameters:
  `collator` - the collator to be used from now on