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
<T> Function<T,T>
identity()
          Get a function that always returns the input.
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.
 
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.

identity

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


Copyright © 2002-2009 Atlassian. All Rights Reserved.