public final class Holder<T>
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
Holder.R<T> |
Constructor and Description |
---|
Holder() |
Modifier and Type | Method and Description |
---|---|
<E extends java.lang.Exception> |
accept(Try.Consumer<? super T,E> action) |
<E extends java.lang.Exception> |
acceptIfNotNull(Try.Consumer<? super T,E> action) |
boolean |
equals(java.lang.Object obj) |
<E extends java.lang.Exception> |
filter(Try.Predicate<? super T,E> predicate) |
<E extends java.lang.Exception> |
filterIfNotNull(Try.Predicate<? super T,E> predicate) |
T |
getAndSet(T value) |
<E extends java.lang.Exception> |
getAndUpdate(Try.UnaryOperator<T,E> updateFunction) |
T |
getValue() |
int |
hashCode() |
boolean |
isNotNull() |
<U,E extends java.lang.Exception> |
map(Try.Function<? super T,U,E> mapper) |
<U,E extends java.lang.Exception> |
mapIfNotNull(Try.Function<? super T,U,E> mapper)
Execute the specified action if value is not null, otherwise return null directly.
|
static <T> Holder<T> |
of(T value) |
<E extends java.lang.Exception> |
orGetIfNull(Try.Supplier<? extends T,E> other)
Return the value is not null, otherwise invoke
other and return the result of that invocation. |
T |
orIfNull(T other)
Return the value is not null, otherwise return
other . |
<X extends java.lang.Throwable> |
orThrowIfNull(Supplier<? extends X> exceptionSupplier)
Return the value is not null, otherwise throw an exception to be created by the provided supplier.
|
T |
setAndGet(T value) |
<E extends java.lang.Exception> |
setIf(T newValue,
Try.BiPredicate<? super T,? super T,E> predicate)
Set with the specified new value and returns
true if predicate returns true. |
<E extends java.lang.Exception> |
setIf(T newValue,
Try.Predicate<? super T,E> predicate)
Set with the specified new value and returns
true if predicate returns true. |
R |
setValue(T value) |
Stream<T> |
stream() |
Stream<T> |
streamIfNotNull() |
java.lang.String |
toString() |
<E extends java.lang.Exception> |
updateAndGet(Try.UnaryOperator<T,E> updateFunction) |
T |
value() |
public static <T> Holder<T> of(T value)
public T value()
public T getValue()
public R setValue(T value)
public T getAndSet(T value)
public T setAndGet(T value)
public final <E extends java.lang.Exception> T getAndUpdate(Try.UnaryOperator<T,E> updateFunction) throws E extends java.lang.Exception
E extends java.lang.Exception
public final <E extends java.lang.Exception> T updateAndGet(Try.UnaryOperator<T,E> updateFunction) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> boolean setIf(T newValue, Try.Predicate<? super T,E> predicate) throws E extends java.lang.Exception
true
if predicate
returns true.
Otherwise just return false
without setting the value to new value.newValue
- predicate
- - test the current value.E extends java.lang.Exception
public <E extends java.lang.Exception> boolean setIf(T newValue, Try.BiPredicate<? super T,? super T,E> predicate) throws E extends java.lang.Exception
true
if predicate
returns true.
Otherwise just return false
without setting the value to new value.newValue
- predicate
- the first parameter is the current value, the second parameter is the new value.E extends java.lang.Exception
public boolean isNotNull()
public <E extends java.lang.Exception> void accept(Try.Consumer<? super T,E> action) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> void acceptIfNotNull(Try.Consumer<? super T,E> action) throws E extends java.lang.Exception
E extends java.lang.Exception
public <U,E extends java.lang.Exception> U map(Try.Function<? super T,U,E> mapper) throws E extends java.lang.Exception
E extends java.lang.Exception
public <U,E extends java.lang.Exception> Nullable<U> mapIfNotNull(Try.Function<? super T,U,E> mapper) throws E extends java.lang.Exception
mapper
- E extends java.lang.Exception
public <E extends java.lang.Exception> Nullable<T> filter(Try.Predicate<? super T,E> predicate) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> Nullable<T> filterIfNotNull(Try.Predicate<? super T,E> predicate) throws E extends java.lang.Exception
E extends java.lang.Exception
public Stream<T> stream()
public Stream<T> streamIfNotNull()
public T orIfNull(T other)
other
.other
- the value to be returned if not present or null, may be nullother
public <E extends java.lang.Exception> T orGetIfNull(Try.Supplier<? extends T,E> other) throws E extends java.lang.Exception
other
and return the result of that invocation.other
- a Supplier
whose result is returned if not present or nullother.get()
java.lang.NullPointerException
- if value is not present and other
is nullE extends java.lang.Exception
public <X extends java.lang.Throwable> T orThrowIfNull(Supplier<? extends X> exceptionSupplier) throws X extends java.lang.Throwable
X
- Type of the exception to be thrownexceptionSupplier
- The supplier which will return the exception to be thrownX
- if not present or nulljava.lang.NullPointerException
- if not present or null and
exceptionSupplier
is nullX extends java.lang.Throwable
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object