public final class LongStreamUtils
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static java.util.stream.LongStream |
defaultLongStream(java.util.Collection<java.lang.Long> objects)
Given a
Collection of Long instances, returns a LongStream of them. |
static java.util.stream.LongStream |
defaultLongStream(long[] array)
Given an array of
long values, returns a LongStream of them. |
static java.util.stream.LongStream |
defaultLongStream(java.util.stream.LongStream stream)
Given a
LongStream returns that stream if it is not null, otherwise returns an empty
LongStream. |
static java.util.stream.LongStream |
defaultLongStream(java.util.stream.Stream<java.lang.Long> stream)
Given a
Stream of Long instances, returns a LongStream from it, or an
empty LongStream if it is null. |
static long |
findAnyLongDefault(long[] longs,
org.perro.functions.stream.FindLongWithDefault findWithDefault)
Attempt to find any matching long value in an array of longs using a predicate, returning a default value if
one is not found.
|
static long |
findAnyLongDefault(long[] longs,
org.perro.functions.stream.FindLongWithDefaultSupplier findWithDefaultSupplier)
Attempt to find any matching long value in an array of longs using a predicate, returning a default value
retrieved using a
LongSupplier if one is not found. |
static java.lang.Long |
findAnyLongDefaultNull(long[] longs,
java.util.function.LongPredicate predicate)
Attempt to find any matching long value in an array of longs using a predicate, returning
null
if one is not found. |
static long |
findFirstLongDefault(long[] longs,
org.perro.functions.stream.FindLongWithDefault findWithDefault)
Attempt to find the first matching long value in an array of longs using a predicate, returning a default value
if one is not found.
|
static long |
findFirstLongDefault(long[] longs,
org.perro.functions.stream.FindLongWithDefaultSupplier findWithDefaultSupplier)
Attempt to find the first matching long value in an array of longs using a predicate, returning a default value
retrieved using a
LongSupplier if one is not found. |
static java.lang.Long |
findFirstLongDefaultNull(long[] longs,
java.util.function.LongPredicate predicate)
Attempt to find the first matching long value in an array of longs using a predicate, returning
null
if one is not found. |
static org.perro.functions.stream.FindLongWithDefault |
findLongDefault(java.util.function.LongPredicate predicate,
long defaultValue)
Retrieves an object representing a predicate for finding a value, and a default long value if one is not found.
|
static org.perro.functions.stream.FindLongWithDefaultSupplier |
findLongDefaultSupplier(java.util.function.LongPredicate predicate,
java.util.function.LongSupplier defaultSupplier)
Retrieves an object representing a predicate for finding a value, and a default
LongSupplier if one
is not found. |
static long |
indexOfFirstLong(long[] longs,
java.util.function.LongPredicate predicate)
Finds the index of the first long in an array that matches a
LongPredicate. |
static boolean |
longAllMatch(long[] longs,
java.util.function.LongPredicate predicate)
Given an array of longs and a
LongPredicate, returns a boolean value indicating whether
all values in the array match the predicate. |
static boolean |
longAnyMatch(long[] longs,
java.util.function.LongPredicate predicate)
Given an array of longs and a
LongPredicate, returns a boolean value indicating whether
any of the values in the array match the predicate. |
static long |
longCount(long[] longs,
java.util.function.LongPredicate predicate)
Given an array of longs and a
LongPredicate, returns a long value indicating the
number of values in the array that match the predicate. |
static long |
longMaxDefault(long[] longs,
org.perro.functions.stream.FindLongWithDefault findWithDefault)
Given an array of longs, and an object representing a
LongPredicate along with a default value,
this method returns the maximum long value in the array that matches the predicate, or the default value if no
matching values are found. |
static long |
longMaxDefault(long[] longs,
org.perro.functions.stream.FindLongWithDefaultSupplier findWithDefaultSupplier)
Given an array of longs, and an object representing a
LongPredicate along with a
Supplier for a default value, this method returns the maximum long value in the array that matches
the predicate, or a default value from the supplier if no matching values are found. |
static long |
longMinDefault(long[] longs,
org.perro.functions.stream.FindLongWithDefault findWithDefault)
Given an array of longs, and an object representing a
LongPredicate along with a default value, this
method returns the minimum long value in the array that matches the predicate, or the default value if no
matching values are found. |
static long |
longMinDefault(long[] longs,
org.perro.functions.stream.FindLongWithDefaultSupplier findWithDefaultSupplier)
Given an array of longs, and an object representing a
LongPredicate along with a
Supplier for a default value, this method returns the minimum long value in the array that matches
the predicate, or a default value from the supplier if no matching values are found. |
static boolean |
longNoneMatch(long[] longs,
java.util.function.LongPredicate predicate)
Given an array of longs and a
LongPredicate, returns a boolean value indicating whether
none of the values in the array match the predicate. |
static java.util.List<long[]> |
toPartitionedLongList(long[] longs,
int partitionSize)
Given an array of longs, and a partition size, this method divides the array into a list of long arrays, each of
whose length is at most
partitionSize. |
static java.util.stream.Stream<long[]> |
toPartitionedLongStream(long[] longs,
int partitionSize)
Given an array of longs, and a partition size, this method divides the array into a stream of long arrays, each
of whose length is at most
partitionSize. |
public static boolean longAllMatch(long[] longs,
java.util.function.LongPredicate predicate)
LongPredicate, returns a boolean value indicating whether
all values in the array match the predicate.longs - An array of longs to be checked whether the given LongPredicate matches all of its values.predicate - A LongPredicate to match against the values in the input array.public static boolean longAnyMatch(long[] longs,
java.util.function.LongPredicate predicate)
LongPredicate, returns a boolean value indicating whether
any of the values in the array match the predicate.longs - An array of longs to be checked whether the given LongPredicate matches any of its values.predicate - A LongPredicate to match against the values in the input array.public static boolean longNoneMatch(long[] longs,
java.util.function.LongPredicate predicate)
LongPredicate, returns a boolean value indicating whether
none of the values in the array match the predicate.longs - An array of longs to be checked whether the given LongPredicate matches none of its values.predicate - A LongPredicate to match against the values in the input array.public static long longCount(long[] longs,
java.util.function.LongPredicate predicate)
LongPredicate, returns a long value indicating the
number of values in the array that match the predicate.longs - An array of longs to be counted for the number of them that match the given LongPredicate.predicate - A LongPredicate to match against the values in the input array.public static long longMaxDefault(long[] longs,
org.perro.functions.stream.FindLongWithDefault findWithDefault)
LongPredicate along with a default value,
this method returns the maximum long value in the array that matches the predicate, or the default value if no
matching values are found.longs - An array of longs from which to get the maximum value or the default value in the given
findWithDefault object.findWithDefault - An object representing a LongPredicate along with a default value.public static long longMaxDefault(long[] longs,
org.perro.functions.stream.FindLongWithDefaultSupplier findWithDefaultSupplier)
LongPredicate along with a
Supplier for a default value, this method returns the maximum long value in the array that matches
the predicate, or a default value from the supplier if no matching values are found.longs - An array of longs from which to get the maximum value or the default value from
the supplier in the given findWithDefaultSupplier object.findWithDefaultSupplier - An object representing a LongPredicate along with a Supplier of a default value.public static long longMinDefault(long[] longs,
org.perro.functions.stream.FindLongWithDefault findWithDefault)
LongPredicate along with a default value, this
method returns the minimum long value in the array that matches the predicate, or the default value if no
matching values are found.longs - An array of longs from which to get the minimum value or the default value in the given
findWithDefault object.findWithDefault - An object representing a LongPredicate along with a default value.public static long longMinDefault(long[] longs,
org.perro.functions.stream.FindLongWithDefaultSupplier findWithDefaultSupplier)
LongPredicate along with a
Supplier for a default value, this method returns the minimum long value in the array that matches
the predicate, or a default value from the supplier if no matching values are found.longs - An array of longs from which to get the minimum value or the default value from
the supplier in the given findWithDefaultSupplier object.findWithDefaultSupplier - An object representing a LongPredicate along with a Supplier of a default value.public static java.lang.Long findAnyLongDefaultNull(long[] longs,
java.util.function.LongPredicate predicate)
null
if one is not found. This method does all filtering with a primitive LongStream, 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 LongStreamUtils.findAnyLongDefaultNull(longArray, LongPredicateUtils.isLongEqual(2L, Function.identity()));
}
Or, with static imports:
{
...
return findAnyLongDefaultNull(longArray, isLongEqual(2L, identity()));
}
longs - An array of primitive long values.predicate - A predicate for finding a Long value.public static long findAnyLongDefault(long[] longs,
org.perro.functions.stream.FindLongWithDefault findWithDefault)
{
...
return LongStreamUtils.findAnyLongDefault(longArray, LongStreamUtils.findLongDefault(LongPredicateUtils.isLongEqual(2L, Function.identity()), -1L));
}
Or, with static imports:
{
...
return findAnyLongDefault(longArray, findLongDefault(isLongEqual(2L, identity()), -1L));
}
longs - An array of primitive long values.findWithDefault - An object representing a predicate for finding a value, and a default if one is not found.
Use the findLongDefault(LongPredicate, long) to provide this parameter.public static long findAnyLongDefault(long[] longs,
org.perro.functions.stream.FindLongWithDefaultSupplier findWithDefaultSupplier)
LongSupplier if one is not found. Here is a contrived example of how this method
would be called:
{
...
return LongStreamUtils.findAnyLongDefault(longArray, LongStreamUtils.findLongDefaultSupplier(
LongPredicateUtils.isLongEqual(2L, Function.identity()), -1L));
}
Or, with static imports:
{
...
return findAnyLongDefault(longArray, findLongDefaultSupplier(isLongEqual(2L, identity()), -1L));
}
longs - An array of primitive long values.findWithDefaultSupplier - An object representing a predicate for finding a value, and a default
LongSupplier if one is not found. Use the
findLongDefaultSupplier(LongPredicate, LongSupplier) method to provide
this parameter.public static java.lang.Long findFirstLongDefaultNull(long[] longs,
java.util.function.LongPredicate predicate)
null
if one is not found. This method does all filtering with a primitive LongStream, 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 LongStreamUtils.findFirstLongDefaultNull(longArray, LongPredicateUtils.isLongEqual(2L, Function.identity()));
}
Or, with static imports:
{
...
return findFirstLongDefaultNull(longArray, isLongEqual(2, identity()));
}
longs - An array of primitive long values.predicate - A predicate for finding a Long value.public static long findFirstLongDefault(long[] longs,
org.perro.functions.stream.FindLongWithDefault findWithDefault)
{
...
return LongStreamUtils.findFirstLongDefault(longArray, LongStreamUtils.findLongDefault(LongPredicateUtils.isLongEqual(2L, Function.identity()), -1L));
}
Or, with static imports:
{
...
return findFirstLongDefault(longArray, findLongDefault(isLongEqual(2L, identity()), -1L));
}
longs - An array of primitive long values.findWithDefault - An object representing a predicate for finding a value, and a default if one is not found.
Use the findLongDefault(LongPredicate, long) to provide this parameter.public static long findFirstLongDefault(long[] longs,
org.perro.functions.stream.FindLongWithDefaultSupplier findWithDefaultSupplier)
LongSupplier if one is not found. Here is a contrived example of how this method
would be called:
{
...
return LongStreamUtils.findAnyLongDefault(longArray, LongStreamUtils.findLongDefaultSupplier(
LongPredicateUtils.isLongEqual(2L, Function.identity()), -1L));
}
Or, with static imports:
{
...
return findAnyLongDefault(longArray, findLongDefaultSupplier(isLongEqual(2L, identity()), -1L));
}
longs - An array of primitive long values.findWithDefaultSupplier - An object representing a predicate for finding a value, and a default LongSupplier
if one is not found. Use the
findLongDefaultSupplier(LongPredicate, LongSupplier) method to provide
this parameter.public static org.perro.functions.stream.FindLongWithDefault findLongDefault(java.util.function.LongPredicate predicate,
long defaultValue)
findAnyLongDefault(long[], FindLongWithDefault) or
findFirstLongDefault(long[], FindLongWithDefault) for usage examples.predicate - A predicate used in finding a particular long value.defaultValue - A default long value to return if one could not be found using the above predicate.public static org.perro.functions.stream.FindLongWithDefaultSupplier findLongDefaultSupplier(java.util.function.LongPredicate predicate,
java.util.function.LongSupplier defaultSupplier)
LongSupplier if one
is not found. See findAnyLongDefault(long[], FindLongWithDefaultSupplier) or
findFirstLongDefault(long[], FindLongWithDefaultSupplier) for usage examples.predicate - A predicate used in finding a particular long value.defaultSupplier - A default LongSupplier used to return if one could not be found using the above predicate.public static long indexOfFirstLong(long[] longs,
java.util.function.LongPredicate predicate)
LongPredicate.longs - Array of primitive long values.predicate - A LongPredicate used to find a matching value.public static java.util.List<long[]> toPartitionedLongList(long[] longs,
int partitionSize)
partitionSize.longs - An array of longs to be partitioned up into a list of long arrays.partitionSize - The maximum length of the individual arrays in the returned list.public static java.util.stream.Stream<long[]> toPartitionedLongStream(long[] longs,
int partitionSize)
partitionSize.longs - An array of longs to be partitioned up into a stream of long arrays.partitionSize - The maximum length of the individual arrays in the returned stream.public static java.util.stream.LongStream defaultLongStream(long[] array)
long values, returns a LongStream of them.array - An array of longs from which to return a LongStream.public static java.util.stream.LongStream defaultLongStream(java.util.stream.LongStream stream)
LongStream returns that stream if it is not null, otherwise returns an empty
LongStream.stream - An input LongStream.public static java.util.stream.LongStream defaultLongStream(java.util.Collection<java.lang.Long> objects)
Collection of Long instances, returns a LongStream of them.objects - A Collection of Long instances.public static java.util.stream.LongStream defaultLongStream(java.util.stream.Stream<java.lang.Long> stream)
Stream of Long instances, returns a LongStream from it, or an
empty LongStream if it is null.stream - A Collection of Long instances.