Package com.landawn.abacus.util
Class u.Nullable<T>
java.lang.Object
com.landawn.abacus.util.u.Nullable<T>
- Type Parameters:
T
-
- All Implemented Interfaces:
Immutable
- Enclosing class:
- u
The Class Nullable.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final u.Nullable<Boolean>
PresentsBoolean.FALSE
.static final u.Nullable<Boolean>
PresentsBoolean.TRUE
. -
Method Summary
Modifier and TypeMethodDescriptionboolean
static <T> u.Nullable<T>
empty()
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.<U,
E extends Exception>
u.Nullable<U>flatMap
(Throwables.Function<? super T, u.Nullable<U>, E> mapper) <U,
E extends Exception>
u.Nullable<U>flatMapIfNotNull
(Throwables.Function<? super T, u.Nullable<U>, E> mapper) Flat map if not null.static <T> u.Nullable<T>
from
(u.Optional<T> optional) static <T> u.Nullable<T>
get()
int
hashCode()
<E extends Exception>
u.Nullable<T>ifNotNull
(Throwables.Consumer<? super T, E> action) If not null.<E extends Exception,
E2 extends Exception>
u.Nullable<T>ifNotNullOrElse
(Throwables.Consumer<? super T, E> action, Throwables.Runnable<E2> emptyAction) If not null or else.<E extends Exception>
u.Nullable<T>ifPresent
(Throwables.Consumer<? super T, E> action) <E extends Exception,
E2 extends Exception>
u.Nullable<T>ifPresentOrElse
(Throwables.Consumer<? super T, E> action, Throwables.Runnable<E2> emptyAction) If present or else.boolean
isEmpty()
Deprecated.boolean
Returnstrue
if the value is present and it's notnull
, otherwise returnsfalse
.boolean
Returnstrue
if the value is not present, otherwise returnsfalse
.boolean
isNull()
Returnstrue
if the value is not present, or it is present but it'snull
, otherwise returnsfalse
.boolean
Returnstrue
if the value is present, otherwise returnsfalse
.<U,
E extends Exception>
u.Nullable<U>map
(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.<E extends Exception>
u.OptionalBooleanmapToBoolean
(Throwables.ToBooleanFunction<? super T, E> mapper) Map to boolean.<E extends Exception>
u.OptionalBooleanmapToBooleanIfNotNull
(Throwables.ToBooleanFunction<? super T, E> mapper) Map to boolean if not null.<E extends Exception>
u.OptionalBytemapToByte
(Throwables.ToByteFunction<? super T, E> mapper) Map to byte.<E extends Exception>
u.OptionalBytemapToByteIfNotNull
(Throwables.ToByteFunction<? super T, E> mapper) Map to byte if not null.<E extends Exception>
u.OptionalCharmapToChar
(Throwables.ToCharFunction<? super T, E> mapper) Map to char.<E extends Exception>
u.OptionalCharmapToCharIfNotNull
(Throwables.ToCharFunction<? super T, E> mapper) Map to char if not null.<E extends Exception>
u.OptionalDoublemapToDouble
(Throwables.ToDoubleFunction<? super T, E> mapper) Map to double.<E extends Exception>
u.OptionalDoublemapToDoubleIfNotNull
(Throwables.ToDoubleFunction<? super T, E> mapper) Map to double if not null.<E extends Exception>
u.OptionalFloatmapToFloat
(Throwables.ToFloatFunction<? super T, E> mapper) Map to float.<E extends Exception>
u.OptionalFloatmapToFloatIfNotNull
(Throwables.ToFloatFunction<? super T, E> mapper) Map to float if not null.<E extends Exception>
u.OptionalIntmapToInt
(Throwables.ToIntFunction<? super T, E> mapper) Map to int.<E extends Exception>
u.OptionalIntmapToIntIfNotNull
(Throwables.ToIntFunction<? super T, E> mapper) Map to int if not null.<E extends Exception>
u.OptionalLongmapToLong
(Throwables.ToLongFunction<? super T, E> mapper) Map to long.<E extends Exception>
u.OptionalLongmapToLongIfNotNull
(Throwables.ToLongFunction<? super T, E> mapper) Map to long if not null.<U,
E extends Exception>
u.Optional<U>mapToNonNull
(Throwables.Function<? super T, ? extends U, E> mapper) <U,
E extends Exception>
u.Optional<U>mapToNonNullIfNotNull
(Throwables.Function<? super T, ? extends U, E> mapper) Map if not null.<E extends Exception>
u.OptionalShortmapToShort
(Throwables.ToShortFunction<? super T, E> mapper) Map to short.<E extends Exception>
u.OptionalShortmapToShortIfNotNull
(Throwables.ToShortFunction<? super T, E> mapper) Map to short if not null.static u.Nullable<String>
static <T> u.Nullable<T>
of
(T value) <E extends Exception>
u.Nullable<T>or
(Throwables.Supplier<u.Nullable<? extends T>, E> supplier) orElseGet
(Throwables.Supplier<? extends T, E> other) Or else get.orElseGetIfNull
(Throwables.Supplier<? extends T, E> other) Or else get if null.orElseIfNull
(T other) Or else if null.Or else throw.orElseThrow
(Supplier<? extends X> exceptionSupplier) Or else throw.Or else throw if null.orElseThrowIfNull
(Supplier<? extends X> exceptionSupplier) Or else throw if null.<E extends Exception>
u.Nullable<T>orIfNull
(Throwables.Supplier<u.Nullable<? extends T>, E> supplier) Or if null.orNull()
Deprecated.usingorElseNull()
stream()
Stream if not null.To immutable list.To immutable list if not null.To immutable set.To immutable set if not null.Returns an emptyjava.util.Optional
if it's empty or value is null.toList()
To list if not null.Returns an emptyOptional
if it's empty or value is null.toSet()
To set if not null.toString()
-
Field Details
-
TRUE
PresentsBoolean.TRUE
. -
FALSE
PresentsBoolean.FALSE
.
-
-
Method Details
-
empty
- Type Parameters:
T
-- Returns:
-
of
-
of
- Type Parameters:
T
-- Parameters:
value
-- Returns:
-
from
- Type Parameters:
T
-- Parameters:
optional
-- Returns:
-
from
- Type Parameters:
T
-- Parameters:
optional
-- Returns:
-
get
- Returns:
- Throws:
NoSuchElementException
- the no such element exception
-
isPresent
public boolean isPresent()Returnstrue
if the value is present, otherwise returnsfalse
.- Returns:
- true, if is present
-
isNotPresent
public boolean isNotPresent()Returnstrue
if the value is not present, otherwise returnsfalse
.- Returns:
- true, if is not present
-
isEmpty
Deprecated.replaced byisNotPresent()
Returnstrue
if the value is not present, otherwise returnsfalse
.- Returns:
- true, if is empty
-
isNull
public boolean isNull()Returnstrue
if the value is not present, or it is present but it'snull
, otherwise returnsfalse
.- Returns:
- true, if is null
-
isNotNull
public boolean isNotNull()Returnstrue
if the value is present and it's notnull
, otherwise returnsfalse
.- 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, E2If present or else.- Type Parameters:
E
-E2
-- Parameters:
action
-emptyAction
-- Returns:
- itself
- Throws:
E
- the eE2
- the e2
-
ifNotNull
public <E extends Exception> u.Nullable<T> ifNotNull(Throwables.Consumer<? super T, E> action) throws EIf 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, E2If not null or else.- Type Parameters:
E
-E2
-- Parameters:
action
-emptyAction
-- Returns:
- itself
- Throws:
E
- the eE2
- 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 EFilter 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, throws EE> mapper) - 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, throws EE> mapper) - 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 EMap 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 EMap 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 EMap 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 EMap 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 EMap 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 EMap 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 EMap 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 EMap 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, 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) 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 EMap 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 EMap 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 EMap 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 EMap 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 EMap 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 EMap 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 EMap 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 EMap 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>, throws EE> mapper) - 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>, throws EE> mapper) Flat map if not null.- Type Parameters:
U
-E
-- Parameters:
mapper
-- Returns:
- Throws:
E
- the e
-
contains
-
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 EOr if null.- Type Parameters:
E
-- Parameters:
supplier
-- Returns:
- Throws:
E
- the e
-
orNull
Deprecated.usingorElseNull()
- Returns:
-
orElseNull
- Returns:
-
orElse
- Parameters:
other
-- Returns:
-
orElseGet
Or else get.- Type Parameters:
E
-- Parameters:
other
-- Returns:
- Throws:
E
- the e
-
orElseThrow
Or else throw.- Returns:
- Throws:
NoSuchElementException
- the no such element exception
-
orElseThrow
Or else throw.- Type Parameters:
X
-- Parameters:
exceptionSupplier
-- Returns:
- Throws:
X
- the x
-
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.- Returns:
- Throws:
NoSuchElementException
- the no such element exception
-
orElseThrowIfNull
Or else throw if null.- Type Parameters:
X
-- Parameters:
exceptionSupplier
-- Returns:
- Throws:
X
- the x
-
stream
- Returns:
-
streamIfNotNull
Stream if not null.- Returns:
-
toList
- Returns:
-
toListIfNotNull
To list if not null.- Returns:
-
toSet
- Returns:
-
toSetIfNotNull
To set if not null.- Returns:
-
toImmutableList
To immutable list.- Returns:
-
toImmutableListIfNotNull
To immutable list if not null.- Returns:
-
toImmutableSet
To immutable set.- Returns:
-
toImmutableSetIfNotNull
To immutable set if not null.- Returns:
-
toOptional
Returns an emptyOptional
if it's empty or value is null.- Returns:
-
toJdkOptional
Returns an emptyjava.util.Optional
if it's empty or value is null.- Returns:
-
equals
-
hashCode
public int hashCode() -
toString
-
isNotPresent()