Package groovy.util
Class GroovyCollections
java.lang.Object
groovy.util.GroovyCollections
A Collections utility class
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic 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 <T> TSelects the maximum value found in an Iterable.static <T> Tmax(T[] items) Selects the maximum value found in an array of items, so max([2, 4, 6] as Object[]) == 6.static <T> TSelects the minimum value found in an Iterable 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 given items.static ObjectSums all the items from an array of items.static ListTransposes an array of lists.static ListTransposes the given lists.static <T> List<T>Returns an ordered set of all the unique items found in the provided argument iterables using the provided closure to compare items.static <T> List<T>Returns an ordered set of all the unique items found in the provided argument iterables.static <T> List<T>union(Comparator<T> comparator, Iterable<T>... iterables) Returns an ordered set of all the unique items found in the provided argument iterables using the provided comparator to compare items.static <T> List<T>Returns an ordered set of all the unique items found in the provided argument iterables.static <T> List<T>Returns an ordered set of all the unique items found in the provided argument iterables using the provided closure to compare items.static <T> List<T>union(List<Iterable<T>> iterables, Comparator<T> comparator) Returns an ordered set of all the unique items found in the provided argument iterables using the provided comparator to compare items.
- 
Constructor Details- 
GroovyCollectionspublic GroovyCollections()
 
- 
- 
Method Details- 
combinationsFinds all combinations of items from the given collections.- Parameters:
- collections- the given collections
- Returns:
- a List of the combinations found
- See Also:
 
- 
subsequencesFinds 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
 
- 
combinationsFinds 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
 
- 
inits
- 
tails
- 
transposeTransposes an array of lists.- Parameters:
- lists- the given lists
- Returns:
- a List of the transposed lists
- See Also:
 
- 
transposeTransposes 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
 
- 
minpublic 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
 
- 
minSelects the minimum value found in an Iterable of items.- Parameters:
- items- an Iterable
- Returns:
- the minimum value
- Since:
- 2.2.0
 
- 
maxpublic static <T> T max(T[] items) Selects the maximum value found in an array of items, so max([2, 4, 6] as Object[]) == 6.- Parameters:
- items- an array of items
- Returns:
- the maximum value
 
- 
maxSelects the maximum value found in an Iterable.- Parameters:
- items- a Collection
- Returns:
- the maximum value
- Since:
- 2.2.0
 
- 
sumSums all the items from an array of items.- Parameters:
- items- an array of items
- Returns:
- the sum of the items
 
- 
sumSums all the given items.- Parameters:
- items- an Iterable of items
- Returns:
- the sum of the item
- Since:
- 2.2.0
 
- 
unionReturns an ordered set of all the unique items found in the provided argument iterables.assert GroovyCollections.union([1, 2], [2, 3], [1, 4]) == [1, 2, 3, 4] - Parameters:
- iterables- the sources of items
- Returns:
- the ordered list of unique values found
- Since:
- 4.0.0
 
- 
unionReturns an ordered set of all the unique items found in the provided argument iterables.assert GroovyCollections.union([[1, 2], [2, 3], [1, 4]]) == [1, 2, 3, 4] - Parameters:
- iterables- the list of source items
- Returns:
- the ordered list of unique values found
- Since:
- 4.0.0
 
- 
unionReturns an ordered set of all the unique items found in the provided argument iterables using the provided comparator to compare items.assert GroovyCollections.union(n -> n.abs(), [1, 2, 5], [-3, -4, -5], [4, 6]) == [1, 2, 5, -3, -4, 6] assert GroovyCollections.union(n -> n.trunc(), [1.1, 2.2], [2.5, 3.3], [3.9, 4.1]) == [1.1, 2.2, 3.3, 4.1] assert GroovyCollections.union(w -> w.toUpperCase(), ['a', 'A'], ['B', 'a', 'c', 'b']) == ['a', 'B', 'c'] - Parameters:
- comparator- a Comparator
- iterables- the sources of items
- Returns:
- the ordered list of unique values found
- Since:
- 4.0.0
 
- 
unionReturns an ordered set of all the unique items found in the provided argument iterables using the provided comparator to compare items.assert GroovyCollections.union([[1, 2, 5], [-3, -4, -5], [4, 6]], n -> n.abs()) == [1, 2, 5, -3, -4, 6] assert GroovyCollections.union([[1.1, 2.2], [2.5, 3.3], [3.9, 4.1]], n -> n.trunc()) == [1.1, 2.2, 3.3, 4.1] assert GroovyCollections.union([['a', 'A'], ['B', 'a', 'c', 'b']], w -> w.toUpperCase()) == ['a', 'B', 'c'] - Parameters:
- iterables- the list of source items
- comparator- a Comparator
- Returns:
- the ordered list of unique values found
- Since:
- 4.0.0
 
- 
unionReturns an ordered set of all the unique items found in the provided argument iterables using the provided closure to compare items.def abs = { n -> n.abs() } assert GroovyCollections.union(abs, [1, 2, 5], [-3, -4, -5], [4, 6]) == [1, 2, 5, -3, -4, 6]- Parameters:
- condition- a Closure used to determine unique items
- iterables- the sources of items
- Returns:
- the ordered list of unique values found
- Since:
- 4.0.0
 
- 
unionReturns an ordered set of all the unique items found in the provided argument iterables using the provided closure to compare items.assert GroovyCollections.union([[1, 2, 5], [-3, -4, -5], [4, 6]]){ n -> n.abs() } == [1, 2, 5, -3, -4, 6]- Parameters:
- iterables- the list of source items
- condition- a Closure used to determine unique items
- Returns:
- the ordered list of unique values found
- Since:
- 4.0.0
 
 
-