Package org.n52.shetland.w3c
Class Nillable<T>
java.lang.Object
org.n52.shetland.w3c.Nillable<T>
- Type Parameters:
T- the instance type
Represents a tri-state object: can be nil (with an optional message), absent (or null) or present.
isNil(), isAbsent() and isPresent() are mutually exclusive true.-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Nillable<T> absent()Creates aNillablefor a absent instance.abstract Tget()Returns the object if present.Returns the optional reason for this object being nil.booleanChecks if thisNillableis nil and has a reason.static <T> Nillable<T> Creates a newNillable, that is nil because it is inapplicable.abstract booleanisAbsent()Checks if thisNillableisnull.abstract booleanisNil()Checks if thisNillableisnil.booleanisNull()Checks if thisNillableisnull.abstract booleanChecks if thisNillableis present.booleanChecks if this this instance is not absent.abstract <X> Nillable<X> Transforms thisNillableto the target type.static <T> Nillable<T> missing()Creates a newNillable, that is nil because it is missing.static <T> Nillable<T> nil()Creates a newNillablethat isnil.static <T> Nillable<T> Creates a newNillablethat isnilbecause of optionally supplied reason.static <T> Nillable<T> of(T obj) Creates a newNillablethat is either present (ifobjis notnull), or absent.static <T> Nillable<T> Creates a newNillablethat is either present (ifobjis notnull), nil (ifreasonis notnull) or absent.static <T> Nillable<T> present(T t) Creates a newNillablefrom a present instance.static <T> Nillable<T> template()Creates a newNillable, that is nil because it is a template value.static <T> Nillable<T> unknown()Creates a newNillable, that is nil because it is unknown.static <T> Nillable<T> withheld()Creates a newNillable, that is nil because it is withheld.
-
Method Details
-
isNil
public abstract boolean isNil()Checks if thisNillableisnil.- Returns:
- whether or not this instance is
nil - See Also:
-
isPresent
public abstract boolean isPresent()Checks if thisNillableis present.- Returns:
- whether or not this instance is present
- See Also:
-
isAbsent
public abstract boolean isAbsent()Checks if thisNillableisnull.- Returns:
- whether or not this instance is
null - See Also:
-
map
Transforms thisNillableto the target type.- Type Parameters:
X- the target type- Parameters:
fun- the transformation function- Returns:
- the
Nillable
-
isNull
public boolean isNull()Checks if thisNillableisnull.- Returns:
- whether or not this instance is
null - See Also:
-
isPresentOrNil
public boolean isPresentOrNil()Checks if this this instance is not absent.- Returns:
- whether this instance is present or nil
-
get
Returns the object if present.- Returns:
- the object
- Throws:
UnsupportedOperationException- if this instance is not present- See Also:
-
hasReason
public boolean hasReason()Checks if thisNillableis nil and has a reason.- Returns:
- whether this instance has a nil reason or not
-
getNilReason
Returns the optional reason for this object being nil.- Returns:
- the nil reason
- Throws:
UnsupportedOperationException- if this instance is not nil- See Also:
-
present
Creates a newNillablefrom a present instance.- Type Parameters:
T- the type- Parameters:
t- the object- Returns:
- the present
Nillable - Throws:
NullPointerException- iftisnull
-
absent
Creates aNillablefor a absent instance.- Type Parameters:
T- the type- Returns:
- the absent
Nillable
-
nil
Creates a newNillablethat isnilbecause of optionally supplied reason.- Type Parameters:
T- the type- Parameters:
reason- the reason (may benull)- Returns:
- the nil
Nillable
-
nil
Creates a newNillablethat isnil.- Type Parameters:
T- the type- Returns:
- the nil
Nillable
-
inapplicable
Creates a newNillable, that is nil because it is inapplicable.- Type Parameters:
T- the type- Returns:
- the nil
Nillable
-
missing
Creates a newNillable, that is nil because it is missing.- Type Parameters:
T- the type- Returns:
- the nil
Nillable
-
template
Creates a newNillable, that is nil because it is a template value.- Type Parameters:
T- the type- Returns:
- the nil
Nillable
-
unknown
Creates a newNillable, that is nil because it is unknown.- Type Parameters:
T- the type- Returns:
- the nil
Nillable
-
withheld
Creates a newNillable, that is nil because it is withheld.- Type Parameters:
T- the type- Returns:
- the nil
Nillable
-
of
Creates a newNillablethat is either present (ifobjis notnull), or absent.- Type Parameters:
T- the type- Parameters:
obj- the object (may benull)- Returns:
- the
Nillable
-
of
Creates a newNillablethat is either present (ifobjis notnull), nil (ifreasonis notnull) or absent.- Type Parameters:
T- the type- Parameters:
obj- the object (may benull)reason- the nil reason (may benull)- Returns:
- the
Nillable
-