public abstract class Maybe<T>
extends java.lang.Object
implements java.io.Serializable, com.google.common.base.Supplier<T>
Modifier and Type | Class and Description |
---|---|
static class |
Maybe.Absent<T> |
static class |
Maybe.AbstractPresent<T> |
static class |
Maybe.Present<T> |
static class |
Maybe.SoftlyPresent<T> |
Constructor and Description |
---|
Maybe() |
Modifier and Type | Method and Description |
---|---|
static <T> Maybe<T> |
absent() |
static <T> Maybe<T> |
absent(java.lang.String message)
Creates an absent whose get throws an
IllegalStateException with the indicated message. |
static <T> Maybe<T> |
absent(java.lang.String message,
java.lang.Throwable cause)
Creates an absent whose get throws an
IllegalStateException with the indicated message and underlying cause. |
static <T> Maybe<T> |
absent(com.google.common.base.Supplier<? extends java.lang.RuntimeException> exceptionSupplier)
Creates an absent whose get throws an
RuntimeException generated on demand from the given supplier |
static <T> Maybe<T> |
absent(java.lang.Throwable cause)
Creates an absent whose get throws an
IllegalStateException with the indicated cause. |
java.util.Set<T> |
asSet() |
boolean |
equals(java.lang.Object obj) |
static <T> Maybe<T> |
fromNullable(T value)
like
Optional.fromNullable(Object) , returns absent if the argument is null |
abstract T |
get() |
int |
hashCode() |
boolean |
isAbsent() |
boolean |
isAbsentOrNull() |
abstract boolean |
isPresent() |
boolean |
isPresentAndNonNull() |
static <T> Maybe<T> |
next(java.util.Iterator<T> iterator)
returns a Maybe containing the next element in the iterator, or absent if none
|
static <T> Maybe<T> |
of(com.google.common.base.Optional<T> value) |
static <T> Maybe<T> |
of(com.google.common.base.Supplier<T> value) |
static <T> Maybe<T> |
of(T value) |
Maybe<T> |
or(Maybe<T> nextValue) |
T |
or(com.google.common.base.Supplier<T> nextValue) |
T |
or(T nextValue) |
T |
orNull() |
static <T> java.lang.Iterable<T> |
presentInstances(java.lang.Iterable<? extends Maybe<? extends T>> maybes)
Returns the value of each present instance from the supplied
maybes , in order,
skipping over occurrences of absent() . |
static <T> Maybe<T> |
soft(T value)
creates an instance wrapping a
SoftReference , so it might go absent later on |
static <T> Maybe<T> |
softThen(T value,
Maybe<T> ifEmpty)
creates an instance wrapping a
SoftReference , using the second item given if lost |
java.lang.String |
toString() |
<V> Maybe<V> |
transform(com.google.common.base.Function<? super T,V> f) |
public static <T> Maybe<T> absent()
public static <T> Maybe<T> absent(java.lang.String message)
IllegalStateException
with the indicated message.
Both stack traces (the cause and the callers) are provided, which can be quite handy.public static <T> Maybe<T> absent(java.lang.Throwable cause)
IllegalStateException
with the indicated cause.
Both stack traces (the cause and the callers) are provided, which can be quite handy.public static <T> Maybe<T> absent(java.lang.String message, java.lang.Throwable cause)
IllegalStateException
with the indicated message and underlying cause.
Both stack traces (the cause and the callers) are provided, which can be quite handy.public static <T> Maybe<T> absent(com.google.common.base.Supplier<? extends java.lang.RuntimeException> exceptionSupplier)
RuntimeException
generated on demand from the given supplierpublic static <T> Maybe<T> of(@Nullable T value)
public static <T> Maybe<T> soft(T value)
SoftReference
, so it might go absent later onpublic static <T> Maybe<T> softThen(T value, Maybe<T> ifEmpty)
SoftReference
, using the second item given if lostpublic static <T> Maybe<T> fromNullable(@Nullable T value)
Optional.fromNullable(Object)
, returns absent if the argument is nullpublic static <T> Maybe<T> of(com.google.common.base.Optional<T> value)
public static <T> Maybe<T> of(com.google.common.base.Supplier<T> value)
public static <T> Maybe<T> next(java.util.Iterator<T> iterator)
public abstract boolean isPresent()
public boolean isAbsent()
public boolean isAbsentOrNull()
public boolean isPresentAndNonNull()
public T orNull()
public java.util.Set<T> asSet()
@Beta public static <T> java.lang.Iterable<T> presentInstances(java.lang.Iterable<? extends Maybe<? extends T>> maybes)
maybes
, in order,
skipping over occurrences of absent()
. Iterators are unmodifiable and are
evaluated lazily.Optional.presentInstances(Iterable)
public java.lang.String toString()
toString
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object