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() and isPresent() are mutually exclusive true.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> Nillable<T>
    Creates a Nillable for a absent instance.
    abstract T
    get()
    Returns the object if present.
    abstract Optional<String>
    Returns the optional reason for this object being nil.
    boolean
    Checks if this Nillable is nil and has a reason.
    static <T> Nillable<T>
    Creates a new Nillable, that is nil because it is inapplicable.
    abstract boolean
    Checks if this Nillable is null.
    abstract boolean
    Checks if this Nillable is nil.
    boolean
    Checks if this Nillable is null.
    abstract boolean
    Checks if this Nillable is present.
    boolean
    Checks if this this instance is not absent.
    abstract <X> Nillable<X>
    map(Function<? super T,X> fun)
    Transforms this Nillable to the target type.
    static <T> Nillable<T>
    Creates a new Nillable, that is nil because it is missing.
    static <T> Nillable<T>
    nil()
    Creates a new Nillable that is nil.
    static <T> Nillable<T>
    nil(String reason)
    Creates a new Nillable that is nil because of optionally supplied reason.
    static <T> Nillable<T>
    of(T obj)
    Creates a new Nillable that is either present (if obj is not null), or absent.
    static <T> Nillable<T>
    of(T obj, String reason)
    Creates a new Nillable that is either present (if obj is not null), nil (if reason is not null) or absent.
    static <T> Nillable<T>
    present(T t)
    Creates a new Nillable from a present instance.
    static <T> Nillable<T>
    Creates a new Nillable, that is nil because it is a template value.
    static <T> Nillable<T>
    Creates a new Nillable, that is nil because it is unknown.
    static <T> Nillable<T>
    Creates a new Nillable, that is nil because it is withheld.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • isNil

      public abstract boolean isNil()
      Checks if this Nillable is nil.
      Returns:
      whether or not this instance is nil
      See Also:
    • isPresent

      public abstract boolean isPresent()
      Checks if this Nillable is present.
      Returns:
      whether or not this instance is present
      See Also:
    • isAbsent

      public abstract boolean isAbsent()
      Checks if this Nillable is null.
      Returns:
      whether or not this instance is null
      See Also:
    • map

      public abstract <X> Nillable<X> map(Function<? super T,X> fun)
      Transforms this Nillable to the target type.
      Type Parameters:
      X - the target type
      Parameters:
      fun - the transformation function
      Returns:
      the Nillable
    • isNull

      public boolean isNull()
      Checks if this Nillable is null.
      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

      public abstract T 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 this Nillable is 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:
    • present

      public static <T> Nillable<T> present(T t)
      Creates a new Nillable from a present instance.
      Type Parameters:
      T - the type
      Parameters:
      t - the object
      Returns:
      the present Nillable
      Throws:
      NullPointerException - if t is null
    • absent

      public static <T> Nillable<T> absent()
      Creates a Nillable for a absent instance.
      Type Parameters:
      T - the type
      Returns:
      the absent Nillable
    • nil

      public static <T> Nillable<T> nil(String reason)
      Creates a new Nillable that is nil because of optionally supplied reason.
      Type Parameters:
      T - the type
      Parameters:
      reason - the reason (may be null)
      Returns:
      the nil Nillable
    • nil

      public static <T> Nillable<T> nil()
      Creates a new Nillable that is nil.
      Type Parameters:
      T - the type
      Returns:
      the nil Nillable
    • inapplicable

      public static <T> Nillable<T> inapplicable()
      Creates a new Nillable, 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 new Nillable, 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 new Nillable, 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 new Nillable, 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 new Nillable, 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 new Nillable that is either present (if obj is not null), or absent.
      Type Parameters:
      T - the type
      Parameters:
      obj - the object (may be null)
      Returns:
      the Nillable
    • of

      public static <T> Nillable<T> of(T obj, String reason)
      Creates a new Nillable that is either present (if obj is not null), nil (if reason is not null) or absent.
      Type Parameters:
      T - the type
      Parameters:
      obj - the object (may be null)
      reason - the nil reason (may be null)
      Returns:
      the Nillable