Package com.landawn.abacus.util
Class Holder<T>
java.lang.Object
com.landawn.abacus.util.Holder<T>
- Type Parameters:
T
-
- All Implemented Interfaces:
Mutable
The Class Holder.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription<E extends Exception>
voidaccept
(Throwables.Consumer<? super T, E> action) <E extends Exception>
voidacceptIfNotNull
(Throwables.Consumer<? super T, E> action) Deprecated.boolean
<E extends Exception>
u.Nullable<T>filter
(Throwables.Predicate<? super T, E> predicate) <E extends Exception>
u.Optional<T>filterIfNotNull
(Throwables.Predicate<? super T, E> predicate) Filter if not null.Gets the and set.getAndUpdate
(Throwables.UnaryOperator<T, E> updateFunction) Gets the and update.getValue()
Deprecated.replace byvalue()
.int
hashCode()
<E extends Exception>
voidifNotNull
(Throwables.Consumer<? super T, E> action) If not null.ifNotNullOrElse
(Throwables.Consumer<? super T, E> action, Throwables.Runnable<E2> emptyAction) If not null or else.boolean
Checks if is not null.boolean
isNull()
Checks if is null.<U,
E extends Exception>
Umap
(Throwables.Function<? super T, ? extends U, E> mapper) <U,
E extends Exception>
u.Nullable<U>mapIfNotNull
(Throwables.Function<? super T, ? extends U, E> mapper) Map if not null.<U,
E extends Exception>
u.Optional<U>mapToNonNullIfNotNull
(Throwables.Function<? super T, ? extends U, E> mapper) static <T> Holder<T>
of
(T value) orElseGetIfNull
(Throwables.Supplier<? extends T, E> other) Or else get if null.orElseIfNull
(T other) Or else if null.orElseThrowIfNull
(Supplier<? extends X> exceptionSupplier) Or else throw if null.Sets the and get.<E extends Exception>
booleansetIf
(T newValue, Throwables.BiPredicate<? super T, ? super T, E> predicate) Deprecated.<E extends Exception>
booleansetIf
(T newValue, Throwables.Predicate<? super T, E> predicate) Set with the specified new value and returnstrue
ifpredicate
returns true.void
Sets the value.stream()
Returns aStream
with thevalue
ifvalue
is not null, otherwise an emptyStream
is returned.Returns a non-emptyNullable
with thevalue
.Returns anOptional
with thevalue
ifvalue
is not null, otherwise an emptyOptional
is returned.toString()
updateAndGet
(Throwables.UnaryOperator<T, E> updateFunction) Update and get.value()
-
Constructor Details
-
Holder
public Holder()Instantiates a new holder.
-
-
Method Details
-
of
- Type Parameters:
T
-- Parameters:
value
-- Returns:
-
value
- Returns:
-
getValue
Deprecated.replace byvalue()
.Gets the value.- Returns:
-
setValue
Sets the value.- Parameters:
value
- the new value
-
getAndSet
Gets the and set.- Parameters:
value
-- Returns:
-
setAndGet
Sets the and get.- Parameters:
value
-- Returns:
-
getAndUpdate
Gets the and update.- Type Parameters:
E
-- Parameters:
updateFunction
-- Returns:
- Throws:
E
- the e
-
updateAndGet
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 ESet with the specified new value and returnstrue
ifpredicate
returns true. Otherwise just returnfalse
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, throws EE> predicate) Deprecated.Set with the specified new value and returnstrue
ifpredicate
returns true. Otherwise just returnfalse
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
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, E2If not null or else.- Type Parameters:
E
-E2
-- Parameters:
action
-emptyAction
-- Throws:
E
- the eE2
- the e2
-
accept
- Type Parameters:
E
-- Parameters:
action
-- Throws:
E
- the e
-
acceptIfNotNull
@Deprecated public <E extends Exception> void acceptIfNotNull(Throwables.Consumer<? super T, E> action) throws EDeprecated.Accept if not null.- Type Parameters:
E
-- Parameters:
action
-- Throws:
E
- the e
-
map
- 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, throws EE> mapper) 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, throws EE> mapper) - Throws:
E extends Exception
-
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 EFilter if not null.- Type Parameters:
E
-- Parameters:
predicate
-- Returns:
- Throws:
E
- the e
-
orElseIfNull
Or else if null.- Parameters:
other
-- Returns:
-
orElseGetIfNull
Or else get if null.- Type Parameters:
E
-- Parameters:
other
-- Returns:
- Throws:
E
- the e
-
orElseThrowIfNull
Or else throw if null.- Type Parameters:
X
-- Parameters:
exceptionSupplier
-- Returns:
- Throws:
X
- the x
-
stream
- Returns:
-
streamIfNotNull
Returns aStream
with thevalue
ifvalue
is not null, otherwise an emptyStream
is returned.- Returns:
-
toNullable
Returns a non-emptyNullable
with thevalue
.- Returns:
-
toOptional
Returns anOptional
with thevalue
ifvalue
is not null, otherwise an emptyOptional
is returned.- Returns:
-
hashCode
public int hashCode() -
equals
-
toString
-
ifNotNull(com.landawn.abacus.util.Throwables.Consumer)