Package org.jeegen.jee6.util
Class CollatingComparator<T>
- java.lang.Object
-
- org.jeegen.jee6.util.CollatingComparator<T>
-
- Type Parameters:
T
- The type to compare.
- All Implemented Interfaces:
Serializable
,Comparator<T>
public abstract class CollatingComparator<T> extends Object implements Comparator<T>, Serializable
This base class initializes aLocale
for comparison purposes.- Author:
- sm
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description CollatingComparator(int order, Locale locale, int strength)
This constructor initializes a localizedCollator
and the sort order.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
asc()
This method sets to ascending sort order.int
compare(T o1, T o2)
This abstract method implements theComparator.compare(Object, Object)
method of theComparator
interface.protected abstract int
compareLocale(T o1, T o2)
This abstract method provides a compare method in a locale way which is provided by the derived class.void
revert()
This method reverts the sort order.-
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 Detail
-
ASC
public static final int ASC
Flag for sorting increasing.- See Also:
- Constant Field Values
-
DESC
public static final int DESC
Flag for sorting decreasing.- See Also:
- Constant Field Values
-
order
protected int order
The sort order flag.
-
-
Method Detail
-
revert
public void revert()
This method reverts the sort order.
-
asc
public void asc()
This method sets to ascending sort order.
-
compare
public int compare(T o1, T o2)
This abstract method implements theComparator.compare(Object, Object)
method of theComparator
interface. By default it calls theCollatingComparator
compareLocale(Object, Object)
method and respects the ascending or descending sort order state. Override this method only if you want to use multipleLocale
s for comparison reasons.- Specified by:
compare
in interfaceComparator<T>
- Parameters:
o1
- The first object to compare.o2
- The second object to compare.- See Also:
Comparator.compare(Object, Object)
-
compareLocale
protected abstract int compareLocale(T o1, T o2)
This abstract method provides a compare method in a locale way which is provided by the derived class. This method should not respect the sort order flag as it is ment to provide alnoy a nativeLocale
comparison method. You can implement cascaded comparisons like surename, forename, etc.- Parameters:
o1
- The first object to compare.o2
- The second object to compare.- Returns:
- An integer which is zero on equal words, a negative integer if v1 is smaller than v2 and a positive number if v1 is greater than v2.
-
-