Top Description Constructors Methods
groovy.util

public Class GroovyCollections

extends Object
Class Inheritance
Imports
org.codehaus.groovy.runtime.DefaultGroovyMethods, org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation, java.util.ArrayList, .Arrays, .Collection, .HashSet, .List, .Set

A Collections utility class

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static List<E>

Returns:

a List of the combinations found
combinations
(Object[]
the given collections
collections
)

Finds all combinations of items from the given collections.

public static List<E>
combinations(Collection<E>
the given collections
collections
)

Deprecated use combinations(Iterable)
public static List<E>

Returns:

a List of the combinations found
combinations
(Iterable<T>
the Iterable of given collections
collections
)

Finds all combinations of items from the given Iterable aggregate of collections.

public static <T> List<List<T>>
inits(Iterable<T> collections)

public static <T> T

Returns:

the maximum value
max
(T[]
an array of items
items
)

Selects the maximum value found in an array of items, so max([2, 4, 6] as Object[]) == 6.

public static <T> T
max(Collection<T> items)

Deprecated use max(Iterable)
public static <T> T

Returns:

the maximum value
max
(Iterable<T>
a Collection
items
)

Selects the maximum value found in an Iterable.

public static <T> T

Returns:

the minimum value
min
(T[]
an array of items
items
)

Selects the minimum value found in an array of items, so min([2, 4, 6] as Object[]) == 2.

public static <T> T
min(Collection<T> items)

Deprecated use min(Iterable)
public static <T> T

Returns:

the minimum value
min
(Iterable<T>
an Iterable
items
)

Selects the minimum value found in an Iterable of items.

public static <T> Set<List<T>>

Returns:

the subsequences from items
subsequences
(List<T>
the List of items
items
)

Finds all non-null subsequences of a list.

public static Object

Returns:

the sum of the items
sum
(Object[]
an array of items
items
)

Sums all the items from an array of items.

public static Object
sum(Collection<E> items)

Deprecated use sum(Iterable)
public static Object

Returns:

the sum of the item
sum
(Iterable<?>
an Iterable of items
items
)

Sums all the given items.

public static <T> List<List<T>>
tails(Iterable<T> collections)

public static List<E>

Returns:

a List of the transposed lists
transpose
(Object[]
the given lists
lists
)

Transposes an array of lists.

public static List<E>

Returns:

a List of the transposed lists
transpose
(List<E>
the given lists
lists
)

Transposes the given lists.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

GroovyCollectionsback to summary
public GroovyCollections()

Method Detail

combinationsback to summary
public static List<E> combinations(Object[] collections)

Finds all combinations of items from the given collections.

Parameters
collections:Object[]

the given collections

Returns:List<E>

a List of the combinations found

See Also
combinations(Collection)
combinationsback to summary
public static List<E> combinations(Collection<E> collections)

Deprecated

use combinations(Iterable)

Parameters
collections:Collection<E>

the given collections

Annotations
@Deprecated
combinationsback to summary
public static List<E> combinations(Iterable<T> 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]] 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.

Parameters
collections:Iterable<T>

the Iterable of given collections

Returns:List<E>

a List of the combinations found

Since
2.2.0
initsback to summary
public static <T> List<List<T>> inits(Iterable<T> collections)
maxback to summary
public 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:T[]

an array of items

Returns:T

the maximum value

maxback to summary
public static <T> T max(Collection<T> items)

Deprecated

use max(Iterable)

Annotations
@Deprecated
maxback to summary
public static <T> T max(Iterable<T> items)

Selects the maximum value found in an Iterable.

Parameters
items:Iterable<T>

a Collection

Returns:T

the maximum value

Since
2.2.0
minback to summary
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:T[]

an array of items

Returns:T

the minimum value

minback to summary
public static <T> T min(Collection<T> items)

Deprecated

use min(Iterable)

Annotations
@Deprecated
minback to summary
public static <T> T min(Iterable<T> items)

Selects the minimum value found in an Iterable of items.

Parameters
items:Iterable<T>

an Iterable

Returns:T

the minimum value

Since
2.2.0
subsequencesback to summary
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:List<T>

the List of items

Returns:Set<List<T>>

the subsequences from items

sumback to summary
public static Object sum(Object[] items)

Sums all the items from an array of items.

Parameters
items:Object[]

an array of items

Returns:Object

the sum of the items

sumback to summary
public static Object sum(Collection<E> items)

Deprecated

use sum(Iterable)

Annotations
@Deprecated
sumback to summary
public static Object sum(Iterable<?> items)

Sums all the given items.

Parameters
items:Iterable<?>

an Iterable of items

Returns:Object

the sum of the item

Since
2.2.0
tailsback to summary
public static <T> List<List<T>> tails(Iterable<T> collections)
transposeback to summary
public static List<E> transpose(Object[] lists)

Transposes an array of lists.

Parameters
lists:Object[]

the given lists

Returns:List<E>

a List of the transposed lists

See Also
transpose(List)
transposeback to summary
public static List<E> transpose(List<E> 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']].

Parameters
lists:List<E>

the given lists

Returns:List<E>

a List of the transposed lists