Skip navigation links
oracle.javatools.util.deferred
Class Thunk<T>
java.lang.Object
oracle.javatools.util.deferred.Thunk<T>
- Direct Known Subclasses:
- WeakThunk
-
public abstract class Thunk<T>
- extends java.lang.Object
Allow the client to provide a unit of delayed computation. Based on Hairy's state pattern
Nested Class Summary |
static class |
Thunk.ThunkException
A unchecked excpetions that thunks can use to communicate with the outside world. |
Constructor Summary |
Thunk()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Thunk
public Thunk()
get
public T get()
-
- Returns:
- The computed value in a single threaded environment this will only create one instance not matter how many times it is called.
compute
protected abstract T compute()
-
- Returns:
- The computed value, this value should only be computed the
getValue
protected T getValue()
-
- Returns:
- The current value, to be override for WeakThunk implementation
setValue
protected void setValue(T value)
resetState
protected void resetState()
- Reset the state of the thunk to initialized
synchronizedThunk
public static <T> Thunk<T> synchronizedThunk(Thunk<T> thunk)
-
- Parameters:
thunk
- The thunk that should be wraped
- Returns:
- A thread safe on acess synchronized thunk
directReference
public static <T> Thunk<T> directReference(T object)
-
- Parameters:
object
- The object this thunk shoud produce
- Returns:
- A thunk that produces the instance provided
Skip navigation links
Copyright © 1997, 2012, Oracle. All rights reserved.