Class Holder<T>

java.lang.Object
com.landawn.abacus.util.Holder<T>
Type Parameters:
T -
All Implemented Interfaces:
Mutable

public final class Holder<T> extends Object implements Mutable
The Class Holder.
  • Constructor Details

    • Holder

      public Holder()
      Instantiates a new holder.
  • Method Details

    • of

      public static <T> Holder<T> of(T value)
      Type Parameters:
      T -
      Parameters:
      value -
      Returns:
    • value

      public T value()
      Returns:
    • getValue

      @Deprecated public T getValue()
      Deprecated.
      replace by value().
      Gets the value.
      Returns:
    • setValue

      public void setValue(T value)
      Sets the value.
      Parameters:
      value - the new value
    • getAndSet

      public T getAndSet(T value)
      Gets the and set.
      Parameters:
      value -
      Returns:
    • setAndGet

      public T setAndGet(T value)
      Sets the and get.
      Parameters:
      value -
      Returns:
    • getAndUpdate

      public <E extends Exception> T getAndUpdate(Throwables.UnaryOperator<T,E> updateFunction) throws E
      Gets the and update.
      Type Parameters:
      E -
      Parameters:
      updateFunction -
      Returns:
      Throws:
      E - the e
    • updateAndGet

      public <E extends Exception> T updateAndGet(Throwables.UnaryOperator<T,E> updateFunction) throws E
      Update and get.
      Type Parameters:
      E -
      Parameters:
      updateFunction -
      Returns:
      Throws:
      E - the e
    • setIf

      public <E extends Exception> boolean setIf(T newValue, Throwables.Predicate<? super T,E> predicate) throws E
      Set with the specified new value and returns true if predicate returns true. Otherwise just return false without setting the value to new value.
      Type Parameters:
      E -
      Parameters:
      newValue -
      predicate - - test the current value.
      Returns:
      Throws:
      E - the e
    • setIf

      @Deprecated public <E extends Exception> boolean setIf(T newValue, Throwables.BiPredicate<? super T,? super T,E> predicate) throws E
      Deprecated.
      Set with the specified new value and returns true if predicate returns true. Otherwise just return false without setting the value to new value.
      Type Parameters:
      E -
      Parameters:
      newValue -
      predicate - the first parameter is the current value, the second parameter is the new value.
      Returns:
      Throws:
      E - the e
    • isNull

      public boolean isNull()
      Checks if is null.
      Returns:
      true, if is null
    • isNotNull

      public boolean isNotNull()
      Checks if is not null.
      Returns:
      true, if is not null
    • ifNotNull

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

      public <E extends Exception, E2 extends Exception> void 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 -
      Throws:
      E - the e
      E2 - the e2
    • accept

      public <E extends Exception> void accept(Throwables.Consumer<? super T,E> action) throws E
      Type Parameters:
      E -
      Parameters:
      action -
      Throws:
      E - the e
    • acceptIfNotNull

      @Deprecated public <E extends Exception> void acceptIfNotNull(Throwables.Consumer<? super T,E> action) throws E
      Deprecated.
      Accept if not null.
      Type Parameters:
      E -
      Parameters:
      action -
      Throws:
      E - the e
    • map

      public <U, E extends Exception> U map(Throwables.Function<? super T,? extends U,E> mapper) throws E
      Type Parameters:
      U -
      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
      Type Parameters:
      U -
      E -
      Parameters:
      mapper -
      Returns:
      Throws:
      E
    • 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
    • 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 <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()
      Returns a Stream with the value if value is not null, otherwise an empty Stream is returned.
      Returns:
    • toNullable

      public u.Nullable<T> toNullable()
      Returns a non-empty Nullable with the value.
      Returns:
    • toOptional

      public u.Optional<T> toOptional()
      Returns an Optional with the value if value is not null, otherwise an empty Optional is returned.
      Returns:
    • hashCode

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

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

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