Package groovy.util
Class GroovyCollections
- java.lang.Object
-
- groovy.util.GroovyCollections
-
public class GroovyCollections extends Object
A Collections utility class
-
-
Constructor Summary
Constructors Constructor Description GroovyCollections()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static Listcombinations(Iterable collections)Finds all combinations of items from the given Iterable aggregate of collections.static Listcombinations(Object[] collections)Finds all combinations of items from the given collections.static Listcombinations(Collection collections)Deprecated.use combinations(Iterable)static <T> List<List<T>>inits(Iterable<T> collections)static <T> Tmax(Iterable<T> items)Selects the maximum value found in an Iterable.static <T> Tmax(Collection<T> items)Deprecated.use max(Iterable)static <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(Iterable<T> items)Selects the minimum value found in an Iterable of items.static <T> Tmin(Collection<T> items)Deprecated.use min(Iterable)static <T> Tmin(T[] items)Selects the minimum value found in an array of items, so min([2, 4, 6] as Object[]) == 2.static <T> Set<List<T>>subsequences(List<T> items)Finds all non-null subsequences of a list.static Objectsum(Iterable items)Sums all the given items.static Objectsum(Object[] items)Sums all the items from an array of items.static Objectsum(Collection items)Deprecated.use sum(Iterable)static <T> List<List<T>>tails(Iterable<T> collections)static Listtranspose(Object[] lists)Transposes an array of lists.static Listtranspose(List lists)Transposes the given lists.
-
-
-
Method Detail
-
combinations
public static List combinations(Object[] collections)
Finds all combinations of items from the given collections.- Parameters:
collections- the given collections- Returns:
- a List of the combinations found
- See Also:
combinations(Collection)
-
subsequences
public static <T> Set<List<T>> subsequences(List<T> items)
Finds all non-null subsequences of a list. E.g.subsequences([1, 2, 3])would be: [[1, 2, 3], [1, 3], [2, 3], [1, 2], [1], [2], [3]]- Parameters:
items- the List of items- Returns:
- the subsequences from items
-
combinations
@Deprecated public static List combinations(Collection collections)
Deprecated.use combinations(Iterable)- Parameters:
collections- the given collections
-
combinations
public static List combinations(Iterable collections)
Finds all combinations of items from the given Iterable aggregate of 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']]. If an empty collection is found within the given collections, the result will be an empty list.- Parameters:
collections- the Iterable of given collections- Returns:
- a List of the combinations found
- Since:
- 2.2.0
-
transpose
public static List transpose(Object[] lists)
Transposes an array of lists.- Parameters:
lists- the given lists- Returns:
- a List of the transposed lists
- See Also:
transpose(List)
-
transpose
public static List transpose(List lists)
Transposes the given lists. So,transpose([['a', 'b'], [1, 2]])is[['a', 1], ['b', 2]]andtranspose([['a', 'b', 'c']])is[['a'], ['b'], ['c']].- Parameters:
lists- the given lists- Returns:
- a List of the transposed lists
-
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
@Deprecated public static <T> T min(Collection<T> items)
Deprecated.use min(Iterable)
-
min
public static <T> T min(Iterable<T> items)
Selects the minimum value found in an Iterable of items.- Parameters:
items- an Iterable- Returns:
- the minimum value
- Since:
- 2.2.0
-
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
@Deprecated public static <T> T max(Collection<T> items)
Deprecated.use max(Iterable)
-
max
public static <T> T max(Iterable<T> items)
Selects the maximum value found in an Iterable.- Parameters:
items- a Collection- Returns:
- the maximum value
- Since:
- 2.2.0
-
sum
public static Object sum(Object[] items)
Sums all the items from an array of items.- Parameters:
items- an array of items- Returns:
- the sum of the items
-
sum
@Deprecated public static Object sum(Collection items)
Deprecated.use sum(Iterable)
-
-