com.atlassian.util.concurrent
Class Functions

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

public final class Functions
extends Object


Method Summary
static
<D,R> Function<D,R>
fromSupplier(Supplier<R> supplier)
          Get a function that uses the Supplier as a factory for all inputs.
static
<T> Function<T,T>
identity()
          Get a function that always returns the input.
static
<T,R> com.google.common.base.Function<T,R>
toGoogleFunction(Function<T,R> function)
          Map to a google-collections Function.
static
<T,R> Function<T,R>
weakMemoize(Function<T,R> f)
          Get a function that weakly memoizes the output – ie.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

fromSupplier

public static <D,R> Function<D,R> fromSupplier(@NotNull
                                               Supplier<R> supplier)
Get a function that uses the Supplier as a factory for all inputs.

Type Parameters:
D - the key type, ignored
R - the result type
Parameters:
supplier - called for all inputs
Returns:
the 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.

weakMemoize

public static <T,R> Function<T,R> weakMemoize(Function<T,R> f)
Get a function that weakly memoizes the output – ie. subsequent calls for the same input value will return the same reference if it has not been garbage collected because there are no external strong referrents to it.

Type Parameters:
T - the input or key type for the function. Must be a value (immutable) and have a well behaved hashcode implementation.
R - the output type of the for the function.
Parameters:
f - the function to call if the value is not already cached.
Returns:
the function that will .

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 © 2014 Atlassian. All Rights Reserved.