Class JsonNullable<T>

  • All Implemented Interfaces:
    java.io.Serializable

    public class JsonNullable<T>
    extends java.lang.Object
    implements java.io.Serializable
    See Also:
    Serialized Form
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object obj)  
      JsonNullable<T> filter​(java.util.function.Predicate<T> predicate)
      If a value is present, and the value matches the given predicate, returns a JsonNullable describing the value, otherwise returns an undefined JsonNullable.
      <U> JsonNullable<U> flatMap​(java.util.function.Function<? super T,​? extends JsonNullable<? extends U>> mapper)
      If a value is present, returns the result of applying the given JsonNullable-bearing mapping function to the value, otherwise returns an undefined JsonNullable.
      T get()
      Obtain the value of this JsonNullable.
      int hashCode()  
      void ifPresent​(java.util.function.Consumer<? super T> action)
      If a value is present, performs the given action with the value, otherwise does nothing.
      void ifPresentOrElse​(java.util.function.Consumer<? super T> action, java.lang.Runnable undefinedAction)
      If a value is present, performs the given action with the value, otherwise performs the given empty-based action.
      boolean isPresent()
      If a value is present, returns true, otherwise false.
      boolean isUndefined()
      If a value is not present, returns true, otherwise false.
      <U> JsonNullable<U> map​(java.util.function.Function<T,​U> mapper)
      If a value is present, returns a JsonNullable describing the result of applying the given mapping function to the value, otherwise returns an undefined JsonNullable.
      static <T> JsonNullable<T> of​(T value)
      Create a JsonNullable from the submitted value.
      JsonNullable<T> or​(java.util.function.Supplier<? extends JsonNullable<? extends T>> supplier)
      If a value is present, returns a JsonNullable describing the value, otherwise returns a JsonNullable produced by the supplying function.
      T orElse​(T other)
      Obtain the value of this JsonNullable.
      T orElseGet​(java.util.function.Supplier<? extends T> supplier)
      If a value is present, returns the value, otherwise returns the result produced by the supplying function.
      T orElseThrow()
      If a value is present, returns the value, otherwise throws NoSuchElementException.
      <X extends java.lang.Throwable>
      T
      orElseThrow​(java.util.function.Supplier<? extends X> supplier)
      If a value is present, returns the value, otherwise throws an exception produced by the exception supplying function.
      java.util.stream.Stream<T> stream()
      If a value is present, returns a sequential Stream containing only that value, otherwise returns an empty Stream.
      java.lang.String toString()  
      static <T> JsonNullable<T> undefined()
      Create a JsonNullable representing an undefined value (not present).
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Method Detail

      • undefined

        public static <T> JsonNullable<T> undefined()
        Create a JsonNullable representing an undefined value (not present).
        Type Parameters:
        T - a type wildcard
        Returns:
        an empty JsonNullable with no value defined
      • of

        public static <T> JsonNullable<T> of​(T value)
        Create a JsonNullable from the submitted value.
        Type Parameters:
        T - the type of the value
        Parameters:
        value - the value
        Returns:
        the JsonNullable with the submitted value present.
      • get

        public T get()
        Obtain the value of this JsonNullable.
        Returns:
        the value, if present
        Throws:
        java.util.NoSuchElementException - if no value is present
      • orElse

        public T orElse​(T other)
        Obtain the value of this JsonNullable.
        Parameters:
        other - the value to be returned if no value is present
        Returns:
        the value of this JsonNullable if present, the submitted value otherwise
      • orElseGet

        public T orElseGet​(java.util.function.Supplier<? extends T> supplier)
        If a value is present, returns the value, otherwise returns the result produced by the supplying function.
        Parameters:
        supplier - the supplying function that produces a value to be returned
        Returns:
        the value, if present, otherwise the result produced by the supplying function
        Throws:
        java.lang.NullPointerException - if no value is present and the supplying function is null
        Since:
        0.2.8
      • orElseThrow

        public T orElseThrow()
        If a value is present, returns the value, otherwise throws NoSuchElementException.
        Returns:
        the value of this JsonNullable
        Throws:
        java.util.NoSuchElementException - if no value if present
        Since:
        0.2.8
      • orElseThrow

        public <X extends java.lang.Throwable> T orElseThrow​(java.util.function.Supplier<? extends X> supplier)
                                                      throws X extends java.lang.Throwable
        If a value is present, returns the value, otherwise throws an exception produced by the exception supplying function.
        Type Parameters:
        X - type of the exception to be thrown
        Parameters:
        supplier - the supplying function that produces an exception to be thrown
        Returns:
        the value, if present
        Throws:
        X - if no value is present
        java.lang.NullPointerException - if no value is present and the exception supplying function is null
        X extends java.lang.Throwable
        Since:
        0.2.8
      • isPresent

        public boolean isPresent()
        If a value is present, returns true, otherwise false.
        Returns:
        true if a value is present, otherwise false
      • isUndefined

        public boolean isUndefined()
        If a value is not present, returns true, otherwise false.
        Returns:
        true if a value is not present, otherwise false
        Since:
        0.2.8
      • ifPresent

        public void ifPresent​(java.util.function.Consumer<? super T> action)
        If a value is present, performs the given action with the value, otherwise does nothing.
        Parameters:
        action - the action to be performed, if a value is present
        Throws:
        java.lang.NullPointerException - if a value is present and the given action is null
      • ifPresentOrElse

        public void ifPresentOrElse​(java.util.function.Consumer<? super T> action,
                                    java.lang.Runnable undefinedAction)
        If a value is present, performs the given action with the value, otherwise performs the given empty-based action.
        Parameters:
        action - the action to be performed, if a value is present
        undefinedAction - the empty-based action to be performed, if no value is present
        Throws:
        java.lang.NullPointerException - if a value is present and the given action is null, or no value is present and the given empty-based action is null
        Since:
        0.2.8
      • filter

        public JsonNullable<T> filter​(java.util.function.Predicate<T> predicate)
        If a value is present, and the value matches the given predicate, returns a JsonNullable describing the value, otherwise returns an undefined JsonNullable.
        Parameters:
        predicate - the predicate to apply to a value, if present
        Returns:
        a JsonNullable describing the value of this JsonNullable, if a value is present and the value matches the given predicate, otherwise an undefined JsonNullable
        Throws:
        java.lang.NullPointerException - if the predicate is null
        Since:
        0.2.8
      • map

        public <U> JsonNullable<U> map​(java.util.function.Function<T,​U> mapper)
        If a value is present, returns a JsonNullable describing the result of applying the given mapping function to the value, otherwise returns an undefined JsonNullable.
        Type Parameters:
        U - the type of the value returned from the mapping function
        Parameters:
        mapper - the mapping function to apply to a value, if present
        Returns:
        a JsonNullable describing the result of applying a mapping function to the value of this JsonNullable, if a value is present, otherwise an undefined JsonNullable
        Throws:
        java.lang.NullPointerException - if the mapping function is null
        Since:
        0.2.8
      • flatMap

        public <U> JsonNullable<U> flatMap​(java.util.function.Function<? super T,​? extends JsonNullable<? extends U>> mapper)
        If a value is present, returns the result of applying the given JsonNullable-bearing mapping function to the value, otherwise returns an undefined JsonNullable.
        Type Parameters:
        U - the type of value of the JsonNullable returned by the mapping function
        Parameters:
        mapper - the mapping function to apply to a value, if present
        Returns:
        the result of applying a JsonNullable-bearing mapping function to the value of this JsonNullable, if a value is present, otherwise an undefined JsonNullable
        Throws:
        java.lang.NullPointerException - if the mapping function is null or returns a null result
        Since:
        0.2.8
      • or

        public JsonNullable<T> or​(java.util.function.Supplier<? extends JsonNullable<? extends T>> supplier)
        If a value is present, returns a JsonNullable describing the value, otherwise returns a JsonNullable produced by the supplying function.
        Parameters:
        supplier - the supplying function that produces a JsonNullable to be returned
        Returns:
        returns a JsonNullable describing the value of this JsonNullable, if a value is present, otherwise a JsonNullable produced by the supplying function.
        Throws:
        java.lang.NullPointerException - if the supplying function is null or produces a null result
        Since:
        0.2.8
      • stream

        public java.util.stream.Stream<T> stream()
        If a value is present, returns a sequential Stream containing only that value, otherwise returns an empty Stream.
        Returns:
        the JsonNullable value as a Stream
        Since:
        0.2.8
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object