com.atlassian.jira.util
Class Functions

java.lang.Object
  extended by com.atlassian.jira.util.Functions

public class Functions
extends Object

Useful standard functions.


Constructor Summary
Functions()
           
 
Method Summary
static
<S,T extends S>
Function<T,S>
coerceToSuper()
          Transform to a super class.
static
<T,R extends T>
Function<T,R>
downcast(Class<R> subclass)
          Get a function that always the input downcast to the supplied class.
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Functions

public Functions()
Method Detail

memoize

public 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. 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 mapped
map - for storing the key-value mappings
Returns:
a memoizing function.

downcast

public static <T,R extends T> Function<T,R> downcast(Class<R> subclass)
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.
Parameters:
subclass - subclass to downcast
Returns:
the identity function.

coerceToSuper

public static <S,T extends S> Function<T,S> 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

public static <T,R> com.google.common.base.Function<T,R> toGoogleFunction(Function<T,R> function)
Map to a google-collections Function.

Type Parameters:
T - input type
R - output type
Parameters:
function - the function to map
Returns:
the mapped function.


Copyright © 2002-2014 Atlassian. All Rights Reserved.