Class JsonNullable<T>

java.lang.Object
org.openapitools.jackson.nullable.JsonNullable<T>
All Implemented Interfaces:
Serializable

public class JsonNullable<T> extends Object implements Serializable
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    filter(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(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.
    get()
    Obtain the value of this JsonNullable.
    int
     
    void
    ifNonNull(Consumer<? super T> action)
    If the value is present and not null, performs the given action with the value, otherwise does nothing.
    void
    ifPresent(Consumer<? super T> action)
    If a value is present, performs the given action with the value, otherwise does nothing.
    void
    ifPresentOrElse(Consumer<? super T> action, Runnable undefinedAction)
    If a value is present, performs the given action with the value, otherwise performs the given empty-based action.
    boolean
    If the value is present and not null, returns true, otherwise false.
    boolean
    If the value is present and null, returns true, otherwise false.
    boolean
    If a value is present, returns true, otherwise false.
    boolean
    If a value is not present, returns true, otherwise false.
    <U> JsonNullable<U>
    map(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.
    static <T> JsonNullable<T>
    Create a JsonNullable representing an explicit null (present, with a null value).
    or(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.
    orElse(T other)
    Obtain the value of this JsonNullable.
    orElseGet(Supplier<? extends T> supplier)
    If a value is present, returns the value, otherwise returns the result produced by the supplying function.
    If a value is present, returns the value, otherwise throws NoSuchElementException.
    <X extends Throwable>
    T
    orElseThrow(Supplier<? extends X> supplier)
    If a value is present, returns the value, otherwise throws an exception produced by the exception supplying function.
    If a value is present, returns a sequential Stream containing only that value, otherwise returns an empty Stream.
     
    static <T> JsonNullable<T>
    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 Details

    • 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
    • ofNull

      public static <T> JsonNullable<T> ofNull()
      Create a JsonNullable representing an explicit null (present, with a null value). Equal to of(null).
      Type Parameters:
      T - a type wildcard
      Returns:
      a JsonNullable holding an explicit null
      Since:
      0.2.13
    • 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:
      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(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:
      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:
      NoSuchElementException - if no value is present
      Since:
      0.2.8
    • orElseThrow

      public <X extends Throwable> T orElseThrow(Supplier<? extends X> supplier) throws X
      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
      NullPointerException - if no value is present and the exception supplying function is null
      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
    • isNull

      public boolean isNull()
      If the value is present and null, returns true, otherwise false. An undefined JsonNullable is not null.
      Returns:
      true if the value is present and null, otherwise false
      Since:
      0.2.13
    • isNonNull

      public boolean isNonNull()
      If the value is present and not null, returns true, otherwise false.
      Returns:
      true if the value is present and not null, otherwise false
      Since:
      0.2.13
    • ifPresent

      public void ifPresent(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:
      NullPointerException - if a value is present and the given action is null
    • ifNonNull

      public void ifNonNull(Consumer<? super T> action)
      If the value is present and not null, performs the given action with the value, otherwise does nothing.
      Parameters:
      action - the action to be performed, if a non-null value is present
      Throws:
      NullPointerException - if a non-null value is present and the given action is null
      Since:
      0.2.13
    • ifPresentOrElse

      public void ifPresentOrElse(Consumer<? super T> action, 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:
      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(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:
      NullPointerException - if the predicate is null
      Since:
      0.2.8
    • map

      public <U> JsonNullable<U> map(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:
      NullPointerException - if the mapping function is null
      Since:
      0.2.8
    • flatMap

      public <U> JsonNullable<U> flatMap(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:
      NullPointerException - if the mapping function is null or returns a null result
      Since:
      0.2.8
    • or

      public JsonNullable<T> or(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:
      NullPointerException - if the supplying function is null or produces a null result
      Since:
      0.2.8
    • stream

      public 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(Object obj)
      Overrides:
      equals in class Object
    • hashCode

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

      public String toString()
      Overrides:
      toString in class Object