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 Details

    • findValue

      Object findValue(Object obj, String field)
      Find the value of the given add name or path of the given object.
      Parameters:
      obj - the object
      field - 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 class
      name - 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 class
      name - the field name
      type - 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 class
      name - 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 class
      name - the method name
      paramTypes - 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 method
      obj - the object
      Returns:
      the return value of the method
      Throws:
      ValueExtractorException - if a IllegalAccessException or a InvocationTargetException occurs
    • 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 field
      obj - the object
      Returns:
      the value of the field
      Throws:
      ValueExtractorException - if a IllegalAccessException occurs