Package com.atlassian.jira.util
Class Functions
java.lang.Object
com.atlassian.jira.util.Functions
Useful standard functions.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <S,
T extends S>
Function<T, S> Transform to a super class.static <T,
R extends T>
Function<T, R> 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 givenfunction
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.
-
Constructor Details
-
Functions
public Functions()
-
-
Method Details
-
memoize
Memoizer maps an input to an output and always returns the mapped result rather than calling the wrapped function every time. Useful when the wrapped function is expensive to call.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.
- Type Parameters:
T
- the input type. MUST be immutable.R
- the result type.- Parameters:
function
- for supplying the initial value that gets mappedmap
- for storing the key-value mappings- Returns:
- a memoizing function.
-
identity
Get a function that always returns the input.- Type Parameters:
T
- the type of the input and the output for the function.- Returns:
- the identity function.
-
mappedVisitor
Get a visitor that will apply the givenfunction
before delegating to another visitor.- Type Parameters:
T
- the inferred type of the function's inputV
- the inferred type of the function's output, which will be passed to the delegate visitor- Parameters:
mappingFunction
- the mapping function to applydelegate
- the visitor to call with the function output values- Returns:
- a visitor that will accept input values for the function
-
downcast
Get a function that always the input downcast to the supplied class.- Type Parameters:
T
- the type of the input and the output for the function.- Returns:
- the identity function.
-
coerceToSuper
Transform to a super class. Usually needs to be called with explicit type parameters, eg:Functions.<SuperClass, SubClass> coerceToSuper();
- Type Parameters:
S
- the super class.T
- the sub class.
-
toGoogleFunction
Map to a google-collections Function.- Type Parameters:
T
- input typeR
- output type- Parameters:
function
- the function to map- Returns:
- the mapped function.
-