T - the element typepublic abstract static class Osgl.Option<T> extends Object implements Iterable<T>, Serializable
T. This class can be used to implement
the else-if semantic in functional programming and eliminate the
null value| Modifier and Type | Class and Description |
|---|---|
class |
Osgl.Option.f
The runtime/instance function namespace
|
| Modifier and Type | Field and Description |
|---|---|
Osgl.Option.f |
f
A reference to this runtime function namesapce
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object obj) |
Osgl.Option<T> |
filter(Osgl.Function<? super T,Boolean> predicate)
If a value is present, and the value matches the given predicate,
return an
Option describing the value, otherwise return
Osgl.NONE. |
<B> Osgl.Option<B> |
flatMap(Osgl.Function<? super T,Osgl.Option<B>> mapper)
If a value is present, apply the provided
Option-bearing
mapping function to it, return that result, otherwise return
Osgl.NONE. |
abstract T |
get()
If a value is present in this
Option, returns the value,
otherwise throws NoSuchElementException. |
int |
hashCode() |
boolean |
isDefined()
|
<B> Osgl.Option<B> |
map(Osgl.Function<? super T,? extends B> mapper)
If a value is present, apply the provided mapping function to it,
and if the result is non-null, return an
Option describing
the result. |
static <T> Osgl.None<T> |
none() |
boolean |
notDefined()
Negate of
isDefined() |
static <T> Osgl.Option<T> |
of(T value)
|
T |
orElse(Osgl.Func0<? extends T> other)
Return the value if present, otherwise invoke
other and return
the result of that invocation. |
T |
orElse(T other)
Return the value if present, otherwise return
other. |
void |
runWith(Osgl.Function<? super T,?> consumer) |
static <T> Osgl.Some<T> |
some(T value)
Returns an
Option with the specified present non-null value. |
abstract String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, waitforEach, iterator, spliteratorpublic final Osgl.Option.f f
public final boolean isDefined()
true if there is a value present, otherwise falsepublic boolean notDefined()
isDefined()true if this option is not definedpublic abstract T get() throws NoSuchElementException
Option, returns the value,
otherwise throws NoSuchElementException.OptionNoSuchElementException - if this Option is Osgl.NONEpublic final Osgl.Option<T> filter(Osgl.Function<? super T,Boolean> predicate)
Option describing the value, otherwise return
Osgl.NONE.predicate - the function to test the value held by this OptionOption describing the value of this Option if
a value is present and the value matches the given predicate,
otherwise Osgl.NONEpublic final <B> Osgl.Option<B> map(Osgl.Function<? super T,? extends B> mapper)
Option describing
the result. Otherwise return Osgl.NONE.B - The type of the result of the mapping functionmapper - a mapping function to apply to the value, if presentOption, if a value is
present, otherwise Osgl.NONENullPointerException - if the mapper function is nullpublic final <B> Osgl.Option<B> flatMap(Osgl.Function<? super T,Osgl.Option<B>> mapper)
Option-bearing
mapping function to it, return that result, otherwise return
Osgl.NONE. This method is similar to map(Osgl.Function),
but the provided mapper is one whose result is already an
Option, and if invoked, flatMap does not wrap it
with an additional Option.B - The type parameter to the Option returned bymapper - a mapping function to apply to the value,Option-bearing mapping
function to the value of this Option, if a value
is present, otherwise Osgl.NONENullPointerException - if the mapping function is null
or returns a null resultpublic final T orElse(T other)
other.other - the value to be returned if there is no value present,
may be nullotherpublic final T orElse(Osgl.Func0<? extends T> other)
other and return
the result of that invocation.other - the function that is applied when no value is presentedother.apply()NullPointerException - if value is not present and other is nullpublic final void runWith(Osgl.Function<? super T,?> consumer)
public static <T> Osgl.None<T> none()
public static <T> Osgl.Some<T> some(T value)
Option with the specified present non-null value.T - the type of the valuevalue - the value that cannot be nullNullPointerException - if the value specified is nullpublic static <T> Osgl.Option<T> of(T value)
T - the type of the valuevalue - the valueOption describing the value if it is not null
or Osgl.NONE if the value is nullCopyright © 2017. All Rights Reserved.