Package at.jku.ssw.fp.util
Class TypeTestFunction<T,R>
- java.lang.Object
-
- at.jku.ssw.fp.util.TypeTestFunction<T,R>
-
- Type Parameters:
T
- the type of the argumentR
- the type of the wrapped return value
- All Implemented Interfaces:
CondFunction<Object,R>
,Function<Object,Optional<R>>
public class TypeTestFunction<T,R> extends Object implements CondFunction<Object,R>
Interface for conditional functions which do a type test of the argument value. If the argument passes the type test, the value is mapped to a result and the result is wrapped into theOptional
. But if the type test is not successful,Optional.empty()
is returned.- Author:
- Herbert Praehofer
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Optional<R>
apply(Object o)
Tests the object and then applies the function on the object.static <T,R>
TypeTestFunction<T,R>of(Class<T> clazz, Function<? super T,? extends R> func)
Creates a typetest function from a class and a function.boolean
test(Object o)
Tests the object if it is of the specific class.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface at.jku.ssw.fp.util.CondFunction
orElse, orElseIf
-
-
-
-
Method Detail
-
of
public static <T,R> TypeTestFunction<T,R> of(Class<T> clazz, Function<? super T,? extends R> func)
Creates a typetest function from a class and a function.- Type Parameters:
T
- the type of the argumentR
- the type of the wrapped return value- Parameters:
clazz
- the class for the typetestfunc
- the function- Returns:
- the typetest function
-
test
public boolean test(Object o)
Tests the object if it is of the specific class.- Specified by:
test
in interfaceCondFunction<T,R>
- Parameters:
o
- the object to test- Returns:
true
if the object is of the specific class.
-
-