T
- The type of the optional value.public final class Some<T> extends Object implements Option<T>, Serializable
Option
. It contains a value which may be null. However, to
create an Option containing null, new Some(null)
has to be called. In all other cases
Option.of(Object)
is sufficient.Constructor and Description |
---|
Some(T value)
Creates a new Some containing the given value.
|
Modifier and Type | Method and Description |
---|---|
default <U> boolean |
corresponds(Iterable<U> that,
java.util.function.BiPredicate<? super T,? super U> predicate)
Tests whether every element of this iterable relates to the corresponding element of another iterable by
satisfying a test predicate.
|
default boolean |
eq(Object o)
A smoothing replacement for
equals . |
boolean |
equals(Object obj)
Clarifies that values have a proper equals() method implemented.
|
default boolean |
exists(java.util.function.Predicate<? super T> predicate)
Checks, if an element exists such that the predicate holds.
|
default boolean |
forAll(java.util.function.Predicate<? super T> predicate)
Checks, if the given predicate holds for all elements.
|
default void |
forEach(java.util.function.Consumer<? super T> action)
Performs an action on each element.
|
T |
get()
Gets the underlying value or throws if no value is present.
|
int |
hashCode()
Clarifies that values have a proper hashCode() method implemented.
|
boolean |
isEmpty()
Returns true, if this is
None , otherwise false, if this is Some . |
static Some<Void> |
nothing()
Return the singleton instance of
Some<Void> . |
default void |
stderr()
Sends the string representations of this value to the standard error stream System.err.
|
default void |
stdout()
Sends the string representations of this value to the standard output stream System.out.
|
default Object[] |
toJavaArray()
Converts this value to an untyped Java array.
|
String |
toString()
Clarifies that values have a proper toString() method implemented.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
filter, flatMap, getOption, isDefined, isSingletonType, iterator, map, none, of, ofOptional, orElse, orElseGet, orElseThrow, peek, some, when
foldLeft, foldRight, get, ifDefined, ifDefined, ifEmpty, ifEmpty, orElseTry, out, out, toArray, toCharSeq, toJavaArray, toJavaList, toJavaMap, toJavaOptional, toJavaSet, toJavaStream, toLazy, toList, toMap, toOption, toQueue, toSet, toStack, toStream, toTree, toTry, toTry, toVector
fold, fold, foldLeft, foldMap, foldRight
lift, lift, lift, lift, lift, lift, lift, lift
spliterator
public Some(T value)
value
- A value, may be nullpublic static Some<Void> nothing()
Some<Void>
.NOTHING
public T get()
Value
public boolean isEmpty()
Option
None
, otherwise false, if this is Some
.public boolean equals(Object obj)
Value
public int hashCode()
Value
See Object.hashCode().
public String toString()
Value
See Object.toString().
public <U> boolean corresponds(Iterable<U> that, java.util.function.BiPredicate<? super T,? super U> predicate)
U
- Component type of that iterablethat
- the other iterablepredicate
- the test predicate, which relates elements from both iterablestrue
if both iterables have the same length and predicate(x, y)
is true
for all corresponding elements x
of this iterable and y
of that
,
otherwise false
.public boolean eq(Object o)
equals
. It is similar to Scala's ==
but better in the way
that it is not limited to collection types, e.g. Some(1) eq List(1)
, None eq Failure(x)
etc.
In a nutshell: eq checks congruence of structures and equality of contained values.
Example:
// ((1, 2), ((3))) => structure: (()(())) values: 1, 2, 3
final Iterable<?> i1 = List.of(List.of(1, 2), Arrays.asList(List.of(3)));
final Iterable<?> i2 = Queue.of(Stream.of(1, 2), List.of(Lazy.of(() -> 3)));
assertThat(i1.eq(i2)).isTrue();
Semantics:
o == this : true
o instanceof javaslang.Iterable : iterable elements are eq, non-iterable elements equals, for all (o1, o2) in (this, o)
o instanceof java.lang.Iterable : this eq Iterator.of((java.lang.Iterable<?>) o);
otherwise : false
o
- An objectpublic boolean exists(java.util.function.Predicate<? super T> predicate)
predicate
- A PredicateNullPointerException
- if predicate
is nullpublic boolean forAll(java.util.function.Predicate<? super T> predicate)
predicate
- A PredicateNullPointerException
- if predicate
is nullpublic void forEach(java.util.function.Consumer<? super T> action)
forEach
in interface Iterable<T>
action
- A Consumer
NullPointerException
- if action
is nullpublic Object[] toJavaArray()
public void stderr()
IllegalStateException
- if PrintStream.checkError()
is true after writing to stderr.public void stdout()
IllegalStateException
- if PrintStream.checkError()
is true after writing to stdout.Copyright © 2015. All Rights Reserved.