public final class DblPredicateUtils
extends java.lang.Object
double types.| Modifier and Type | Method and Description |
|---|---|
static java.util.function.DoublePredicate |
dblConstant(boolean b)
Builds a double predicate based on a passed constant
boolean value. |
static java.util.function.DoublePredicate |
dblGt(double compareTo)
Builds a
DoublePredicate that determines whether a value is greater than a passed constant double
value. |
static <R extends java.lang.Comparable<R>> |
dblGt(java.util.function.DoubleFunction<? extends R> function,
R compareTo)
Given a
DoubleFunction that returns a value of type <R>, and a constant value of type
<R>, this method builds a DoublePredicate 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.DoublePredicate |
dblGte(double compareTo)
Builds a
DoublePredicate that determines whether a value is greater than or equal to a passed
constant double value. |
static <R extends java.lang.Comparable<R>> |
dblGte(java.util.function.DoubleFunction<? extends R> function,
R compareTo)
Given a
DoubleFunction that returns a value of type <R>, and a constant value of type
<R>, this method builds a DoublePredicate 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.DoublePredicate |
dblIsNotNull(java.util.function.DoubleFunction<?> function)
Given a
DoubleFunction that returns a value of an arbitrary type, this method builds a
DoublePredicate that determines whether that returned value is not null. |
static java.util.function.DoublePredicate |
dblIsNull(java.util.function.DoubleFunction<?> function)
Given a
DoubleFunction that returns a value of an arbitrary type, this method builds a
DoublePredicate that determines whether that returned value is null. |
static java.util.function.DoublePredicate |
dblLt(double compareTo)
Builds a
DoublePredicate that determines whether a value is less than a passed constant double
value. |
static <R extends java.lang.Comparable<R>> |
dblLt(java.util.function.DoubleFunction<? extends R> function,
R compareTo)
Given a
DoubleFunction that returns a value of type <R>, and a constant value of type
<R>, this method builds a DoublePredicate 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.DoublePredicate |
dblLte(double compareTo)
Builds a
DoublePredicate that determines whether a value is less than or equal to a passed constant
double value. |
static <R extends java.lang.Comparable<R>> |
dblLte(java.util.function.DoubleFunction<? extends R> function,
R compareTo)
Given a
DoubleFunction that returns a value of type <R>, and a constant value of type
<R>, this method builds a DoublePredicate 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.DoublePredicate |
dblMapAndFilter(java.util.function.DoubleFunction<? extends T> function,
java.util.function.Predicate<? super T> predicate)
Given a
DoubleFunction that returns a value of type <T>, and a Predicate, this
method builds a DoublePredicate that applies the return value of the DoubleFunction to
the given predicate. |
static java.util.function.DoublePredicate |
dblNot(java.util.function.DoublePredicate predicate)
A
DoublePredicate that simply negates the passed DoublePredicate. |
static <U> java.util.function.DoublePredicate |
dblPredicate(java.util.function.BiPredicate<java.lang.Double,? super U> biPredicate,
U value)
Builds a
DoublePredicate from a passed BiPredicate<Double, U>, which can be very
useful in the common situation where you are streaming through a collection of elements, and have a double
predicate method to call that takes two parameters - the first one being the double element on which
you are streaming, and the second being some constant value that will be passed to all invocations. |
static java.util.function.DoublePredicate |
dblPredicate(java.util.function.DoublePredicate predicate)
Simply casts a method reference, which takes a single parameter of type
double or
Double, and returns a boolean or Boolean, to a
DoublePredicate. |
static <R> java.util.function.DoublePredicate |
dblToObjContains(java.util.Collection<? extends R> collection,
java.util.function.DoubleFunction<? extends R> function)
Given a
Collection whose elements are of type <R>, and a DoubleFunction that
returns a value of type <R>, this method builds a DoublePredicate that determines if the given
collection contains the value returned by the double function. |
static <R> java.util.function.DoublePredicate |
dblToObjsAllMatch(java.util.function.DoubleFunction<? extends java.util.Collection<R>> function,
java.util.function.Predicate<R> predicate)
Given a
DoubleFunction that returns a Collection of type <R>, and a
Predicate, this method builds a DoublePredicate that determines whether all
elements in the returned Collection match the Predicate. |
static <R> java.util.function.DoublePredicate |
dblToObjsAnyMatch(java.util.function.DoubleFunction<? extends java.util.Collection<R>> function,
java.util.function.Predicate<R> predicate)
Given a
DoubleFunction that returns a Collection of type <R>, and a
Predicate, this method builds a DoublePredicate that determines whether any of the
elements in the returned Collection match the Predicate. |
static <R> java.util.function.DoublePredicate |
dblToObjsNoneMatch(java.util.function.DoubleFunction<? extends java.util.Collection<R>> function,
java.util.function.Predicate<R> predicate)
Given a
DoubleFunction that returns a Collection of type <R>, and a
Predicate, this method builds a DoublePredicate that determines whether none of the
elements in the returned Collection match the Predicate. |
static org.perro.functions.predicate.DoubleWithDelta |
dblWithDelta(double value,
double delta)
Combines a
double value for use in a comparison, with a delta. |
static <U> java.util.function.DoublePredicate |
inverseDblPredicate(java.util.function.BiPredicate<? super U,java.lang.Double> biPredicate,
U value)
Builds a
DoublePredicate from a passed BiPredicate<Double, U>, which can be very
useful in the common situation where you are streaming through a collection of elements, and have a double
predicate method to call that takes two parameters. |
static <R> java.util.function.DoublePredicate |
inverseDblToObjContains(java.util.function.DoubleFunction<? extends java.util.Collection<R>> function,
R value)
Given a
DoubleFunction that returns a Collection<R>, this method builds a
DoublePredicate that determines if the collection returned by that double function contains the
passed value of type <R>. |
static <T> java.util.function.Predicate<T> |
inverseObjToDblContains(java.util.function.Function<T,double[]> function,
double value)
Given a
Function that takes an element of type <T> and returns an array of doubles, this
method builds a Predicate that determines if the array returned by that function contains the passed
constant double value. |
static <T> java.util.function.Predicate<T> |
isDblArrayEmpty(java.util.function.Function<? super T,double[]> function)
Given a
Function that returns an array of doubles, this method builds a Predicate that
determines whether the returned array is empty. |
static <T> java.util.function.Predicate<T> |
isDblArrayNotEmpty(java.util.function.Function<? super T,double[]> function)
Given a
Function that returns an array of doubles, this method builds a Predicate that
determines whether the returned array is not empty. |
static java.util.function.DoublePredicate |
isDblCollEmpty(java.util.function.DoubleFunction<? extends java.util.Collection<?>> function)
Given a
DoubleFunction that returns a Collection of elements of an arbitrary type, this
method builds a DoublePredicate that determines whether the returned Collection is
empty. |
static java.util.function.DoublePredicate |
isDblCollNotEmpty(java.util.function.DoubleFunction<? extends java.util.Collection<?>> function)
Given a
DoubleFunction that returns a Collection of elements of an arbitrary type, this
method builds a DoublePredicate that determines whether the returned Collection is
not empty. |
static java.util.function.DoublePredicate |
isDblEqual(double value)
This method builds a
DoublePredicate whose parameter is to be compared for equality to the passed
double constant value. |
static java.util.function.DoublePredicate |
isDblEqual(double value,
double delta)
This method builds a
DoublePredicate whose parameter is to be compared for equality to the passed
double constant value. |
static java.util.function.DoublePredicate |
isDblEqual(java.util.function.DoubleUnaryOperator operator,
double value)
Given a
DoubleUnaryOperator this method builds a DoublePredicate that determines if the
value returned by that operator is equal to the passed constant double value. |
static java.util.function.DoublePredicate |
isDblEqual(java.util.function.DoubleUnaryOperator operator,
org.perro.functions.predicate.DoubleWithDelta doubleWithDelta)
Given a
DoubleUnaryOperator this method builds a DoublePredicate that determines if a
value returned by that operator is equal to a constant double value, within a delta parameter. |
static java.util.function.DoublePredicate |
isDblNotEqual(double value)
This method builds a
DoublePredicate whose parameter is to be compared for inequality to the passed
double constant value. |
static java.util.function.DoublePredicate |
isDblNotEqual(double value,
double delta)
This method builds a
DoublePredicate whose parameter is to be compared for inequality to the passed
double constant value. |
static java.util.function.DoublePredicate |
isDblNotEqual(java.util.function.DoubleUnaryOperator operator,
double value)
Given a
DoubleUnaryOperator this method builds a DoublePredicate that determines if the
value returned by that operator is not equal to the passed constant double value. |
static java.util.function.DoublePredicate |
isDblNotEqual(java.util.function.DoubleUnaryOperator operator,
org.perro.functions.predicate.DoubleWithDelta doubleWithDelta)
Given a
DoubleUnaryOperator this method builds a DoublePredicate that determines if a
value returned by that operator is equal to a constant double value, within a delta parameter. |
static <T> java.util.function.Predicate<T> |
mapToDblAndFilter(java.util.function.ToDoubleFunction<? super T> function,
java.util.function.DoublePredicate predicate)
Given a
ToDoubleFunction taking a value of type <T>, and a DoublePredicate, this
method builds a Predicate that takes an element of type <T>, and applies the return value of
the ToDoubleFunction to the given predicate. |
static <T> java.util.function.Predicate<T> |
objToDblContains(double[] doubles,
java.util.function.ToDoubleFunction<? super T> function)
Given a
double array, and a ToDoubleFunction that takes an element of type <T>,
this method builds a Predicate that determines if the given array contains the value returned by the
ToDoubleFunction. |
static <T> java.util.function.Predicate<T> |
objToDblsAllMatch(java.util.function.Function<T,? extends double[]> function,
java.util.function.DoublePredicate predicate)
Given a
Function that takes an element of type <T> and returns an array of doubles, and a
DoublePredicate, this method builds a Predicate that determines whether all doubles
in the returned array match the DoublePredicate. |
static <T> java.util.function.Predicate<T> |
objToDblsAnyMatch(java.util.function.Function<T,? extends double[]> function,
java.util.function.DoublePredicate predicate)
Given a
Function that takes an element of type <T> and returns an array of doubles, and a
DoublePredicate, this method builds a Predicate that determines whether any of the
doubles in the returned array match the DoublePredicate. |
static <T> java.util.function.Predicate<T> |
objToDblsNoneMatch(java.util.function.Function<T,? extends double[]> function,
java.util.function.DoublePredicate predicate)
Given a
Function that takes an element of type <T> and returns an array of doubles, and a
DoublePredicate, this method builds a Predicate that determines whether none of the
doubles in the returned array match the DoublePredicate. |
static <T> java.util.function.Predicate<T> |
toDblGt(java.util.function.ToDoubleFunction<? super T> function,
double compareTo)
Given a
ToDoubleFunction 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 double value. |
static <T> java.util.function.Predicate<T> |
toDblGte(java.util.function.ToDoubleFunction<? super T> function,
double compareTo)
Given a
ToDoubleFunction 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 double value. |
static <T> java.util.function.Predicate<T> |
toDblLt(java.util.function.ToDoubleFunction<? super T> function,
double compareTo)
Given a
ToDoubleFunction 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 double value. |
static <T> java.util.function.Predicate<T> |
toDblLte(java.util.function.ToDoubleFunction<? super T> function,
double compareTo)
Given a
ToDoubleFunction 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 double value. |
public static java.util.function.DoublePredicate dblPredicate(java.util.function.DoublePredicate predicate)
double or
Double, and returns a boolean or Boolean, to a
DoublePredicate. This could be useful in a situation where methods of the
DoublePredicate functional interface are to be called on a method reference. For example:
private double[] getDoublesInRange(double[] doubles) {
return Arrays.stream(doubles)
.filter(DblPredicateUtils.dblPredicate(this::isGreaterThanOrEqualToMin)
.and(this::isLessThanOrEqualToMax))
.toArray();
}
private boolean isGreaterThanOrEqualToMin(double target) {
...
}
private boolean isLessThanOrEqualToMax(double target) {
...
}
The DoublePredicate.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 DoublePredicate.and(...) already
takes a DoublePredicate just like this method, and so is already doing a cast.predicate - A method reference to be cast to a DoublePredicate.public static <U> java.util.function.DoublePredicate dblPredicate(java.util.function.BiPredicate<java.lang.Double,? super U> biPredicate,
U value)
DoublePredicate from a passed BiPredicate<Double, U>, which can be very
useful in the common situation where you are streaming through a collection of elements, and have a double
predicate method to call that takes two parameters - the first one being the double 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 DoubleStream. 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:
private double[] getHighestPriceOfStockBelowLimit(Collection<Stock> stocks, Client client) {
return stocks.stream()
.mapToDouble(Stock::getPrice)
.filter(DblPredicateUtils.dblPredicate(this::isPriceBelowLimit, client))
.max()
.orElse(-1.0D);
}
private boolean isPriceBelowLimit(double price, Client client) {
...
}
Or, with static imports:
return stocks.stream()
.mapToDouble(Stock::getPrice)
.filter(dblPredicate(this::isPriceBelowLimit, client))
.max()
.orElse(-1.0D);
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
Double, and the second of type <U>. The method reference will be converted by this
method to a DoublePredicate. 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.DoublePredicate inverseDblPredicate(java.util.function.BiPredicate<? super U,java.lang.Double> biPredicate,
U value)
DoublePredicate from a passed BiPredicate<Double, U>, which can be very
useful in the common situation where you are streaming through a collection of elements, and have a double
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 dblPredicate(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 double element on which you are streaming. This would
typically be called from within a chain of method calls based on a DoubleStream. 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:
private double[] getHighestPriceOfStockBelowLimit(Collection<Stock> stocks, Client client) {
return stocks.stream()
.mapToDouble(Stock::getPrice)
.filter(DblPredicateUtils.inverseDblPredicate(this::isPriceBelowLimit, client))
.max()
.orElse(-1.0D);
}
private boolean isPriceBelowLimit(Client client, double price) {
...
}
Or, with static imports:
return stocks.stream()
.mapToDouble(Stock::getPrice)
.filter(inverseDblPredicate(this::isPriceBelowLimit, client))
.max()
.orElse(-1.0D);
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 Double. The method reference will be converted by this
method to a DoublePredicate. 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.DoublePredicate dblConstant(boolean b)
boolean value. The target element of type
double 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:
private double[] getHighestPriceOfStockBelowLimit(Collection<Stock> stocks, Client client) {
boolean hasLimit = client.getLimit() > 0.0D;
return stocks.stream()
.mapToDouble(Stock::getPrice)
.filter(DblPredicateUtils.dblNot(DblPredicateUtils.dblConstant(hasLimit))
.or(DblPredicateUtils.dblPredicate(this::isPriceBelowLimit, client))
.max()
.orElse(-1.0D);
}
private boolean isPriceBelowLimit(double price, Client client) {
...
}
Or, with static imports:
return stocks.stream()
.mapToDouble(Stock::getPrice)
.filter(dblNot(dblConstant(hasLimit))
.or(dblPredicate(this::isPriceBelowLimit, client))
.max()
.orElse(-1.0D);
b - A constant boolean value that will be the result of every invocation of the returned DoublePredicate.public static java.util.function.DoublePredicate dblNot(java.util.function.DoublePredicate predicate)
DoublePredicate that simply negates the passed DoublePredicate. A predicate can
always be negated via predicate.negate(), however using this method may improve readability.predicate - A DoublePredicate whose result is to be negated.public static java.util.function.DoublePredicate isDblEqual(double value)
DoublePredicate whose parameter is to be compared for equality to the passed
double constant value.value - A constant value to be compared to the parameter of the DoublePredicate built by this method.public static java.util.function.DoublePredicate isDblEqual(double value,
double delta)
DoublePredicate whose parameter is to be compared for equality to the passed
double constant value. If the absolute value of the difference between the two numbers is less than
or equal to a passed delta, the values will be considered equal.value - A constant value to be compared to the parameter of the DoublePredicate built by this method.delta - A delta value meaning that if the absolute value of the difference between the two numbers to be
compared is less than or equal to the delta, the values will be considered equal.public static java.util.function.DoublePredicate isDblEqual(java.util.function.DoubleUnaryOperator operator,
double value)
DoubleUnaryOperator this method builds a DoublePredicate that determines if the
value returned by that operator is equal to the passed constant double value. For example:
double[] doubles = IntStream.range(1, 10).asDoubleStream().toArray();
double[] evens = Arrays.stream(doubles)
.filter(DblPredicateUtils.isDblEqual(DblMapperUtils.dblModulo(2.0D), 0.0D))
.toArray();
Or, with static imports:
double[] evens = Arrays.stream(doubles)
.filter(isDblEqual(dblModulo(2.0D), 0.0D))
.toArray();
operator - A DoubleUnaryOperator whose return value is to be compared with a passed constant double value
for equality.value - A value to be compared to the result of the passed operator for equality.public static java.util.function.DoublePredicate isDblEqual(java.util.function.DoubleUnaryOperator operator,
org.perro.functions.predicate.DoubleWithDelta doubleWithDelta)
DoubleUnaryOperator this method builds a DoublePredicate that determines if a
value returned by that operator is equal to a constant double value, within a delta parameter.
double[] doubles = IntStream.range(1, 10).asDoubleStream().toArray();
double[] evens = Arrays.stream(doubles)
.filter(DblPredicateUtils.isDblEqual(DblMapperUtils.dblModulo(2.0D), DblPredicateUtils.dblWithDelta(0.0D, 0.000001D)))
.toArray();
Or, with static imports:
double[] evens = Arrays.stream(doubles)
.filter(isDblEqual(dblModulo(2.0D), dblWithDelta(0.0D, 0.000001D)))
.toArray();
operator - A DoubleUnaryOperator whose return value is to be compared with a passed constant double
value for equality.doubleWithDelta - An object containing a constant double value for comparison, and a double delta.public static java.util.function.DoublePredicate isDblNotEqual(double value)
DoublePredicate whose parameter is to be compared for inequality to the passed
double constant value.value - A constant value to be compared to the parameter of the DoublePredicate built by this method.public static java.util.function.DoublePredicate isDblNotEqual(double value,
double delta)
DoublePredicate whose parameter is to be compared for inequality to the passed
double constant value. If the absolute value of the difference between the two numbers is greater
than a passed delta, the values will be considered not equal.value - A constant value to be compared to the parameter of the DoublePredicate built by this method.delta - A delta value meaning that if the absolute value of the difference between the two numbers to be
compared is greater than the delta, the values will be considered not equal.public static java.util.function.DoublePredicate isDblNotEqual(java.util.function.DoubleUnaryOperator operator,
double value)
DoubleUnaryOperator this method builds a DoublePredicate that determines if the
value returned by that operator is not equal to the passed constant double value. For example:
double[] doubles = IntStream.range(1, 10).asDoubleStream().toArray();
double[] odds = Arrays.stream(doubles)
.filter(DblPredicateUtils.isDblNotEqual(DblMapperUtils.dblModulo(2.0D), 0.0D))
.toArray();
Or, with static imports:
double[] odds = Arrays.stream(doubles)
.filter(isDblNotEqual(dblModulo(2.0D), 0.0D))
.toArray();
operator - A DoubleUnaryOperator whose return value is to be compared with a passed constant double value
for inequality.value - A value to be compared to the result of the passed operator for inequality.public static java.util.function.DoublePredicate isDblNotEqual(java.util.function.DoubleUnaryOperator operator,
org.perro.functions.predicate.DoubleWithDelta doubleWithDelta)
DoubleUnaryOperator this method builds a DoublePredicate that determines if a
value returned by that operator is equal to a constant double value, within a delta parameter.
double[] doubles = IntStream.range(1, 10).asDoubleStream().toArray();
double[] odds = Arrays.stream(doubles)
.filter(DblPredicateUtils.isDblNotEqual(DblMapperUtils.dblModulo(2.0D), DblPredicateUtils.dblWithDelta(0.0D, 0.000001D)))
.toArray();
Or, with static imports:
double[] odds = Arrays.stream(doubles)
.filter(isDblNotEqual(dblModulo(2.0D), dblWithDelta(0.0D, 0.000001D)))
.toArray();
operator - A DoubleUnaryOperator whose return value is to be compared with a constant double value
for inequality, within a delta.doubleWithDelta - An object containing a constant double value for comparison, and a double delta.public static <R> java.util.function.DoublePredicate dblToObjContains(java.util.Collection<? extends R> collection,
java.util.function.DoubleFunction<? extends R> function)
Collection whose elements are of type <R>, and a DoubleFunction that
returns a value of type <R>, this method builds a DoublePredicate that determines if the given
collection contains the value returned by the double function. More formally, the DoublePredicate
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
double function.R - The type of elements in the passed Collection. Also, the type of the value returned by the
passed DoubleFunction.collection - A Collection of elements of type <R>, to be checked for whether it contains a value
returned from a passed DoubleFunction.function - A DoubleFunction returning a value of type <R> to be checked for whether it is contained
in a passed Collection.public static <R> java.util.function.DoublePredicate inverseDblToObjContains(java.util.function.DoubleFunction<? extends java.util.Collection<R>> function,
R value)
DoubleFunction that returns a Collection<R>, this method builds a
DoublePredicate that determines if the collection returned by that double function contains the
passed value of type <R>. More formally, the DoublePredicate 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 dblToObjContains(Collection, DoubleFunction), 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 double function contains a passed value.
R - The type of elements for collections returned by a passed DoubleFunction. Also, the type of the
passed value.function - A DoubleFunction 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
DoubleFunction contains it.public static <T> java.util.function.Predicate<T> objToDblContains(double[] doubles,
java.util.function.ToDoubleFunction<? super T> function)
double array, and a ToDoubleFunction that takes an element of type <T>,
this method builds a Predicate that determines if the given array contains the value returned by the
ToDoubleFunction.T - The type of the element taken by the Predicate built by this method.doubles - An array of doubles, to be checked for whether it contains a value returned from a passed
ToDoubleFunction.function - A ToDoubleFunction 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> inverseObjToDblContains(java.util.function.Function<T,double[]> function,
double value)
Function that takes an element of type <T> and returns an array of doubles, this
method builds a Predicate that determines if the array returned by that function contains the passed
constant double value.
This method is similar to objToDblContains(double[], ToDoubleFunction), 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 double value.
T - The type of the element taken by the Predicate built by this method.function - A Function that returns an array of doubles.value - A constant double value to be checked for whether an array of doubles returned by the above
Function contains it.public static java.util.function.DoublePredicate dblIsNull(java.util.function.DoubleFunction<?> function)
DoubleFunction that returns a value of an arbitrary type, this method builds a
DoublePredicate that determines whether that returned value is null.function - A DoubleFunction that returns a value of an arbitrary type.public static java.util.function.DoublePredicate dblIsNotNull(java.util.function.DoubleFunction<?> function)
DoubleFunction that returns a value of an arbitrary type, this method builds a
DoublePredicate that determines whether that returned value is not null.function - A DoubleFunction that returns a value of an arbitrary type.public static java.util.function.DoublePredicate dblGt(double compareTo)
DoublePredicate that determines whether a value is greater than a passed constant double
value.compareTo - A constant double value to be compared to the target value of a DoublePredicate built by this
method.public static <R extends java.lang.Comparable<R>> java.util.function.DoublePredicate dblGt(java.util.function.DoubleFunction<? extends R> function,
R compareTo)
DoubleFunction that returns a value of type <R>, and a constant value of type
<R>, this method builds a DoublePredicate 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 DoubleFunction parameter. Also, the type of the passed constant
value.function - A DoubleFunction 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 DoubleFunction.public static <T> java.util.function.Predicate<T> toDblGt(java.util.function.ToDoubleFunction<? super T> function,
double compareTo)
ToDoubleFunction 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 double value.T - The type of the element taken by the Predicate built by this method.function - A ToDoubleFunction 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 double value to see whether it is
greater.compareTo - A constant double value to be compared with a value returned by a passed ToDoubleFunction.public static java.util.function.DoublePredicate dblGte(double compareTo)
DoublePredicate that determines whether a value is greater than or equal to a passed
constant double value.compareTo - A constant double value to be compared to the target value of a DoublePredicate built by this
method.public static <R extends java.lang.Comparable<R>> java.util.function.DoublePredicate dblGte(java.util.function.DoubleFunction<? extends R> function,
R compareTo)
DoubleFunction that returns a value of type <R>, and a constant value of type
<R>, this method builds a DoublePredicate 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 DoubleFunction parameter. Also, the type of the passed constant
value.function - A DoubleFunction 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 DoubleFunction.public static <T> java.util.function.Predicate<T> toDblGte(java.util.function.ToDoubleFunction<? super T> function,
double compareTo)
ToDoubleFunction 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 double value.T - The type of the element taken by the Predicate built by this method.function - A ToDoubleFunction 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 double value to see whether it is
greater than or equal to it.compareTo - A constant double value to be compared with a value returned by a passed ToDoubleFunction.public static java.util.function.DoublePredicate dblLt(double compareTo)
DoublePredicate that determines whether a value is less than a passed constant double
value.compareTo - A constant double value to be compared to the target value of a DoublePredicate built by this
method.public static <R extends java.lang.Comparable<R>> java.util.function.DoublePredicate dblLt(java.util.function.DoubleFunction<? extends R> function,
R compareTo)
DoubleFunction that returns a value of type <R>, and a constant value of type
<R>, this method builds a DoublePredicate 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 DoubleFunction parameter. Also, the type of the passed constant
value.function - A DoubleFunction 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 DoubleFunction.public static <T> java.util.function.Predicate<T> toDblLt(java.util.function.ToDoubleFunction<? super T> function,
double compareTo)
ToDoubleFunction 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 double value.T - The type of the element taken by the Predicate built by this method.function - A ToDoubleFunction 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 double value to see whether it is
less than it.compareTo - A constant double value to be compared with a value returned by a passed ToDoubleFunction.public static java.util.function.DoublePredicate dblLte(double compareTo)
DoublePredicate that determines whether a value is less than or equal to a passed constant
double value.compareTo - A constant double value to be compared to the target value of a DoublePredicate built by this
method.public static <R extends java.lang.Comparable<R>> java.util.function.DoublePredicate dblLte(java.util.function.DoubleFunction<? extends R> function,
R compareTo)
DoubleFunction that returns a value of type <R>, and a constant value of type
<R>, this method builds a DoublePredicate 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 DoubleFunction parameter. Also, the type of the passed constant
value.function - A DoubleFunction 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 DoubleFunction.public static <T> java.util.function.Predicate<T> toDblLte(java.util.function.ToDoubleFunction<? super T> function,
double compareTo)
ToDoubleFunction 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 double value.T - The type of the element taken by the Predicate built by this method.function - A ToDoubleFunction 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 double value to see whether it is
less than or equal to it.compareTo - A constant double value to be compared with a value returned by a passed ToDoubleFunction.public static java.util.function.DoublePredicate isDblCollEmpty(java.util.function.DoubleFunction<? extends java.util.Collection<?>> function)
DoubleFunction that returns a Collection of elements of an arbitrary type, this
method builds a DoublePredicate that determines whether the returned Collection is
empty.function - A DoubleFunction that returns a Collection of elements of an arbitrary type.public static java.util.function.DoublePredicate isDblCollNotEmpty(java.util.function.DoubleFunction<? extends java.util.Collection<?>> function)
DoubleFunction that returns a Collection of elements of an arbitrary type, this
method builds a DoublePredicate that determines whether the returned Collection is
not empty.function - A DoubleFunction that returns a Collection of elements of an arbitrary type.public static <T> java.util.function.Predicate<T> isDblArrayEmpty(java.util.function.Function<? super T,double[]> function)
Function that returns an array of doubles, 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 doubles.public static <T> java.util.function.Predicate<T> isDblArrayNotEmpty(java.util.function.Function<? super T,double[]> function)
Function that returns an array of doubles, 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 doubles.public static <T> java.util.function.Predicate<T> objToDblsAllMatch(java.util.function.Function<T,? extends double[]> function,
java.util.function.DoublePredicate predicate)
Function that takes an element of type <T> and returns an array of doubles, and a
DoublePredicate, this method builds a Predicate that determines whether all doubles
in the returned array match the DoublePredicate.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 doubles.predicate - A DoublePredicate that will be applied to all elements of an array of doubles returned by the
passed Function.public static <R> java.util.function.DoublePredicate dblToObjsAllMatch(java.util.function.DoubleFunction<? extends java.util.Collection<R>> function,
java.util.function.Predicate<R> predicate)
DoubleFunction that returns a Collection of type <R>, and a
Predicate, this method builds a DoublePredicate 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 DoubleFunction. Also the type of
elements taken by a passed Predicate that will be applied to all elements of that Collection.function - A DoubleFunction 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
DoubleFunction.public static <T> java.util.function.Predicate<T> objToDblsAnyMatch(java.util.function.Function<T,? extends double[]> function,
java.util.function.DoublePredicate predicate)
Function that takes an element of type <T> and returns an array of doubles, and a
DoublePredicate, this method builds a Predicate that determines whether any of the
doubles in the returned array match the DoublePredicate.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 doubles.predicate - A DoublePredicate that will be applied to all elements of an array of doubles returned by the
passed Function to determine whether any match.public static <R> java.util.function.DoublePredicate dblToObjsAnyMatch(java.util.function.DoubleFunction<? extends java.util.Collection<R>> function,
java.util.function.Predicate<R> predicate)
DoubleFunction that returns a Collection of type <R>, and a
Predicate, this method builds a DoublePredicate 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 DoubleFunction. Also the type of
elements taken by a passed Predicate that will be applied to all elements of that Collection.function - A DoubleFunction 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
DoubleFunction to determine whether any match.public static <T> java.util.function.Predicate<T> objToDblsNoneMatch(java.util.function.Function<T,? extends double[]> function,
java.util.function.DoublePredicate predicate)
Function that takes an element of type <T> and returns an array of doubles, and a
DoublePredicate, this method builds a Predicate that determines whether none of the
doubles in the returned array match the DoublePredicate.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 doubles.predicate - A DoublePredicate that will be applied to all elements of an array of doubles returned by the
passed Function to determine whether none match.public static <R> java.util.function.DoublePredicate dblToObjsNoneMatch(java.util.function.DoubleFunction<? extends java.util.Collection<R>> function,
java.util.function.Predicate<R> predicate)
DoubleFunction that returns a Collection of type <R>, and a
Predicate, this method builds a DoublePredicate 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 DoubleFunction. Also the type of
elements taken by a passed Predicate that will be applied to all elements of that Collection.function - A DoubleFunction 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
DoubleFunction to determine whether none match.public static <T> java.util.function.Predicate<T> mapToDblAndFilter(java.util.function.ToDoubleFunction<? super T> function,
java.util.function.DoublePredicate predicate)
ToDoubleFunction taking a value of type <T>, and a DoublePredicate, this
method builds a Predicate that takes an element of type <T>, and applies the return value of
the ToDoubleFunction to the given predicate. It is a way of adapting a DoublePredicate
to a Stream of a different type. For example, the
DblStreamUtils.indexOfFirstDbl(double[], DoublePredicate) method uses this predicate in its
implementation (Note that the dblPairWithIndex() below refers to
DblMapperUtils.dblPairWithIndex()):
public static int indexOfFirstDbl(double[] doubles, DoublePredicate doublePredicate) {
return defaultDblStream(doubles)
.mapToObj(dblPairWithIndex())
.filter(mapToDblAndFilter(DoubleIndexPair::getDoubleValue, doublePredicate))
.mapToInt(DoubleIndexPair::getIndex)
.findFirst()
.orElse(-1);
}
The map-and-filter predicate is necessary in this case because we have a predicate that operates on the original
double type of the stream, but a mapping operation has changed the type to a
DoubleIndexPair. The DoubleIndexPair::getDoubleValue method reference, passed as the
ToDoubleFunction argument to this method, retrieves the original double value before the
DoublePredicate 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 double 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 ToDoubleFunction to transform an element of type <T> to a double before it is passed to
a DoublePredicate.predicate - A DoublePredicate whose value will be retrieved from a given transformer function.public static <T> java.util.function.DoublePredicate dblMapAndFilter(java.util.function.DoubleFunction<? extends T> function,
java.util.function.Predicate<? super T> predicate)
DoubleFunction that returns a value of type <T>, and a Predicate, this
method builds a DoublePredicate that applies the return value of the DoubleFunction to
the given predicate. It is a way of adapting a double value to a Predicate. This method is the
inverse of mapToDblAndFilter(ToDoubleFunction, DoublePredicate). In that method, we map from a value of
type <T> to a double, and then apply a DoublePredicate. In this method we map
from a double 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 DoubleFunction to transform a double 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 DoubleFunction.public static org.perro.functions.predicate.DoubleWithDelta dblWithDelta(double value,
double delta)
double value for use in a comparison, with a delta. When an equality comparison is made,
if the difference in values is smaller than the delta, then the values are considered equal. This method is used
to build the second parameter to the isDblEqual(DoubleUnaryOperator, DoubleWithDelta) and
isDblNotEqual(DoubleUnaryOperator, DoubleWithDelta) methods.value - A double value to be compared with another value.delta - A delta value to be used - if the difference of two values is within it, they are still considered
equal.