Class ExtractDerivedParameter<S,T>

Object
ExtractDerivedParameter<S,T>
Type Parameters:
S - type of parameter to extract from (source)
T - type of parameter that is maybe derived (target)

public class ExtractDerivedParameter<S,T> extends Object
Extracts one type of parameter from another, if possible.
Author:
Owen Feehan
  • Constructor Details

    • ExtractDerivedParameter

      public ExtractDerivedParameter(Class<?> targetClass, Function<S,T> extractionFunction)
      Creates with only a targetClass.
      Parameters:
      targetClass - the class of the target type.
      extractionFunction - a function to extract the target from the source.
    • ExtractDerivedParameter

      public ExtractDerivedParameter(Class<?> targetClass, Function<S,T> extractionFunction, Class<?> sourceBaseClass)
      Creates with a classOfTarget and a baseClassOfSource.
      Parameters:
      targetClass - the class of the target type.
      extractionFunction - a function to extract the target from the source.
      sourceBaseClass - a class the source-param must be assignable to. It will be checked by reflection.
  • Method Details

    • extractIfPossible

      public Optional<T> extractIfPossible(S parameter)
      Extracts a derived parameter if possible from parameter.
      Parameters:
      parameter - the parameter to maybe derive an extracted parameter from.
      Returns:
      the extracted parameter or Optional.empty() if it is not possible.
    • getTargetClass

      public Class<?> getTargetClass()
      The class of the target type T.