|
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.MethodComparator<T>
public class MethodComparator<T>
compares objects by the return value of a specified method name. This Comparator uses reflection to access the return values of the methods to be compared. If the return value in used is not Comparable, a UniversalComparator is used to handle the comparison.
| Constructor Summary | |
|---|---|
MethodComparator(String methodName)
calls MethodComparator(methodName, true) |
|
MethodComparator(String methodName,
boolean ascending)
the methodName (usually a 'getter'-method) must have no arguments for the objects to be compared. |
|
| Method Summary | |
|---|---|
int |
compare(T o1,
T o2)
if the object returned by the specified method of the first given object doesn't implement Comparable, the toString()
value of that object is used instead. |
String |
getMethodName()
|
UniversalComparator |
getUniversalComparator()
returns the embedded UniversalComparator in use for customization |
static String[] |
getUsableMethodNames(Class<?> c,
boolean comparableReturnValuesOnly)
lists all method names of the given class that take no parameters and return something but void - and are therefore usable for a MethodComparator. |
boolean |
isAscending()
|
| 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 MethodComparator(String methodName)
MethodComparator(methodName, true)
public MethodComparator(String methodName,
boolean ascending)
compareTo(Object) will be reversed.
| Method Detail |
|---|
public UniversalComparator getUniversalComparator()
public static String[] getUsableMethodNames(Class<?> c,
boolean comparableReturnValuesOnly)
public String getMethodName()
public boolean isAscending()
public int compare(T o1,
T o2)
throws ClassCastException
Comparable, the toString()
value of that object is used instead.
If a null value is encountered, it is considered to come before any other value.
compare in interface Comparator<T>ClassCastException - if any of the following Exceptions occur:
InvocationTargetException, NoSuchMethodException,
NoSuchMethodException
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||