Package org.bremersee.comparator
Interface ValueExtractor
- All Known Implementing Classes:
DefaultValueExtractor
public interface ValueExtractor
The value extractor finds the value of a given field name or path by reflection.
- Author:
- Christian Bremer
-
Method Summary
Modifier and TypeMethodDescriptionFind field with the given name of the specified class.Find the field with the given name of the specified class.findMethod(Class<?> clazz, String name) Find the method with the given name and no parameters of the specified class.findMethod(Class<?> clazz, String name, Class<?>... paramTypes) Find the method with the given name and parameters of the specified class.Find the value of the given add name or path of the given object.default String[]getPossibleMethodNames(String name) Get possible method names of the given field name.default ObjectInvoke the given field on the given object.default ObjectInvoke the given method on the given object.
-
Method Details
-
findValue
Find the value of the given add name or path of the given object.- Parameters:
obj- the objectfield- the field name or path- Returns:
- the object
- Throws:
ValueExtractorException- if no add nor method is found
-
findField
Find field with the given name of the specified class.- Parameters:
clazz- the classname- the field name- Returns:
- the field
-
findField
Find the field with the given name of the specified class.- Parameters:
clazz- the classname- the field nametype- the type of the field- Returns:
- the field
-
getPossibleMethodNames
Get possible method names of the given field name. The default implementation returns the field name, it's getter for an object and a primitive boolean.If '
firstName' is given for example, 'firstName', 'getFirstName' and 'isFirstName' will be returned.- Parameters:
name- the field name- Returns:
- the possible method names
-
findMethod
Find the method with the given name and no parameters of the specified class.- Parameters:
clazz- the classname- the method name- Returns:
- the method
-
findMethod
Find the method with the given name and parameters of the specified class.- Parameters:
clazz- the classname- the method nameparamTypes- the parameter types- Returns:
- the method
-
invoke
Invoke the given method on the given object. If the method is not accessible,setAccessible(true)will be called.- Parameters:
method- the methodobj- the object- Returns:
- the return value of the method
- Throws:
ValueExtractorException- if aIllegalAccessExceptionor aInvocationTargetExceptionoccurs
-
invoke
Invoke the given field on the given object. If the field is not accessible,setAccessible(true)will be called.- Parameters:
field- the fieldobj- the object- Returns:
- the value of the field
- Throws:
ValueExtractorException- if aIllegalAccessExceptionoccurs
-