|
Holger's Java API |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.antelmann.util.UniversalComparator
public class UniversalComparator
The UniversalComparator is useful as a default if no other more specific sorting strategy is present. Its Collator first tries to order the objects by their natural order - if applicable (except for Strings, which will be sorted with a default Collator). If that fails, the objects will be sorted based on their toString() value using the embedded instance of a Collator. Also, this class gracefully handles null values.
Collator| Constructor Summary | |
|---|---|
UniversalComparator()
uses the default Collator instance |
|
UniversalComparator(boolean caseSensitive)
uses no Collator but direct String comparison instead |
|
UniversalComparator(Collator collator)
if a null value is given, String comparison is used instead of a collator |
|
| Method Summary | ||
|---|---|---|
static
|
combine(Comparator<? super T> c1,
Comparator<? super T> c2)
|
|
int |
compare(Number n1,
Number n2)
|
|
int |
compare(Object o1,
Object o2)
null values are accepted and are sorted before a non-null value |
|
int |
compare(String o1,
String o2)
|
|
Collator |
getCollator()
provides access to the embedded collator (which may be null); its standard instance is the default value. |
|
static UniversalComparator |
getDefaultInstance()
returns one global default instance, which uses the default Collator instance by default |
|
boolean |
isCaseSensitive()
if true, the String comparison (if it applies) is case sensitive (false is the default). |
|
static
|
reverse(Comparator<T> c)
a utility method for convenience that simply reverses the given ordering |
|
Comparator<Object> |
reversed()
|
|
void |
setCaseSensitive(boolean flag)
if set to true, the String comparison (if it applies) is case sensitive. |
|
void |
setCollator(Collator collator)
allows to change the default collator in use; if set to null, the String comparison is used directly without a 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 |
| Constructor Detail |
|---|
public UniversalComparator()
public UniversalComparator(boolean caseSensitive)
public UniversalComparator(Collator collator)
| Method Detail |
|---|
public static UniversalComparator getDefaultInstance()
public Collator getCollator()
public void setCollator(Collator collator)
String.compareTo(String)public boolean isCaseSensitive()
public void setCaseSensitive(boolean flag)
public int compare(String o1,
String o2)
public int compare(Number n1,
Number n2)
public int compare(Object o1,
Object o2)
compare in interface Comparator<Object>public Comparator<Object> reversed()
public static <T> Comparator<T> reverse(Comparator<T> c)
public static <T> Comparator<T> combine(Comparator<? super T> c1,
Comparator<? super T> c2)
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||