public final class IntPredicateUtils
extends java.lang.Object
int types.| Modifier and Type | Method and Description |
|---|---|
static java.util.function.IntPredicate |
intConstant(boolean b)
Builds an integer predicate based on a passed constant
boolean value. |
static java.util.function.IntPredicate |
intGt(int compareTo)
Builds an
IntPredicate that determines whether a value is greater than a passed constant int value. |
static <R extends java.lang.Comparable<R>> |
intGt(java.util.function.IntFunction<? extends R> function,
R compareTo)
Given an
IntFunction that returns a value of type <R>, and a constant value of type <R>,
this method builds an IntPredicate that applies that function to its target value, and determines
whether the returned Comparable value is greater than a passed constant value of type <R>
(also a Comparable). |
static java.util.function.IntPredicate |
intGte(int compareTo)
Builds an
IntPredicate that determines whether a value is greater than or equal to a passed constant
int value. |
static <R extends java.lang.Comparable<R>> |
intGte(java.util.function.IntFunction<? extends R> function,
R compareTo)
Given an
IntFunction that returns a value of type <R>, and a constant value of type <R>,
this method builds an IntPredicate that applies that function to its target value, and determines
whether the returned Comparable value is greater than or equal to a passed constant value of type
<R> (also a Comparable). |
static java.util.function.IntPredicate |
intIsNotNull(java.util.function.IntFunction<?> function)
Given an
IntFunction that returns a value of an arbitrary type, this method builds an
IntPredicate that determines whether that returned value is not null. |
static java.util.function.IntPredicate |
intIsNull(java.util.function.IntFunction<?> function)
Given an
IntFunction that returns a value of an arbitrary type, this method builds an
IntPredicate that determines whether that returned value is null. |
static java.util.function.IntPredicate |
intLt(int compareTo)
Builds an
IntPredicate that determines whether a value is less than a passed constant int value. |
static <R extends java.lang.Comparable<R>> |
intLt(java.util.function.IntFunction<? extends R> function,
R compareTo)
Given an
IntFunction that returns a value of type <R>, and a constant value of type <R>,
this method builds an IntPredicate that applies that function to its target value, and determines
whether the returned Comparable value is less than a passed constant value of type <R> (also a
Comparable). |
static java.util.function.IntPredicate |
intLte(int compareTo)
Builds an
IntPredicate that determines whether a value is less than or equal to a passed constant
int value. |
static <R extends java.lang.Comparable<R>> |
intLte(java.util.function.IntFunction<? extends R> function,
R compareTo)
Given an
IntFunction that returns a value of type <R>, and a constant value of type <R>,
this method builds an IntPredicate that applies that function to its target value, and determines
whether the returned Comparable value is less than or equal to a passed constant value of type
<R> (also a Comparable). |
static <T> java.util.function.IntPredicate |
intMapAndFilter(java.util.function.IntFunction<? extends T> function,
java.util.function.Predicate<? super T> predicate)
Given an
IntFunction that returns a value of type <T>, and a Predicate, this
method builds an IntPredicate that applies the return value of the IntFunction to the
given predicate. |
static java.util.function.IntPredicate |
intNot(java.util.function.IntPredicate predicate)
An
IntPredicate that simply negates the passed IntPredicate. |
static <U> java.util.function.IntPredicate |
intPredicate(java.util.function.BiPredicate<java.lang.Integer,? super U> biPredicate,
U value)
Builds an
IntPredicate from a passed BiPredicate<Integer, U>, which can be very
useful in the common situation where you are streaming through a collection of elements, and have an integer
predicate method to call that takes two parameters - the first one being the int element on which
you are streaming, and the second being some constant value that will be passed to all invocations. |
static java.util.function.IntPredicate |
intPredicate(java.util.function.IntPredicate predicate)
Simply casts a method reference, which takes a single parameter of type
int or
Integer, and returns a boolean or Boolean, to an
IntPredicate. |
static <R> java.util.function.IntPredicate |
intToObjContains(java.util.Collection<? extends R> collection,
java.util.function.IntFunction<? extends R> function)
Given a
Collection whose elements are of type <R>, and an IntFunction that
returns a value of type <R>, this method builds an IntPredicate that determines if the given
collection contains the value returned by the int function. |
static <R> java.util.function.IntPredicate |
intToObjectsAllMatch(java.util.function.IntFunction<? extends java.util.Collection<R>> function,
java.util.function.Predicate<R> predicate)
Given an
IntFunction that returns a Collection of type <R>, and a
Predicate, this method builds an IntPredicate that determines whether all elements in
the returned Collection match the Predicate. |
static <R> java.util.function.IntPredicate |
intToObjectsAnyMatch(java.util.function.IntFunction<? extends java.util.Collection<R>> function,
java.util.function.Predicate<R> predicate)
Given an
IntFunction that returns a Collection of type <R>, and a
Predicate, this method builds an IntPredicate that determines whether any of the
elements in the returned Collection match the Predicate. |
static <R> java.util.function.IntPredicate |
intToObjectsNoneMatch(java.util.function.IntFunction<? extends java.util.Collection<R>> function,
java.util.function.Predicate<R> predicate)
Given an
IntFunction that returns a Collection of type <R>, and a
Predicate, this method builds an IntPredicate that determines whether none of the
elements in the returned Collection match the Predicate. |
static <U> java.util.function.IntPredicate |
inverseIntPredicate(java.util.function.BiPredicate<? super U,java.lang.Integer> biPredicate,
U value)
Builds an
IntPredicate from a passed BiPredicate<Integer, U>, which can be very
useful in the common situation where you are streaming through a collection of elements, and have an integer
predicate method to call that takes two parameters. |
static <R> java.util.function.IntPredicate |
inverseIntToObjContains(java.util.function.IntFunction<? extends java.util.Collection<R>> function,
R value)
Given an
IntFunction that returns a Collection<R>, this method builds an
IntPredicate that determines if the collection returned by that int function contains the passed
value of type <R>. |
static <T> java.util.function.Predicate<T> |
inverseObjToIntContains(java.util.function.Function<T,int[]> function,
int value)
Given a
Function that takes an element of type <T> and returns an array of ints, this method
builds a Predicate that determines if the array returned by that function contains the passed
constant int value. |
static <T> java.util.function.Predicate<T> |
isIntArrayEmpty(java.util.function.Function<? super T,int[]> function)
Given a
Function that returns an array of int, this method builds a Predicate that
determines whether the returned array is empty. |
static <T> java.util.function.Predicate<T> |
isIntArrayNotEmpty(java.util.function.Function<? super T,int[]> function)
Given a
Function that returns an array of ints, this method builds a Predicate that
determines whether the returned array is not empty. |
static java.util.function.IntPredicate |
isIntCollEmpty(java.util.function.IntFunction<? extends java.util.Collection<?>> function)
Given an
IntFunction that returns a Collection of elements of an arbitrary type, this
method builds an IntPredicate that determines whether the returned Collection is empty. |
static java.util.function.IntPredicate |
isIntCollNotEmpty(java.util.function.IntFunction<? extends java.util.Collection<?>> function)
Given an
IntFunction that returns a Collection of elements of an arbitrary type, this
method builds an IntPredicate that determines whether the returned Collection is
not empty. |
static java.util.function.IntPredicate |
isIntEqual(int value)
This method builds an
IntPredicate whose parameter is to be compared for equality to the passed
int constant value. |
static java.util.function.IntPredicate |
isIntEqual(java.util.function.IntUnaryOperator operator,
int value)
Given an
IntUnaryOperator this method builds an IntPredicate that determines if the
value returned by that operator is equal to the passed constant int value. |
static java.util.function.IntPredicate |
isIntNotEqual(int value)
This method builds an
IntPredicate whose parameter is to be compared for inequality to the passed
int constant value. |
static java.util.function.IntPredicate |
isIntNotEqual(java.util.function.IntUnaryOperator operator,
int value)
Given an
IntUnaryOperator this method builds an IntPredicate that determines if the
value returned by that operator is not equal to the passed constant int value. |
static <T> java.util.function.Predicate<T> |
mapToIntAndFilter(java.util.function.ToIntFunction<? super T> function,
java.util.function.IntPredicate predicate)
Given a
ToIntFunction taking a value of type <T>, and an IntPredicate, this
method builds a Predicate that takes an element of type <T>, and applies the return value of
the ToIntFunction to the given predicate. |
static <T> java.util.function.Predicate<T> |
objToIntContains(int[] ints,
java.util.function.ToIntFunction<? super T> function)
Given an
int array, and a ToIntFunction that takes an element of type <T>,
this method builds a Predicate that determines if the given array contains the value returned by the
ToIntFunction. |
static <T> java.util.function.Predicate<T> |
objToIntsAllMatch(java.util.function.Function<T,? extends int[]> function,
java.util.function.IntPredicate predicate)
Given a
Function that takes an element of type <T> and returns an array of ints, and an
IntPredicate, this method builds a Predicate that determines whether all ints in the
returned array match the IntPredicate. |
static <T> java.util.function.Predicate<T> |
objToIntsAnyMatch(java.util.function.Function<T,? extends int[]> function,
java.util.function.IntPredicate predicate)
Given a
Function that takes an element of type <T> and returns an array of ints, and an
IntPredicate, this method builds a Predicate that determines whether any of the ints in
the returned array match the IntPredicate. |
static <T> java.util.function.Predicate<T> |
objToIntsNoneMatch(java.util.function.Function<T,? extends int[]> function,
java.util.function.IntPredicate predicate)
Given a
Function that takes an element of type <T> and returns an array of ints, and an
IntPredicate, this method builds a Predicate that determines whether none of the ints
in the returned array match the IntPredicate. |
static <T> java.util.function.Predicate<T> |
toIntGt(java.util.function.ToIntFunction<? super T> function,
int compareTo)
Given a
ToIntFunction that takes an element of type <T>, this method builds a
Predicate that compares the return value of that function, and determines whether it is greater than
a passed constant int value. |
static <T> java.util.function.Predicate<T> |
toIntGte(java.util.function.ToIntFunction<? super T> function,
int compareTo)
Given a
ToIntFunction that takes an element of type <T>, this method builds a
Predicate that compares the return value of that function, and determines whether it is greater than
or equal to a passed constant int value. |
static <T> java.util.function.Predicate<T> |
toIntLt(java.util.function.ToIntFunction<? super T> function,
int compareTo)
Given a
ToIntFunction that takes an element of type <T>, this method builds a
Predicate that compares the return value of that function, and determines whether it is less than a
passed constant int value. |
static <T> java.util.function.Predicate<T> |
toIntLte(java.util.function.ToIntFunction<? super T> function,
int compareTo)
Given a
ToIntFunction that takes an element of type <T>, this method builds a
Predicate that compares the return value of that function, and determines whether it is less than or
equal to a passed constant int value. |
public static java.util.function.IntPredicate intPredicate(java.util.function.IntPredicate predicate)
int or
Integer, and returns a boolean or Boolean, to an
IntPredicate. This could be useful in a situation where methods of the
IntPredicate functional interface are to be called on a method reference. For example:
private int[] getIntsInRange(int[] ints) {
return Arrays.stream(ints)
.filter(IntPredicateUtils.intPredicate(this::isGreaterThanOrEqualToMin)
.and(this::isLessThanOrEqualToMax))
.toArray();
}
private boolean isGreaterThanOrEqualToMin(int target) {
...
}
private boolean isLessThanOrEqualToMax(int target) {
...
}
The IntPredicate.and(...) method can only be called on the method reference because of the cast.
Note that the second predicate does not need to be cast, because IntPredicate.and(...) already
takes an IntPredicate just like this method, and so is already doing a cast.predicate - A method reference to be cast to an IntPredicate.public static <U> java.util.function.IntPredicate intPredicate(java.util.function.BiPredicate<java.lang.Integer,? super U> biPredicate,
U value)
IntPredicate from a passed BiPredicate<Integer, U>, which can be very
useful in the common situation where you are streaming through a collection of elements, and have an integer
predicate method to call that takes two parameters - the first one being the int element on which
you are streaming, and the second being some constant value that will be passed to all invocations. This would
typically be called from within a chain of method calls based on a IntStream. In the following
example, assume the Stock objects passed to the getHighestPriceOfStockBelowLimit(...)
method are to be filtered based on whether their price is less than a limit for the passed Client.
Also, assume that the monetary values are being stored as integral values in cents:
private int[] getHighestPriceOfStockBelowLimit(Collection<Stock> stocks, Client client) {
return stocks.stream()
.mapToInt(Stock::getPrice)
.filter(IntPredicateUtils.intPredicate(this::isPriceBelowLimit, client))
.max()
.orElse(-1);
}
private boolean isPriceBelowLimit(int price, Client client) {
...
}
Or, with static imports:
return stocks.stream()
.mapToInt(Stock::getPrice)
.filter(intPredicate(this::isPriceBelowLimit, client))
.max()
.orElse(-1);
U - The type of the constant value to be passed as the second parameter to each invocation of
biPredicate.biPredicate - A method reference (a BiPredicate) which takes two parameters - the first of type
Integer, and the second of type <U>. The method reference will be converted by this
method to an IntPredicate. Behind the scenes, this BiPredicate will be called, passing the
constant value to each invocation as the second parameter.value - A constant value, in that it will be passed to every invocation of the passed biPredicate as
the second parameter to it, and will have the same value for each of them.public static <U> java.util.function.IntPredicate inverseIntPredicate(java.util.function.BiPredicate<? super U,java.lang.Integer> biPredicate,
U value)
IntPredicate from a passed BiPredicate<Integer, U>, which can be very
useful in the common situation where you are streaming through a collection of elements, and have an integer
predicate method to call that takes two parameters. In the BiPredicate passed to this method, the
parameters are basically the same as in the call to intPredicate(BiPredicate, Object), but in the
inverse order. Here, the first parameter is a constant value that will be passed to all invocations of the
method, and the second parameter is the target int element on which you are streaming. This would
typically be called from within a chain of method calls based on an IntStream. In the following
example, assume the Stock objects passed to the getHighestPriceOfStockBelowLimit(...)
method are to be filtered based on whether their price is less than a limit for the passed Client.
Also, assume that the monetary values are being stored as integral values in cents:
private int[] getHighestPriceOfStockBelowLimit(Collection<Stock> stocks, Client client) {
return stocks.stream()
.mapToInt(Stock::getPrice)
.filter(IntPredicateUtils.inverseIntPredicate(this::isPriceBelowLimit, client))
.max()
.orElse(-1);
}
private boolean isPriceBelowLimit(Client client, int price) {
...
}
Or, with static imports:
return stocks.stream()
.mapToInt(Stock::getPrice)
.filter(inverseIntPredicate(this::isPriceBelowLimit, client))
.max()
.orElse(-1);
U - The type of the constant value to be passed as the first parameter to each invocation of
biPredicate.biPredicate - A method reference (a BiPredicate) which takes two parameters - the first of type
<U>, and the second of type Integer. The method reference will be converted by this
method to an IntPredicate. Behind the scenes, this BiPredicate will be called, passing the
constant value to each invocation as the first parameter.value - A constant value, in that it will be passed to every invocation of the passed biPredicate as
the first parameter to it, and will have the same value for each of them.public static java.util.function.IntPredicate intConstant(boolean b)
boolean value. The target element of type
int that is passed to the predicate is ignored, and the constant value is simply returned. This
comes in handy when combining one predicate with another using Predicate.and(...) or
Predicate.or(...). Consider the following example, assuming that the monetary values are being
stored as integral values in cents:
private int[] getHighestPriceOfStockBelowLimit(Collection<Stock> stocks, Client client) {
boolean hasLimit = client.getLimit() > 0;
return stocks.stream()
.mapToInt(Stock::getPrice)
.filter(IntPredicateUtils.intNot(IntPredicateUtils.intConstant(hasLimit))
.or(IntPredicateUtils.intPredicate(this::isPriceBelowLimit, client))
.max()
.orElse(-1.0D);
}
private boolean isPriceBelowLimit(int price, Client client) {
...
}
Or, with static imports:
return stocks.stream()
.mapToInt(Stock::getPrice)
.filter(intNot(intConstant(hasLimit))
.or(intPredicate(this::isPriceBelowLimit, client))
.max()
.orElse(-1.0D);
b - A constant boolean value that will be the result of every invocation of the returned IntPredicate.public static java.util.function.IntPredicate intNot(java.util.function.IntPredicate predicate)
IntPredicate that simply negates the passed IntPredicate. A predicate can
always be negated via predicate.negate(), however using this method may improve readability.predicate - An IntPredicate whose result is to be negated.public static java.util.function.IntPredicate isIntEqual(int value)
IntPredicate whose parameter is to be compared for equality to the passed
int constant value.value - A constant value to be compared to the parameter of the IntPredicate built by this method.public static java.util.function.IntPredicate isIntEqual(java.util.function.IntUnaryOperator operator,
int value)
IntUnaryOperator this method builds an IntPredicate that determines if the
value returned by that operator is equal to the passed constant int value. For example:
int[] ints = IntStream.range(1, 10).toArray();
int[] evens = Arrays.stream(ints)
.filter(IntPredicateUtils.isIntEqual(IntMapperUtils.intModulo(2), 0))
.toArray();
Or, with static imports:
int[] evens = Arrays.stream(ints)
.filter(isIntEqual(intModulo(2), 0))
.toArray();
operator - An IntUnaryOperator whose return value is to be compared with a passed constant int value
for equality.value - A value to be compared to the result of the passed operator for equality.public static java.util.function.IntPredicate isIntNotEqual(int value)
IntPredicate whose parameter is to be compared for inequality to the passed
int constant value.value - A constant value to be compared to the parameter of the IntPredicate built by this method.public static java.util.function.IntPredicate isIntNotEqual(java.util.function.IntUnaryOperator operator,
int value)
IntUnaryOperator this method builds an IntPredicate that determines if the
value returned by that operator is not equal to the passed constant int value. For example:
int[] ints = IntStream.range(1, 10).toArray();
int[] odds = Arrays.stream(ints)
.filter(IntPredicateUtils.isIntNotEqual(IntMapperUtils.dblModulo(2), 0))
.toArray();
Or, with static imports:
int[] odds = Arrays.stream(ints)
.filter(isIntNotEqual(intModulo(2), 0))
.toArray();
operator - An IntUnaryOperator whose return value is to be compared with a passed constant int value for
inequality.value - A value to be compared to the result of the passed operator for inequality.public static <R> java.util.function.IntPredicate intToObjContains(java.util.Collection<? extends R> collection,
java.util.function.IntFunction<? extends R> function)
Collection whose elements are of type <R>, and an IntFunction that
returns a value of type <R>, this method builds an IntPredicate that determines if the given
collection contains the value returned by the int function. More formally, the IntPredicate built by
this method returns true if and only if the passed collection contains at least one element e such
that (o == null ? e == null : o.equals(e)), o being the value returned from the passed int function.R - The type of elements in the passed Collection. Also, the type of the value returned by the
passed IntFunction.collection - A Collection of elements of type <R>, to be checked for whether it contains a value
returned from a passed IntFunction.function - An IntFunction returning a value of type <R> to be checked for whether it is contained in
a passed Collection.public static <R> java.util.function.IntPredicate inverseIntToObjContains(java.util.function.IntFunction<? extends java.util.Collection<R>> function,
R value)
IntFunction that returns a Collection<R>, this method builds an
IntPredicate that determines if the collection returned by that int function contains the passed
value of type <R>. More formally, the IntPredicate built by this method returns
true if and only if the returned collection contains at least one element e such that
(o == null ? e == null : o.equals(e)), o being the passed constant value of type <R>.
This method is similar to intToObjContains(Collection, IntFunction), but instead of a built predicate
checking whether a passed collection contains a value returned by a function, in this method it checks whether
a collection returned by an int function contains a passed value.
R - The type of elements for collections returned by a passed IntFunction. Also, the type of the
passed value.function - An IntFunction that returns a Collection of elements of type <R>.value - A value of type <R> to be checked for whether a Collection returned by the above
IntFunction contains it.public static <T> java.util.function.Predicate<T> objToIntContains(int[] ints,
java.util.function.ToIntFunction<? super T> function)
int array, and a ToIntFunction that takes an element of type <T>,
this method builds a Predicate that determines if the given array contains the value returned by the
ToIntFunction.T - The type of the element taken by the Predicate built by this method.ints - An array of ints, to be checked for whether it contains a value returned from a passed
ToIntFunction.function - A ToIntFunction taking a value of type <T>, whose return value is to be checked for
whether it is contained in a passed array.public static <T> java.util.function.Predicate<T> inverseObjToIntContains(java.util.function.Function<T,int[]> function,
int value)
Function that takes an element of type <T> and returns an array of ints, this method
builds a Predicate that determines if the array returned by that function contains the passed
constant int value.
This method is similar to objToIntContains(int[], ToIntFunction), but instead of a built predicate
checking whether a passed array contains a value returned by a function, in this method it checks
whether an array returned by a function contains a passed int value.
T - The type of the element taken by the Predicate built by this method.function - A Function that returns an array of ints.value - A constant int value to be checked for whether an array of ints returned by the above Function
contains it.public static java.util.function.IntPredicate intIsNull(java.util.function.IntFunction<?> function)
IntFunction that returns a value of an arbitrary type, this method builds an
IntPredicate that determines whether that returned value is null.function - An IntFunction that returns a value of an arbitrary type.public static java.util.function.IntPredicate intIsNotNull(java.util.function.IntFunction<?> function)
IntFunction that returns a value of an arbitrary type, this method builds an
IntPredicate that determines whether that returned value is not null.function - An IntFunction that returns a value of an arbitrary type.public static java.util.function.IntPredicate intGt(int compareTo)
IntPredicate that determines whether a value is greater than a passed constant int value.compareTo - A constant int value to be compared to the target value of an IntPredicate built by this method.public static <R extends java.lang.Comparable<R>> java.util.function.IntPredicate intGt(java.util.function.IntFunction<? extends R> function,
R compareTo)
IntFunction that returns a value of type <R>, and a constant value of type <R>,
this method builds an IntPredicate that applies that function to its target value, and determines
whether the returned Comparable value is greater than a passed constant value of type <R>
(also a Comparable).R - The return type of the passed IntFunction parameter. Also, the type of the passed constant
value.function - An IntFunction whose return value of type <R> is to be compared to the passed Comparable
value of type <R>.compareTo - A constant value of type <R> to be compared to the return value of an IntFunction.public static <T> java.util.function.Predicate<T> toIntGt(java.util.function.ToIntFunction<? super T> function,
int compareTo)
ToIntFunction that takes an element of type <T>, this method builds a
Predicate that compares the return value of that function, and determines whether it is greater than
a passed constant int value.T - The type of the element taken by the Predicate built by this method.function - A ToIntFunction that takes an element of type <T>, whose return value is to be compared
by the Predicate built by this method, with a passed constant int value to see whether it is
greater.compareTo - A constant int value to be compared with a value returned by a passed ToIntFunction.public static java.util.function.IntPredicate intGte(int compareTo)
IntPredicate that determines whether a value is greater than or equal to a passed constant
int value.compareTo - A constant int value to be compared to the target value of an IntPredicate built by this method.public static <R extends java.lang.Comparable<R>> java.util.function.IntPredicate intGte(java.util.function.IntFunction<? extends R> function,
R compareTo)
IntFunction that returns a value of type <R>, and a constant value of type <R>,
this method builds an IntPredicate that applies that function to its target value, and determines
whether the returned Comparable value is greater than or equal to a passed constant value of type
<R> (also a Comparable).R - The return type of the passed IntFunction parameter. Also, the type of the passed constant
value.function - An IntFunction whose return value of type <R> is to be compared to the passed Comparable
value of type <R>.compareTo - A constant value of type <R> to be compared to the return value of an IntFunction.public static <T> java.util.function.Predicate<T> toIntGte(java.util.function.ToIntFunction<? super T> function,
int compareTo)
ToIntFunction that takes an element of type <T>, this method builds a
Predicate that compares the return value of that function, and determines whether it is greater than
or equal to a passed constant int value.T - The type of the element taken by the Predicate built by this method.function - A ToIntFunction that takes an element of type <T>, whose return value is to be compared
by the Predicate built by this method, with a passed constant int value to see whether it is
greater than or equal to it.compareTo - A constant int value to be compared with a value returned by a passed ToIntFunction.public static java.util.function.IntPredicate intLt(int compareTo)
IntPredicate that determines whether a value is less than a passed constant int value.compareTo - A constant int value to be compared to the target value of an IntPredicate built by this method.public static <R extends java.lang.Comparable<R>> java.util.function.IntPredicate intLt(java.util.function.IntFunction<? extends R> function,
R compareTo)
IntFunction that returns a value of type <R>, and a constant value of type <R>,
this method builds an IntPredicate that applies that function to its target value, and determines
whether the returned Comparable value is less than a passed constant value of type <R> (also a
Comparable).R - The return type of the passed IntFunction parameter. Also, the type of the passed constant
value.function - An IntFunction whose return value of type <R> is to be compared to the passed Comparable
value of type <R>.compareTo - A constant value of type <R> to be compared to the return value of an IntFunction.public static <T> java.util.function.Predicate<T> toIntLt(java.util.function.ToIntFunction<? super T> function,
int compareTo)
ToIntFunction that takes an element of type <T>, this method builds a
Predicate that compares the return value of that function, and determines whether it is less than a
passed constant int value.T - The type of the element taken by the Predicate built by this method.function - A ToIntFunction that takes an element of type <T>, whose return value is to be compared
by the Predicate built by this method, with a passed constant int value to see whether it is
less than it.compareTo - A constant int value to be compared with a value returned by a passed ToIntFunction.public static java.util.function.IntPredicate intLte(int compareTo)
IntPredicate that determines whether a value is less than or equal to a passed constant
int value.compareTo - A constant int value to be compared to the target value of an IntPredicate built by this method.public static <R extends java.lang.Comparable<R>> java.util.function.IntPredicate intLte(java.util.function.IntFunction<? extends R> function,
R compareTo)
IntFunction that returns a value of type <R>, and a constant value of type <R>,
this method builds an IntPredicate that applies that function to its target value, and determines
whether the returned Comparable value is less than or equal to a passed constant value of type
<R> (also a Comparable).R - The return type of the passed IntFunction parameter. Also, the type of the passed constant
value.function - An IntFunction whose return value of type <R> is to be compared to the passed Comparable
value of type <R>.compareTo - A constant value of type <R> to be compared to the return value of an IntFunction.public static <T> java.util.function.Predicate<T> toIntLte(java.util.function.ToIntFunction<? super T> function,
int compareTo)
ToIntFunction that takes an element of type <T>, this method builds a
Predicate that compares the return value of that function, and determines whether it is less than or
equal to a passed constant int value.T - The type of the element taken by the Predicate built by this method.function - A ToIntFunction that takes an element of type <T>, whose return value is to be compared
by the Predicate built by this method, with a passed constant int value to see whether it is
less than or equal to it.compareTo - A constant int value to be compared with a value returned by a passed ToIntFunction.public static java.util.function.IntPredicate isIntCollEmpty(java.util.function.IntFunction<? extends java.util.Collection<?>> function)
IntFunction that returns a Collection of elements of an arbitrary type, this
method builds an IntPredicate that determines whether the returned Collection is empty.function - An IntFunction that returns a Collection of elements of an arbitrary type.public static java.util.function.IntPredicate isIntCollNotEmpty(java.util.function.IntFunction<? extends java.util.Collection<?>> function)
IntFunction that returns a Collection of elements of an arbitrary type, this
method builds an IntPredicate that determines whether the returned Collection is
not empty.function - An IntFunction that returns a Collection of elements of an arbitrary type.public static <T> java.util.function.Predicate<T> isIntArrayEmpty(java.util.function.Function<? super T,int[]> function)
Function that returns an array of int, this method builds a Predicate that
determines whether the returned array is empty.T - The type of the element taken by the Predicate built by this method.function - A Function that returns an array of ints.public static <T> java.util.function.Predicate<T> isIntArrayNotEmpty(java.util.function.Function<? super T,int[]> function)
Function that returns an array of ints, this method builds a Predicate that
determines whether the returned array is not empty.T - The type of the element taken by the Predicate built by this method.function - A Function that returns an array of ints.public static <T> java.util.function.Predicate<T> objToIntsAllMatch(java.util.function.Function<T,? extends int[]> function,
java.util.function.IntPredicate predicate)
Function that takes an element of type <T> and returns an array of ints, and an
IntPredicate, this method builds a Predicate that determines whether all ints in the
returned array match the IntPredicate.T - The type of the element taken by the Predicate built by this method.function - A Function that takes en element of type <T> and returns an array of ints.predicate - An IntPredicate that will be applied to all elements of an array of ints returned by the passed
Function.public static <R> java.util.function.IntPredicate intToObjectsAllMatch(java.util.function.IntFunction<? extends java.util.Collection<R>> function,
java.util.function.Predicate<R> predicate)
IntFunction that returns a Collection of type <R>, and a
Predicate, this method builds an IntPredicate that determines whether all elements in
the returned Collection match the Predicate.R - The type of the elements of a Collection returned by a passed IntFunction. Also the type of
elements taken by a passed Predicate that will be applied to all elements of that Collection.function - An IntFunction that returns a Collection of elements of type <R>.predicate - A Predicate that will be applied to all elements of a Collection returned by the passed
IntFunction.public static <T> java.util.function.Predicate<T> objToIntsAnyMatch(java.util.function.Function<T,? extends int[]> function,
java.util.function.IntPredicate predicate)
Function that takes an element of type <T> and returns an array of ints, and an
IntPredicate, this method builds a Predicate that determines whether any of the ints in
the returned array match the IntPredicate.T - The type of the element taken by the Predicate built by this method.function - A Function that takes en element of type <T> and returns an array of ints.predicate - An IntPredicate that will be applied to all elements of an array of ints returned by the passed
Function to determine whether any match.public static <R> java.util.function.IntPredicate intToObjectsAnyMatch(java.util.function.IntFunction<? extends java.util.Collection<R>> function,
java.util.function.Predicate<R> predicate)
IntFunction that returns a Collection of type <R>, and a
Predicate, this method builds an IntPredicate that determines whether any of the
elements in the returned Collection match the Predicate.R - The type of the elements of a Collection returned by a passed IntFunction. Also the type of
elements taken by a passed Predicate that will be applied to all elements of that Collection.function - An IntFunction that returns a Collection of elements of type <R>.predicate - A Predicate that will be applied to all elements of a Collection returned by the passed
IntFunction to determine whether any match.public static <T> java.util.function.Predicate<T> objToIntsNoneMatch(java.util.function.Function<T,? extends int[]> function,
java.util.function.IntPredicate predicate)
Function that takes an element of type <T> and returns an array of ints, and an
IntPredicate, this method builds a Predicate that determines whether none of the ints
in the returned array match the IntPredicate.T - The type of the element taken by the Predicate built by this method.function - A Function that takes en element of type <T> and returns an array of ints.predicate - An IntPredicate that will be applied to all elements of an array of ints returned by the passed
Function to determine whether none match.public static <R> java.util.function.IntPredicate intToObjectsNoneMatch(java.util.function.IntFunction<? extends java.util.Collection<R>> function,
java.util.function.Predicate<R> predicate)
IntFunction that returns a Collection of type <R>, and a
Predicate, this method builds an IntPredicate that determines whether none of the
elements in the returned Collection match the Predicate.R - The type of the elements of a Collection returned by a passed IntFunction. Also the type of
elements taken by a passed Predicate that will be applied to all elements of that Collection.function - An IntFunction that returns a Collection of elements of type <R>.predicate - A Predicate that will be applied to all elements of a Collection returned by the passed
IntFunction to determine whether none match.public static <T> java.util.function.Predicate<T> mapToIntAndFilter(java.util.function.ToIntFunction<? super T> function,
java.util.function.IntPredicate predicate)
ToIntFunction taking a value of type <T>, and an IntPredicate, this
method builds a Predicate that takes an element of type <T>, and applies the return value of
the ToIntFunction to the given predicate. It is a way of adapting an IntPredicate to a
Stream of a different type. For example, the
IntStreamUtils.indexOfFirstInt(int[], IntPredicate) method uses this predicate in its implementation
(Note that the intPairWithIndex() below refers to IntMapperUtils.intPairWithIndex()):
public static int indexOfFirstInt(int[] ints, IntPredicate intPredicate) {
return defaultIntStream(ints)
.mapToObj(intPairWithIndex())
.filter(mapToIntAndFilter(IntIndexPair::getIntValue, intPredicate))
.mapToInt(IntIndexPair::getIndex)
.findFirst()
.orElse(-1);
}
The map-and-filter predicate is necessary in this case because we have a predicate that operates on the original
int type of the stream, but a mapping operation has changed the type to an
IntIndexPair. The IntIndexPair::getIntValue method reference, passed as the
ToIntFunction argument to this method, retrieves the original int value before the
IntPredicate evaluates it.
As a side note, the pairing of an object with another can be very useful in streaming operations. In this case, we need to have both the int value and its index available at the same point in the stream, so we temporarily pair the two together, before mapping to just the index.
T - The type of the element taken by the Predicate built by this method.function - A ToIntFunction to transform an element of type <T> to an int before it is passed to an
IntPredicate.predicate - An IntPredicate whose value will be retrieved from a given transformer function.public static <T> java.util.function.IntPredicate intMapAndFilter(java.util.function.IntFunction<? extends T> function,
java.util.function.Predicate<? super T> predicate)
IntFunction that returns a value of type <T>, and a Predicate, this
method builds an IntPredicate that applies the return value of the IntFunction to the
given predicate. It is a way of adapting a int value to a Predicate. This method is the inverse of
mapToIntAndFilter(ToIntFunction, IntPredicate). In that method, we map from a value of type <T> to
an int, and then apply an IntPredicate. In this method we map from an int
to a value of type <T>, and then apply a Predicate<T>.T - The type of the element taken by the Predicate built by this method.function - An IntFunction to transform an int value to an element of type <T> before it is passed to
a Predicate.predicate - A Predicate whose value will be retrieved from a given IntFunction.