Interface Nullable<T>

  • All Known Implementing Classes:
    Binary, InflatableSet

    public interface Nullable<T>
    An interface that any class can implement to mark itself as "nullable", which allows it to be used in a more optimal way with collections that support "nullable" keys and/or values.

    While technically not a marker interface, this interface can typically be used as such as it provides a reasonable default implementation of the get method that simply returns the instance itself.

    The rest of the methods in this interface are static factory methods that allow creation of a Nullable values from various primitive, wrapper and reference types, as well as a static get(Nullable) method that allows you to "unwrap" any Nullable and return either the value itself or a null, if the specified Nullable is empty.

    Since:
    24.03
    Author:
    Aleks Seovic 2024.01.08
    • Method Summary

      All Methods Static Methods Instance Methods Default Methods 
      Modifier and Type Method Description
      static <T> Nullable<T> empty()
      Create an empty Nullable value.
      default T get()
      Return the raw value of this Nullable.
      static <T> T get​(Nullable<? extends T> value)
      Return the value of the specified Nullable.
      static Nullable<Boolean> of​(boolean value)
      Create a Nullable representation of the specified boolean value.
      static Nullable<Byte> of​(byte value)
      Create a Nullable representation of the specified byte value.
      static Nullable<Double> of​(double value)
      Create a Nullable representation of the specified double value.
      static Nullable<Float> of​(float value)
      Create a Nullable representation of the specified float value.
      static Nullable<Integer> of​(int value)
      Create a Nullable representation of the specified int value.
      static Nullable<Long> of​(long value)
      Create a Nullable representation of the specified long value.
      static Nullable<Short> of​(short value)
      Create a Nullable representation of the specified short value.
      static Nullable<Boolean> of​(Boolean value)
      Create a Nullable representation of the specified Boolean value.
      static Nullable<Byte> of​(Byte value)
      Create a Nullable representation of the specified Byte value.
      static Nullable<Double> of​(Double value)
      Create a Nullable representation of the specified Double value.
      static Nullable<Float> of​(Float value)
      Create a Nullable representation of the specified Float value.
      static Nullable<Integer> of​(Integer value)
      Create a Nullable representation of the specified Integer value.
      static Nullable<Long> of​(Long value)
      Create a Nullable representation of the specified Long value.
      static Nullable<Short> of​(Short value)
      Create a Nullable representation of the specified Short value.
      static <T> Nullable<T> of​(T value)
      Create a Nullable representation of the specified reference value.
    • Method Detail

      • of

        static <T> Nullable<T> of​(T value)
        Create a Nullable representation of the specified reference value.
        Type Parameters:
        T - the type of wrapped reference value
        Parameters:
        value - the value to create a Nullable for
        Returns:
        a Nullable representation of the specified value
      • of

        static Nullable<Integer> of​(int value)
        Create a Nullable representation of the specified int value.
        Parameters:
        value - the value to create a Nullable for
        Returns:
        a Nullable representation of the specified value
      • of

        static Nullable<Integer> of​(Integer value)
        Create a Nullable representation of the specified Integer value.
        Parameters:
        value - the value to create a Nullable for
        Returns:
        a Nullable representation of the specified value
      • of

        static Nullable<Long> of​(long value)
        Create a Nullable representation of the specified long value.
        Parameters:
        value - the value to create a Nullable for
        Returns:
        a Nullable representation of the specified value
      • of

        static Nullable<Long> of​(Long value)
        Create a Nullable representation of the specified Long value.
        Parameters:
        value - the value to create a Nullable for
        Returns:
        a Nullable representation of the specified value
      • of

        static Nullable<Short> of​(short value)
        Create a Nullable representation of the specified short value.
        Parameters:
        value - the value to create a Nullable for
        Returns:
        a Nullable representation of the specified value
      • of

        static Nullable<Short> of​(Short value)
        Create a Nullable representation of the specified Short value.
        Parameters:
        value - the value to create a Nullable for
        Returns:
        a Nullable representation of the specified value
      • of

        static Nullable<Byte> of​(byte value)
        Create a Nullable representation of the specified byte value.
        Parameters:
        value - the value to create a Nullable for
        Returns:
        a Nullable representation of the specified value
      • of

        static Nullable<Byte> of​(Byte value)
        Create a Nullable representation of the specified Byte value.
        Parameters:
        value - the value to create a Nullable for
        Returns:
        a Nullable representation of the specified value
      • of

        static Nullable<Double> of​(double value)
        Create a Nullable representation of the specified double value.
        Parameters:
        value - the value to create a Nullable for
        Returns:
        a Nullable representation of the specified value
      • of

        static Nullable<Double> of​(Double value)
        Create a Nullable representation of the specified Double value.
        Parameters:
        value - the value to create a Nullable for
        Returns:
        a Nullable representation of the specified value
      • of

        static Nullable<Float> of​(float value)
        Create a Nullable representation of the specified float value.
        Parameters:
        value - the value to create a Nullable for
        Returns:
        a Nullable representation of the specified value
      • of

        static Nullable<Float> of​(Float value)
        Create a Nullable representation of the specified Float value.
        Parameters:
        value - the value to create a Nullable for
        Returns:
        a Nullable representation of the specified value
      • of

        static Nullable<Boolean> of​(boolean value)
        Create a Nullable representation of the specified boolean value.
        Parameters:
        value - the value to create a Nullable for
        Returns:
        a Nullable representation of the specified value
      • of

        static Nullable<Boolean> of​(Boolean value)
        Create a Nullable representation of the specified Boolean value.
        Parameters:
        value - the value to create a Nullable for
        Returns:
        a Nullable representation of the specified value
      • empty

        static <T> Nullable<T> empty()
        Create an empty Nullable value.
        Returns:
        an empty Nullable
      • get

        static <T> T get​(Nullable<? extends T> value)
        Return the value of the specified Nullable.
        Type Parameters:
        T - the type of Nullable value
        Parameters:
        value - the Nullable value to get the value from
        Returns:
        the value of the specified Nullable, or null if the Nullable is empty
      • get

        default T get()
        Return the raw value of this Nullable.
        Returns:
        the raw value of this Nullable