Class Possible<T>

  • Type Parameters:
    T - JSON Property Type

    public class Possible<T>
    extends Object
    Represents a JSON property that may be absent, but never null if it's present.
    • Method Detail

      • of

        public static <T> Possible<T> of​(T value)
        Returns a Possible with a non-null, present value.
        Type Parameters:
        T - JSON Property Type
        Parameters:
        value - A non-null value for a new Possible to represent.
        Returns:
        An instance of Possible whose value is always present and never null.
        Throws:
        NullPointerException - If value is null.
      • absent

        public static <T> Possible<T> absent()
        Returns a Possible with an absent value.
        Type Parameters:
        T - JSON Property Type
        Returns:
        An instance of Possible whose value is absent, but not necessarily null.
      • get

        public T get()
        Returns an instance of T if this instance of Possible represents a non-absent value.
        Returns:
        An instance of T, if it is present. Guaranteed to never be null.
        Throws:
        NoSuchElementException - If the value is absent.
      • isAbsent

        public boolean isAbsent()
        Checks whether the instance of this Possible represents an absent value.
        Returns:
        True is the value is absent, false otherwise.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object