T
- The type of the value represented by this instancepublic interface Option<T> extends Iterable<T>
Some
or None
.Some
holds a non-null value whilst None
holds no value.Modifier and Type | Field and Description |
---|---|
static None |
DEFAULT_NONE
|
Modifier and Type | Method and Description |
---|---|
static <T> Option<T> |
apply(T value)
|
default Optional<T> |
asOptional()
|
default boolean |
contains(T other)
|
default int |
count()
Returns the count which means
1 for nonempty Option's and 0 for empty. |
static <T> Option<T> |
empty()
Creates an empty Option.
In practice this returns a singleton as it anyways cannot represent a value/state. |
boolean |
exists(java.util.function.Predicate<T> p)
Returns
true if this option is nonempty and the predicate p returns true when applied to this Option's value. |
default Option<T> |
filter(java.util.function.Predicate<T> p)
Returns this Option if it is nonempty and applying the predicate p to this Option's value returns
true . |
default Option<T> |
filterNot(java.util.function.Predicate<T> p)
Returns this Option if it is nonempty and applying the predicate p to this Option's value returns
false . |
default boolean |
forall(java.util.function.Predicate<T> p)
Returns
true if the Option is nonempty and the predicate holds true , else false .In an essence exactly the same as exists(Predicate) . |
T |
get()
Returns this Option's value if such exists, else
NoSuchElementException is raised. |
T |
getOrElse(java.util.function.Supplier<T> supplier)
Returns this Option's value if such exists, else the value provided by the supplier.
|
default boolean |
isDefined()
|
default boolean |
isEmpty()
|
default Iterator<T> |
iterator()
|
<R> Option<R> |
map(java.util.function.Function<T,R> function)
Returns an Option consisting of the result of applying the given function to the current
Some . |
static <T> Option<T> |
ofOptional(Optional<T> optional)
|
Option<T> |
orElse(java.util.function.Supplier<Option<T>> supplier)
Returns this Option if it is nonempty, otherwise return the result of provided by the supplier.
|
default T |
orNull()
Returns the Option's value if it is nonempty, or
null if it is empty. |
java.util.stream.Stream<T> |
stream()
Returns the Option's value in a Stream if it is nonempty, or an empty Stream if it is empty.
|
forEach, spliterator
static final None DEFAULT_NONE
static <T> Option<T> apply(T value)
null
value is provided then None
is returned, else Some
containing the provided value.T
- The type for the value this Option representsvalue
- The value this Option shall representstatic <T> Option<T> empty()
singleton
as it anyways cannot represent a value/state.T
- The type for the value this Option representsNone
instancedefault boolean contains(T other)
other
- The other object to compare toSome
contains the provided objectdefault int count()
1
for nonempty Option's and 0
for empty.boolean exists(java.util.function.Predicate<T> p)
true
if this option is nonempty and the predicate p returns true
when applied to this Option's value.p
- The predicatedefault Option<T> filter(java.util.function.Predicate<T> p)
true
.p
- The predicatedefault Option<T> filterNot(java.util.function.Predicate<T> p)
false
.p
- The predicatedefault boolean forall(java.util.function.Predicate<T> p)
true
if the Option is nonempty and the predicate holds true
, else false
.exists(Predicate)
.p
- The predicateT get()
NoSuchElementException
is raised.T getOrElse(java.util.function.Supplier<T> supplier)
supplier
- The supplier to use in case this is a None
default boolean isDefined()
Some
default boolean isEmpty()
None
<R> Option<R> map(java.util.function.Function<T,R> function)
Some
. None
will always yield None
.R
- The type for the return value from the functionfunction
- The function to useOption<T> orElse(java.util.function.Supplier<Option<T>> supplier)
supplier
- The supplier to use in case of None
default T orNull()
null
if it is empty.null
in case of None
java.util.stream.Stream<T> stream()
Copyright © 2015. All rights reserved.