public abstract class Maybe<T>
extends java.lang.Object
implements java.io.Serializable
Modifier and Type | Class and Description |
---|---|
static class |
Maybe.Absent<T> |
static class |
Maybe.AbsentNull<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(
Creates an absent whose get throws an
RuntimeException generated on demand from the given supplier |
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(java.lang.Throwable cause)
Creates an absent whose get throws an
IllegalStateException with the indicated cause. |
static <T> Maybe<T> |
absentNull()
as
absentNull(String) but with a generic message |
static <T> Maybe<T> |
absentNull(java.lang.String message)
like
absent(String) but isNull() will return true on the result. |
java.util.Set<T> |
asSet() |
boolean |
equals(java.lang.Object obj) |
static <T> Maybe<T> |
fromNullable(T value)
Creates a new Maybe object using
ofDisallowingNull(Object) semantics. |
abstract T |
get() |
int |
hashCode() |
boolean |
isAbsent() |
boolean |
isAbsentOrNull() |
abstract boolean |
isNull()
Whether the value is null, if present, or
if it was specified as absent because it was null,
e.g.
|
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( |
static <T> Maybe<T> |
of( |
static <T> Maybe<T> |
of(T value)
Creates a new Maybe object.
|
static <T> Maybe<T> |
ofAllowingNull(T value)
Creates a new Maybe object which is present.
|
static <T> Maybe<T> |
ofDisallowingNull(T value)
Creates a new Maybe object which is present if and only if the argument is not null.
|
T |
or( |
Maybe<T> |
or(Maybe<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 the first argument is dereferenced. |
java.lang.String |
toString() |
<V> Maybe<V> |
transform( |
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(exceptionSupplier)
RuntimeException
generated on demand from the given supplierpublic static <T> Maybe<T> absentNull()
absentNull(String)
but with a generic messagepublic static <T> Maybe<T> absentNull(java.lang.String message)
absent(String)
but isNull()
will return true on the result.public static <T> Maybe<T> ofAllowingNull(@Nullable T value)
Optional
usages) but
may be natural in others (where null is a valid value, distinguished from no value set).
See also ofDisallowingNull(Object)
.public static <T> Maybe<T> ofDisallowingNull(@Nullable T value)
absentNull()
is returned,
on which isNull()
will be true.public static <T> Maybe<T> of(@Nullable T value)
ofAllowingNull(Object)
semantics,
but it is recommended to use that method for clarity
if the argument might be null.public static <T> Maybe<T> fromNullable(@Nullable T value)
ofDisallowingNull(Object)
semantics.
It is recommended to use that method for clarity.
This method is provided for consistency with Optional#fromNullable(Object)
.public static <T> Maybe<T> soft(@Nonnull T value)
SoftReference
, so it might go absent later on.
if null is supplied the result is a present null.public static <T> Maybe<T> softThen(T value, Maybe<T> ifEmpty)
SoftReference
, using the second item given
if the first argument is dereferenced.
however if the first argument is null, this is a permanent present null,
as of(Object)
with null.public static <T> Maybe<T> of(value)
public static <T> Maybe<T> of(value)
public static <T> Maybe<T> next(java.util.Iterator<T> iterator)
public abstract boolean isPresent()
public abstract T get()
public boolean isAbsent()
public boolean isAbsentOrNull()
public boolean isPresentAndNonNull()
public abstract boolean isNull()
fromNullable(Object)
.public T or(nextValue)
public T orNull()
public java.util.Set<T> asSet()
public <V> Maybe<V> transform(f)
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