Package org.n52.shetland.w3c
Class Nillable<T>
- java.lang.Object
-
- org.n52.shetland.w3c.Nillable<T>
-
- Type Parameters:
T- the instance type
public abstract class Nillable<T> extends Object
Represents a tri-state object: can be nil (with an optional message), absent (or null) or present.isNil(),isAbsent()andisPresent()are mutually exclusivetrue.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static <T> Nillable<T>absent()Creates aNillablefor a absent instance.abstract Tget()Returns the object if present.abstract Optional<String>getNilReason()Returns the optional reason for this object being nil.booleanhasReason()Checks if thisNillableis nil and has a reason.static <T> Nillable<T>inapplicable()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 booleanisPresent()Checks if thisNillableis present.booleanisPresentOrNil()Checks if this this instance is not absent.abstract <X> Nillable<X>map(Function<? super T,X> fun)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>nil(String reason)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>of(T obj, String reason)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 Detail
-
isNil
public abstract boolean isNil()
Checks if thisNillableisnil.- Returns:
- whether or not this instance is
nil - See Also:
isPresent(),isAbsent()
-
isPresent
public abstract boolean isPresent()
Checks if thisNillableis present.- Returns:
- whether or not this instance is present
- See Also:
isNil(),isAbsent()
-
isAbsent
public abstract boolean isAbsent()
Checks if thisNillableisnull.- Returns:
- whether or not this instance is
null - See Also:
isNil(),isPresent()
-
map
public abstract <X> Nillable<X> map(Function<? super T,X> fun)
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:
isAbsent()
-
isPresentOrNil
public boolean isPresentOrNil()
Checks if this this instance is not absent.- Returns:
- whether this instance is present or nil
-
get
public abstract T get()
Returns the object if present.- Returns:
- the object
- Throws:
UnsupportedOperationException- if this instance is not present- See Also:
isPresent()
-
hasReason
public boolean hasReason()
Checks if thisNillableis nil and has a reason.- Returns:
- whether this instance has a nil reason or not
-
getNilReason
public abstract Optional<String> getNilReason()
Returns the optional reason for this object being nil.- Returns:
- the nil reason
- Throws:
UnsupportedOperationException- if this instance is not nil- See Also:
isNil()
-
present
public static <T> Nillable<T> present(T t)
Creates a newNillablefrom a present instance.- Type Parameters:
T- the type- Parameters:
t- the object- Returns:
- the present
Nillable - Throws:
NullPointerException- iftisnull
-
absent
public static <T> Nillable<T> absent()
Creates aNillablefor a absent instance.- Type Parameters:
T- the type- Returns:
- the absent
Nillable
-
nil
public static <T> Nillable<T> nil(String reason)
Creates a newNillablethat isnilbecause of optionally supplied reason.- Type Parameters:
T- the type- Parameters:
reason- the reason (may benull)- Returns:
- the nil
Nillable
-
nil
public static <T> Nillable<T> nil()
Creates a newNillablethat isnil.- Type Parameters:
T- the type- Returns:
- the nil
Nillable
-
inapplicable
public static <T> Nillable<T> inapplicable()
Creates a newNillable, that is nil because it is inapplicable.- Type Parameters:
T- the type- Returns:
- the nil
Nillable
-
missing
public static <T> Nillable<T> missing()
Creates a newNillable, that is nil because it is missing.- Type Parameters:
T- the type- Returns:
- the nil
Nillable
-
template
public static <T> Nillable<T> template()
Creates a newNillable, that is nil because it is a template value.- Type Parameters:
T- the type- Returns:
- the nil
Nillable
-
unknown
public static <T> Nillable<T> unknown()
Creates a newNillable, that is nil because it is unknown.- Type Parameters:
T- the type- Returns:
- the nil
Nillable
-
withheld
public static <T> Nillable<T> withheld()
Creates a newNillable, that is nil because it is withheld.- Type Parameters:
T- the type- Returns:
- the nil
Nillable
-
of
public static <T> Nillable<T> of(T obj)
Creates a newNillablethat is either present (ifobjis notnull), or absent.- Type Parameters:
T- the type- Parameters:
obj- the object (may benull)- Returns:
- the
Nillable
-
-