Class u.Nullable<T>

java.lang.Object
com.landawn.abacus.util.u.Nullable<T>
Type Parameters:
T -
All Implemented Interfaces:
Immutable
Enclosing class:
u

@Immutable public static final class u.Nullable<T> extends Object implements Immutable
The Class Nullable.
  • Field Details

  • Method Details

    • empty

      public static <T> u.Nullable<T> empty()
      Type Parameters:
      T -
      Returns:
    • of

      public static u.Nullable<String> of(String value)
    • of

      public static <T> u.Nullable<T> of(T value)
      Type Parameters:
      T -
      Parameters:
      value -
      Returns:
    • from

      public static <T> u.Nullable<T> from(u.Optional<T> optional)
      Type Parameters:
      T -
      Parameters:
      optional -
      Returns:
    • from

      public static <T> u.Nullable<T> from(Optional<T> optional)
      Type Parameters:
      T -
      Parameters:
      optional -
      Returns:
    • get

      public T get() throws NoSuchElementException
      Returns:
      Throws:
      NoSuchElementException - the no such element exception
    • isPresent

      public boolean isPresent()
      Returns true if the value is present, otherwise returns false.
      Returns:
      true, if is present
    • isNotPresent

      public boolean isNotPresent()
      Returns true if the value is not present, otherwise returns false.
      Returns:
      true, if is not present
    • isEmpty

      @Deprecated public boolean isEmpty()
      Deprecated.
      replaced by isNotPresent()
      Returns true if the value is not present, otherwise returns false.
      Returns:
      true, if is empty
    • isNull

      public boolean isNull()
      Returns true if the value is not present, or it is present but it's null, otherwise returns false.
      Returns:
      true, if is null
    • isNotNull

      public boolean isNotNull()
      Returns true if the value is present and it's not null, otherwise returns false.
      Returns:
      true, if is not null
    • ifPresent

      public <E extends Exception> u.Nullable<T> ifPresent(Throwables.Consumer<? super T,E> action) throws E
      Type Parameters:
      E -
      Parameters:
      action -
      Returns:
      itself
      Throws:
      E - the e
    • ifPresentOrElse

      public <E extends Exception, E2 extends Exception> u.Nullable<T> ifPresentOrElse(Throwables.Consumer<? super T,E> action, Throwables.Runnable<E2> emptyAction) throws E, E2
      If present or else.
      Type Parameters:
      E -
      E2 -
      Parameters:
      action -
      emptyAction -
      Returns:
      itself
      Throws:
      E - the e
      E2 - the e2
    • ifNotNull

      public <E extends Exception> u.Nullable<T> ifNotNull(Throwables.Consumer<? super T,E> action) throws E
      If not null.
      Type Parameters:
      E -
      Parameters:
      action -
      Returns:
      itself
      Throws:
      E - the e
    • ifNotNullOrElse

      public <E extends Exception, E2 extends Exception> u.Nullable<T> ifNotNullOrElse(Throwables.Consumer<? super T,E> action, Throwables.Runnable<E2> emptyAction) throws E, E2
      If not null or else.
      Type Parameters:
      E -
      E2 -
      Parameters:
      action -
      emptyAction -
      Returns:
      itself
      Throws:
      E - the e
      E2 - the e2
    • filter

      public <E extends Exception> u.Nullable<T> filter(Throwables.Predicate<? super T,E> predicate) throws E
      Type Parameters:
      E -
      Parameters:
      predicate -
      Returns:
      Throws:
      E - the e
    • filterIfNotNull

      public <E extends Exception> u.Optional<T> filterIfNotNull(Throwables.Predicate<? super T,E> predicate) throws E
      Filter if not null.
      Type Parameters:
      E -
      Parameters:
      predicate -
      Returns:
      Throws:
      E - the e
    • map

      public <U, E extends Exception> u.Nullable<U> map(Throwables.Function<? super T,? extends U,E> mapper) throws E
      Type Parameters:
      U -
      E -
      Parameters:
      mapper -
      Returns:
      Throws:
      E - the e
    • mapToNonNull

      public <U, E extends Exception> u.Optional<U> mapToNonNull(Throwables.Function<? super T,? extends U,E> mapper) throws E
      Type Parameters:
      U -
      E -
      Parameters:
      mapper -
      Returns:
      Throws:
      E - the e
    • mapToBoolean

      public <E extends Exception> u.OptionalBoolean mapToBoolean(Throwables.ToBooleanFunction<? super T,E> mapper) throws E
      Map to boolean.
      Type Parameters:
      E -
      Parameters:
      mapper -
      Returns:
      Throws:
      E - the e
    • mapToChar

      public <E extends Exception> u.OptionalChar mapToChar(Throwables.ToCharFunction<? super T,E> mapper) throws E
      Map to char.
      Type Parameters:
      E -
      Parameters:
      mapper -
      Returns:
      Throws:
      E - the e
    • mapToByte

      public <E extends Exception> u.OptionalByte mapToByte(Throwables.ToByteFunction<? super T,E> mapper) throws E
      Map to byte.
      Type Parameters:
      E -
      Parameters:
      mapper -
      Returns:
      Throws:
      E - the e
    • mapToShort

      public <E extends Exception> u.OptionalShort mapToShort(Throwables.ToShortFunction<? super T,E> mapper) throws E
      Map to short.
      Type Parameters:
      E -
      Parameters:
      mapper -
      Returns:
      Throws:
      E - the e
    • mapToInt

      public <E extends Exception> u.OptionalInt mapToInt(Throwables.ToIntFunction<? super T,E> mapper) throws E
      Map to int.
      Type Parameters:
      E -
      Parameters:
      mapper -
      Returns:
      Throws:
      E - the e
    • mapToLong

      public <E extends Exception> u.OptionalLong mapToLong(Throwables.ToLongFunction<? super T,E> mapper) throws E
      Map to long.
      Type Parameters:
      E -
      Parameters:
      mapper -
      Returns:
      Throws:
      E - the e
    • mapToFloat

      public <E extends Exception> u.OptionalFloat mapToFloat(Throwables.ToFloatFunction<? super T,E> mapper) throws E
      Map to float.
      Type Parameters:
      E -
      Parameters:
      mapper -
      Returns:
      Throws:
      E - the e
    • mapToDouble

      public <E extends Exception> u.OptionalDouble mapToDouble(Throwables.ToDoubleFunction<? super T,E> mapper) throws E
      Map to double.
      Type Parameters:
      E -
      Parameters:
      mapper -
      Returns:
      Throws:
      E - the e
    • mapIfNotNull

      public <U, E extends Exception> u.Nullable<U> mapIfNotNull(Throwables.Function<? super T,? extends U,E> mapper) throws E
      Map if not null.
      Type Parameters:
      U -
      E -
      Parameters:
      mapper -
      Returns:
      Throws:
      E - the e
    • mapToNonNullIfNotNull

      public <U, E extends Exception> u.Optional<U> mapToNonNullIfNotNull(Throwables.Function<? super T,? extends U,E> mapper) throws E
      Map if not null.
      Type Parameters:
      U -
      E -
      Parameters:
      mapper -
      Returns:
      Throws:
      E - the e
    • mapToBooleanIfNotNull

      public <E extends Exception> u.OptionalBoolean mapToBooleanIfNotNull(Throwables.ToBooleanFunction<? super T,E> mapper) throws E
      Map to boolean if not null.
      Type Parameters:
      E -
      Parameters:
      mapper -
      Returns:
      Throws:
      E - the e
    • mapToCharIfNotNull

      public <E extends Exception> u.OptionalChar mapToCharIfNotNull(Throwables.ToCharFunction<? super T,E> mapper) throws E
      Map to char if not null.
      Type Parameters:
      E -
      Parameters:
      mapper -
      Returns:
      Throws:
      E - the e
    • mapToByteIfNotNull

      public <E extends Exception> u.OptionalByte mapToByteIfNotNull(Throwables.ToByteFunction<? super T,E> mapper) throws E
      Map to byte if not null.
      Type Parameters:
      E -
      Parameters:
      mapper -
      Returns:
      Throws:
      E - the e
    • mapToShortIfNotNull

      public <E extends Exception> u.OptionalShort mapToShortIfNotNull(Throwables.ToShortFunction<? super T,E> mapper) throws E
      Map to short if not null.
      Type Parameters:
      E -
      Parameters:
      mapper -
      Returns:
      Throws:
      E - the e
    • mapToIntIfNotNull

      public <E extends Exception> u.OptionalInt mapToIntIfNotNull(Throwables.ToIntFunction<? super T,E> mapper) throws E
      Map to int if not null.
      Type Parameters:
      E -
      Parameters:
      mapper -
      Returns:
      Throws:
      E - the e
    • mapToLongIfNotNull

      public <E extends Exception> u.OptionalLong mapToLongIfNotNull(Throwables.ToLongFunction<? super T,E> mapper) throws E
      Map to long if not null.
      Type Parameters:
      E -
      Parameters:
      mapper -
      Returns:
      Throws:
      E - the e
    • mapToFloatIfNotNull

      public <E extends Exception> u.OptionalFloat mapToFloatIfNotNull(Throwables.ToFloatFunction<? super T,E> mapper) throws E
      Map to float if not null.
      Type Parameters:
      E -
      Parameters:
      mapper -
      Returns:
      Throws:
      E - the e
    • mapToDoubleIfNotNull

      public <E extends Exception> u.OptionalDouble mapToDoubleIfNotNull(Throwables.ToDoubleFunction<? super T,E> mapper) throws E
      Map to double if not null.
      Type Parameters:
      E -
      Parameters:
      mapper -
      Returns:
      Throws:
      E - the e
    • flatMap

      public <U, E extends Exception> u.Nullable<U> flatMap(Throwables.Function<? super T,u.Nullable<U>,E> mapper) throws E
      Type Parameters:
      U -
      E -
      Parameters:
      mapper -
      Returns:
      Throws:
      E - the e
    • flatMapIfNotNull

      public <U, E extends Exception> u.Nullable<U> flatMapIfNotNull(Throwables.Function<? super T,u.Nullable<U>,E> mapper) throws E
      Flat map if not null.
      Type Parameters:
      U -
      E -
      Parameters:
      mapper -
      Returns:
      Throws:
      E - the e
    • contains

      public boolean contains(T element)
    • or

      public <E extends Exception> u.Nullable<T> or(Throwables.Supplier<u.Nullable<? extends T>,E> supplier) throws E
      Type Parameters:
      E -
      Parameters:
      supplier -
      Returns:
      Throws:
      E - the e
    • orIfNull

      public <E extends Exception> u.Nullable<T> orIfNull(Throwables.Supplier<u.Nullable<? extends T>,E> supplier) throws E
      Or if null.
      Type Parameters:
      E -
      Parameters:
      supplier -
      Returns:
      Throws:
      E - the e
    • orNull

      @Deprecated public T orNull()
      Deprecated.
      Returns:
    • orElseNull

      public T orElseNull()
      Returns:
    • orElse

      public T orElse(T other)
      Parameters:
      other -
      Returns:
    • orElseGet

      public <E extends Exception> T orElseGet(Throwables.Supplier<? extends T,E> other) throws E
      Or else get.
      Type Parameters:
      E -
      Parameters:
      other -
      Returns:
      Throws:
      E - the e
    • orElseThrow

      public T orElseThrow() throws NoSuchElementException
      Or else throw.
      Returns:
      Throws:
      NoSuchElementException - the no such element exception
    • orElseThrow

      public <X extends Throwable> T orElseThrow(Supplier<? extends X> exceptionSupplier) throws X
      Or else throw.
      Type Parameters:
      X -
      Parameters:
      exceptionSupplier -
      Returns:
      Throws:
      X - the x
    • orElseIfNull

      public T orElseIfNull(T other)
      Or else if null.
      Parameters:
      other -
      Returns:
    • orElseGetIfNull

      public <E extends Exception> T orElseGetIfNull(Throwables.Supplier<? extends T,E> other) throws E
      Or else get if null.
      Type Parameters:
      E -
      Parameters:
      other -
      Returns:
      Throws:
      E - the e
    • orElseThrowIfNull

      public T orElseThrowIfNull() throws NoSuchElementException
      Or else throw if null.
      Returns:
      Throws:
      NoSuchElementException - the no such element exception
    • orElseThrowIfNull

      public <X extends Throwable> T orElseThrowIfNull(Supplier<? extends X> exceptionSupplier) throws X
      Or else throw if null.
      Type Parameters:
      X -
      Parameters:
      exceptionSupplier -
      Returns:
      Throws:
      X - the x
    • stream

      public Stream<T> stream()
      Returns:
    • streamIfNotNull

      public Stream<T> streamIfNotNull()
      Stream if not null.
      Returns:
    • toList

      public List<T> toList()
      Returns:
    • toListIfNotNull

      public List<T> toListIfNotNull()
      To list if not null.
      Returns:
    • toSet

      public Set<T> toSet()
      Returns:
    • toSetIfNotNull

      public Set<T> toSetIfNotNull()
      To set if not null.
      Returns:
    • toImmutableList

      public ImmutableList<T> toImmutableList()
      To immutable list.
      Returns:
    • toImmutableListIfNotNull

      public ImmutableList<T> toImmutableListIfNotNull()
      To immutable list if not null.
      Returns:
    • toImmutableSet

      public ImmutableSet<T> toImmutableSet()
      To immutable set.
      Returns:
    • toImmutableSetIfNotNull

      public ImmutableSet<T> toImmutableSetIfNotNull()
      To immutable set if not null.
      Returns:
    • toOptional

      public u.Optional<T> toOptional()
      Returns an empty Optional if it's empty or value is null.
      Returns:
    • toJdkOptional

      public Optional<T> toJdkOptional()
      Returns an empty java.util.Optional if it's empty or value is null.
      Returns:
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
      Parameters:
      obj -
      Returns:
    • hashCode

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

      public String toString()
      Overrides:
      toString in class Object
      Returns: