T
- The type of the value represented by this instancepublic final class Some<T> extends Object implements Option<T>, Serializable
Option
holding a value. Some
is guaranteed to keep a non-null value object. None
. Some
as a collection of size 1. Option<String> option = new Some<>("Peter is Great!");
Option<String> option = Option.apply("Peter is Great!");For examples on usage refer to the documentation for
Option
.DEFAULT_NONE
Constructor and Description |
---|
Some(T value)
Creates an instance for the provided value.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object other)
|
boolean |
exists(java.util.function.Predicate<T> p)
Returns
true if the predicate matches the value. |
<R> Option<R> |
flatMap(java.util.function.Function<T,Option<R>> function)
Returns an Option consisting of the result of applying the given function to the current value.
|
T |
get()
Always returns the value for this instance.
|
T |
getOrElse(java.util.function.Supplier<T> s)
Always returns the value for this instance.
|
int |
hashCode()
Returns the hashCode based on the value of this instance.
|
Iterator<T> |
iterator()
Returns an iterator containing the single value of this instance.
|
<R> Option<R> |
map(java.util.function.Function<T,R> f)
Returns an
Option containing the value of applying the given function to the current value. |
Option<T> |
orElse(java.util.function.Supplier<Option<T>> s)
Always returns this.
|
java.util.stream.Stream<T> |
stream()
Returns a stream of size one containing the value of this instance.
|
<R> Either<T,R> |
toLeft(java.util.function.Supplier<R> right)
Returns a
Left containing the value of this instance. |
<L> Either<L,T> |
toRight(java.util.function.Supplier<L> left)
Returns a
Right containing the value of this instance. |
String |
toString()
Returns a String representation of the instance.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
apply, asOptional, contains, count, empty, filter, filterNot, forall, isDefined, isEmpty, iterator, None, ofOptional, orNull, stream
forEach, spliterator
public Some(T value)
value
- The value represented by this Somepublic boolean exists(java.util.function.Predicate<T> p)
true
if the predicate matches the value.public T get()
public T getOrElse(java.util.function.Supplier<T> s)
public <R> Option<R> map(java.util.function.Function<T,R> f)
Option
containing the value of applying the given function to the current value.public <R> Option<R> flatMap(java.util.function.Function<T,Option<R>> function)
public Option<T> orElse(java.util.function.Supplier<Option<T>> s)
public <R> Either<T,R> toLeft(java.util.function.Supplier<R> right)
Left
containing the value of this instance.public <L> Either<L,T> toRight(java.util.function.Supplier<L> left)
Right
containing the value of this instance.public boolean equals(Object other)
public int hashCode()
public String toString()
public final Iterator<T> iterator()
public final java.util.stream.Stream<T> stream()
Copyright © 2015, Peter Nerg Apache License v2.0