Groovy 1.7.0

groovy.util
Class GroovyCollections

java.lang.Object
  groovy.util.GroovyCollections

class GroovyCollections
extends Object

A Collections utility class

author:
Paul King
author:
Jim White


Constructor Summary
GroovyCollections()

 
Method Summary
static List combinations(Object[] collections)

Finds all combinations of items from the given collections.

static List combinations(Collection collections)

Finds all combinations of items from the given collections.

static T max(T[] items)

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

static T max(Collection items)

Selects the maximum value found in a collection

static T min(T[] items)

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

static T min(Collection items)

Selects the minimum value found in a collection of items.

static Set subsequences(List items)

Finds all non-null subsequences of a list.

static Object sum(Object[] items)

Sums all the items from an array of items.

static Object sum(Collection items)

Sums all the items from a collection of items.

static List transpose(Object[] lists)

Transposes an array of lists.

static List transpose(List lists)

Transposes the given lists.

 
Methods inherited from class Object
wait, wait, wait, hashCode, getClass, equals, toString, notify, notifyAll
 

Constructor Detail

GroovyCollections

GroovyCollections()


 
Method Detail

combinations

public static List combinations(Object[] collections)
Finds all combinations of items from the given collections.
param:
collections the given collections
return:
a List of the combinations found
see:
#combinations(Collection)


combinations

public static List combinations(Collection 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']].
param:
collections the given collections
return:
a List of the combinations found


max

public static T max(T[] items)
Selects the maximum value found in an array of items, so min([2, 4, 6] as Object[]) == 6.
param:
items an array of items
return:
the maximum value


max

public static T max(Collection items)
Selects the maximum value found in a collection
param:
items a Collection
return:
the maximum value


min

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


min

public static T min(Collection items)
Selects the minimum value found in a collection of items.
param:
items a Collection
return:
the minimum value


subsequences

public static Set subsequences(List 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]]
param:
items the List of items
return:
the subsequences from items


sum

public static Object sum(Object[] items)
Sums all the items from an array of items.
param:
items an array of items
return:
the sum of the items


sum

public static Object sum(Collection items)
Sums all the items from a collection of items.
param:
items a collection of items
return:
the sum of the items


transpose

public static List transpose(Object[] lists)
Transposes an array of lists.
param:
lists the given lists
return:
a List of the transposed lists
see:
#transpose(List)


transpose

public static List transpose(List 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']].
param:
lists the given lists
return:
a List of the transposed lists


 

Copyright © 2003-2009 The Codehaus. All rights reserved.