public class GroovyCollections
extends java.lang.Object
Constructor and Description |
---|
GroovyCollections() |
Modifier and Type | Method and Description |
---|---|
static java.util.List |
combinations(java.util.Collection collections)
Finds all combinations of items from the given collections.
|
static java.util.List |
combinations(java.lang.Object[] collections)
Finds all combinations of items from the given collections.
|
static <T> T |
max(java.util.Collection<T> items)
Selects the maximum value found in a collection
|
static <T> T |
max(T[] items)
Selects the maximum value found in an array of items, so
min([2, 4, 6] as Object[]) == 6.
|
static <T> T |
min(java.util.Collection<T> items)
Selects the minimum value found in a collection of items.
|
static <T> T |
min(T[] items)
Selects the minimum value found in an array of items, so
min([2, 4, 6] as Object[]) == 2.
|
static <T> java.util.Set<java.util.List<T>> |
subsequences(java.util.List<T> items)
Finds all non-null subsequences of a list.
|
static java.lang.Object |
sum(java.util.Collection items)
Sums all the items from a collection of items.
|
static java.lang.Object |
sum(java.lang.Object[] items)
Sums all the items from an array of items.
|
static java.util.List |
transpose(java.util.List lists)
Transposes the given lists.
|
static java.util.List |
transpose(java.lang.Object[] lists)
Transposes an array of lists.
|
public static java.util.List combinations(java.lang.Object[] collections)
collections
- the given collectionscombinations(Collection)
public static <T> java.util.Set<java.util.List<T>> subsequences(java.util.List<T> items)
subsequences([1, 2, 3])
would be:
[[1, 2, 3], [1, 3], [2, 3], [1, 2], [1], [2], [3]]items
- the List of itemspublic static java.util.List combinations(java.util.Collection collections)
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']]
.collections
- the given collectionspublic static java.util.List transpose(java.lang.Object[] lists)
lists
- the given liststranspose(List)
public static java.util.List transpose(java.util.List lists)
transpose([['a', 'b'], [1, 2]])
is [['a', 1], ['b', 2]]
and
transpose([['a', 'b', 'c']])
is [['a'], ['b'], ['c']]
.lists
- the given listspublic static <T> T min(T[] items)
items
- an array of itemspublic static <T> T min(java.util.Collection<T> items)
items
- a Collectionpublic static <T> T max(T[] items)
items
- an array of itemspublic static <T> T max(java.util.Collection<T> items)
items
- a Collectionpublic static java.lang.Object sum(java.lang.Object[] items)
items
- an array of itemspublic static java.lang.Object sum(java.util.Collection items)
items
- a collection of items