Package org.bremersee.comparator
Interface ValueExtractor
-
- All Known Implementing Classes:
DefaultValueExtractor
public interface ValueExtractorThe value extractor finds the value of a given field name or path by reflection.- Author:
- Christian Bremer
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default Optional<Field>findField(Class<?> clazz, String name)Find field with the given name of the specified class.default Optional<Field>findField(Class<?> clazz, String name, Class<?> type)Find the field with the given name of the specified class.default Optional<Method>findMethod(Class<?> clazz, String name)Find the method with the given name and no parameters of the specified class.default Optional<Method>findMethod(Class<?> clazz, String name, Class<?>... paramTypes)Find the method with the given name and parameters of the specified class.ObjectfindValue(Object obj, String field)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(Field field, Object obj)Invoke the given field on the given object.default Objectinvoke(Method method, Object obj)Invoke the given method on the given object.
-
-
-
Method Detail
-
findValue
Object findValue(Object obj, String field)
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
default Optional<Field> findField(Class<?> clazz, String name)
Find field with the given name of the specified class.- Parameters:
clazz- the classname- the field name- Returns:
- the field
-
findField
default Optional<Field> findField(Class<?> clazz, String name, Class<?> type)
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
default String[] getPossibleMethodNames(String name)
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
default Optional<Method> findMethod(Class<?> clazz, String name)
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
default Optional<Method> findMethod(Class<?> clazz, String name, Class<?>... paramTypes)
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
default Object invoke(Method method, Object obj)
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
default Object invoke(Field field, Object obj)
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
-
-