Class ExtractDerivedParameter<S,T>
Object
org.anchoranalysis.bean.initializable.property.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 Summary
Constructors Constructor Description ExtractDerivedParameter(Class<?> targetClass, Function<S,T> extractionFunction)Creates with only atargetClass.ExtractDerivedParameter(Class<?> targetClass, Function<S,T> extractionFunction, Class<?> sourceBaseClass)Creates with aclassOfTargetand abaseClassOfSource. -
Method Summary
Modifier and Type Method Description Optional<T>extractIfPossible(S parameter)Extracts a derived parameter if possible fromparameter.Class<?>getTargetClass()The class of the target typeT.
-
Constructor Details
-
ExtractDerivedParameter
Creates with only atargetClass.- 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 aclassOfTargetand abaseClassOfSource.- 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
Extracts a derived parameter if possible fromparameter.- Parameters:
parameter- the parameter to maybe derive an extracted parameter from.- Returns:
- the extracted parameter or
Optional.empty()if it is not possible.
-
getTargetClass
The class of the target typeT.
-