public class Functions extends Object
Constructor and Description |
---|
Functions() |
Modifier and Type | Method and Description |
---|---|
static <S,T extends S> |
coerceToSuper()
Transform to a super class.
|
static <T,R extends T> |
downcast(Class<R> subclass)
Get a function that always the input downcast to the supplied class.
|
static <T> Function<T,T> |
identity()
Get a function that always returns the input.
|
static <T,V> Visitor<T> |
mappedVisitor(Function<T,V> mappingFunction,
Visitor<V> delegate)
Get a visitor that will apply the given
function before delegating to another visitor. |
static <T,R> Function<T,R> |
memoize(Function<T,R> function,
ConcurrentMap<T,R> map)
Memoizer maps an input to an output and always returns the mapped result
rather than calling the wrapped function every time.
|
static <T,R> com.google.common.base.Function<T,R> |
toGoogleFunction(Function<T,R> function)
Map to a google-collections Function.
|
public static <T,R> Function<T,R> memoize(Function<T,R> function, ConcurrentMap<T,R> map)
Note, once mapped the input and the result can only be externally removed. Also, if the supplied function returns nulls then no memoization will occur.
T
- the input type. MUST be immutable.R
- the result type.function
- for supplying the initial value that gets mappedmap
- for storing the key-value mappingspublic static <T> Function<T,T> identity()
T
- the type of the input and the output for the function.public static <T,V> Visitor<T> mappedVisitor(Function<T,V> mappingFunction, Visitor<V> delegate)
function
before delegating to another visitor.T
- the inferred type of the function's inputV
- the inferred type of the function's output, which will be passed to the delegate visitormappingFunction
- the mapping function to applydelegate
- the visitor to call with the function output valuespublic static <T,R extends T> Function<T,R> downcast(Class<R> subclass)
T
- the type of the input and the output for the function.public static <S,T extends S> Function<T,S> coerceToSuper()
Functions.<SuperClass, SubClass> coerceToSuper();
S
- the super class.T
- the sub class.public static <T,R> com.google.common.base.Function<T,R> toGoogleFunction(Function<T,R> function)
T
- input typeR
- output typefunction
- the function to mapCopyright © 2002-2017 Atlassian. All Rights Reserved.