Package gnu.mapping
Class Promise<T>
- java.lang.Object
-
- gnu.mapping.Promise<T>
-
- All Implemented Interfaces:
gnu.kawa.format.Printable,Lazy<T>
public class Promise<T> extends java.lang.Object implements gnu.kawa.format.Printable, Lazy<T>
Implement Scheme "promises". This is a final class, because in some cases (as required by SRFI-45) we copy the fields of one Promise from other Promise, and such copying would be dubious if either operand is a sub-class.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description LazycheckAlias()voidcheckBlank()static Lazy<java.lang.Object>coerceToLazy(java.lang.Object value)static java.lang.Objectforce(java.lang.Object arg)Forces the argument, if needed, to a non-Lazy value.static java.lang.Objectforce(java.lang.Object arg, java.lang.Class target)If argument is Lazy, force it, unless already an instance of target.static java.lang.Objectforce1(java.lang.Object arg)Forces the argument, if needed.TgetValue()Return the actual value.booleanisBlank()static <T> Promise<T>makeBlank()static <T> Lazy<T>makeBoundPromise(T value)Wrap value as a forced Promise.voidprint(Consumer out)voidprint(java.lang.Appendable out)voidsetAlias(Lazy promise)Bind promise to be an alias of another Lazy value.voidsetException(java.lang.Throwable exception)Bind this promise so forcing it throws the given exception.voidsetForceValueIfPromise(boolean value)Set whether to recursively call getValue if getValue yields a Lazy value.voidsetThunk(Procedure thunk)Bind this promise so forcing it evaluates the given procedure.voidsetValue(java.lang.Object value)Bind this promise to a given (eager) value.java.lang.StringtoString()
-
-
-
Constructor Detail
-
Promise
public Promise()
Create new "blank" Promise. Calling getValue just waits until one of setValue, setAlias, setException or setThunk is invoked. One of these is typically done by some other "producer" thread.
-
Promise
public Promise(Procedure thunk)
Create a new Promise that will evaluate thunk when forced.
-
-
Method Detail
-
setForceValueIfPromise
public void setForceValueIfPromise(boolean value)
Set whether to recursively call getValue if getValue yields a Lazy value.
-
makeBlank
public static <T> Promise<T> makeBlank()
-
makeBoundPromise
public static <T> Lazy<T> makeBoundPromise(T value)
Wrap value as a forced Promise.
-
coerceToLazy
public static Lazy<java.lang.Object> coerceToLazy(java.lang.Object value)
-
getValue
public T getValue()
Description copied from interface:LazyReturn the actual value. Note thatgetValue()may returnthis, if this object isn't actually lazy. It may also return another lazy value. Normally you should usePromise.force{val}to extra a non-lazy (eager) value.
-
isBlank
public final boolean isBlank()
-
checkBlank
public void checkBlank()
-
setValue
public void setValue(java.lang.Object value)
Bind this promise to a given (eager) value.
-
setAlias
public void setAlias(Lazy promise)
Bind promise to be an alias of another Lazy value.
-
setException
public void setException(java.lang.Throwable exception)
Bind this promise so forcing it throws the given exception.
-
setThunk
public void setThunk(Procedure thunk)
Bind this promise so forcing it evaluates the given procedure.
-
checkAlias
public Lazy checkAlias()
-
force1
public static java.lang.Object force1(java.lang.Object arg)
Forces the argument, if needed. I.e. callsLazy.getValue()once if the argument is Lazy.
-
force
public static java.lang.Object force(java.lang.Object arg)
Forces the argument, if needed, to a non-Lazy value. I.e. callsLazy.getValue()as many times as needed.
-
force
public static java.lang.Object force(java.lang.Object arg, java.lang.Class target)If argument is Lazy, force it, unless already an instance of target.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
print
public void print(Consumer out)
- Specified by:
printin interfacegnu.kawa.format.Printable
-
print
public void print(java.lang.Appendable out) throws java.io.IOException- Throws:
java.io.IOException
-
-