Class GroovyCollections
java.lang.Object
groovy.util.GroovyCollections
A Collections utility class
- Author:
- Paul King, Jim White
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Listcombinations(Object[] collections) Finds all combinations of items from the given collections.static Listcombinations(Collection collections) Finds all combinations of items from the given collections.static <T> Tmax(Collection<T> items) Selects the maximum value found in a collectionstatic <T> Tmax(T[] items) Selects the maximum value found in an array of items, so min([2, 4, 6] as Object[]) == 6.static <T> Tmin(Collection<T> items) Selects the minimum value found in a collection of items.static <T> Tmin(T[] items) Selects the minimum value found in an array of items, so min([2, 4, 6] as Object[]) == 2.subsequences(List<T> items) Finds all non-null subsequences of a list.static ObjectSums all the items from an array of items.static Objectsum(Collection items) Sums all the items from a collection of items.static ListTransposes an array of lists.static ListTransposes the given lists.
-
Constructor Details
-
GroovyCollections
public GroovyCollections()
-
-
Method Details
-
combinations
-
subsequences
-
combinations
Finds all combinations of items from the given collections. So,combinations([[true, false], [true, false]])is[[true, true], [false, true], [true, false], [false, false]]andcombinations([['a', 'b'],[1, 2, 3]])is[['a', 1], ['b', 1], ['a', 2], ['b', 2], ['a', 3], ['b', 3]]. If a non-collection item is given, it is treated as a singleton collection, i.e.combinations([[1, 2], 'x'])is[[1, 'x'], [2, 'x']].- Parameters:
collections- the given collections- Returns:
- a List of the combinations found
-
transpose
-
transpose
-
min
public static <T> T min(T[] items) Selects the minimum value found in an array of items, so min([2, 4, 6] as Object[]) == 2.- Parameters:
items- an array of items- Returns:
- the minimum value
-
min
Selects the minimum value found in a collection of items.- Parameters:
items- a Collection- Returns:
- the minimum value
-
max
public static <T> T max(T[] items) Selects the maximum value found in an array of items, so min([2, 4, 6] as Object[]) == 6.- Parameters:
items- an array of items- Returns:
- the maximum value
-
max
Selects the maximum value found in a collection- Parameters:
items- a Collection- Returns:
- the maximum value
-
sum
-
sum
Sums all the items from a collection of items.- Parameters:
items- a collection of items- Returns:
- the sum of the items
-