public final class IntStreamUtils
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static java.util.stream.IntStream |
defaultIntStream(java.util.Collection<java.lang.Integer> objects)
Given a
Collection of Integer instances, returns an IntStream of them. |
static java.util.stream.IntStream |
defaultIntStream(int[] array)
Given an array of
int values, returns an IntStream of them. |
static java.util.stream.IntStream |
defaultIntStream(java.util.stream.IntStream stream)
Given an
IntStream returns that stream if it is not null, otherwise returns an empty
IntStream. |
static java.util.stream.IntStream |
defaultIntStream(java.util.stream.Stream<java.lang.Integer> stream)
Given a
Stream of Integer instances, returns an IntStream from it, or an
empty IntStream if it is null. |
static int |
findAnyIntDefault(int[] ints,
org.perro.functions.stream.FindIntWithDefault findWithDefault)
Attempt to find any matching int value in an array of ints using a predicate, returning a default value if one is
not found.
|
static int |
findAnyIntDefault(int[] ints,
org.perro.functions.stream.FindIntWithDefaultSupplier findWithDefaultSupplier)
Attempt to find any matching int value in an array of ints using a predicate, returning a default value retrieved
using an
IntSupplier if one is not found. |
static java.lang.Integer |
findAnyIntDefaultNull(int[] ints,
java.util.function.IntPredicate predicate)
Attempt to find any matching int value in an array of ints using a predicate, returning
null
if one is not found. |
static int |
findFirstIntDefault(int[] ints,
org.perro.functions.stream.FindIntWithDefault findWithDefault)
Attempt to find the first matching int value in an array of ints using a predicate, returning a default
value if one is not found.
|
static int |
findFirstIntDefault(int[] ints,
org.perro.functions.stream.FindIntWithDefaultSupplier findWithDefaultSupplier)
Attempt to find the first matching int value in an array of ints using a predicate, returning a default value
retrieved using an
IntSupplier if one is not found. |
static java.lang.Integer |
findFirstIntDefaultNull(int[] ints,
java.util.function.IntPredicate predicate)
Attempt to find the first matching int value in an array of ints using a predicate, returning
null
if one is not found. |
static org.perro.functions.stream.FindIntWithDefault |
findIntDefault(java.util.function.IntPredicate predicate,
int defaultValue)
Retrieves an object representing a predicate for finding a value, and a default int value if one is not found.
|
static org.perro.functions.stream.FindIntWithDefaultSupplier |
findIntDefault(java.util.function.IntPredicate predicate,
java.util.function.IntSupplier defaultSupplier)
Retrieves an object representing a predicate for finding a value, and a default
DoubleSupplier if
one is not found. |
static int |
indexOfFirstInt(int[] ints,
java.util.function.IntPredicate predicate)
Finds the index of the first int in an array that matches an
IntPredicate. |
static boolean |
intAllMatch(int[] ints,
java.util.function.IntPredicate predicate)
Given an array of ints and an
IntPredicate, returns a boolean value indicating whether
all values in the array match the predicate. |
static boolean |
intAnyMatch(int[] ints,
java.util.function.IntPredicate predicate)
Given an array of ints and an
IntPredicate, returns a boolean value indicating whether
any of the values in the array match the predicate. |
static long |
intCount(int[] ints,
java.util.function.IntPredicate predicate)
Given an array of ints and an
IntPredicate, returns a long value indicating the
number of values in the array that match the predicate. |
static int |
intMaxDefault(int[] ints,
org.perro.functions.stream.FindIntWithDefault findWithDefault)
Given an array of ints, and an object representing an
IntPredicate along with a default value, this
method returns the maximum int value in the array that matches the predicate, or the default value if no matching
values are found. |
static int |
intMaxDefault(int[] ints,
org.perro.functions.stream.FindIntWithDefaultSupplier findWithDefaultSupplier)
Given an array of ints, and an object representing an
IntPredicate along with a
Supplier for a default value, this method returns the maximum int value in the array that matches
the predicate, or a default value from the supplier if no matching values are found. |
static int |
intMinDefault(int[] ints,
org.perro.functions.stream.FindIntWithDefault findWithDefault)
Given an array of ints, and an object representing an
IntPredicate along with a default value, this
method returns the minimum int value in the array that matches the predicate, or the default value if no matching
values are found. |
static int |
intMinDefault(int[] ints,
org.perro.functions.stream.FindIntWithDefaultSupplier findWithDefaultSupplier)
Given an array of ints, and an object representing an
IntPredicate along with a
Supplier for a default value, this method returns the minimum int value in the array that matches
the predicate, or a default value from the supplier if no matching values are found. |
static boolean |
intNoneMatch(int[] ints,
java.util.function.IntPredicate predicate)
Given an array of ints and an
IntPredicate, returns a boolean value indicating whether
none of the values in the array match the predicate. |
static java.util.List<int[]> |
toPartitionedIntList(int[] ints,
int partitionSize)
Given an array of ints, and a partition size, this method divides the array into a list of int arrays, each of
whose length is at most
partitionSize. |
static java.util.stream.Stream<int[]> |
toPartitionedIntStream(int[] ints,
int partitionSize)
Given an array of ints, and a partition size, this method divides the array into a stream of int arrays, each of
whose length is at most
partitionSize. |
public static boolean intAllMatch(int[] ints,
java.util.function.IntPredicate predicate)
IntPredicate, returns a boolean value indicating whether
all values in the array match the predicate.ints - An array of ints to be checked whether the given IntPredicate matches all of its values.predicate - An IntPredicate to match against the values in the input array.public static boolean intAnyMatch(int[] ints,
java.util.function.IntPredicate predicate)
IntPredicate, returns a boolean value indicating whether
any of the values in the array match the predicate.ints - An array of ints to be checked whether the given IntPredicate matches any of its values.predicate - An IntPredicate to match against the values in the input array.public static boolean intNoneMatch(int[] ints,
java.util.function.IntPredicate predicate)
IntPredicate, returns a boolean value indicating whether
none of the values in the array match the predicate.ints - An array of ints to be checked whether the given IntPredicate matches none of its values.predicate - A IntPredicate to match against the values in the input array.public static long intCount(int[] ints,
java.util.function.IntPredicate predicate)
IntPredicate, returns a long value indicating the
number of values in the array that match the predicate.ints - An array of ints to be counted for the number of them that match the given IntPredicate.predicate - An IntPredicate to match against the values in the input array.public static int intMaxDefault(int[] ints,
org.perro.functions.stream.FindIntWithDefault findWithDefault)
IntPredicate along with a default value, this
method returns the maximum int value in the array that matches the predicate, or the default value if no matching
values are found.ints - An array of ints from which to get the maximum value or the default value in the given
findWithDefault object.findWithDefault - An object representing an IntPredicate along with a default value.public static int intMaxDefault(int[] ints,
org.perro.functions.stream.FindIntWithDefaultSupplier findWithDefaultSupplier)
IntPredicate along with a
Supplier for a default value, this method returns the maximum int value in the array that matches
the predicate, or a default value from the supplier if no matching values are found.ints - An array of ints from which to get the maximum value or the default value from the
supplier in the given findWithDefaultSupplier object.findWithDefaultSupplier - An object representing an IntPredicate along with a Supplier of a default value.public static int intMinDefault(int[] ints,
org.perro.functions.stream.FindIntWithDefault findWithDefault)
IntPredicate along with a default value, this
method returns the minimum int value in the array that matches the predicate, or the default value if no matching
values are found.ints - An array of ints from which to get the minimum value or the default value in the given
findWithDefault object.findWithDefault - An object representing an IntPredicate along with a default value.public static int intMinDefault(int[] ints,
org.perro.functions.stream.FindIntWithDefaultSupplier findWithDefaultSupplier)
IntPredicate along with a
Supplier for a default value, this method returns the minimum int value in the array that matches
the predicate, or a default value from the supplier if no matching values are found.ints - An array of ints from which to get the minimum value or the default value from the
supplier in the given findWithDefaultSupplier object.findWithDefaultSupplier - An object representing an IntPredicate along with a Supplier of a default value.public static java.lang.Integer findAnyIntDefaultNull(int[] ints,
java.util.function.IntPredicate predicate)
null
if one is not found. This method does all filtering with a primitive IntStream, boxing the stream
and calling Stream.findAny() only after it has been filtered. Here is a contrived example of how
this method would be called:
{
...
return IntStreamUtils.findAnyIntDefaultNull(intArray, IntPredicateUtils.isIntEqual(2, Function.identity()));
}
Or, with static imports:
{
...
return findAnyIntDefaultNull(intArray, isIntEqual(2, identity()));
}
ints - An array of primitive int values.predicate - A predicate for finding an Integer value.public static int findAnyIntDefault(int[] ints,
org.perro.functions.stream.FindIntWithDefault findWithDefault)
{
...
return IntStreamUtils.findAnyIntDefault(intArray, IntStreamUtils.findIntDefault(IntPredicateUtils.isIntEqual(2, Function.identity()), -1));
}
Or, with static imports:
{
...
return findAnyIntDefault(intArray, findIntDefault(isIntEqual(2, identity()), -1));
}
ints - An array of primitive int values.findWithDefault - An object representing a predicate for finding a value, and a default if one is not found.
Use the findIntDefault(IntPredicate, int) to provide this parameter.public static int findAnyIntDefault(int[] ints,
org.perro.functions.stream.FindIntWithDefaultSupplier findWithDefaultSupplier)
IntSupplier if one is not found. Here is a contrived example of how this method would be
called:
{
...
return IntStreamUtils.findAnyIntDefault(intArray, IntStreamUtils.findIntDefault(
IntPredicateUtils.isIntEqual(2, Function.identity()), -1));
}
Or, with static imports:
{
...
return findAnyIntDefault(intArray, findIntDefault(isIntEqual(2.0D, identity()), -1));
}
ints - An array of primitive int values.findWithDefaultSupplier - An object representing a predicate for finding a value, and a default IntSupplier
if one is not found. Use the
findIntDefault(IntPredicate, IntSupplier) method to provide this
parameter.public static java.lang.Integer findFirstIntDefaultNull(int[] ints,
java.util.function.IntPredicate predicate)
null
if one is not found. This method does all filtering with a primitive IntStream, boxing the stream
and calling Stream.findAny() only after it has been filtered. Here is a contrived example of how
this method would be called:
{
...
return IntStreamUtils.findFirstIntDefaultNull(intArray, IntPredicateUtils.isIntEqual(2, Function.identity()));
}
Or, with static imports:
{
...
return findFirstIntDefaultNull(intArray, isIntEqual(2, identity()));
}
ints - An array of primitive int values.predicate - A predicate for finding an Integer value.public static int findFirstIntDefault(int[] ints,
org.perro.functions.stream.FindIntWithDefault findWithDefault)
{
...
return IntStreamUtils.findFirstIntDefault(intArray, IntStreamUtils.findIntDefault(IntPredicateUtils.isIntEqual(2, Function.identity()), -1));
}
Or, with static imports:
{
...
return findFirstIntDefault(intArray, findIntDefault(isIntEqual(2, identity()), -1));
}
ints - An array of primitive int values.findWithDefault - An object representing a predicate for finding a value, and a default if one is not found.
Use the findIntDefault(IntPredicate, int) method to provide this parameter.public static int findFirstIntDefault(int[] ints,
org.perro.functions.stream.FindIntWithDefaultSupplier findWithDefaultSupplier)
IntSupplier if one is not found. Here is a contrived example of how this method
would be called:
{
...
return IntStreamUtils.findAnyIntDefault(intArray, IntStreamUtils.findIntDefault(
IntPredicateUtils.isIntEqual(2, Function.identity()), -1));
}
Or, with static imports:
{
...
return findAnyIntDefault(intArray, findIntDefault(isIntEqual(2, identity()), -1));
}
ints - An array of primitive int values.findWithDefaultSupplier - An object representing a predicate for finding a value, and a default IntSupplier
if one is not found. Use the
findIntDefault(IntPredicate, IntSupplier) method to provide this
parameter.public static org.perro.functions.stream.FindIntWithDefault findIntDefault(java.util.function.IntPredicate predicate,
int defaultValue)
findAnyIntDefault(int[], FindIntWithDefault) or
findFirstIntDefault(int[], FindIntWithDefaultSupplier) for usage examples.predicate - A predicate used in finding a particular int value.defaultValue - A default int value to return if one could not be found using the above predicate.public static org.perro.functions.stream.FindIntWithDefaultSupplier findIntDefault(java.util.function.IntPredicate predicate,
java.util.function.IntSupplier defaultSupplier)
DoubleSupplier if
one is not found. See findAnyIntDefault(int[], FindIntWithDefault) or
findFirstIntDefault(int[], FindIntWithDefaultSupplier) for usage examples.predicate - A predicate used in finding a particular double value.defaultSupplier - A default DoubleSupplier used to return if one could not be found using the above
predicate.public static int indexOfFirstInt(int[] ints,
java.util.function.IntPredicate predicate)
IntPredicate.ints - Array of primitive int values.predicate - An IntPredicate used to find a matching value.public static java.util.List<int[]> toPartitionedIntList(int[] ints,
int partitionSize)
partitionSize.ints - An array of ints to be partitioned up into a list of int arrays.partitionSize - The maximum length of the individual arrays in the returned list.public static java.util.stream.Stream<int[]> toPartitionedIntStream(int[] ints,
int partitionSize)
partitionSize.ints - An array of ints to be partitioned up into a stream of int arrays.partitionSize - The maximum length of the individual arrays in the returned stream.public static java.util.stream.IntStream defaultIntStream(int[] array)
int values, returns an IntStream of them.array - An array of ints from which to return an IntStream.public static java.util.stream.IntStream defaultIntStream(java.util.stream.IntStream stream)
IntStream returns that stream if it is not null, otherwise returns an empty
IntStream.stream - An input IntStream.public static java.util.stream.IntStream defaultIntStream(java.util.Collection<java.lang.Integer> objects)
Collection of Integer instances, returns an IntStream of them.objects - A Collection of Integer instances.public static java.util.stream.IntStream defaultIntStream(java.util.stream.Stream<java.lang.Integer> stream)
Stream of Integer instances, returns an IntStream from it, or an
empty IntStream if it is null.stream - A Collection of Integer instances.