|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.atlassian.plugin.util.Option<A>
A - the value type.public abstract class Option<A>
A class that encapsulates null (missing) values. An Option may be either
some value or not.
If it is a value it may be tested with the isDefined() method, but
more often it is useful to either return the value or an alternative if
not set, or map or
filter.
Mapping a None of type A to type B will simply return None of type B
if performed on a None of type A. Similarly, filtering will always
fail on a None.
While this class is public and abstract it does not expose a constructor as
only the concrete Some and None subclasses are meant to be
used.
| Method Summary | ||
|---|---|---|
static
|
defined()
Filters defined options only. |
|
boolean |
equals(Object obj)
|
|
boolean |
exists(com.google.common.base.Predicate<A> p)
Returns this Option if it is nonempty and
applying the predicate to this option's value returns true. |
|
Option<A> |
filter(com.google.common.base.Predicate<? super A> p)
Returns this Option if it is nonempty and
applying the predicate to this option's value returns true. |
|
static
|
filterNone(Iterable<Option<T>> options)
Filter out undefined options. |
|
static
|
find(Iterable<Option<T>> options)
Find the first option that isDefined, or if there aren't any, then none. |
|
|
flatMap(com.google.common.base.Function<? super A,Option<B>> f)
Apply f to the value if defined. |
|
abstract
|
fold(com.google.common.base.Supplier<? extends B> none,
com.google.common.base.Function<? super A,B> some)
If this is a some value apply the some function, otherwise get the none value. |
|
abstract A |
get()
Get the value if defined. |
|
|
getOrElse(B other)
Get the value if defined, otherwise returns other. |
|
A |
getOrElse(com.google.common.base.Supplier<A> supplier)
Get the value if defined or call the supplier and return its value if not. |
|
A |
getOrNull()
Get the value if defined or null if not. |
|
int |
hashCode()
|
|
abstract boolean |
isDefined()
|
|
boolean |
isEmpty()
|
|
Iterator<A> |
iterator()
|
|
|
map(com.google.common.base.Function<? super A,B> f)
Apply f to the value if defined. |
|
static
|
none()
Factory method for None instances. |
|
static
|
none(Class<A> type)
Factory method for None instances where the type token is handy. |
|
static
|
noneSupplier()
Supplies None as required. |
|
static
|
option(A a)
Factory method for Option instances. |
|
static
|
some(A value)
Factory method for Some instances. |
|
String |
toString()
|
|
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Method Detail |
|---|
public static <A> Option<A> option(A a)
Option instances.
A - the held typea - the value to hold
Some if the parameter is not null or a None if
it ispublic static <A> Option<A> some(A value)
Some instances.
A - the held typevalue - the value to hold
Some if the parameter is not null
NullPointerException - if the parameter is nullpublic static <A> Option<A> none()
None instances.
A - the held type
Nonepublic static <A> Option<A> none(Class<A> type)
None instances where the type token is handy.
Allows calling in-line where the type inferencer would otherwise
complain.
A - the held typetype - token of the right type, unused, only here for the type
inferencer
Nonepublic static <T> Option<T> find(Iterable<Option<T>> options)
T - the held typeoptions - an Iterable of options to search throughpublic static <T> Iterable<Option<T>> filterNone(Iterable<Option<T>> options)
T - the held typeoptions - many options that may or may not be defined
public static <T> com.google.common.base.Predicate<T> defined()
T - the held type
public static <A> com.google.common.base.Supplier<Option<A>> noneSupplier()
None as required. Useful as the zero value for folds.
A - the held type
Supplier of None instances
public abstract <B> B fold(com.google.common.base.Supplier<? extends B> none,
com.google.common.base.Function<? super A,B> some)
B - the result typenone - the supplier of the None typesome - the function to apply if this is a Some
public abstract A get()
get in interface com.google.common.base.Supplier<A>NoSuchElementException - if this is a nonepublic abstract boolean isDefined()
true if this is a Some, false otherwise.public final <B extends A> A getOrElse(B other)
other.
other - value to return if this is a none
Some, otherwise returns
otherpublic final A getOrElse(com.google.common.base.Supplier<A> supplier)
Supplierpublic final A getOrNull()
Although the use of null is discouraged, code written to use Option must often interface with code that expects and returns nulls.
public final <B> Option<B> map(com.google.common.base.Function<? super A,B> f)
f to the value if defined.
Transforms to an option of the functions result type.
B - return type of ff - function to apply to wrapped value
public final <B> Option<B> flatMap(com.google.common.base.Function<? super A,Option<B>> f)
f to the value if defined.
Transforms to an option of the functions result type.
B - return type of ff - function to apply to wrapped value
fpublic final Option<A> filter(com.google.common.base.Predicate<? super A> p)
Option if it is nonempty and
applying the predicate to this option's value returns true. Otherwise,
return none().
p - the predicate to testpublic final boolean exists(com.google.common.base.Predicate<A> p)
Option if it is nonempty and
applying the predicate to this option's value returns true. Otherwise,
return none().
p - the predicate to testpublic final boolean isEmpty()
false if this is a Some, true otherwise.public final Iterator<A> iterator()
iterator in interface Iterable<A>Some, an empty one
otherwise.public final int hashCode()
hashCode in class Objectpublic final boolean equals(Object obj)
equals in class Objectpublic final String toString()
toString in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||