|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.rice.cs.plt.tuple.Tuple
edu.rice.cs.plt.tuple.Option<T>
public abstract class Option<T>
A wrapper for optional values. This provides a strictly-typed alternative to using
null to represent the absence of a value. Options have two variants: "some"
and "none." The "some" case is represented by Wrappers; the "none" case is
represented by the Null singleton. Option values may be decomposed
by invoking unwrap() or unwrap(Object), or by using an
OptionVisitor.
| Constructor Summary | |
|---|---|
Option()
|
|
| Method Summary | ||
|---|---|---|
abstract
|
apply(OptionVisitor<? super T,? extends Ret> visitor)
Calls the appropriate case in the visitor. |
|
boolean |
isNone()
Determine whether this Option is a "none" case. |
|
abstract boolean |
isSome()
Determine whether this Option is a "some" case. |
|
static
|
none()
Return the "none" case singleton, cast to the appropriate type. |
|
static
|
some(T val)
Create a "some" case wrapper for the given value. |
|
abstract T |
unwrap()
Get the value wrapped by this Option, or throw an OptionUnwrapException if there
is no wrapped value. |
|
abstract T |
unwrap(T forNone)
Get the value wrapped by this Option, or forNone if there is no wrapped value. |
|
static
|
wrap(T val)
Treat a possibly-null value as an Option: if the value is null, produce
a "none"; otherwise, produce a "some" wrapping the value. |
|
| Methods inherited from class edu.rice.cs.plt.tuple.Tuple |
|---|
generateHashCode, hashCode |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Option()
| Method Detail |
|---|
public abstract <Ret> Ret apply(OptionVisitor<? super T,? extends Ret> visitor)
public abstract boolean isSome()
isNone().
public final boolean isNone()
isSome().
public abstract T unwrap()
throws OptionUnwrapException
OptionUnwrapException if there
is no wrapped value.
OptionUnwrapExceptionpublic abstract T unwrap(T forNone)
forNone if there is no wrapped value.
public static <T> Option<T> some(T val)
public static <T> Option<T> none()
public static <T> Option<T> wrap(T val)
Option: if the value is null, produce
a "none"; otherwise, produce a "some" wrapping the value.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||