public final class OptionalInts extends Object
OptionalInt
.Modifier and Type | Field and Description |
---|---|
static IntPredicate |
IS_NEGATIVE
Predicate returning
true for all values less than zero. |
static IntPredicate |
IS_NEGATIVE_OR_ZERO
Predicate returning
true for all values less than or equal to zero. |
static IntPredicate |
IS_POSITIVE
Predicate returning
true for all values greater than zero. |
static IntPredicate |
IS_POSITIVE_OR_ZERO
Predicate returning
true for all values greater than or equal to
zero. |
Modifier and Type | Method and Description |
---|---|
static Optional<Integer> |
boxed(OptionalInt optional)
|
static OptionalInt |
filter(OptionalInt optional,
IntPredicate predicate)
If a value is present, and the value matches the given predicate, return an
OptionalInt describing the value, otherwise return an empty
OptionalInt . |
static OptionalInt |
flatMap(OptionalInt optional,
IntFunction<OptionalInt> mapper)
If a value is present, apply the provided
OptionalInt -bearing mapping
function to it, return that result, otherwise return an empty
OptionalInt . |
static OptionalDouble |
flatMapToDouble(OptionalInt optional,
IntFunction<OptionalDouble> mapper)
If a value is present, apply the provided
OptionalDouble -bearing
mapping function to it, return that result, otherwise return an empty
OptionalDouble . |
static OptionalLong |
flatMapToLong(OptionalInt optional,
IntFunction<OptionalLong> mapper)
If a value is present, apply the provided
OptionalLong -bearing
mapping function to it, return that result, otherwise return an empty
OptionalLong . |
static <T> Optional<T> |
flatMapToObj(OptionalInt optional,
IntFunction<Optional<T>> mapper)
|
static OptionalInt |
map(OptionalInt optional,
IntToIntFunction mapper)
|
static OptionalDouble |
mapToDouble(OptionalInt optional,
IntToDoubleFunction mapper)
If a value is present, applies
mapper to optional and returns
an OptionalDouble describing the result. |
static OptionalLong |
mapToLong(OptionalInt optional,
IntToLongFunction mapper)
If a value is present, applies
mapper to optional and returns
an OptionalLong describing the result. |
static <T> Optional<T> |
mapToObj(OptionalInt optional,
IntFunction<T> mapper)
|
static OptionalInt |
ofNon(IntPredicate isEmpty,
int value)
Returns an
OptionalInt describing the specified value, if non-empty,
otherwise returns an empty OptionalInt . |
static OptionalInt |
ofNullable(Integer value)
Returns an
OptionalInt describing the specified value, if non-null,
otherwise returns an empty OptionalInt . |
static IntStream |
stream(OptionalInt... optionals)
Returns a stream consisting of present elements.
|
public static final IntPredicate IS_NEGATIVE
true
for all values less than zero.public static final IntPredicate IS_NEGATIVE_OR_ZERO
true
for all values less than or equal to zero.public static final IntPredicate IS_POSITIVE
true
for all values greater than zero.public static final IntPredicate IS_POSITIVE_OR_ZERO
true
for all values greater than or equal to
zero.public static Optional<Integer> boxed(OptionalInt optional)
public static OptionalInt filter(OptionalInt optional, IntPredicate predicate)
OptionalInt
describing the value, otherwise return an empty
OptionalInt
.optional
- optional valuepredicate
- a predicate to apply to the value, if presentOptionalInt
describing the value of optional
if a
value is present and the value matches the given predicate, otherwise
an empty OptionalInt
public static OptionalInt flatMap(OptionalInt optional, IntFunction<OptionalInt> mapper)
OptionalInt
-bearing mapping
function to it, return that result, otherwise return an empty
OptionalInt
. This method is similar to
map(OptionalInt, IntToIntFunction)
, but the provided mapper is one
whose result is already an OptionalInt
, and if invoked,
flatMap
does not wrap it with an additional OptionalInt
.optional
- optional valuemapper
- a mapping function to apply to the value, if present the
mapping functionOptionalInt
-bearing mapping
function to the value of this OptionalInt
, if a value is
present, otherwise an empty OptionalInt
public static OptionalDouble flatMapToDouble(OptionalInt optional, IntFunction<OptionalDouble> mapper)
OptionalDouble
-bearing
mapping function to it, return that result, otherwise return an empty
OptionalDouble
. This method is similar to
mapToDouble(OptionalInt, IntToDoubleFunction)
, but the provided
mapper is one whose result is already an OptionalDouble
, and if
invoked, flatMapToDouble
does not wrap it with an additional
OptionalDouble
.optional
- optional valuemapper
- a mapping function to apply to the value, if present the
mapping functionOptionalDouble
-bearing mapping
function to the value of this OptionalDouble
, if a value is
present, otherwise an empty OptionalDouble
public static OptionalLong flatMapToLong(OptionalInt optional, IntFunction<OptionalLong> mapper)
OptionalLong
-bearing
mapping function to it, return that result, otherwise return an empty
OptionalLong
. This method is similar to
mapToLong(OptionalInt, IntToLongFunction)
, but the provided mapper
is one whose result is already an OptionalLong
, and if invoked,
flatMapToDouble
does not wrap it with an additional
OptionalLong
.optional
- optional valuemapper
- a mapping function to apply to the value, if present the
mapping functionOptionalLong
-bearing mapping
function to the value of this OptionalLong
, if a value is
present, otherwise an empty OptionalLong
public static <T> Optional<T> flatMapToObj(OptionalInt optional, IntFunction<Optional<T>> mapper)
Optional
-bearing mapping
function to it, return that result, otherwise return an empty
Optional
. This method is similar to
mapToObj(OptionalInt, IntFunction)
, but the provided mapper is one
whose result is already an Optional
, and if invoked,
flatMapToDouble
does not wrap it with an additional Optional
.T
- the type parameter to the Optional
returnedoptional
- optional valuemapper
- a mapping function to apply to the value, if present the
mapping functionOptional
-bearing mapping function
to the value of this Optional
, if a value is present,
otherwise an empty Optional
public static OptionalInt map(OptionalInt optional, IntToIntFunction mapper)
mapper
to optional
and returns
an OptionalInt
describing the result. Otherwise returns an empty
OptionalInt
.optional
- optional valuemapper
- a mapping function to apply to the value, if presentOptionalInt
describing the result of applying
mapper
function to the value of optional
, if a value
is present, otherwise an empty OptionalInt
public static OptionalDouble mapToDouble(OptionalInt optional, IntToDoubleFunction mapper)
mapper
to optional
and returns
an OptionalDouble
describing the result. Otherwise returns an empty
OptionalDouble
.optional
- optional valuemapper
- a mapping function to apply to the value, if presentOptionalDouble
describing the result of applying
mapper
function to the value of optional
, if a value
is present, otherwise an empty OptionalDouble
public static OptionalLong mapToLong(OptionalInt optional, IntToLongFunction mapper)
mapper
to optional
and returns
an OptionalLong
describing the result. Otherwise returns an empty
OptionalLong
.optional
- optional valuemapper
- a mapping function to apply to the value, if presentOptionalLong
describing the result of applying
mapper
function to the value of optional
, if a value
is present, otherwise an empty OptionalLong
public static <T> Optional<T> mapToObj(OptionalInt optional, IntFunction<T> mapper)
mapper
to optional
and returns
an Optional
describing the result. Otherwise returns an empty
Optional
.T
- the type of the result of mapper
optional
- optional valuemapper
- a mapping function to apply to the value, if presentOptional
describing the result of applying mapper
function to the value of optional
, if a value is present,
otherwise an empty Optional
public static OptionalInt ofNon(IntPredicate isEmpty, int value)
OptionalInt
describing the specified value, if non-empty,
otherwise returns an empty OptionalInt
. The term empty is
described by isEmpty
.isEmpty
- predicate describing the term emptyvalue
- the possibly-empty value to describeOptionalInt
with a present value if the specified value is
non-empty, otherwise an empty OptionalInt
public static OptionalInt ofNullable(@Nullable Integer value)
OptionalInt
describing the specified value, if non-null,
otherwise returns an empty OptionalInt
.value
- the possibly-null value to describeOptionalInt
with a present value if the specified value is
non-null, otherwise an empty OptionalInt
@SafeVarargs public static IntStream stream(OptionalInt... optionals)
optionals
- array of optional elementsCopyright © 2025. All rights reserved.