public final class CollectionsUtil extends Object
Modifier and Type | Method and Description |
---|---|
static <T> boolean |
allMatch(Iterable<T> inputs,
Predicate<T> predicate)
Returns whether all elements in
inputs match predicate . |
static <T> boolean |
allMatch(T[] inputs,
Predicate<T> predicate)
Returns whether all elements in
inputs match predicate . |
static <T> boolean |
anyMatch(Iterable<T> inputs,
Predicate<T> predicate)
Returns whether any elements in
inputs match predicate . |
static <T> boolean |
anyMatch(T[] inputs,
Predicate<T> predicate)
Returns whether any elements in
inputs match predicate . |
static <T> Iterable<T> |
concat(Iterable<T> a,
Iterable<T> b)
Concatenates two iterables into a single iterable.
|
static <T> Iterable<T> |
concat(List<Iterable<T>> iterables)
Concatenates multiple iterables into a single iterable.
|
static <T,R> R[] |
filterAndMapToArray(T[] inputs,
Predicate<? super T> predicate,
Function<? super T,? extends R> mapper,
IntFunction<R[]> arrayGenerator)
Filters
inputs with predicate , applies mapper and adds them in the
array provided by arrayGenerator . |
static <T> List<T> |
filterToList(List<T> inputs,
Predicate<? super T> predicate)
Returns a new list consisting of the elements in
inputs that match predicate . |
static <T> List<T> |
filterToList(List<T> inputs,
Predicate<? super T> predicate,
Supplier<List<T>> listGenerator)
Appends elements of
inputs that match predicate to the list generated by
listGenerator . |
static <T,R> String |
mapAndJoin(Iterable<T> inputs,
Function<? super T,? extends R> mapper,
String delimiter)
Applies
mapper on the elements in inputs , and joins them together separated
by delimiter . |
static <T,R> String |
mapAndJoin(Iterable<T> inputs,
Function<? super T,? extends R> mapper,
String delimiter,
String prefix)
Applies
mapper on the elements in inputs , and joins them together separated
by delimiter and starting with prefix . |
static <T,R> String |
mapAndJoin(Iterable<T> inputs,
Function<? super T,? extends R> mapper,
String delimiter,
String prefix,
String suffix)
Applies
mapper on the elements in inputs , and joins them together separated
by delimiter and starting with prefix and ending with suffix . |
static <T,R> String |
mapAndJoin(T[] inputs,
Function<? super T,? extends R> mapper,
String delimiter)
Applies
mapper on the elements in inputs , and joins them together separated
by delimiter . |
static <T,R> String |
mapAndJoin(T[] inputs,
Function<? super T,? extends R> mapper,
String delimiter,
String prefix)
Applies
mapper on the elements in inputs , and joins them together separated
by delimiter and starting with prefix . |
static <T,R> String |
mapAndJoin(T[] inputs,
Function<? super T,? extends R> mapper,
String delimiter,
String prefix,
String suffix)
Applies
mapper on the elements in inputs , and joins them together separated
by delimiter and starting with prefix and ending with suffix . |
static <T,R> R[] |
mapToArray(Collection<T> inputs,
Function<? super T,? extends R> mapper,
IntFunction<R[]> arrayGenerator)
Applies
mapper on the elements in inputs and adds them in the array provided
by arrayGenerator . |
static <T,R> R[] |
mapToArray(T[] inputs,
Function<? super T,? extends R> mapper,
IntFunction<R[]> arrayGenerator)
Applies
mapper on the elements in inputs and adds them in the array provided
by arrayGenerator . |
public static <T> Iterable<T> concat(Iterable<T> a, Iterable<T> b)
Iterator.remove()
even if the input iterables do.NullPointerException
- if a
or b
is null
public static <T> Iterable<T> concat(List<Iterable<T>> iterables)
Iterator.remove()
even if the input iterables do.NullPointerException
- if iterables
or any of its elements are null
public static <T> boolean allMatch(T[] inputs, Predicate<T> predicate)
inputs
match predicate
. May not evaluate
predicate
on all elements if not necessary for determining the result. If
inputs
is empty then true
is returned and predicate
is not evaluated.true
if either all elements in inputs
match predicate
or
inputs
is empty, otherwise false
.public static <T> boolean allMatch(Iterable<T> inputs, Predicate<T> predicate)
inputs
match predicate
. May not evaluate
predicate
on all elements if not necessary for determining the result. If
inputs
is empty then true
is returned and predicate
is not evaluated.true
if either all elements in inputs
match predicate
or
inputs
is empty, otherwise false
.public static <T> boolean anyMatch(T[] inputs, Predicate<T> predicate)
inputs
match predicate
. May not evaluate
predicate
on all elements if not necessary for determining the result. If
inputs
is empty then false
is returned and predicate
is not
evaluated.true
if any elements in inputs
match predicate
, otherwise
false
.public static <T> boolean anyMatch(Iterable<T> inputs, Predicate<T> predicate)
inputs
match predicate
. May not evaluate
predicate
on all elements if not necessary for determining the result. If
inputs
is empty then false
is returned and predicate
is not
evaluated.true
if any elements in inputs
match predicate
, otherwise
false
.public static <T> List<T> filterToList(List<T> inputs, Predicate<? super T> predicate)
inputs
that match predicate
.public static <T> List<T> filterToList(List<T> inputs, Predicate<? super T> predicate, Supplier<List<T>> listGenerator)
inputs
that match predicate
to the list generated by
listGenerator
.listGenerator
.public static <T,R> R[] filterAndMapToArray(T[] inputs, Predicate<? super T> predicate, Function<? super T,? extends R> mapper, IntFunction<R[]> arrayGenerator)
inputs
with predicate
, applies mapper
and adds them in the
array provided by arrayGenerator
.arrayGenerator
.public static <T,R> R[] mapToArray(T[] inputs, Function<? super T,? extends R> mapper, IntFunction<R[]> arrayGenerator)
mapper
on the elements in inputs
and adds them in the array provided
by arrayGenerator
.arrayGenerator
.public static <T,R> R[] mapToArray(Collection<T> inputs, Function<? super T,? extends R> mapper, IntFunction<R[]> arrayGenerator)
mapper
on the elements in inputs
and adds them in the array provided
by arrayGenerator
.arrayGenerator
.public static <T,R> String mapAndJoin(T[] inputs, Function<? super T,? extends R> mapper, String delimiter)
mapper
on the elements in inputs
, and joins them together separated
by delimiter
.inputs
.public static <T,R> String mapAndJoin(T[] inputs, Function<? super T,? extends R> mapper, String delimiter, String prefix)
mapper
on the elements in inputs
, and joins them together separated
by delimiter
and starting with prefix
.inputs
.public static <T,R> String mapAndJoin(T[] inputs, Function<? super T,? extends R> mapper, String delimiter, String prefix, String suffix)
mapper
on the elements in inputs
, and joins them together separated
by delimiter
and starting with prefix
and ending with suffix
.inputs
.public static <T,R> String mapAndJoin(Iterable<T> inputs, Function<? super T,? extends R> mapper, String delimiter)
mapper
on the elements in inputs
, and joins them together separated
by delimiter
.inputs
.public static <T,R> String mapAndJoin(Iterable<T> inputs, Function<? super T,? extends R> mapper, String delimiter, String prefix)
mapper
on the elements in inputs
, and joins them together separated
by delimiter
and starting with prefix
.inputs
.public static <T,R> String mapAndJoin(Iterable<T> inputs, Function<? super T,? extends R> mapper, String delimiter, String prefix, String suffix)
mapper
on the elements in inputs
, and joins them together separated
by delimiter
and starting with prefix
and ending with suffix
.inputs
.