| Modifiers | Name | Description |
|---|---|---|
static class |
CollectionExtensionMethods.AverageStats |
|
static class |
CollectionExtensionMethods.TransposingIterator |
| Type Params | Return Type | Name and description |
|---|---|---|
<V extends Number> |
static CollectionExtensionMethods.AverageStats |
average(Collection<V> collection)Calculate the mean, median, variance and standard deviation of a Collection of Numbers |
<T> |
static T |
rand(List<T> self)Select a single random element from a List |
<T> |
static List<T> |
rand(List<T> self, int n)Select a list of n unique items from the List |
<T> |
static List<T> |
rand(List<T> self, int n, boolean allowDuplicates)Select a list of n items from the List |
<T> |
static List<T> |
rand(List<T> self, int n, boolean allowDuplicates, Random r)Select a list of n items from the List |
<T> |
static T |
rand(Iterator<T> self)Select a single random element from an Iterator |
<T> |
static List<T> |
rand(Iterator<T> self, int n)Select a list of n unique items from the Iterator |
<T> |
static List<T> |
rand(Iterator<T> self, int n, boolean allowDuplicates)Select a list of n items from the Iterator |
<T> |
static List<T> |
rand(Iterator<T> self, int n, boolean allowDuplicates, Random rnd)Select a list of n random items from the Iterator |
|
static Collection |
sort(Collection self, boolean mutate, Closure... closures)Sort a list based on a collection of Closures. |
|
static List |
take(List self, int n)Take up to n items from a List. |
<T> |
static Iterator<T> |
transposedIterator(List<List<T>> lists)Return a TransposingIterator that returns an element from each list in turn. |
<T> |
static Iterator<T> |
transposedIterator(List<List<T>> lists, List<Integer> amounts)Return a TransposingIterator that returns an element from each list in turn. |
Calculate the mean, median, variance and standard deviation of a Collection of Numbers
def avg = (1..10).average() assert avg.mean == 5.5 assert avg.median == 5.5 assert avg.variance == 8.25 assert String.format( '%.5g', avg.stdDev ) == '2.8723'
collection - The Collection of Number elements to generate stats forAverageStats objectSelect a single random element from a List
self - The List to select fromSelect a list of n unique items from the List
self - The List to select fromn - The number of items to selectSelect a list of n items from the List
self - The List to select fromn - The number of items to selectallowDuplicates - If true, the same element can be selected more than once.Select a list of n items from the List
self - The List to select fromn - The number of items to selectallowDuplicates - If true, the same element can be selected more than once.r - An instance of Random so we can set a seed to get reproducible random resultsSelect a single random element from an Iterator
self - The Iterator to select fromSelect a list of n unique items from the Iterator
self - The Iterator to select fromn - The number of items to selectSelect a list of n items from the Iterator
self - The Iterator to select fromn - The number of items to selectallowDuplicates - If true, the same element can be selected more than once.Select a list of n random items from the Iterator
self - The Iterator to select fromn - The number of items to selectallowDuplicates - If true, the same element can be selected more than once.r - An instance of Random so we can set a seed to get reproducible random resultsSort a list based on a collection of Closures. If the first closure fails to differentiate the objects in the list, it moves to the second, and continues until all Closures have been executed.
self - The collection to sortmutate - Should the original list be mutatedclosures - The list of Closures used to sort the CollectionTake up to n items from a List. If n is negative, take off the end of the list, else delegate to the existing Groovy take method.
self - The collection to take items from.n - The number of elements to take.Return a TransposingIterator that returns an element from each list in turn.
def left = [ 1, 2, 3 ] def right = [ 'a', 'b', 'c', 'd' ] def result = [left,right].transposedIterator().collect() assert result == [ 1, 'a', 2, 'b', 3, 'c', 'd' ]
lists - A List of Lists to cycle overReturn a TransposingIterator that returns an element from each list in turn.
def left = [ 1, 2, 3 ] def right = [ 'a', 'b', 'c', 'd' ] def result = [left,right].transposedIterator( [ 1, 2 ] ).collect() assert result == [ 1, 'a', 'b', 2, 'c', 'd', 3 ]
lists - A List of Lists to cycle overamounts - The number to take from each list