public class GroovyCollections extends Object
Type Params | Return Type | Name and description |
---|---|---|
|
public static List<List> |
combinations(Object[] collections) Finds all combinations of items from the given collections. |
|
public static List<List> |
combinations(Iterable<?> collections) Finds all combinations of items from the given collections. |
<T> |
public static List<List<T>> |
inits(Iterable<T> collections)
|
<T> |
public static T |
max(T[] items) Selects the maximum value found in an array of items, so max([2, 4, 6] as Object[]) == 6. |
<T> |
public static T |
max(Iterable<T> items) Selects the maximum value found in an Iterable. |
<T> |
public static T |
min(T[] items) Selects the minimum value found in an array of items, so min([2, 4, 6] as Object[]) == 2. |
<T> |
public static T |
min(Iterable<T> items) Selects the minimum value found in an Iterable of items. |
<T> |
public static Set<List<T>> |
subsequences(List<T> items) Finds all non-empty subsequences of a list. |
|
public static Object |
sum(Object[] items) Sums all the items from an array of items. |
|
public static Object |
sum(Iterable<?> items) Sums all the given items. |
<T> |
public static List<List<T>> |
tails(Iterable<T> collections)
|
|
public static List |
transpose(Object[] lists) Transposes an array of lists. |
|
public static List |
transpose(List lists) Transposes the given lists. |
<T> |
public static List<T> |
union(Iterable<T> iterables) Returns an ordered set of all the unique items found in the provided argument iterables. |
<T> |
public static List<T> |
union(List<Iterable<T>> iterables) Returns an ordered set of all the unique items found in the provided argument iterables. |
<T> |
public static 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. |
<T> |
public static 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. |
<T> |
public static List<T> |
union(Closure condition, Iterable<T> iterables) Returns an ordered set of all the unique items found in the provided argument iterables using the provided closure to compare items. |
<T> |
public static List<T> |
union(List<Iterable<T>> iterables, Closure condition) Returns an ordered set of all the unique items found in the provided argument iterables using the provided closure to compare items. |
Finds all combinations of items from the given collections.
collections
- the given collections Finds all combinations of items from the given collections.
So, combinations([[true, false], [true, false]])
is [[true, true], [false, true], [true, false], [false, false]]
and combinations([['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.
collections
- the Iterable of given collectionsSelects the maximum value found in an array of items, so max([2, 4, 6] as Object[]) == 6.
items
- an array of itemsSelects the maximum value found in an Iterable.
items
- a CollectionSelects the minimum value found in an array of items, so min([2, 4, 6] as Object[]) == 2.
items
- an array of itemsSelects the minimum value found in an Iterable of items.
items
- an Iterable Finds all non-empty subsequences of a list.
E.g. subsequences([1, 2, 3])
would be:
[[1, 2, 3], [1, 3], [2, 3], [1, 2], [1], [2], [3]]
items
- the List of itemsSums all the items from an array of items.
items
- an array of itemsSums all the given items.
items
- an Iterable of itemsTransposes an array of lists.
lists
- the given lists Transposes the given lists.
So, transpose([['a', 'b'], [1, 2]])
is [['a', 1], ['b', 2]]
and
transpose([['a', 'b', 'c']])
is [['a'], ['b'], ['c']]
.
lists
- the given listsReturns 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]
iterables
- the sources of itemsReturns 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]
iterables
- the list of source itemsReturns 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']
comparator
- a Comparatoriterables
- the sources of itemsReturns 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']
iterables
- the list of source itemscomparator
- a ComparatorReturns 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]
condition
- a Closure used to determine unique itemsiterables
- the sources of itemsReturns 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]
iterables
- the list of source itemscondition
- a Closure used to determine unique items