com.atlassian.util.concurrent
Class Lazy

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

public final class Lazy
extends java.lang.Object

Factory for creating lazily populated references.

Since:
2.1

Constructor Summary
Lazy()
           
 
Method Summary
static
<T> Supplier<T>
supplier(Supplier<T> factory)
          Memoizing reference that is lazily computed using the supplied factory.
static
<T> Supplier<T>
timeToIdle(Supplier<T> factory, long time, java.util.concurrent.TimeUnit unit)
          Memoizing reference that expires the specified amount of time after the last time it was accessed.
static
<T> Supplier<T>
timeToLive(Supplier<T> factory, long time, java.util.concurrent.TimeUnit unit)
          Memoizing reference that expires the specified amount of time after creation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Lazy

public Lazy()
Method Detail

supplier

public static <T> Supplier<T> supplier(Supplier<T> factory)
Memoizing reference that is lazily computed using the supplied factory.

The factory is not held on to after it is used, enabling it to be garbage collected.

Type Parameters:
T - the type.
Parameters:
factory - for populating the initial value, called only once.
Returns:
a supplier

timeToLive

public static <T> Supplier<T> timeToLive(Supplier<T> factory,
                                         long time,
                                         java.util.concurrent.TimeUnit unit)
Memoizing reference that expires the specified amount of time after creation.

Type Parameters:
T - the type.
Parameters:
factory - for populating the initial value, called only once.
time - the amount
unit - the units the amount is in
Returns:
a supplier

timeToIdle

public static <T> Supplier<T> timeToIdle(Supplier<T> factory,
                                         long time,
                                         java.util.concurrent.TimeUnit unit)
Memoizing reference that expires the specified amount of time after the last time it was accessed.

Type Parameters:
T - the type.
Parameters:
factory - for populating the initial value, called only once.
time - the amount
unit - the units the amount is in
Returns:
a supplier


Copyright © 2011 Atlassian. All Rights Reserved.