public final class LongPredicateUtils
extends java.lang.Object
long types.| Modifier and Type | Method and Description |
|---|---|
static <U> java.util.function.LongPredicate |
inverseLongPredicate(java.util.function.BiPredicate<? super U,java.lang.Long> biPredicate,
U value)
Builds a
LongPredicate from a passed BiPredicate<Long, U>, which can be very
useful in the common situation where you are streaming through a collection of elements, and have a long
predicate method to call that takes two parameters. |
static <R> java.util.function.LongPredicate |
inverseLongToObjContains(java.util.function.LongFunction<? extends java.util.Collection<R>> function,
R value)
Given a
LongFunction that returns a Collection<R>, this method builds a
LongPredicate that determines if the collection returned by that long function contains the passed
value of type <R>. |
static <T> java.util.function.Predicate<T> |
inverseObjToLongContains(java.util.function.Function<T,? extends long[]> function,
long value)
Given a
Function that takes an element of type <T> and returns an array of longs, this method
builds a Predicate that determines if the array returned by that function contains the passed
constant long value. |
static <T> java.util.function.Predicate<T> |
isLongArrayEmpty(java.util.function.Function<? super T,long[]> function)
Given a
Function that returns an array of longs, this method builds a Predicate that
determines whether the returned array is empty. |
static <T> java.util.function.Predicate<T> |
isLongArrayNotEmpty(java.util.function.Function<? super T,long[]> function)
Given a
Function that returns an array of longs, this method builds a Predicate that
determines whether the returned array is not empty. |
static java.util.function.LongPredicate |
isLongCollEmpty(java.util.function.LongFunction<? extends java.util.Collection<?>> function)
Given a
LongFunction that returns a Collection of elements of an arbitrary type, this
method builds a LongPredicate that determines whether the returned Collection is empty. |
static java.util.function.LongPredicate |
isLongCollNotEmpty(java.util.function.LongFunction<? extends java.util.Collection<?>> function)
Given a
LongFunction that returns a Collection of elements of an arbitrary type, this
method builds a LongPredicate that determines whether the returned Collection is
not empty. |
static java.util.function.LongPredicate |
isLongEqual(long value)
This method builds a
LongPredicate whose parameter is to be compared for equality to the passed
long constant value. |
static java.util.function.LongPredicate |
isLongEqual(java.util.function.LongUnaryOperator operator,
long value)
Given a
LongUnaryOperator this method builds a LongPredicate that determines if the
value returned by that operator is equal to the passed constant long value. |
static java.util.function.LongPredicate |
isLongNotEqual(long value)
This method builds a
LongPredicate whose parameter is to be compared for inequality to the passed
long constant value. |
static java.util.function.LongPredicate |
isLongNotEqual(java.util.function.LongUnaryOperator operator,
long value)
Given a
LongUnaryOperator this method builds a LongPredicate that determines if the
value returned by that operator is not equal to the passed constant long value. |
static java.util.function.LongPredicate |
longConstant(boolean b)
Builds a long predicate based on a passed constant
boolean value. |
static java.util.function.LongPredicate |
longGt(long compareTo)
Builds a
LongPredicate that determines whether a value is greater than a passed constant long value. |
static <R extends java.lang.Comparable<R>> |
longGt(java.util.function.LongFunction<? extends R> function,
R compareTo)
Given a
LongFunction that returns a value of type <R>, and a constant value of type <R>,
this method builds a LongPredicate 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.LongPredicate |
longGte(long compareTo)
Builds a
LongPredicate that determines whether a value is greater than or equal to a passed constant
long value. |
static <R extends java.lang.Comparable<R>> |
longGte(java.util.function.LongFunction<? extends R> function,
R compareTo)
Given a
LongFunction that returns a value of type <R>, and a constant value of type <R>,
this method builds a LongPredicate 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.LongPredicate |
longIsNotNull(java.util.function.LongFunction<?> function)
Given a
LongFunction that returns a value of an arbitrary type, this method builds a
LongPredicate that determines whether that returned value is not null. |
static java.util.function.LongPredicate |
longIsNull(java.util.function.LongFunction<?> function)
Given a
LongFunction that returns a value of an arbitrary type, this method builds a
LongPredicate that determines whether that returned value is null. |
static java.util.function.LongPredicate |
longLt(long compareTo)
Builds a
LongPredicate that determines whether a value is less than a passed constant long value. |
static <R extends java.lang.Comparable<R>> |
longLt(java.util.function.LongFunction<? extends R> function,
R compareTo)
Given a
LongFunction that returns a value of type <R>, and a constant value of type <R>,
this method builds a LongPredicate 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.LongPredicate |
longLte(long compareTo)
Builds a
LongPredicate that determines whether a value is less than or equal to a passed constant
long value. |
static <R extends java.lang.Comparable<R>> |
longLte(java.util.function.LongFunction<? extends R> function,
R compareTo)
Given a
LongFunction that returns a value of type <R>, and a constant value of type <R>,
this method builds a LongPredicate 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.LongPredicate |
longMapAndFilter(java.util.function.LongFunction<? extends T> function,
java.util.function.Predicate<? super T> predicate)
Given a
LongFunction that returns a value of type <T>, and a Predicate, this
method builds a LongPredicate that applies the return value of the LongFunction to
the given predicate. |
static java.util.function.LongPredicate |
longNot(java.util.function.LongPredicate predicate)
A
LongPredicate that simply negates the passed LongPredicate. |
static <U> java.util.function.LongPredicate |
longPredicate(java.util.function.BiPredicate<java.lang.Long,? super U> biPredicate,
U value)
Builds a
LongPredicate from a passed BiPredicate<Long, U>, which can be very
useful in the common situation where you are streaming through a collection of elements, and have a long
predicate method to call that takes two parameters - the first one being the long element on which
you are streaming, and the second being some constant value that will be passed to all invocations. |
static java.util.function.LongPredicate |
longPredicate(java.util.function.LongPredicate predicate)
Simply casts a method reference, which takes a single parameter of type
long or
Long, and returns a boolean or Boolean, to a
LongPredicate. |
static <R> java.util.function.LongPredicate |
longToObjContains(java.util.Collection<? extends R> collection,
java.util.function.LongFunction<? extends R> function)
Given a
Collection whose elements are of type <R>, and a LongFunction that
returns a value of type <R>, this method builds a LongPredicate that determines if the given
collection contains the value returned by the long function. |
static <R> java.util.function.LongPredicate |
longToObjectsAllMatch(java.util.function.LongFunction<? extends java.util.Collection<R>> function,
java.util.function.Predicate<R> predicate)
Given a
LongFunction that returns a Collection of type <R>, and a
Predicate, this method builds a LongPredicate that determines whether all elements in
the returned Collection match the Predicate. |
static <R> java.util.function.LongPredicate |
longToObjectsAnyMatch(java.util.function.LongFunction<? extends java.util.Collection<R>> function,
java.util.function.Predicate<R> predicate)
Given a
LongFunction that returns a Collection of type <R>, and a
Predicate, this method builds a LongPredicate that determines whether any of the
elements in the returned Collection match the Predicate. |
static <R> java.util.function.LongPredicate |
longToObjectsNoneMatch(java.util.function.LongFunction<? extends java.util.Collection<R>> function,
java.util.function.Predicate<R> predicate)
Given a
LongFunction that returns a Collection of type <R>, and a
Predicate, this method builds a LongPredicate that determines whether none of the
elements in the returned Collection match the Predicate. |
static <T> java.util.function.Predicate<T> |
mapToLongAndFilter(java.util.function.ToLongFunction<? super T> function,
java.util.function.LongPredicate predicate)
Given a
ToLongFunction taking a value of type <T>, and a LongPredicate, this
method builds a Predicate that takes an element of type <T>, and applies the return value of
the ToLongFunction to the given predicate. |
static <T> java.util.function.Predicate<T> |
objToLongContains(long[] longs,
java.util.function.ToLongFunction<? super T> function)
Given a
long array, and a ToLongFunction that takes an element of type <T>, this
method builds a Predicate that determines if the given array contains the value returned by the
ToLongFunction. |
static <T> java.util.function.Predicate<T> |
objToLongsAllMatch(java.util.function.Function<T,? extends long[]> function,
java.util.function.LongPredicate predicate)
Given a
Function that takes an element of type <T> and returns an array of longs, and a
LongPredicate, this method builds a Predicate that determines whether all longs in the
returned array match the LongPredicate. |
static <T> java.util.function.Predicate<T> |
objToLongsAnyMatch(java.util.function.Function<T,? extends long[]> function,
java.util.function.LongPredicate predicate)
Given a
Function that takes an element of type <T> and returns an array of longs, and a
LongPredicate, this method builds a Predicate that determines whether any of the longs
in the returned array match the LongPredicate. |
static <T> java.util.function.Predicate<T> |
objToLongsNoneMatch(java.util.function.Function<T,? extends long[]> function,
java.util.function.LongPredicate predicate)
Given a
Function that takes an element of type <T> and returns an array of longs, and a
LongPredicate, this method builds a Predicate that determines whether none of the
longs in the returned array match the LongPredicate. |
static <T> java.util.function.Predicate<T> |
toLongGt(java.util.function.ToLongFunction<? super T> function,
long compareTo)
Given a
ToLongFunction 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 long value. |
static <T> java.util.function.Predicate<T> |
toLongGte(java.util.function.ToLongFunction<? super T> function,
long compareTo)
Given a
ToLongFunction 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 long value. |
static <T> java.util.function.Predicate<T> |
toLongLt(java.util.function.ToLongFunction<? super T> function,
long compareTo)
Given a
ToLongFunction 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 long value. |
static <T> java.util.function.Predicate<T> |
toLongLte(java.util.function.ToLongFunction<? super T> function,
long compareTo)
Given a
ToLongFunction 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 long value. |
public static java.util.function.LongPredicate longPredicate(java.util.function.LongPredicate predicate)
long or
Long, and returns a boolean or Boolean, to a
LongPredicate. This could be useful in a situation where methods of the
LongPredicate functional interface are to be called on a method reference. For example:
private long[] getLongsInRange(long[] longs) {
return Arrays.stream(longs)
.filter(LongPredicateUtils.longPredicate(this::isGreaterThanOrEqualToMin)
.and(this::isLessThanOrEqualToMax))
.toArray();
}
private boolean isGreaterThanOrEqualToMin(long target) {
...
}
private boolean isLessThanOrEqualToMax(long target) {
...
}
The LongPredicate.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 LongPredicate.and(...) already
takes a LongPredicate just like this method, and so is already doing a cast.predicate - A method reference to be cast to a LongPredicate.public static <U> java.util.function.LongPredicate longPredicate(java.util.function.BiPredicate<java.lang.Long,? super U> biPredicate,
U value)
LongPredicate from a passed BiPredicate<Long, U>, which can be very
useful in the common situation where you are streaming through a collection of elements, and have a long
predicate method to call that takes two parameters - the first one being the long 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 LongStream. 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 long[] getHighestPriceOfStockBelowLimit(Collection<Stock> stocks, Client client) {
return stocks.stream()
.mapToLong(Stock::getPrice)
.filter(LongPredicateUtils.longPredicate(this::isPriceBelowLimit, client))
.max()
.orElse(-1L);
}
private boolean isPriceBelowLimit(long price, Client client) {
...
}
Or, with static imports:
return stocks.stream()
.mapToLong(Stock::getPrice)
.filter(longPredicate(this::isPriceBelowLimit, client))
.max()
.orElse(-1L);
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
Long, and the second of type <U>. The method reference will be converted by this
method to a LongPredicate. 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.LongPredicate inverseLongPredicate(java.util.function.BiPredicate<? super U,java.lang.Long> biPredicate,
U value)
LongPredicate from a passed BiPredicate<Long, U>, which can be very
useful in the common situation where you are streaming through a collection of elements, and have a long
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 longPredicate(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 long element on which you are streaming. This would
typically be called from within a chain of method calls based on a LongStream. 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 long[] getHighestPriceOfStockBelowLimit(Collection<Stock> stocks, Client client) {
return stocks.stream()
.mapToLong(Stock::getPrice)
.filter(LongPredicateUtils.inverseLongPredicate(this::isPriceBelowLimit, client))
.max()
.orElse(-1L);
}
private boolean isPriceBelowLimit(Client client, long price) {
...
}
Or, with static imports:
return stocks.stream()
.mapToLong(Stock::getPrice)
.filter(inverseLongPredicate(this::isPriceBelowLimit, client))
.max()
.orElse(-1L);
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 Long. The method reference will be converted by this
method to a LongPredicate. 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.LongPredicate longConstant(boolean b)
boolean value. The target element of type
long 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 long[] getHighestPriceOfStockBelowLimit(Collection<Stock> stocks, Client client) {
boolean hasLimit = client.getLimit() > 0L;
return stocks.stream()
.mapToLong(Stock::getPrice)
.filter(LongPredicateUtils.longNot(LongPredicateUtils.longConstant(hasLimit))
.or(LongPredicateUtils.longPredicate(this::isPriceBelowLimit, client))
.max()
.orElse(-1L);
}
private boolean isPriceBelowLimit(long price, Client client) {
...
}
Or, with static imports:
return stocks.stream()
.mapToLong(Stock::getPrice)
.filter(longNot(longConstant(hasLimit))
.or(longPredicate(this::isPriceBelowLimit, client))
.max()
.orElse(-1L);
b - A constant boolean value that will be the result of every invocation of the returned LongPredicate.public static java.util.function.LongPredicate longNot(java.util.function.LongPredicate predicate)
LongPredicate that simply negates the passed LongPredicate. A predicate can
always be negated via predicate.negate(), however using this method may improve readability.predicate - A LongPredicate whose result is to be negated.public static java.util.function.LongPredicate isLongEqual(long value)
LongPredicate whose parameter is to be compared for equality to the passed
long constant value.value - A constant value to be compared to the parameter of the LongPredicate built by this method.public static java.util.function.LongPredicate isLongEqual(java.util.function.LongUnaryOperator operator,
long value)
LongUnaryOperator this method builds a LongPredicate that determines if the
value returned by that operator is equal to the passed constant long value. For example:
long[] longs = LongStream.range(1L, 10L).toArray();
long[] evens = Arrays.stream(longs)
.filter(LongPredicateUtils.isLongEqual(LongMapperUtils.longModulo(2L), 0L))
.toArray();
Or, with static imports:
long[] evens = Arrays.stream(longs)
.filter(isLongEqual(longModulo(2L), 0L))
.toArray();
operator - A LongUnaryOperator whose return value is to be compared with a passed constant long value for
equality.value - A value to be compared to the result of the passed operator for equality.public static java.util.function.LongPredicate isLongNotEqual(long value)
LongPredicate whose parameter is to be compared for inequality to the passed
long constant value.value - A constant value to be compared to the parameter of the LongPredicate built by this method.public static java.util.function.LongPredicate isLongNotEqual(java.util.function.LongUnaryOperator operator,
long value)
LongUnaryOperator this method builds a LongPredicate that determines if the
value returned by that operator is not equal to the passed constant long value. For example:
long[] longs = LongStream.range(1L, 10L).toArray();
long[] odds = Arrays.stream(longs)
.filter(LongPredicateUtils.isLongNotEqual(LongMapperUtils.longModulo(2L), 0L))
.toArray();
Or, with static imports:
long[] odds = Arrays.stream(longs)
.filter(isLongNotEqual(longModulo(2L), 0L))
.toArray();
operator - A LongUnaryOperator whose return value is to be compared with a passed constant long value for
inequality.value - A value to be compared to the result of the passed operator for inequality.public static <R> java.util.function.LongPredicate longToObjContains(java.util.Collection<? extends R> collection,
java.util.function.LongFunction<? extends R> function)
Collection whose elements are of type <R>, and a LongFunction that
returns a value of type <R>, this method builds a LongPredicate that determines if the given
collection contains the value returned by the long function. More formally, the LongPredicate 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 long
function.R - The type of elements in the passed Collection. Also, the type of the value returned by the
passed LongFunction.collection - A Collection of elements of type <R>, to be checked for whether it contains a value
returned from a passed LongFunction.function - A LongFunction returning a value of type <R> to be checked for whether it is contained in
a passed Collection.public static <R> java.util.function.LongPredicate inverseLongToObjContains(java.util.function.LongFunction<? extends java.util.Collection<R>> function,
R value)
LongFunction that returns a Collection<R>, this method builds a
LongPredicate that determines if the collection returned by that long function contains the passed
value of type <R>. More formally, the LongPredicate 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 longToObjContains(Collection, LongFunction), 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 a long function contains a passed value.
R - The type of elements for collections returned by a passed LongFunction. Also, the type of the
passed value.function - A LongFunction 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
LongFunction contains it.public static <T> java.util.function.Predicate<T> objToLongContains(long[] longs,
java.util.function.ToLongFunction<? super T> function)
long array, and a ToLongFunction that takes an element of type <T>, this
method builds a Predicate that determines if the given array contains the value returned by the
ToLongFunction.T - The type of the element taken by the Predicate built by this method.longs - An array of longs, to be checked for whether it contains a value returned from a passed
ToLongFunction.function - A ToLongFunction 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> inverseObjToLongContains(java.util.function.Function<T,? extends long[]> function,
long value)
Function that takes an element of type <T> and returns an array of longs, this method
builds a Predicate that determines if the array returned by that function contains the passed
constant long value.
This method is similar to objToLongContains(long[], ToLongFunction), 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 long value.
T - The type of the element taken by the Predicate built by this method.function - A Function that returns an array of longs.value - A constant long value to be checked for whether an array of longs returned by the above Function
contains it.public static java.util.function.LongPredicate longIsNull(java.util.function.LongFunction<?> function)
LongFunction that returns a value of an arbitrary type, this method builds a
LongPredicate that determines whether that returned value is null.function - A LongFunction that returns a value of an arbitrary type.public static java.util.function.LongPredicate longIsNotNull(java.util.function.LongFunction<?> function)
LongFunction that returns a value of an arbitrary type, this method builds a
LongPredicate that determines whether that returned value is not null.function - A LongFunction that returns a value of an arbitrary type.public static java.util.function.LongPredicate longGt(long compareTo)
LongPredicate that determines whether a value is greater than a passed constant long value.compareTo - A constant long value to be compared to the target value of a LongPredicate built by this
method.public static <R extends java.lang.Comparable<R>> java.util.function.LongPredicate longGt(java.util.function.LongFunction<? extends R> function,
R compareTo)
LongFunction that returns a value of type <R>, and a constant value of type <R>,
this method builds a LongPredicate 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 LongFunction parameter. Also, the type of the passed constant
value.function - A LongFunction 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 a LongFunction.public static <T> java.util.function.Predicate<T> toLongGt(java.util.function.ToLongFunction<? super T> function,
long compareTo)
ToLongFunction 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 long value.T - The type of the element taken by the Predicate built by this method.function - A ToLongFunction 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 long value to see whether it is
greater.compareTo - A constant long value to be compared with a value returned by a passed ToLongFunction.public static java.util.function.LongPredicate longGte(long compareTo)
LongPredicate that determines whether a value is greater than or equal to a passed constant
long value.compareTo - A constant long value to be compared to the target value of a LongPredicate built by this
method.public static <R extends java.lang.Comparable<R>> java.util.function.LongPredicate longGte(java.util.function.LongFunction<? extends R> function,
R compareTo)
LongFunction that returns a value of type <R>, and a constant value of type <R>,
this method builds a LongPredicate 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 LongFunction parameter. Also, the type of the passed constant
value.function - A LongFunction 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 a LongFunction.public static <T> java.util.function.Predicate<T> toLongGte(java.util.function.ToLongFunction<? super T> function,
long compareTo)
ToLongFunction 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 long value.T - The type of the element taken by the Predicate built by this method.function - A ToLongFunction 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 long value to see whether it is
greater than or equal to it.compareTo - A constant long value to be compared with a value returned by a passed ToLongFunction.public static java.util.function.LongPredicate longLt(long compareTo)
LongPredicate that determines whether a value is less than a passed constant long value.compareTo - A constant long value to be compared to the target value of a LongPredicate built by this
method.public static <R extends java.lang.Comparable<R>> java.util.function.LongPredicate longLt(java.util.function.LongFunction<? extends R> function,
R compareTo)
LongFunction that returns a value of type <R>, and a constant value of type <R>,
this method builds a LongPredicate 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 LongFunction parameter. Also, the type of the passed constant
value.function - A LongFunction 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 a LongFunction.public static <T> java.util.function.Predicate<T> toLongLt(java.util.function.ToLongFunction<? super T> function,
long compareTo)
ToLongFunction 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 long value.T - The type of the element taken by the Predicate built by this method.function - A ToLongFunction 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 long value to see whether it is
less than it.compareTo - A constant long value to be compared with a value returned by a passed ToLongFunction.public static java.util.function.LongPredicate longLte(long compareTo)
LongPredicate that determines whether a value is less than or equal to a passed constant
long value.compareTo - A constant long value to be compared to the target value of a LongPredicate built by this
method.public static <R extends java.lang.Comparable<R>> java.util.function.LongPredicate longLte(java.util.function.LongFunction<? extends R> function,
R compareTo)
LongFunction that returns a value of type <R>, and a constant value of type <R>,
this method builds a LongPredicate 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 LongFunction parameter. Also, the type of the passed constant
value.function - A LongFunction 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 a LongFunction.public static <T> java.util.function.Predicate<T> toLongLte(java.util.function.ToLongFunction<? super T> function,
long compareTo)
ToLongFunction 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 long value.T - The type of the element taken by the Predicate built by this method.function - A ToLongFunction 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 long value to see whether it is
less than or equal to it.compareTo - A constant long value to be compared with a value returned by a passed ToLongFunction.public static java.util.function.LongPredicate isLongCollEmpty(java.util.function.LongFunction<? extends java.util.Collection<?>> function)
LongFunction that returns a Collection of elements of an arbitrary type, this
method builds a LongPredicate that determines whether the returned Collection is empty.function - A LongFunction that returns a Collection of elements of an arbitrary type.public static java.util.function.LongPredicate isLongCollNotEmpty(java.util.function.LongFunction<? extends java.util.Collection<?>> function)
LongFunction that returns a Collection of elements of an arbitrary type, this
method builds a LongPredicate that determines whether the returned Collection is
not empty.function - A LongFunction that returns a Collection of elements of an arbitrary type.public static <T> java.util.function.Predicate<T> isLongArrayEmpty(java.util.function.Function<? super T,long[]> function)
Function that returns an array of longs, 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 longs.public static <T> java.util.function.Predicate<T> isLongArrayNotEmpty(java.util.function.Function<? super T,long[]> function)
Function that returns an array of longs, 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 longs.public static <T> java.util.function.Predicate<T> objToLongsAllMatch(java.util.function.Function<T,? extends long[]> function,
java.util.function.LongPredicate predicate)
Function that takes an element of type <T> and returns an array of longs, and a
LongPredicate, this method builds a Predicate that determines whether all longs in the
returned array match the LongPredicate.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 longs.predicate - A LongPredicate that will be applied to all elements of an array of longs returned by the passed
Function.public static <R> java.util.function.LongPredicate longToObjectsAllMatch(java.util.function.LongFunction<? extends java.util.Collection<R>> function,
java.util.function.Predicate<R> predicate)
LongFunction that returns a Collection of type <R>, and a
Predicate, this method builds a LongPredicate 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 LongFunction. Also the type of
elements taken by a passed Predicate that will be applied to all elements of that Collection.function - A LongFunction 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
LongFunction.public static <T> java.util.function.Predicate<T> objToLongsAnyMatch(java.util.function.Function<T,? extends long[]> function,
java.util.function.LongPredicate predicate)
Function that takes an element of type <T> and returns an array of longs, and a
LongPredicate, this method builds a Predicate that determines whether any of the longs
in the returned array match the LongPredicate.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 longs.predicate - A LongPredicate that will be applied to all elements of an array of longs returned by the passed
Function to determine whether any match.public static <R> java.util.function.LongPredicate longToObjectsAnyMatch(java.util.function.LongFunction<? extends java.util.Collection<R>> function,
java.util.function.Predicate<R> predicate)
LongFunction that returns a Collection of type <R>, and a
Predicate, this method builds a LongPredicate 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 LongFunction. Also the type of
elements taken by a passed Predicate that will be applied to all elements of that Collection.function - A LongFunction 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
LongFunction to determine whether any match.public static <T> java.util.function.Predicate<T> objToLongsNoneMatch(java.util.function.Function<T,? extends long[]> function,
java.util.function.LongPredicate predicate)
Function that takes an element of type <T> and returns an array of longs, and a
LongPredicate, this method builds a Predicate that determines whether none of the
longs in the returned array match the LongPredicate.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 longs.predicate - A LongPredicate that will be applied to all elements of an array of longs returned by the passed
Function to determine whether none match.public static <R> java.util.function.LongPredicate longToObjectsNoneMatch(java.util.function.LongFunction<? extends java.util.Collection<R>> function,
java.util.function.Predicate<R> predicate)
LongFunction that returns a Collection of type <R>, and a
Predicate, this method builds a LongPredicate 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 LongFunction. Also the type of
elements taken by a passed Predicate that will be applied to all elements of that Collection.function - A LongFunction 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
LongFunction to determine whether none match.public static <T> java.util.function.Predicate<T> mapToLongAndFilter(java.util.function.ToLongFunction<? super T> function,
java.util.function.LongPredicate predicate)
ToLongFunction taking a value of type <T>, and a LongPredicate, this
method builds a Predicate that takes an element of type <T>, and applies the return value of
the ToLongFunction to the given predicate. It is a way of adapting a LongPredicate to a
Stream of a different type. For example, the
LongStreamUtils.indexOfFirstLong(long[], LongPredicate) method uses this predicate in its implementation
(Note that the longPairWithIndex() below refers to LongMapperUtils.longPairWithIndex()):
public static int indexOfFirstLong(long[] longs, LongPredicate longPredicate) {
return defaultLongStream(longs)
.mapToObj(longPairWithIndex())
.filter(mapToLongAndFilter(LongIndexPair::getLongValue, longPredicate))
.mapToInt(LongIndexPair::getIndex)
.findFirst()
.orElse(-1);
}
The map-and-filter predicate is necessary in this case because we have a predicate that operates on the original
long type of the stream, but a mapping operation has changed the type to a
LongIndexPair. The LongIndexPair::getLongValue method reference, passed as the
ToLongFunction argument to this method, retrieves the original long value before the
LongPredicate 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 long 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 ToLongFunction to transform an element of type <T> to a long before it is passed to a
LongPredicate.predicate - A LongPredicate whose value will be retrieved from a given transformer function.public static <T> java.util.function.LongPredicate longMapAndFilter(java.util.function.LongFunction<? extends T> function,
java.util.function.Predicate<? super T> predicate)
LongFunction that returns a value of type <T>, and a Predicate, this
method builds a LongPredicate that applies the return value of the LongFunction to
the given predicate. It is a way of adapting a long value to a Predicate. This method is the
inverse of mapToLongAndFilter(ToLongFunction, LongPredicate). In that method, we map from a value of
type <T> to a long, and then apply a LongPredicate. In this method we map from a
long 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 - A LongFunction to transform a long 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 LongFunction.