Class DefaultGroovyMethods
public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport
public static String reverse(String self)
provides a reverse()
method for String
.
NOTE: While this class contains many 'public' static methods, it is primarily regarded as an internal class (its internal package name suggests this also). We value backwards compatibility of these methods when used within Groovy but value less backwards compatibility at the Java method call level. I.e. future versions of Groovy may remove or move a method call in this file but would normally aim to keep the method available from within Groovy.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.Class[]
ADDITIONAL_CLASSES
static java.lang.Class[]
DGM_LIKE_CLASSES
-
Constructor Summary
Constructors Constructor Description DefaultGroovyMethods()
-
Method Summary
Modifier and Type Method Description static double
abs(java.lang.Double number)
Get the absolute valuestatic float
abs(java.lang.Float number)
Get the absolute valuestatic long
abs(java.lang.Long number)
Get the absolute valuestatic int
abs(java.lang.Number number)
Get the absolute valuestatic <T> boolean
addAll(java.util.Collection<T> self, java.lang.Iterable<? extends T> items)
Adds all items from the iterable to the Collection.static <T> boolean
addAll(java.util.Collection<T> self, java.util.Iterator<? extends T> items)
Adds all items from the iterator to the Collection.static <T> boolean
addAll(java.util.Collection<T> self, T[] items)
Modifies the collection by adding all of the elements in the specified array to the collection.static <T> boolean
addAll(java.util.List<T> self, int index, T[] items)
Modifies this list by inserting all of the elements in the specified array into the list at the specified position.static void
addShutdownHook(java.lang.Object self, Closure closure)
Allows the usage of addShutdownHook without getting the runtime first.static java.lang.Boolean
and(java.lang.Boolean left, java.lang.Boolean right)
Logical conjunction of two boolean operators.static java.lang.Number
and(java.lang.Number left, java.lang.Number right)
Bitwise AND together two Numbers.static java.util.BitSet
and(java.util.BitSet left, java.util.BitSet right)
Bitwise AND together two BitSets.static <T> boolean
any(java.lang.Iterable<T> self, Closure predicate)
Iterates over the contents of an iterable, and checks whether a predicate is valid for at least one element.static boolean
any(java.lang.Object self)
Iterates over the elements of a collection, and checks whether at least one element is true according to the Groovy Truth.static boolean
any(java.lang.Object self, Closure predicate)
Iterates over the contents of an object or collection, and checks whether a predicate is valid for at least one element.static <T> boolean
any(java.util.Iterator<T> self, Closure predicate)
Iterates over the contents of an iterator, and checks whether a predicate is valid for at least one element.static <K, V> boolean
any(java.util.Map<K,V> self, Closure<?> predicate)
Iterates over the entries of a map, and checks whether a predicate is valid for at least one entry.static <T> boolean
any(T[] self, Closure predicate)
Iterates over the contents of an Array, and checks whether a predicate is valid for at least one element.static boolean
asBoolean(boolean[] array)
Coerces a boolean array to a boolean value.static boolean
asBoolean(byte[] array)
Coerces a byte array to a boolean value.static boolean
asBoolean(char[] array)
Coerces a char array to a boolean value.static boolean
asBoolean(double[] array)
Coerces a double array to a boolean value.static boolean
asBoolean(float[] array)
Coerces a float array to a boolean value.static boolean
asBoolean(int[] array)
Coerces an int array to a boolean value.static boolean
asBoolean(long[] array)
Coerces a long array to a boolean value.static boolean
asBoolean(short[] array)
Coerces a short array to a boolean value.static boolean
asBoolean(java.lang.Boolean bool)
Coerce a Boolean instance to a boolean value.static boolean
asBoolean(java.lang.Character character)
Coerce a character to a boolean value.static boolean
asBoolean(java.lang.Double object)
Coerce a Double instance to a boolean value.static boolean
asBoolean(java.lang.Float object)
Coerce a Float instance to a boolean value.static boolean
asBoolean(java.lang.Number number)
Coerce a number to a boolean value.static boolean
asBoolean(java.lang.Object object)
Coerce an object instance to a boolean value.static boolean
asBoolean(java.lang.Object[] array)
Coerce an Object array to a boolean value.static boolean
asBoolean(java.util.Collection collection)
Coerce a collection instance to a boolean value.static boolean
asBoolean(java.util.Enumeration enumeration)
Coerce an enumeration instance to a boolean value.static boolean
asBoolean(java.util.Iterator iterator)
Coerce an iterator instance to a boolean value.static boolean
asBoolean(java.util.Map map)
Coerce a map instance to a boolean value.static <T> java.util.Collection<T>
asCollection(java.lang.Iterable<T> self)
Converts this Iterable to a Collection.static <T> java.util.Collection<T>
asImmutable(java.util.Collection<T> self)
A convenience method for creating an immutable Collection.static <T> java.util.List<T>
asImmutable(java.util.List<T> self)
A convenience method for creating an immutable List.static <K, V> java.util.Map<K,V>
asImmutable(java.util.Map<K,V> self)
A convenience method for creating an immutable Map.static <T> java.util.Set<T>
asImmutable(java.util.Set<T> self)
A convenience method for creating an immutable Set.static <K, V> java.util.SortedMap<K,V>
asImmutable(java.util.SortedMap<K,V> self)
A convenience method for creating an immutable SortedMap.static <T> java.util.SortedSet<T>
asImmutable(java.util.SortedSet<T> self)
A convenience method for creating an immutable SortedSet.static <T> java.util.List<T>
asList(java.lang.Iterable<T> self)
Converts this Iterable to a List.static <T> java.util.List<T>
asList(java.util.Collection<T> self)
Deprecated.Use the Iterable version of asList insteadstatic java.lang.String
asString(java.lang.Throwable self)
Get the detail information ofThrowable
instance's stack tracestatic <T> java.util.Collection<T>
asSynchronized(java.util.Collection<T> self)
A convenience method for creating a synchronized Collection.static <T> java.util.List<T>
asSynchronized(java.util.List<T> self)
A convenience method for creating a synchronized List.static <K, V> java.util.Map<K,V>
asSynchronized(java.util.Map<K,V> self)
A convenience method for creating a synchronized Map.static <T> java.util.Set<T>
asSynchronized(java.util.Set<T> self)
A convenience method for creating a synchronized Set.static <K, V> java.util.SortedMap<K,V>
asSynchronized(java.util.SortedMap<K,V> self)
A convenience method for creating a synchronized SortedMap.static <T> java.util.SortedSet<T>
asSynchronized(java.util.SortedSet<T> self)
A convenience method for creating a synchronized SortedSet.static <T> T
asType(Closure impl, java.lang.Class<T> type)
Coerces the closure to an implementation of the given class.static <T> T
asType(java.lang.Iterable iterable, java.lang.Class<T> clazz)
Converts the given iterable to another type.static <T> T
asType(java.lang.Number self, java.lang.Class<T> c)
Transform this number to a the given type, using the 'as' operator.static <T> T
asType(java.lang.Object[] ary, java.lang.Class<T> clazz)
Converts the given array to either a List, Set, or SortedSet.static <T> T
asType(java.lang.Object obj, java.lang.Class<T> type)
Converts a given object to a type.static <T> T
asType(java.util.Collection col, java.lang.Class<T> clazz)
Converts the given collection to another type.static <T> T
asType(java.util.Map map, java.lang.Class<T> clazz)
Coerces this map to the given type, using the map's keys as the public method names, and values as the implementation.static <T> java.util.Collection<T>
asUnmodifiable(java.util.Collection<T> self)
Creates an unmodifiable view of a Collection.static <T> java.util.List<T>
asUnmodifiable(java.util.List<T> self)
Creates an unmodifiable view of a List.static <K, V> java.util.Map<K,V>
asUnmodifiable(java.util.Map<K,V> self)
Creates an unmodifiable view of a Map.static <T> java.util.Set<T>
asUnmodifiable(java.util.Set<T> self)
Creates an unmodifiable view of a Set.static <K, V> java.util.SortedMap<K,V>
asUnmodifiable(java.util.SortedMap<K,V> self)
Creates an unmodifiable view of a SortedMap.static <T> java.util.SortedSet<T>
asUnmodifiable(java.util.SortedSet<T> self)
Creates an unmodifiable view of a SortedSet.static java.math.BigDecimal
average(byte[] self)
Calculates the average of the bytes in the array.static double
average(double[] self)
Calculates the average of the doubles in the array.static double
average(float[] self)
Calculates the average of the floats in the array.static java.math.BigDecimal
average(int[] self)
Calculates the average of the ints in the array.static java.math.BigDecimal
average(long[] self)
Calculates the average of the longs in the array.static java.math.BigDecimal
average(short[] self)
Calculates the average of the shorts in the array.static java.lang.Object
average(java.lang.Iterable<?> self)
Averages the items in an Iterable.static <T> java.lang.Object
average(java.lang.Iterable<T> self, Closure closure)
Averages the result of applying a closure to each item of an Iterable.static java.lang.Object
average(java.lang.Object[] self)
Averages the items in an array.static java.lang.Object
average(java.util.Iterator<?> self)
Averages the items from an Iterator.static <T> java.lang.Object
average(java.util.Iterator<T> self, Closure closure)
Averages the result of applying a closure to each item returned from an iterator.static <T> java.lang.Object
average(T[] self, Closure closure)
Averages the result of applying a closure to each item of an array.static java.lang.Number
bitwiseNegate(java.lang.Number left)
Bitwise NEGATE a Number.static java.util.BitSet
bitwiseNegate(java.util.BitSet self)
Bitwise NEGATE a BitSet.static <T> BufferedIterator<T>
buffered(java.util.Iterator<T> self)
Returns aBufferedIterator
that allows examining the next element without consuming it.static <T> BufferedIterator<T>
bufferedIterator(java.lang.Iterable<T> self)
Returns aBufferedIterator
that allows examining the next element without consuming it.static <T> BufferedIterator<T>
bufferedIterator(java.util.List<T> self)
Returns aBufferedIterator
that allows examining the next element without consuming it.protected static <T> T
callClosureForLine(Closure<T> closure, java.lang.String line, int counter)
protected static <T, K, V> T
callClosureForMapEntry(Closure<T> closure, java.util.Map.Entry<K,V> entry)
protected static <T, K, V> T
callClosureForMapEntryAndCounter(Closure<T> closure, java.util.Map.Entry<K,V> entry, int counter)
static <T> java.util.List<java.util.List<T>>
chop(java.lang.Iterable<T> self, int... chopSizes)
Chops the Iterable into pieces, returning lists with sizes corresponding to the supplied chop sizes.static <T> java.util.List<java.util.List<T>>
chop(java.util.Iterator<T> self, int... chopSizes)
Chops the iterator items into pieces, returning lists with sizes corresponding to the supplied chop sizes.static <T> java.util.List<java.util.List<T>>
chop(T[] self, int... chopSizes)
Chops the array into pieces, returning lists with sizes corresponding to the supplied chop sizes.static <T> java.util.List<java.util.List<T>>
collate(java.lang.Iterable<T> self, int size)
Collates this iterable into sub-lists of lengthsize
.static <T> java.util.List<java.util.List<T>>
collate(java.lang.Iterable<T> self, int size, boolean keepRemainder)
Collates this iterable into sub-lists of lengthsize
.static <T> java.util.List<java.util.List<T>>
collate(java.lang.Iterable<T> self, int size, int step)
Collates this iterable into sub-lists of lengthsize
stepping through the codestep
elements for each subList.static <T> java.util.List<java.util.List<T>>
collate(java.lang.Iterable<T> self, int size, int step, boolean keepRemainder)
Collates this iterable into sub-lists of lengthsize
stepping through the codestep
elements for each sub-list.static <T> java.util.List<java.util.List<T>>
collate(java.util.List<T> self, int size)
Deprecated.use the Iterable variant insteadstatic <T> java.util.List<java.util.List<T>>
collate(java.util.List<T> self, int size, boolean keepRemainder)
Deprecated.use the Iterable variant insteadstatic <T> java.util.List<java.util.List<T>>
collate(java.util.List<T> self, int size, int step)
Deprecated.use the Iterable variant insteadstatic <T> java.util.List<java.util.List<T>>
collate(java.util.List<T> self, int size, int step, boolean keepRemainder)
Deprecated.use the Iterable variant insteadstatic <T> java.util.List<java.util.List<T>>
collate(T[] self, int size)
Collates an array.static <T> java.util.List<java.util.List<T>>
collate(T[] self, int size, boolean keepRemainder)
Collates this array into sub-lists.static <T> java.util.List<java.util.List<T>>
collate(T[] self, int size, int step)
Collates an array into sub-lists.static <T> java.util.List<java.util.List<T>>
collate(T[] self, int size, int step, boolean keepRemainder)
Collates this array into into sub-lists.static <S, T> java.util.List<T>
collect(java.lang.Iterable<S> self, Closure<T> transform)
Iterates through this Iterable transforming each entry into a new value using thetransform
closure returning a list of transformed values.static <S, T> java.util.Collection<T>
collect(java.lang.Iterable<S> self, java.util.Collection<T> collector, Closure<? extends T> transform)
Iterates through this collection transforming each value into a new value using thetransform
closure and adding it to the suppliedcollector
.static <T> java.util.List<T>
collect(java.lang.Iterable<T> self)
Iterates through this collection transforming each entry into a new value using Closure.IDENTITY as a transformer, basically returning a list of items copied from the original collection.static java.util.Collection
collect(java.lang.Object self)
Iterates through this aggregate Object transforming each item into a new value using Closure.IDENTITY as a transformer, basically returning a list of items copied from the original object.static <T> java.util.List<T>
collect(java.lang.Object self, Closure<T> transform)
Iterates through this aggregate Object transforming each item into a new value using thetransform
closure, returning a list of transformed values.static <T> java.util.Collection<T>
collect(java.lang.Object self, java.util.Collection<T> collector, Closure<? extends T> transform)
Iterates through this aggregate Object transforming each item into a new value using thetransform
closure and adding it to the suppliedcollector
.static <S, T> java.util.List<T>
collect(java.util.Collection<S> self, Closure<T> transform)
Deprecated.use the Iterable version insteadstatic <S, T> java.util.Collection<T>
collect(java.util.Collection<S> self, java.util.Collection<T> collector, Closure<? extends T> transform)
Deprecated.use the Iterable version insteadstatic <T> java.util.List<T>
collect(java.util.Collection<T> self)
Deprecated.use the Iterable version insteadstatic <S, T> java.util.List<T>
collect(java.util.Iterator<S> self, Closure<T> transform)
Iterates through this Iterator transforming each item into a new value using thetransform
closure, returning a list of transformed values.static <S, T> java.util.Collection<T>
collect(java.util.Iterator<S> self, java.util.Collection<T> collector, Closure<? extends T> transform)
Iterates through this Iterator transforming each item into a new value using thetransform
closure and adding it to the suppliedcollector
.static <T, K, V> java.util.List<T>
collect(java.util.Map<K,V> self, Closure<T> transform)
Iterates through this Map transforming each map entry into a new value using thetransform
closure returning a list of transformed values.static <T, K, V> java.util.Collection<T>
collect(java.util.Map<K,V> self, java.util.Collection<T> collector, Closure<? extends T> transform)
Iterates through this Map transforming each map entry into a new value using thetransform
closure returning thecollector
with all transformed values added to it.static <S, T> java.util.List<T>
collect(S[] self, Closure<T> transform)
Iterates through this Array transforming each item into a new value using thetransform
closure, returning a list of transformed values.static <S, T> java.util.Collection<T>
collect(S[] self, java.util.Collection<T> collector, Closure<? extends T> transform)
Iterates through this Array transforming each item into a new value using thetransform
closure and adding it to the suppliedcollector
.static java.util.List
collectAll(java.util.Collection self, Closure transform)
Deprecated.Use collectNested insteadstatic java.util.Collection
collectAll(java.util.Collection self, java.util.Collection collector, Closure transform)
Deprecated.Use collectNested insteadstatic <K, V, E> java.util.Map<K,V>
collectEntries(E[] self)
A variant of collectEntries using the identity closure as the transform.static <K, V, E> java.util.Map<K,V>
collectEntries(E[] self, Closure<?> transform)
Iterates through this array transforming each item using thetransform
closure and returning a map of the resulting transformed entries.static <K, V, E> java.util.Map<K,V>
collectEntries(E[] self, java.util.Map<K,V> collector)
A variant of collectEntries using the identity closure as the transform.static <K, V, E> java.util.Map<K,V>
collectEntries(E[] self, java.util.Map<K,V> collector, Closure<?> transform)
Iterates through this array transforming each item using thetransform
closure and returning a map of the resulting transformed entries.static <K, V> java.util.Map<K,V>
collectEntries(java.lang.Iterable<?> self)
A variant of collectEntries for Iterable objects using the identity closure as the transform.static <K, V> java.util.Map<K,V>
collectEntries(java.lang.Iterable<?> self, java.util.Map<K,V> collector)
A variant of collectEntries for Iterables using the identity closure as the transform and a supplied map as the destination of transformed entries.static <K, V, E> java.util.Map<K,V>
collectEntries(java.lang.Iterable<E> self, Closure<?> transform)
Iterates through this Iterable transforming each item using thetransform
closure and returning a map of the resulting transformed entries.static <K, V, E> java.util.Map<K,V>
collectEntries(java.lang.Iterable<E> self, java.util.Map<K,V> collector, Closure<?> transform)
Iterates through this Iterable transforming each item using the closure as a transformer into a map entry, returning the supplied map with all of the transformed entries added to it.static <K, V> java.util.Map<K,V>
collectEntries(java.util.Collection<?> self)
Deprecated.Use the Iterable version of collectEntries insteadstatic <K, V> java.util.Map<K,V>
collectEntries(java.util.Collection<?> self, Closure<?> transform)
Deprecated.Use the Iterable version of collectEntries insteadstatic <K, V> java.util.Map<K,V>
collectEntries(java.util.Collection<?> self, java.util.Map<K,V> collector)
Deprecated.Use the Iterable version of collectEntries insteadstatic <K, V> java.util.Map<K,V>
collectEntries(java.util.Collection<?> self, java.util.Map<K,V> collector, Closure<?> transform)
Deprecated.Use the Iterable version of collectEntries insteadstatic <K, V> java.util.Map<K,V>
collectEntries(java.util.Iterator<?> self)
A variant of collectEntries for Iterators using the identity closure as the transform.static <K, V> java.util.Map<K,V>
collectEntries(java.util.Iterator<?> self, java.util.Map<K,V> collector)
A variant of collectEntries for Iterators using the identity closure as the transform and a supplied map as the destination of transformed entries.static <K, V, E> java.util.Map<K,V>
collectEntries(java.util.Iterator<E> self, Closure<?> transform)
A variant of collectEntries for Iterators.static <K, V, E> java.util.Map<K,V>
collectEntries(java.util.Iterator<E> self, java.util.Map<K,V> collector, Closure<?> transform)
A variant of collectEntries for Iterators using a supplied map as the destination of transformed entries.static <K, V, X, Y> java.util.Map<K,V>
collectEntries(java.util.Map<X,Y> self, Closure<?> transform)
Iterates through this Map transforming each entry using thetransform
closure and returning a map of the transformed entries.static <K, V, X, Y> java.util.Map<K,V>
collectEntries(java.util.Map<X,Y> self, java.util.Map<K,V> collector, Closure<?> transform)
Iterates through this Map transforming each map entry using thetransform
closure returning a map of the transformed entries.static <T, E> java.util.List<T>
collectMany(E[] self, Closure<? extends java.util.Collection<? extends T>> projection)
Projects each item from a source array to a collection and concatenates (flattens) the resulting collections into a single list.static <T, E> java.util.Collection<T>
collectMany(E[] self, java.util.Collection<T> collector, Closure<? extends java.util.Collection<? extends T>> projection)
Projects each item from a source array to a collection and concatenates (flattens) the resulting collections into a single list.static <T, E> java.util.List<T>
collectMany(java.lang.Iterable<E> self, Closure<? extends java.util.Collection<? extends T>> projection)
Projects each item from a source Iterable to a collection and concatenates (flattens) the resulting collections into a single list.static <T, E> java.util.Collection<T>
collectMany(java.lang.Iterable<E> self, java.util.Collection<T> collector, Closure<? extends java.util.Collection<? extends T>> projection)
Projects each item from a source collection to a result collection and concatenates (flattens) the resulting collections adding them into thecollector
.static <T, E> java.util.List<T>
collectMany(java.util.Collection<E> self, Closure<? extends java.util.Collection<? extends T>> projection)
Deprecated.Use the Iterable version of collectMany insteadstatic <T, E> java.util.Collection<T>
collectMany(java.util.Collection<E> self, java.util.Collection<T> collector, Closure<? extends java.util.Collection<? extends T>> projection)
Deprecated.Use the Iterable version of collectMany insteadstatic <T, E> java.util.List<T>
collectMany(java.util.Iterator<E> self, Closure<? extends java.util.Collection<? extends T>> projection)
Projects each item from a source iterator to a collection and concatenates (flattens) the resulting collections into a single list.static <T, E> java.util.Collection<T>
collectMany(java.util.Iterator<E> self, java.util.Collection<T> collector, Closure<? extends java.util.Collection<? extends T>> projection)
Projects each item from a source iterator to a collection and concatenates (flattens) the resulting collections into a single list.static <T, K, V> java.util.List<T>
collectMany(java.util.Map<K,V> self, Closure<? extends java.util.Collection<? extends T>> projection)
Projects each item from a source map to a result collection and concatenates (flattens) the resulting collections adding them into a collection.static <T, K, V> java.util.Collection<T>
collectMany(java.util.Map<K,V> self, java.util.Collection<T> collector, Closure<? extends java.util.Collection<? extends T>> projection)
Projects each item from a source map to a result collection and concatenates (flattens) the resulting collections adding them into thecollector
.static <T, K, V> java.util.Collection<T>
collectMany$$bridge(java.util.Map<K,V> self, Closure<? extends java.util.Collection<? extends T>> projection)
Deprecated.static java.util.List
collectNested(java.lang.Iterable self, Closure transform)
Recursively iterates through this Iterable transforming each non-Collection value into a new value using the closure as a transformer.static java.util.Collection
collectNested(java.lang.Iterable self, java.util.Collection collector, Closure transform)
Recursively iterates through this Iterable transforming each non-Collection value into a new value using thetransform
closure.static java.util.List
collectNested(java.util.Collection self, Closure transform)
Recursively iterates through this collection transforming each non-Collection value into a new value using the closure as a transformer.static java.util.Collection
collectNested(java.util.Collection self, java.util.Collection collector, Closure transform)
Deprecated.Use the Iterable version of collectNested insteadstatic java.util.List
combinations(java.lang.Iterable self)
Adds GroovyCollections#combinations(Iterable) as a method on Iterables.static java.util.List
combinations(java.lang.Iterable self, Closure<?> function)
Adds GroovyCollections#combinations(Iterable, Closure) as a method on collections.static java.util.List
combinations(java.util.Collection self)
Deprecated.Use the Iterable version of combinations insteadstatic int
compareTo(java.lang.Character left, java.lang.Character right)
Compare two Characters.static int
compareTo(java.lang.Character left, java.lang.Number right)
Compare a Character and a Number.static int
compareTo(java.lang.Number left, java.lang.Character right)
Compare a Number and a Character.static int
compareTo(java.lang.Number left, java.lang.Number right)
Compare two Numbers.static boolean
contains(boolean[] self, java.lang.Object value)
Checks whether the array contains the given value.static boolean
contains(byte[] self, java.lang.Object value)
Checks whether the array contains the given value.static boolean
contains(char[] self, java.lang.Object value)
Checks whether the array contains the given value.static boolean
contains(double[] self, java.lang.Object value)
Checks whether the array contains the given value.static boolean
contains(float[] self, java.lang.Object value)
Checks whether the array contains the given value.static boolean
contains(int[] self, java.lang.Object value)
Checks whether the array contains the given value.static boolean
contains(long[] self, java.lang.Object value)
Checks whether the array contains the given value.static boolean
contains(short[] self, java.lang.Object value)
Checks whether the array contains the given value.static boolean
contains(java.lang.Iterable self, java.lang.Object item)
Returns true if this iterable contains the item.static boolean
contains(java.lang.Object[] self, java.lang.Object value)
Checks whether the array contains the given value.static boolean
containsAll(java.lang.Iterable self, java.lang.Object[] items)
Returns true if this iterable contains all of the elements in the specified array.static boolean
containsAll(java.util.Collection self, java.lang.Object[] items)
Deprecated.use the Iterable variant insteadstatic java.lang.Number
count(boolean[] self, java.lang.Object value)
Counts the number of occurrences of the given value inside this array.static java.lang.Number
count(byte[] self, java.lang.Object value)
Counts the number of occurrences of the given value inside this array.static java.lang.Number
count(char[] self, java.lang.Object value)
Counts the number of occurrences of the given value inside this array.static java.lang.Number
count(double[] self, java.lang.Object value)
Counts the number of occurrences of the given value inside this array.static java.lang.Number
count(float[] self, java.lang.Object value)
Counts the number of occurrences of the given value inside this array.static java.lang.Number
count(int[] self, java.lang.Object value)
Counts the number of occurrences of the given value inside this array.static java.lang.Number
count(long[] self, java.lang.Object value)
Counts the number of occurrences of the given value inside this array.static java.lang.Number
count(short[] self, java.lang.Object value)
Counts the number of occurrences of the given value inside this array.static <T> java.lang.Number
count(java.lang.Iterable<T> self, Closure closure)
Counts the number of occurrences which satisfy the given closure from inside this Iterable.static java.lang.Number
count(java.lang.Iterable self, java.lang.Object value)
Counts the number of occurrences of the given value inside this Iterable.static java.lang.Number
count(java.lang.Object[] self, java.lang.Object value)
Counts the number of occurrences of the given value inside this array.static java.lang.Number
count(java.util.Collection self, Closure closure)
Deprecated.use count(Iterable, Closure)static java.lang.Number
count(java.util.Collection self, java.lang.Object value)
Deprecated.use count(Iterable, Closure)static <T> java.lang.Number
count(java.util.Iterator<T> self, Closure closure)
Counts the number of occurrences which satisfy the given closure from the items within this Iterator.static java.lang.Number
count(java.util.Iterator self, java.lang.Object value)
Counts the number of occurrences of the given value from the items within this Iterator.static <K, V> java.lang.Number
count(java.util.Map<K,V> self, Closure<?> closure)
Counts the number of occurrences which satisfy the given closure from inside this map.static <T> java.lang.Number
count(T[] self, Closure closure)
Counts the number of occurrences which satisfy the given closure from inside this array.static <K, E> java.util.Map<K,java.lang.Integer>
countBy(E[] self, Closure<K> closure)
Sorts all array members into groups determined by the supplied mapping closure and counts the group size.static <K, E> java.util.Map<K,java.lang.Integer>
countBy(java.lang.Iterable<E> self, Closure<K> closure)
Sorts all collection members into groups determined by the supplied mapping closure and counts the group size.static <K> java.util.Map<K,java.lang.Integer>
countBy(java.util.Collection self, Closure<K> closure)
Deprecated.Use the Iterable version of countBy insteadstatic <K, E> java.util.Map<K,java.lang.Integer>
countBy(java.util.Iterator<E> self, Closure<K> closure)
Sorts all iterator items into groups determined by the supplied mapping closure and counts the group size.static <K, U, V> java.util.Map<K,java.lang.Integer>
countBy(java.util.Map<U,V> self, Closure<K> closure)
Groups the members of a map into groups determined by the supplied mapping closure and counts the frequency of the created groups.static boolean
disjoint(java.lang.Iterable left, java.lang.Iterable right)
Returnstrue
if the intersection of two iterables is empty.static boolean
disjoint(java.util.Collection left, java.util.Collection right)
Deprecated.use the Iterable variant insteadstatic java.lang.Number
div(java.lang.Character left, java.lang.Character right)
Divide one Character by another.static java.lang.Number
div(java.lang.Character left, java.lang.Number right)
Divide a Character by a Number.static java.lang.Number
div(java.lang.Number left, java.lang.Character right)
Divide a Number by a Character.static void
downto(double self, java.lang.Number to, Closure closure)
Iterates from this number down to the given number, inclusive, decrementing by one each time.static void
downto(float self, java.lang.Number to, Closure closure)
Iterates from this number down to the given number, inclusive, decrementing by one each time.static void
downto(long self, java.lang.Number to, Closure closure)
Iterates from this number down to the given number, inclusive, decrementing by one each time.static void
downto(java.lang.Double self, java.lang.Number to, Closure closure)
Iterates from this number down to the given number, inclusive, decrementing by one each time.static void
downto(java.lang.Float self, java.lang.Number to, Closure closure)
Iterates from this number down to the given number, inclusive, decrementing by one each time.static void
downto(java.lang.Long self, java.lang.Number to, Closure closure)
Iterates from this number down to the given number, inclusive, decrementing by one each time.static void
downto(java.lang.Number self, java.lang.Number to, Closure closure)
Iterates from this number down to the given number, inclusive, decrementing by one each time.static void
downto(java.math.BigDecimal self, java.lang.Number to, Closure closure)
Iterates from this number down to the given number, inclusive, decrementing by one each time.static void
downto(java.math.BigInteger self, java.lang.Number to, Closure closure)
Iterates from this number down to the given number, inclusive, decrementing by one each time.static <T> java.util.Collection<T>
drop(java.lang.Iterable<T> self, int num)
Drops the given number of elements from the head of this Iterable.static <T> java.util.Iterator<T>
drop(java.util.Iterator<T> self, int num)
Drops the given number of elements from the head of this iterator if they are available.static <T> java.util.List<T>
drop(java.util.List<T> self, int num)
Drops the given number of elements from the head of this List.static <K, V> java.util.Map<K,V>
drop(java.util.Map<K,V> self, int num)
Drops the given number of key/value pairs from the head of this map if they are available.static <T> java.util.SortedSet<T>
drop(java.util.SortedSet<T> self, int num)
Drops the given number of elements from the head of this List.static <T> T[]
drop(T[] self, int num)
Drops the given number of elements from the head of this array if they are available.static <T> java.util.Collection<T>
dropRight(java.lang.Iterable<T> self, int num)
Drops the given number of elements from the tail of this Iterable.static <T> java.util.Iterator<T>
dropRight(java.util.Iterator<T> self, int num)
Drops the given number of elements from the tail of this Iterator.static <T> java.util.List<T>
dropRight(java.util.List<T> self, int num)
Drops the given number of elements from the tail of this List.static <T> java.util.SortedSet<T>
dropRight(java.util.SortedSet<T> self, int num)
Drops the given number of elements from the tail of this SortedSet.static <T> T[]
dropRight(T[] self, int num)
Drops the given number of elements from the tail of this array if they are available.static <T> java.util.Collection<T>
dropWhile(java.lang.Iterable<T> self, Closure condition)
Returns a suffix of this Iterable where elements are dropped from the front while the given closure evaluates to true.static <T> java.util.Iterator<T>
dropWhile(java.util.Iterator<T> self, Closure<?> condition)
Creates an Iterator that returns a suffix of the elements from an original Iterator.static <T> java.util.List<T>
dropWhile(java.util.List<T> self, Closure condition)
Returns a suffix of this List where elements are dropped from the front while the given Closure evaluates to true.static <K, V> java.util.Map<K,V>
dropWhile(java.util.Map<K,V> self, Closure condition)
Create a suffix of the given Map by dropping as many entries as possible from the front of the original Map such that calling the given closure condition evaluates to true when passed each of the dropped entries (or key/value pairs).static <T> java.util.SortedSet<T>
dropWhile(java.util.SortedSet<T> self, Closure condition)
Returns a suffix of this SortedSet where elements are dropped from the front while the given Closure evaluates to true.static <T> T[]
dropWhile(T[] self, Closure<?> condition)
Create a suffix of the given array by dropping as many elements as possible from the front of the original array such that calling the given closure condition evaluates to true when passed each of the dropped elements.static java.lang.String
dump(java.lang.Object self)
Generates a detailed dump string of an object showing its class, hashCode and fields.static <T> java.lang.Iterable<T>
each(java.lang.Iterable<T> self, Closure closure)
Iterates through an Iterable, passing each item to the given closure.static <T> java.util.Collection<T>
each(java.util.Collection<T> self, Closure closure)
Iterates through a Collection, passing each item to the given closure.static <T> java.util.Iterator<T>
each(java.util.Iterator<T> self, Closure closure)
Iterates through an Iterator, passing each item to the given closure.static <T> java.util.List<T>
each(java.util.List<T> self, Closure closure)
Iterates through a List, passing each item to the given closure.static <K, V> java.util.Map<K,V>
each(java.util.Map<K,V> self, Closure closure)
Allows a Map to be iterated through using a closure.static <T> java.util.Set<T>
each(java.util.Set<T> self, Closure closure)
Iterates through a Set, passing each item to the given closure.static <T> java.util.SortedSet<T>
each(java.util.SortedSet<T> self, Closure closure)
Iterates through a SortedSet, passing each item to the given closure.static <T> T[]
each(T[] self, Closure closure)
Iterates through an array passing each array entry to the given closure.static <T> T
each(T self, Closure closure)
Iterates through an aggregate type or data structure, passing each item to the given closure.static void
eachByte(byte[] self, Closure closure)
Traverse through each byte of this byte array.static void
eachByte(java.lang.Byte[] self, Closure closure)
Traverse through each byte of this Byte array.static void
eachCombination(java.lang.Iterable self, Closure<?> function)
Applies a function on each combination of the input lists.static <T> java.util.Iterator<java.util.List<T>>
eachPermutation(java.lang.Iterable<T> self, Closure closure)
Iterates over all permutations of a collection, running a closure for each iteration.static <T> java.util.Iterator<java.util.List<T>>
eachPermutation(java.util.Collection<T> self, Closure closure)
Deprecated.Use the Iterable version of eachPermutation insteadstatic <T> java.lang.Iterable<T>
eachWithIndex(java.lang.Iterable<T> self, Closure closure)
Iterates through an iterable type, passing each item and the item's index (a counter starting at zero) to the given closure.static <T> java.util.Collection<T>
eachWithIndex(java.util.Collection<T> self, Closure closure)
Iterates through a Collection, passing each item and the item's index (a counter starting at zero) to the given closure.static <T> java.util.Iterator<T>
eachWithIndex(java.util.Iterator<T> self, Closure closure)
Iterates through an iterator type, passing each item and the item's index (a counter starting at zero) to the given closure.static <T> java.util.List<T>
eachWithIndex(java.util.List<T> self, Closure closure)
Iterates through a List, passing each item and the item's index (a counter starting at zero) to the given closure.static <K, V> java.util.Map<K,V>
eachWithIndex(java.util.Map<K,V> self, Closure closure)
Allows a Map to be iterated through using a closure.static <T> java.util.Set<T>
eachWithIndex(java.util.Set<T> self, Closure closure)
Iterates through a Set, passing each item and the item's index (a counter starting at zero) to the given closure.static <T> java.util.SortedSet<T>
eachWithIndex(java.util.SortedSet<T> self, Closure closure)
Iterates through a SortedSet, passing each item and the item's index (a counter starting at zero) to the given closure.static <T> T[]
eachWithIndex(T[] self, Closure closure)
Iterates through an array, passing each array element and the element's index (a counter starting at zero) to the given closure.static <T> T
eachWithIndex(T self, Closure closure)
Iterates through an aggregate type or data structure, passing each item and the item's index (a counter starting at zero) to the given closure.static boolean
equals(int[] left, int[] right)
Compare the contents of this array to the contents of the given array.static boolean
equals(java.lang.Object[] left, java.util.List right)
Determines if the contents of this array are equal to the contents of the given list, in the same order.static boolean
equals(java.util.List left, java.lang.Object[] right)
Determines if the contents of this list are equal to the contents of the given array in the same order.static boolean
equals(java.util.List left, java.util.List right)
Compare the contents of two Lists.static boolean
equals(java.util.Map self, java.util.Map other)
Compares two Maps treating coerced numerical values as identical.static <T> boolean
equals(java.util.Set<T> self, java.util.Set<T> other)
Compare the contents of two Sets for equality using Groovy's coercion rules.static boolean
equalsIgnoreZeroSign(java.lang.Double number, java.lang.Object other)
Compares this object against the specified object returning the same result asDouble.equals(Object)
but returning true if this object and the specified object are both zero and negative zero respectively or vice versa.static boolean
equalsIgnoreZeroSign(java.lang.Float number, java.lang.Object other)
Compares this object against the specified object returning the same result asFloat.equals(Object)
but returning true if this object and the specified object are both zero and negative zero respectively or vice versa.static <T> boolean
every(java.lang.Iterable<T> self, Closure predicate)
Used to determine if the given predicate closure is valid (i.e.static boolean
every(java.lang.Object self)
Iterates over every element of a collection, and checks whether all elements aretrue
according to the Groovy Truth.static boolean
every(java.lang.Object self, Closure predicate)
Used to determine if the given predicate closure is valid (i.e.static <T> boolean
every(java.util.Iterator<T> self, Closure predicate)
Used to determine if the given predicate closure is valid (i.e.static <K, V> boolean
every(java.util.Map<K,V> self, Closure predicate)
Iterates over the entries of a map, and checks whether a predicate is valid for all entries.static <T> boolean
every(T[] self, Closure predicate)
Used to determine if the given predicate closure is valid (i.e.static java.lang.Object
find(java.lang.Object self)
Finds the first item matching the IDENTITY Closure (i.e. matching Groovy truth).static java.lang.Object
find(java.lang.Object self, Closure closure)
Finds the first value matching the closure condition.static <T> T
find(java.util.Collection<T> self)
Finds the first item matching the IDENTITY Closure (i.e. matching Groovy truth).static <T> T
find(java.util.Collection<T> self, Closure closure)
Finds the first value matching the closure condition.static <K, V> java.util.Map.Entry<K,V>
find(java.util.Map<K,V> self, Closure<?> closure)
Finds the first entry matching the closure condition.static <T> T
find(T[] self, Closure condition)
Finds the first element in the array that matches the given closure condition.static java.util.Collection
findAll(java.lang.Object self)
Finds all items matching the IDENTITY Closure (i.e. matching Groovy truth).static java.util.Collection
findAll(java.lang.Object self, Closure closure)
Finds all items matching the closure condition.static <T> java.util.Collection<T>
findAll(java.util.Collection<T> self)
Finds the items matching the IDENTITY Closure (i.e. matching Groovy truth).static <T> java.util.Collection<T>
findAll(java.util.Collection<T> self, Closure closure)
Finds all values matching the closure condition.static <T> java.util.List<T>
findAll(java.util.List<T> self)
Finds the items matching the IDENTITY Closure (i.e. matching Groovy truth).static <T> java.util.List<T>
findAll(java.util.List<T> self, Closure closure)
Finds all values matching the closure condition.static <K, V> java.util.Map<K,V>
findAll(java.util.Map<K,V> self, Closure closure)
Finds all entries matching the closure condition.static <T> java.util.Set<T>
findAll(java.util.Set<T> self)
Finds the items matching the IDENTITY Closure (i.e. matching Groovy truth).static <T> java.util.Set<T>
findAll(java.util.Set<T> self, Closure closure)
Finds all values matching the closure condition.static <T> java.util.Collection<T>
findAll(T[] self)
Finds the elements of the array matching the IDENTITY Closure (i.e. matching Groovy truth).static <T> java.util.Collection<T>
findAll(T[] self, Closure condition)
Finds all elements of the array matching the given Closure condition.static <T> int
findIndexOf(java.lang.Iterable<T> self, int startIndex, Closure condition)
Iterates over the elements of an Iterable, starting from a specified startIndex, and returns the index of the first item that satisfies the condition specified by the closure.static <T> int
findIndexOf(java.lang.Iterable<T> self, Closure condition)
Iterates over the elements of an Iterable and returns the index of the first item that satisfies the condition specified by the closure.static int
findIndexOf(java.lang.Object self, int startIndex, Closure condition)
Iterates over the elements of an aggregate of items, starting from a specified startIndex, and returns the index of the first item that matches the condition specified in the closure.static int
findIndexOf(java.lang.Object self, Closure condition)
Iterates over the elements of an aggregate of items and returns the index of the first item that matches the condition specified in the closure.static <T> int
findIndexOf(java.util.Iterator<T> self, int startIndex, Closure condition)
Iterates over the elements of an Iterator, starting from a specified startIndex, and returns the index of the first item that satisfies the condition specified by the closure.static <T> int
findIndexOf(java.util.Iterator<T> self, Closure condition)
Iterates over the elements of an Iterator and returns the index of the first item that satisfies the condition specified by the closure.static <T> int
findIndexOf(T[] self, int startIndex, Closure condition)
Iterates over the elements of an Array, starting from a specified startIndex, and returns the index of the first item that satisfies the condition specified by the closure.static <T> int
findIndexOf(T[] self, Closure condition)
Iterates over the elements of an Array and returns the index of the first item that satisfies the condition specified by the closure.static <T> java.util.List<java.lang.Number>
findIndexValues(java.lang.Iterable<T> self, Closure condition)
Iterates over the elements of an Iterable and returns the index values of the items that match the condition specified in the closure.static <T> java.util.List<java.lang.Number>
findIndexValues(java.lang.Iterable<T> self, java.lang.Number startIndex, Closure condition)
Iterates over the elements of an Iterable, starting from a specified startIndex, and returns the index values of the items that match the condition specified in the closure.static java.util.List<java.lang.Number>
findIndexValues(java.lang.Object self, Closure condition)
Iterates over the elements of an aggregate of items and returns the index values of the items that match the condition specified in the closure.static java.util.List<java.lang.Number>
findIndexValues(java.lang.Object self, java.lang.Number startIndex, Closure condition)
Iterates over the elements of an aggregate of items, starting from a specified startIndex, and returns the index values of the items that match the condition specified in the closure.static <T> java.util.List<java.lang.Number>
findIndexValues(java.util.Iterator<T> self, Closure condition)
Iterates over the elements of an Iterator and returns the index values of the items that match the condition specified in the closure.static <T> java.util.List<java.lang.Number>
findIndexValues(java.util.Iterator<T> self, java.lang.Number startIndex, Closure condition)
Iterates over the elements of an Iterator, starting from a specified startIndex, and returns the index values of the items that match the condition specified in the closure.static <T> java.util.List<java.lang.Number>
findIndexValues(T[] self, Closure condition)
Iterates over the elements of an Array and returns the index values of the items that match the condition specified in the closure.static <T> java.util.List<java.lang.Number>
findIndexValues(T[] self, java.lang.Number startIndex, Closure condition)
Iterates over the elements of an Array, starting from a specified startIndex, and returns the index values of the items that match the condition specified in the closure.static <T> int
findLastIndexOf(java.lang.Iterable<T> self, int startIndex, Closure condition)
Iterates over the elements of an Iterable, starting from a specified startIndex, and returns the index of the last item that matches the condition specified in the closure.static <T> int
findLastIndexOf(java.lang.Iterable<T> self, Closure condition)
Iterates over the elements of an Iterable and returns the index of the last item that matches the condition specified in the closure.static int
findLastIndexOf(java.lang.Object self, int startIndex, Closure condition)
Iterates over the elements of an aggregate of items, starting from a specified startIndex, and returns the index of the last item that matches the condition specified in the closure.static int
findLastIndexOf(java.lang.Object self, Closure condition)
Iterates over the elements of an aggregate of items and returns the index of the last item that matches the condition specified in the closure.static <T> int
findLastIndexOf(java.util.Iterator<T> self, int startIndex, Closure condition)
Iterates over the elements of an Iterator, starting from a specified startIndex, and returns the index of the last item that matches the condition specified in the closure.static <T> int
findLastIndexOf(java.util.Iterator<T> self, Closure condition)
Iterates over the elements of an Iterator and returns the index of the last item that matches the condition specified in the closure.static <T> int
findLastIndexOf(T[] self, int startIndex, Closure condition)
Iterates over the elements of an Array, starting from a specified startIndex, and returns the index of the last item that matches the condition specified in the closure.static <T> int
findLastIndexOf(T[] self, Closure condition)
Iterates over the elements of an Array and returns the index of the last item that matches the condition specified in the closure.static <S, T, U extends T, V extends T>
TfindResult(java.lang.Iterable<S> self, U defaultResult, Closure<V> condition)
Iterates through the Iterable calling the given closure condition for each item but stopping once the first non-null result is found and returning that result.static <T, U> T
findResult(java.lang.Iterable<U> self, Closure<T> condition)
Iterates through the Iterable calling the given closure condition for each item but stopping once the first non-null result is found and returning that result.static java.lang.Object
findResult(java.lang.Object self, Closure condition)
Treats the object as iterable, iterating through the values it represents and returns the first non-null result obtained from calling the closure, otherwise returns null.static java.lang.Object
findResult(java.lang.Object self, java.lang.Object defaultResult, Closure condition)
Treats the object as iterable, iterating through the values it represents and returns the first non-null result obtained from calling the closure, otherwise returns the defaultResult.static <S, T> T
findResult(java.util.Collection<S> self, Closure<T> condition)
Deprecated.use the Iterable version insteadstatic <S, T, U extends T, V extends T>
TfindResult(java.util.Collection<S> self, U defaultResult, Closure<V> condition)
Deprecated.use the Iterable version insteadstatic <S, T, U extends T, V extends T>
TfindResult(java.util.Iterator<S> self, U defaultResult, Closure<V> condition)
Iterates through the Iterator calling the given closure condition for each item but stopping once the first non-null result is found and returning that result.static <T, U> T
findResult(java.util.Iterator<U> self, Closure<T> condition)
Iterates through the Iterator calling the given closure condition for each item but stopping once the first non-null result is found and returning that result.static <T, U extends T, V extends T, A, B>
TfindResult(java.util.Map<A,B> self, U defaultResult, Closure<V> condition)
Returns the first non-null closure result found by passing each map entry to the closure, otherwise the defaultResult is returned.static <T, K, V> T
findResult(java.util.Map<K,V> self, Closure<T> condition)
Returns the first non-null closure result found by passing each map entry to the closure, otherwise null is returned.static <S, T> T
findResult(S[] self, Closure<T> condition)
Iterates through the Array calling the given closure condition for each item but stopping once the first non-null result is found and returning that result.static <S, T, U extends T, V extends T>
TfindResult(S[] self, U defaultResult, Closure<V> condition)
Iterates through the Array calling the given closure condition for each item but stopping once the first non-null result is found and returning that result.static <T, U> java.util.Collection<T>
findResults(java.lang.Iterable<U> self, Closure<T> filteringTransform)
Iterates through the Iterable transforming items using the supplied closure and collecting any non-null results.static <T, U> java.util.Collection<T>
findResults(java.util.Collection<U> self, Closure<T> filteringTransform)
Deprecated.Use the Iterable version of findResults insteadstatic <T, U> java.util.Collection<T>
findResults(java.util.Iterator<U> self, Closure<T> filteringTransform)
Iterates through the Iterator transforming items using the supplied closure and collecting any non-null results.static <T, K, V> java.util.Collection<T>
findResults(java.util.Map<K,V> self, Closure<T> filteringTransform)
Iterates through the map transforming items using the supplied closure and collecting any non-null results.static <T, U> java.util.Collection<T>
findResults(U[] self, Closure<T> filteringTransform)
Iterates through the Array transforming items using the supplied closure and collecting any non-null results.static <T> T
first(java.lang.Iterable<T> self)
Returns the first item from the Iterable.static <T> T
first(java.util.List<T> self)
Returns the first item from the List.static <T> T
first(T[] self)
Returns the first item from the array.static java.util.Collection
flatten(boolean[] self)
Flatten an array.static java.util.Collection
flatten(byte[] self)
Flatten an array.static java.util.Collection
flatten(char[] self)
Flatten an array.static java.util.Collection
flatten(double[] self)
Flatten an array.static java.util.Collection
flatten(float[] self)
Flatten an array.static java.util.Collection
flatten(int[] self)
Flatten an array.static java.util.Collection
flatten(long[] self)
Flatten an array.static java.util.Collection
flatten(short[] self)
Flatten an array.static java.util.Collection<?>
flatten(java.lang.Iterable<?> self)
Flatten an Iterable.static <T> java.util.Collection<T>
flatten(java.lang.Iterable<T> self, Closure<? extends T> flattenUsing)
Flatten an Iterable.static java.util.Collection
flatten(java.lang.Object[] self)
Flatten an array.static java.util.Collection<?>
flatten(java.util.Collection<?> self)
Flatten a Collection.static <T> java.util.Collection<T>
flatten(java.util.Collection<T> self, Closure<? extends T> flattenUsing)
Deprecated.Use the Iterable version of flatten insteadstatic java.util.List<?>
flatten(java.util.List<?> self)
Flatten a List.static java.util.Set<?>
flatten(java.util.Set<?> self)
Flatten a Set.static java.util.SortedSet<?>
flatten(java.util.SortedSet<?> self)
Flatten a SortedSet.static <K, V> V
get(java.util.Map<K,V> map, K key, V defaultValue)
Looks up an item in a Map for the given key and returns the value - unless there is no entry for the given key in which case add the default value to the map and return that.static java.util.List<java.lang.Boolean>
getAt(boolean[] array, IntRange range)
Support the subscript operator with an IntRange for a boolean arraystatic java.util.List<java.lang.Boolean>
getAt(boolean[] array, ObjectRange range)
Support the subscript operator with an ObjectRange for a byte arraystatic java.util.List<java.lang.Boolean>
getAt(boolean[] array, Range range)
Support the subscript operator with a range for a boolean arraystatic java.util.List<java.lang.Boolean>
getAt(boolean[] array, java.util.Collection indices)
Support the subscript operator with a collection for a boolean arraystatic java.util.List<java.lang.Byte>
getAt(byte[] array, IntRange range)
Support the subscript operator with an IntRange for a byte arraystatic java.util.List<java.lang.Byte>
getAt(byte[] array, ObjectRange range)
Support the subscript operator with an ObjectRange for a byte arraystatic java.util.List<java.lang.Byte>
getAt(byte[] array, Range range)
Support the subscript operator with a range for a byte arraystatic java.util.List<java.lang.Byte>
getAt(byte[] array, java.util.Collection indices)
Support the subscript operator with a collection for a byte arraystatic java.util.List<java.lang.Character>
getAt(char[] array, IntRange range)
Support the subscript operator with an IntRange for a char arraystatic java.util.List<java.lang.Character>
getAt(char[] array, ObjectRange range)
Support the subscript operator with an ObjectRange for a char arraystatic java.util.List<java.lang.Character>
getAt(char[] array, Range range)
Support the subscript operator with a range for a char arraystatic java.util.List<java.lang.Character>
getAt(char[] array, java.util.Collection indices)
Support the subscript operator with a collection for a char arraystatic java.util.List<java.lang.Double>
getAt(double[] array, IntRange range)
Support the subscript operator with an IntRange for a double arraystatic java.util.List<java.lang.Double>
getAt(double[] array, ObjectRange range)
Support the subscript operator with an ObjectRange for a double arraystatic java.util.List<java.lang.Double>
getAt(double[] array, Range range)
Support the subscript operator with a range for a double arraystatic java.util.List<java.lang.Double>
getAt(double[] array, java.util.Collection indices)
Support the subscript operator with a collection for a double arraystatic java.util.List<java.lang.Float>
getAt(float[] array, IntRange range)
Support the subscript operator with an IntRange for a float arraystatic java.util.List<java.lang.Float>
getAt(float[] array, ObjectRange range)
Support the subscript operator with an ObjectRange for a float arraystatic java.util.List<java.lang.Float>
getAt(float[] array, Range range)
Support the subscript operator with a range for a float arraystatic java.util.List<java.lang.Float>
getAt(float[] array, java.util.Collection indices)
Support the subscript operator with a collection for a float arraystatic java.util.List<java.lang.Integer>
getAt(int[] array, IntRange range)
Support the subscript operator with an IntRange for an int arraystatic java.util.List<java.lang.Integer>
getAt(int[] array, ObjectRange range)
Support the subscript operator with an ObjectRange for an int arraystatic java.util.List<java.lang.Integer>
getAt(int[] array, Range range)
Support the subscript operator with a range for an int arraystatic java.util.List<java.lang.Integer>
getAt(int[] array, java.util.Collection indices)
Support the subscript operator with a collection for an int arraystatic java.util.List<java.lang.Long>
getAt(long[] array, IntRange range)
Support the subscript operator with an IntRange for a long arraystatic java.util.List<java.lang.Long>
getAt(long[] array, ObjectRange range)
Support the subscript operator with an ObjectRange for a long arraystatic java.util.List<java.lang.Long>
getAt(long[] array, Range range)
Support the subscript operator with a range for a long arraystatic java.util.List<java.lang.Long>
getAt(long[] array, java.util.Collection indices)
Support the subscript operator with a collection for a long arraystatic java.util.List<java.lang.Short>
getAt(short[] array, IntRange range)
Support the subscript operator with an IntRange for a short arraystatic java.util.List<java.lang.Short>
getAt(short[] array, ObjectRange range)
Support the subscript operator with an ObjectRange for a short arraystatic java.util.List<java.lang.Short>
getAt(short[] array, Range range)
Support the subscript operator with a range for a short arraystatic java.util.List<java.lang.Short>
getAt(short[] array, java.util.Collection indices)
Support the subscript operator with a collection for a short arraystatic <T> java.util.List<T>
getAt(ListWithDefault<T> self, EmptyRange range)
Support the range subscript operator for an eager or lazy List.static <T> java.util.List<T>
getAt(ListWithDefault<T> self, Range range)
Support the range subscript operator for an eager or lazy List.static <T> java.util.List<T>
getAt(ListWithDefault<T> self, java.util.Collection indices)
Select a List of items from an eager or lazy List using a Collection to identify the indices to be selected.static <T> T
getAt(java.lang.Iterable<T> self, int idx)
Support the subscript operator for an Iterable.static java.lang.Object
getAt(java.lang.Object self, java.lang.String property)
Allows the subscript operator to be used to lookup dynamic property values.static boolean
getAt(java.util.BitSet self, int index)
Support the subscript operator for a Bitsetstatic java.util.BitSet
getAt(java.util.BitSet self, IntRange range)
Support retrieving a subset of a BitSet using a Rangestatic java.util.List
getAt(java.util.Collection coll, java.lang.String property)
Support the subscript operator for Collection.static <T> T
getAt(java.util.Iterator<T> self, int idx)
Support the subscript operator for an Iterator.static <T> T
getAt(java.util.List<T> self, int idx)
Support the subscript operator for a List.static <T> java.util.List<T>
getAt(java.util.List<T> self, EmptyRange range)
Support the range subscript operator for a List.static <T> java.util.List<T>
getAt(java.util.List<T> self, Range range)
Support the range subscript operator for a List.static <T> T
getAt(java.util.List<T> self, java.lang.Number idx)
Support subscript operator for list access.static <T> java.util.List<T>
getAt(java.util.List<T> self, java.util.Collection indices)
Select a List of items from a List using a Collection to identify the indices to be selected.static <K, V> V
getAt(java.util.Map<K,V> self, java.lang.Object key)
Support the subscript operator for a Map.static <T> java.util.List<T>
getAt(T[] array, EmptyRange range)
static <T> java.util.List<T>
getAt(T[] array, IntRange range)
static <T> java.util.List<T>
getAt(T[] array, ObjectRange range)
static <T> java.util.List<T>
getAt(T[] array, Range range)
Support the range subscript operator for an Arraystatic <T> java.util.List<T>
getAt(T[] self, java.util.Collection indices)
Select a List of items from an array using a Collection to identify the indices to be selected.static Groovydoc
getGroovydoc(java.lang.reflect.AnnotatedElement holder)
Get runtime groovydocstatic IntRange
getIndices(boolean[] self)
Returns indices of the boolean array.static IntRange
getIndices(byte[] self)
Returns indices of the byte array.static IntRange
getIndices(char[] self)
Returns indices of the char array.static IntRange
getIndices(double[] self)
Returns indices of the double array.static IntRange
getIndices(float[] self)
Returns indices of the float array.static IntRange
getIndices(int[] self)
Returns indices of the int array.static IntRange
getIndices(long[] self)
Returns indices of the long array.static IntRange
getIndices(short[] self)
Returns indices of the short array.static IntRange
getIndices(java.util.Collection self)
Returns indices of the collection.static <T> IntRange
getIndices(T[] self)
Returns indices of the array.static java.net.URL
getLocation(java.lang.Class self)
Gets the url of the jar file/source file containing the specified classstatic MetaClass
getMetaClass(GroovyObject obj)
Obtains a MetaClass for an object either from the registry or in the case of a GroovyObject from the object itself.static MetaClass
getMetaClass(java.lang.Class c)
Adds a "metaClass" property to all class objects so you can use the syntaxString.metaClass.myMethod = { println "foo" }
static MetaClass
getMetaClass(java.lang.Object obj)
Obtains a MetaClass for an object either from the registry or in the case of a GroovyObject from the object itself.static java.util.List<PropertyValue>
getMetaPropertyValues(java.lang.Object self)
Retrieves the list ofMetaProperty
objects for 'self' and wraps it in a list ofPropertyValue
objects that additionally provide the value for each property of 'self'.static java.util.Map
getProperties(java.lang.Object self)
Convenience method that callsgetMetaPropertyValues(java.lang.Object)
(self) and provides the data in form of simple key/value pairs, i.e.static java.lang.ClassLoader
getRootLoader(java.lang.ClassLoader self)
Iterates through the classloader parents until it finds a loader with a class named "org.codehaus.groovy.tools.RootLoader".protected static java.util.List
getSubList(java.util.List self, java.util.List splice)
Deprecated.static java.util.Collection
grep(java.lang.Object self)
Iterates over the collection of items which this Object represents and returns each item that matches using the IDENTITY Closure as a filter - effectively returning all elements which satisfy Groovy truth.static java.util.Collection
grep(java.lang.Object self, java.lang.Object filter)
Iterates over the collection of items which this Object represents and returns each item that matches the given filter - calling the
method used by switch statements.isCase(java.lang.Object, java.lang.Object)
static <T> java.util.Collection<T>
grep(java.util.Collection<T> self)
Iterates over the collection returning each element that matches using the IDENTITY Closure as a filter - effectively returning all elements which satisfy Groovy truth.static <T> java.util.Collection<T>
grep(java.util.Collection<T> self, java.lang.Object filter)
Iterates over the collection of items and returns each item that matches the given filter - calling the
method used by switch statements.isCase(java.lang.Object, java.lang.Object)
static <T> java.util.List<T>
grep(java.util.List<T> self)
Iterates over the collection returning each element that matches using the IDENTITY Closure as a filter - effectively returning all elements which satisfy Groovy truth.static <T> java.util.List<T>
grep(java.util.List<T> self, java.lang.Object filter)
Iterates over the collection of items and returns each item that matches the given filter - calling the
method used by switch statements.isCase(java.lang.Object, java.lang.Object)
static <T> java.util.Set<T>
grep(java.util.Set<T> self)
Iterates over the collection returning each element that matches using the IDENTITY Closure as a filter - effectively returning all elements which satisfy Groovy truth.static <T> java.util.Set<T>
grep(java.util.Set<T> self, java.lang.Object filter)
Iterates over the collection of items and returns each item that matches the given filter - calling the
method used by switch statements.isCase(java.lang.Object, java.lang.Object)
static <T> java.util.Collection<T>
grep(T[] self)
Iterates over the array returning each element that matches using the IDENTITY Closure as a filter - effectively returning all elements which satisfy Groovy truth.static <T> java.util.Collection<T>
grep(T[] self, java.lang.Object filter)
Iterates over the array of items and returns a collection of items that match the given filter - calling the
method used by switch statements.isCase(java.lang.Object, java.lang.Object)
protected static <K, T> void
groupAnswer(java.util.Map<K,java.util.List<T>> answer, T element, K value)
Groups the current element according to the valuestatic <K, T> java.util.Map<K,java.util.List<T>>
groupBy(java.lang.Iterable<T> self, Closure<K> closure)
Sorts all Iterable members into groups determined by the supplied mapping closure.static java.util.Map
groupBy(java.lang.Iterable self, java.lang.Object... closures)
Sorts all Iterable members into (sub)groups determined by the supplied mapping closures.static java.util.Map
groupBy(java.lang.Iterable self, java.util.List<Closure> closures)
Sorts all Iterable members into (sub)groups determined by the supplied mapping closures.static java.util.Map
groupBy(java.lang.Object[] self, java.lang.Object... closures)
Sorts all array members into (sub)groups determined by the supplied mapping closures as per the Iterable variant of this method.static java.util.Map
groupBy(java.lang.Object[] self, java.util.List<Closure> closures)
Sorts all array members into (sub)groups determined by the supplied mapping closures as per the list variant of this method.static <K, T> java.util.Map<K,java.util.List<T>>
groupBy(java.util.Collection<T> self, Closure<K> closure)
Deprecated.Use the Iterable version of groupBy insteadstatic java.util.Map
groupBy(java.util.Collection self, java.lang.Object... closures)
Deprecated.Use the Iterable version of groupBy insteadstatic java.util.Map
groupBy(java.util.Collection self, java.util.List<Closure> closures)
Deprecated.Use the Iterable version of groupBy insteadstatic <G, K, V> java.util.Map<G,java.util.Map<K,V>>
groupBy(java.util.Map<K,V> self, Closure<G> closure)
Groups the members of a map into sub maps determined by the supplied mapping closure.static java.util.Map<java.lang.Object,java.util.Map>
groupBy(java.util.Map self, java.lang.Object... closures)
Groups the members of a map into sub maps determined by the supplied mapping closures.static java.util.Map<java.lang.Object,java.util.Map>
groupBy(java.util.Map self, java.util.List<Closure> closures)
Groups the members of a map into sub maps determined by the supplied mapping closures.static <K, T> java.util.Map<K,java.util.List<T>>
groupBy(T[] self, Closure<K> closure)
Sorts all array members into groups determined by the supplied mapping closure.static <G, K, V> java.util.Map<G,java.util.List<java.util.Map.Entry<K,V>>>
groupEntriesBy(java.util.Map<K,V> self, Closure<G> closure)
Groups all map entries into groups determined by the supplied mapping closure.static MetaProperty
hasProperty(java.lang.Object self, java.lang.String name)
Returns true of the implementing MetaClass has a property of the given namestatic <T> T
head(java.lang.Iterable<T> self)
Returns the first item from the Iterable.static <T> T
head(java.util.List<T> self)
Returns the first item from the List.static <T> T
head(T[] self)
Returns the first item from the Object array.static <T, U> T
identity(U self, Closure<T> closure)
Allows the closure to be called for the object reference self.static java.lang.Boolean
implies(java.lang.Boolean left, java.lang.Boolean right)
Logical implication of two boolean operatorsstatic java.util.Map<java.lang.Integer,java.lang.Double>
indexed(double[] self)
Zips a double[] with indices in (index, value) order starting from index 0.static java.util.Map<java.lang.Integer,java.lang.Double>
indexed(double[] self, int offset)
Zips a double[] with indices in (index, value) order.static java.util.Map<java.lang.Integer,java.lang.Integer>
indexed(int[] self)
Zips an int[] with indices in (index, value) order starting from index 0.static java.util.Map<java.lang.Integer,java.lang.Integer>
indexed(int[] self, int offset)
Zips an int[] with indices in (index, value) order.static java.util.Map<java.lang.Integer,java.lang.Long>
indexed(long[] self)
Zips a long[] with indices in (index, value) order starting from index 0.static java.util.Map<java.lang.Integer,java.lang.Long>
indexed(long[] self, int offset)
Zips a long[] with indices in (index, value) order.static <E> java.util.Map<java.lang.Integer,E>
indexed(java.lang.Iterable<E> self)
Zips an Iterable with indices in (index, value) order.static <E> java.util.Map<java.lang.Integer,E>
indexed(java.lang.Iterable<E> self, int offset)
Zips an Iterable with indices in (index, value) order.static <E> java.util.Iterator<Tuple2<java.lang.Integer,E>>
indexed(java.util.Iterator<E> self)
Zips an iterator with indices in (index, value) order.static <E> java.util.Iterator<Tuple2<java.lang.Integer,E>>
indexed(java.util.Iterator<E> self, int offset)
Zips an iterator with indices in (index, value) order.static <T> java.util.Collection<T>
init(java.lang.Iterable<T> self)
Returns the items from the Iterable excluding the last item.static <T> java.util.Iterator<T>
init(java.util.Iterator<T> self)
Returns an Iterator containing all of the items from this iterator except the last one.static <T> java.util.List<T>
init(java.util.List<T> self)
Returns the items from the List excluding the last item.static <T> java.util.SortedSet<T>
init(java.util.SortedSet<T> self)
Returns the items from the SortedSet excluding the last item.static <T> T[]
init(T[] self)
Returns the items from the Object array excluding the last item.static <T> java.util.List<java.util.List<T>>
inits(java.lang.Iterable<T> self)
Calculates the init values of this Iterable: the first value will be this list of all items from the iterable and the final one will be an empty list, with the intervening values the results of successive applications of init on the items.static <E, T, V extends T>
Tinject(E[] self, Closure<V> closure)
Iterates through the given array as with inject(Object[],initialValue,closure), but using the first element of the array as the initialValue, and then iterating the remaining elements of the array.static <E, T, U extends T, V extends T>
Tinject(E[] self, U initialValue, Closure<V> closure)
Iterates through the given array, passing in the initial value to the closure along with the first item.static <T, V extends T>
Tinject(java.lang.Object self, Closure<V> closure)
Iterates through the given Object, passing in the first value to the closure along with the first item.static <T, U extends T, V extends T>
Tinject(java.lang.Object self, U initialValue, Closure<V> closure)
Iterates through the given Object, passing in the initial value to the closure along with the first item.static <E, T, U extends T, V extends T>
Tinject(java.util.Collection<E> self, U initialValue, Closure<V> closure)
Iterates through the given Collection, passing in the initial value to the 2-arg closure along with the first item.static <T, V extends T>
Tinject(java.util.Collection<T> self, Closure<V> closure)
Performs the same function as the version of inject that takes an initial value, but uses the head of the Collection as the initial value, and iterates over the tail.static <E, T, U extends T, V extends T>
Tinject(java.util.Iterator<E> self, U initialValue, Closure<V> closure)
Iterates through the given Iterator, passing in the initial value to the closure along with the first item.static <K, V, T, U extends T, W extends T>
Tinject(java.util.Map<K,V> self, U initialValue, Closure<W> closure)
Iterates through the given Map, passing in the initial value to the 2-arg Closure along with the first item (or 3-arg Closure along with the first key and value).static java.lang.String
inspect(java.lang.Object self)
Inspects returns the String that matches what would be typed into a terminal to create this object.static java.lang.Number
intdiv(java.lang.Character left, java.lang.Character right)
Integer Divide two Characters.static java.lang.Number
intdiv(java.lang.Character left, java.lang.Number right)
Integer Divide a Character by a Number.static java.lang.Number
intdiv(java.lang.Number left, java.lang.Character right)
Integer Divide a Number by a Character.static java.lang.Number
intdiv(java.lang.Number left, java.lang.Number right)
Integer Divide two Numbers.static <T> java.util.Collection<T>
intersect(java.lang.Iterable<T> left, java.lang.Iterable<T> right)
Create a Collection composed of the intersection of both iterables.static <T> java.util.Collection<T>
intersect(java.lang.Iterable<T> left, java.lang.Iterable<T> right, java.util.Comparator<T> comparator)
Create a Collection composed of the intersection of both iterables.static <T> java.util.Collection<T>
intersect(java.util.Collection<T> left, java.util.Collection<T> right)
Create a Collection composed of the intersection of both collections.static <T> java.util.Collection<T>
intersect(java.util.Collection<T> left, java.util.Collection<T> right, java.util.Comparator<T> comparator)
Create a Collection composed of the intersection of both collections.static <T> java.util.List<T>
intersect(java.util.List<T> left, java.lang.Iterable<T> right)
Create a List composed of the intersection of a List and an Iterable.static <T> java.util.List<T>
intersect(java.util.List<T> left, java.lang.Iterable<T> right, java.util.Comparator<T> comparator)
Create a List composed of the intersection of a List and an Iterable.static <K, V> java.util.Map<K,V>
intersect(java.util.Map<K,V> left, java.util.Map<K,V> right)
Create a Map composed of the intersection of both maps.static <T> java.util.Set<T>
intersect(java.util.Set<T> left, java.lang.Iterable<T> right)
Create a Set composed of the intersection of a Set and an Iterable.static <T> java.util.Set<T>
intersect(java.util.Set<T> left, java.lang.Iterable<T> right, java.util.Comparator<T> comparator)
Create a Set composed of the intersection of a Set and an Iterable.static <T> java.util.SortedSet<T>
intersect(java.util.SortedSet<T> left, java.lang.Iterable<T> right)
Create a SortedSet composed of the intersection of a SortedSet and an Iterable.static <T> java.util.SortedSet<T>
intersect(java.util.SortedSet<T> left, java.lang.Iterable<T> right, java.util.Comparator<T> comparator)
Create a SortedSet composed of the intersection of a SortedSet and an Iterable.static java.lang.Object
invokeMethod(java.lang.Object object, java.lang.String method, java.lang.Object arguments)
Provide a dynamic method invocation method which can be overloaded in classes to implement dynamic proxies easily.static boolean
is(java.lang.Object self, java.lang.Object other)
Identity check.static java.lang.Boolean
isAtLeast(java.math.BigDecimal left, java.lang.String right)
Compare a BigDecimal to a String representing a number.static java.lang.Boolean
isAtLeast(java.math.BigDecimal left, java.math.BigDecimal right)
Compare a BigDecimal to another.static boolean
isCase(java.lang.Class caseValue, java.lang.Object switchValue)
Special 'Case' implementation for Class, which allows testing whether some switch value is assignable from the given case class.static boolean
isCase(java.lang.Number caseValue, java.lang.Number switchValue)
Special 'case' implementation for all numbers, which delegates to thecompareTo()
method for comparing numbers of different types.static boolean
isCase(java.lang.Object caseValue, java.lang.Object switchValue)
Method for overloading the behavior of the 'case' method in switch statements.static boolean
isCase(java.util.Collection caseValue, java.lang.Object switchValue)
'Case' implementation for collections which tests if the 'switch' operand is contained in any of the 'case' values.static boolean
isCase(java.util.Map caseValue, java.lang.Object switchValue)
'Case' implementation for maps which tests the groovy truth value obtained using the 'switch' operand as key.static boolean
isDigit(java.lang.Character self)
Determines if a character is a digit.static boolean
isEmpty(java.lang.Iterable self)
Check whether anIterable
has elementsstatic boolean
isLetter(java.lang.Character self)
Determines if a character is a letter.static boolean
isLetterOrDigit(java.lang.Character self)
Determines if a character is a letter or digit.static boolean
isLowerCase(java.lang.Character self)
Determine if a Character is lowercase.static boolean
isUpperCase(java.lang.Character self)
Determine if a Character is uppercase.static boolean
isWhitespace(java.lang.Character self)
Determines if a character is a whitespace character.static java.util.Iterator
iterator(java.lang.Object o)
Attempts to create an Iterator for the given object by first converting it to a Collection.static <T> java.util.Iterator<T>
iterator(java.util.Enumeration<T> enumeration)
Allows an Enumeration to behave like an Iterator.static <T> java.util.Iterator<T>
iterator(java.util.Iterator<T> self)
An identity function for iterators, supporting 'duck-typing' when trying to get an iterator for each object within a collection, some of which may already be iterators.static <T> java.util.Iterator<T>
iterator(T[] a)
Attempts to create an Iterator for the given object by first converting it to a Collection.static java.lang.String
join(boolean[] self, java.lang.String separator)
Concatenates the string representation of each items in this array, with the given String as a separator between each item.static java.lang.String
join(byte[] self, java.lang.String separator)
Concatenates the string representation of each items in this array, with the given String as a separator between each item.static java.lang.String
join(char[] self, java.lang.String separator)
Concatenates the string representation of each items in this array, with the given String as a separator between each item.static java.lang.String
join(double[] self, java.lang.String separator)
Concatenates the string representation of each items in this array, with the given String as a separator between each item.static java.lang.String
join(float[] self, java.lang.String separator)
Concatenates the string representation of each items in this array, with the given String as a separator between each item.static java.lang.String
join(int[] self, java.lang.String separator)
Concatenates the string representation of each items in this array, with the given String as a separator between each item.static java.lang.String
join(long[] self, java.lang.String separator)
Concatenates the string representation of each items in this array, with the given String as a separator between each item.static java.lang.String
join(short[] self, java.lang.String separator)
Concatenates the string representation of each items in this array, with the given String as a separator between each item.static java.lang.String
join(java.lang.Iterable<?> self, java.lang.String separator)
Concatenates thetoString()
representation of each item in this Iterable, with the given String as a separator between each item.static java.lang.String
join(java.util.Collection self, java.lang.String separator)
Deprecated.Use the Iterable version of join insteadstatic java.lang.String
join(java.util.Iterator<?> self, java.lang.String separator)
Concatenates thetoString()
representation of each item from the iterator, with the given String as a separator between each item.static <T> java.lang.String
join(T[] self, java.lang.String separator)
Concatenates thetoString()
representation of each items in this array, with the given String as a separator between each item.static <T> T
last(java.lang.Iterable<T> self)
Returns the last item from the Iterable.static <T> T
last(java.util.Deque<T> self)
An optimized version oflast(List)
.static <T> T
last(java.util.List<T> self)
Returns the last item from the List.static <T> T
last(T[] self)
Returns the last item from the array.static java.lang.Number
leftShift(java.lang.Number self, java.lang.Number operand)
Implementation of the left shift operator for integral types.static <T> java.util.Collection<T>
leftShift(java.util.Collection<T> self, T value)
Overloads the left shift operator to provide an easy way to append objects to a Collection.static <T> java.util.concurrent.BlockingQueue<T>
leftShift(java.util.concurrent.BlockingQueue<T> self, T value)
Overloads the left shift operator to provide an easy way to append objects to a BlockingQueue.static <T> java.util.List<T>
leftShift(java.util.List<T> self, T value)
Overloads the left shift operator to provide an easy way to append objects to a List.static <K, V> java.util.Map<K,V>
leftShift(java.util.Map<K,V> self, java.util.Map.Entry<K,V> entry)
Overloads the left shift operator to provide an easy way to append Map.Entry values to a Map.static <K, V> java.util.Map<K,V>
leftShift(java.util.Map<K,V> self, java.util.Map<K,V> other)
Overloads the left shift operator to provide an easy way to put one maps entries into another map.static <T> java.util.Set<T>
leftShift(java.util.Set<T> self, T value)
Overloads the left shift operator to provide an easy way to append objects to a Set.static <T> java.util.SortedSet<T>
leftShift(java.util.SortedSet<T> self, T value)
Overloads the left shift operator to provide an easy way to append objects to a SortedSet.static double
max(double[] self)
Adds max() method to double arrays.static int
max(int[] self)
Adds max() method to int arrays.static long
max(long[] self)
Adds max() method to long arrays.static <T> T
max(java.lang.Iterable<T> self)
Adds max() method to Iterable objects.static <T> T
max(java.lang.Iterable<T> self, Closure closure)
Selects the item in the iterable which when passed as a parameter to the supplied closure returns the maximum value.static <T> T
max(java.lang.Iterable<T> self, java.util.Comparator<T> comparator)
Selects the maximum value found in the Iterable using the given comparator.static <T> T
max(java.util.Collection<T> self)
Deprecated.Use the Iterable version of max insteadstatic <T> T
max(java.util.Collection<T> self, Closure closure)
Deprecated.Use the Iterable version of max insteadstatic <T> T
max(java.util.Collection<T> self, java.util.Comparator<T> comparator)
Deprecated.Use the Iterable version of max insteadstatic <T> T
max(java.util.Iterator<T> self)
Adds max() method to Iterator objects.static <T> T
max(java.util.Iterator<T> self, Closure closure)
Selects the maximum value found from the Iterator using the closure to determine the correct ordering.static <T> T
max(java.util.Iterator<T> self, java.util.Comparator<T> comparator)
Selects the maximum value found from the Iterator using the given comparator.static <K, V> java.util.Map.Entry<K,V>
max(java.util.Map<K,V> self, Closure closure)
Selects an entry in the map having the maximum calculated value as determined by the supplied closure.static <T> T
max(T[] self)
Adds max() method to Object arrays.static <T> T
max(T[] self, Closure closure)
Selects the maximum value found from the Object array using the closure to determine the correct ordering.static <T> T
max(T[] self, java.util.Comparator<T> comparator)
Selects the maximum value found from the Object array using the given comparator.static MetaClass
metaClass(java.lang.Class self, Closure closure)
Sets/updates the metaclass for a given class to a closure.static MetaClass
metaClass(java.lang.Object self, Closure closure)
Sets/updates the metaclass for a given object to a closure.static double
min(double[] self)
Adds min() method to double arrays.static int
min(int[] self)
Adds min() method to int arrays.static long
min(long[] self)
Adds min() method to long arrays.static <T> T
min(java.lang.Iterable<T> self)
Adds min() method to Collection objects.static <T> T
min(java.lang.Iterable<T> self, Closure closure)
Selects the item in the iterable which when passed as a parameter to the supplied closure returns the minimum value.static <T> T
min(java.lang.Iterable<T> self, java.util.Comparator<T> comparator)
Selects the minimum value found in the Iterable using the given comparator.static <T> T
min(java.util.Collection<T> self)
Deprecated.Use the Iterable version of min insteadstatic <T> T
min(java.util.Collection<T> self, Closure closure)
Deprecated.Use the Iterable version of min insteadstatic <T> T
min(java.util.Collection<T> self, java.util.Comparator<T> comparator)
Deprecated.Use the Iterable version of min insteadstatic <T> T
min(java.util.Iterator<T> self)
Adds min() method to Iterator objects.static <T> T
min(java.util.Iterator<T> self, Closure closure)
Selects the minimum value found from the Iterator using the closure to determine the correct ordering.static <T> T
min(java.util.Iterator<T> self, java.util.Comparator<T> comparator)
Selects the minimum value found from the Iterator using the given comparator.static <K, V> java.util.Map.Entry<K,V>
min(java.util.Map<K,V> self, Closure closure)
Selects an entry in the map having the minimum calculated value as determined by the supplied closure.static <T> T
min(T[] self)
Adds min() method to Object arrays.static <T> T
min(T[] self, Closure closure)
Selects the minimum value found from the Object array using the closure to determine the correct ordering.static <T> T
min(T[] self, java.util.Comparator<T> comparator)
Selects the minimum value found from the Object array using the given comparator.static java.lang.Number
minus(java.lang.Character left, java.lang.Character right)
Subtract one Character from another.static java.lang.Number
minus(java.lang.Character left, java.lang.Number right)
Subtract a Number from a Character.static <T> java.util.Collection<T>
minus(java.lang.Iterable<T> self, java.lang.Iterable<?> removeMe)
Create a new Collection composed of the elements of the first Iterable minus every occurrence of elements of the given Iterable.static <T> java.util.Collection<T>
minus(java.lang.Iterable<T> self, java.lang.Object removeMe)
Create a new Collection composed of the elements of the first Iterable minus every occurrence of the given element to remove.static java.lang.Number
minus(java.lang.Number left, java.lang.Character right)
Subtract a Character from a Number.static <T> java.util.Collection<T>
minus(java.util.Collection<T> self, java.util.Collection<?> removeMe)
Create a new Collection composed of the elements of the first Collection minus every occurrence of elements of the given Collection.static <T> java.util.List<T>
minus(java.util.List<T> self, java.lang.Iterable<?> removeMe)
Create a new List composed of the elements of the first List minus every occurrence of elements of the given Iterable.static <T> java.util.List<T>
minus(java.util.List<T> self, java.lang.Object removeMe)
Create a new List composed of the elements of the first List minus every occurrence of the given element to remove.static <T> java.util.List<T>
minus(java.util.List<T> self, java.util.Collection<?> removeMe)
Create a List composed of the elements of the first list minus every occurrence of elements of the given Collection.static <K, V> java.util.Map<K,V>
minus(java.util.Map<K,V> self, java.util.Map removeMe)
Create a Map composed of the entries of the first map minus the entries of the given map.static <T> java.util.Set<T>
minus(java.util.Set<T> self, java.lang.Iterable<?> removeMe)
Create a Set composed of the elements of the first Set minus the elements from the given Iterable.static <T> java.util.Set<T>
minus(java.util.Set<T> self, java.lang.Object removeMe)
Create a Set composed of the elements of the first Set minus the given element.static <T> java.util.Set<T>
minus(java.util.Set<T> self, java.util.Collection<?> removeMe)
Create a Set composed of the elements of the first Set minus the elements of the given Collection.static <T> java.util.SortedSet<T>
minus(java.util.SortedSet<T> self, java.lang.Iterable<?> removeMe)
Create a SortedSet composed of the elements of the first SortedSet minus the elements of the given Iterable.static <T> java.util.SortedSet<T>
minus(java.util.SortedSet<T> self, java.lang.Object removeMe)
Create a SortedSet composed of the elements of the first SortedSet minus the given element.static <T> java.util.SortedSet<T>
minus(java.util.SortedSet<T> self, java.util.Collection<?> removeMe)
Create a SortedSet composed of the elements of the first SortedSet minus the elements of the given Collection.static <T> T[]
minus(T[] self, java.lang.Iterable removeMe)
Create a new array composed of the elements of the first array minus the elements of the given Iterable.static <T> T[]
minus(T[] self, java.lang.Object removeMe)
Create a new array composed of the elements of the first array minus the element to remove.static <T> T[]
minus(T[] self, java.lang.Object[] removeMe)
Create a new array composed of the elements of the first array minus the elements of the given array.static void
mixin(MetaClass self, java.lang.Class categoryClass)
Extend class globally with category methods.static void
mixin(MetaClass self, java.lang.Class[] categoryClass)
Extend class globally with category methods.static void
mixin(MetaClass self, java.util.List<java.lang.Class> categoryClasses)
Extend object with category methods.static void
mixin(java.lang.Class self, java.lang.Class categoryClass)
Extend class globally with category methods.static void
mixin(java.lang.Class self, java.lang.Class[] categoryClass)
Extend class globally with category methods.static void
mixin(java.lang.Class self, java.util.List<java.lang.Class> categoryClasses)
Extend class globally with category methods.static java.lang.Number
mod(java.lang.Number left, java.lang.Number right)
Performs a division modulus operation.static java.lang.Number
multiply(java.lang.Character left, java.lang.Character right)
Multiply two Characters.static java.lang.Number
multiply(java.lang.Character left, java.lang.Number right)
Multiply a Character by a Number.static <T> java.util.Collection<T>
multiply(java.lang.Iterable<T> self, java.lang.Number factor)
Create a Collection composed of the elements of this Iterable, repeated a certain number of times.static java.lang.Number
multiply(java.lang.Number left, java.lang.Character right)
Multiply a Number by a Character.static java.lang.Number
multiply(java.math.BigDecimal left, java.lang.Double right)
Multiply a BigDecimal and a Double.static java.lang.Number
multiply(java.math.BigDecimal left, java.math.BigInteger right)
Multiply a BigDecimal and a BigInteger.static <T> java.util.Collection<T>
multiply(java.util.Collection<T> self, java.lang.Number factor)
Deprecated.use the Iterable variant insteadstatic <T> java.util.List<T>
multiply(java.util.List<T> self, java.lang.Number factor)
Create a List composed of the elements of this Iterable, repeated a certain number of times.static <T> T
newInstance(java.lang.Class<T> c)
Convenience method to dynamically create a new instance of this class.static <T> T
newInstance(java.lang.Class<T> c, java.lang.Object[] args)
Helper to construct a new instance from the given arguments.static java.lang.Character
next(java.lang.Character self)
Increment a Character by one.static java.lang.Number
next(java.lang.Number self)
Increment a Number by one.static int
numberAwareCompareTo(java.lang.Comparable self, java.lang.Comparable other)
Provides a method that compares two comparables using Groovy's default number aware comparator.static java.lang.Boolean
or(java.lang.Boolean left, java.lang.Boolean right)
Logical disjunction of two boolean operatorsstatic java.lang.Number
or(java.lang.Number left, java.lang.Number right)
Bitwise OR together two numbers.static java.util.BitSet
or(java.util.BitSet left, java.util.BitSet right)
Bitwise OR together two BitSets.static <T> java.util.Set<java.util.List<T>>
permutations(java.lang.Iterable<T> self)
Finds all permutations of an iterable.static <T, V> java.util.List<V>
permutations(java.lang.Iterable<T> self, Closure<V> function)
Finds all permutations of an iterable, applies a function to each permutation and collects the result into a list.static <T, V> java.util.List<V>
permutations(java.util.List<T> self, Closure<V> function)
Deprecated.Use the Iterable version of permutations insteadstatic java.lang.Number
plus(java.lang.Character left, java.lang.Character right)
Add one Character to another.static java.lang.Number
plus(java.lang.Character left, java.lang.Number right)
Add a Character and a Number.static <T> java.util.Collection<T>
plus(java.lang.Iterable<T> left, java.lang.Iterable<T> right)
Create a Collection as a union of two iterables.static <T> java.util.Collection<T>
plus(java.lang.Iterable<T> left, T right)
Create a collection as a union of an Iterable and an Object.static java.lang.Number
plus(java.lang.Number left, java.lang.Character right)
Add a Number and a Character.static <T> java.util.Collection<T>
plus(java.util.Collection<T> left, java.lang.Iterable<T> right)
Create a Collection as a union of a Collection and an Iterable.static <T> java.util.Collection<T>
plus(java.util.Collection<T> left, java.util.Collection<T> right)
Create a Collection as a union of two collections.static <T> java.util.Collection<T>
plus(java.util.Collection<T> left, T right)
Create a collection as a union of a Collection and an Object.static <T> java.util.List<T>
plus(java.util.List<T> self, int index, java.lang.Iterable<T> additions)
Creates a new List by inserting all of the elements in the given Iterable to the elements from this List at the specified index.static <T> java.util.List<T>
plus(java.util.List<T> self, int index, java.util.List<T> additions)
Creates a new List by inserting all of the elements in the given additions List to the elements from the original List at the specified index.static <T> java.util.List<T>
plus(java.util.List<T> self, int index, T[] items)
Creates a new List by inserting all of the elements in the specified array to the elements from the original List at the specified index.static <T> java.util.List<T>
plus(java.util.List<T> left, java.lang.Iterable<T> right)
Create a List as a union of a List and an Iterable.static <T> java.util.List<T>
plus(java.util.List<T> left, java.util.Collection<T> right)
Create a List as a union of a List and a Collection.static <T> java.util.List<T>
plus(java.util.List<T> left, T right)
Create a List as a union of a List and an Object.static <K, V> java.util.Map<K,V>
plus(java.util.Map<K,V> self, java.util.Collection<? extends java.util.Map.Entry<? extends K,? extends V>> entries)
Returns a newMap
containing all entries fromself
andentries
, giving precedence toentries
.static <K, V> java.util.Map<K,V>
plus(java.util.Map<K,V> left, java.util.Map<K,V> right)
Returns a newMap
containing all entries fromleft
andright
, giving precedence toright
.static <T> java.util.Set<T>
plus(java.util.Set<T> left, java.lang.Iterable<T> right)
Create a Set as a union of a Set and an Iterable.static <T> java.util.Set<T>
plus(java.util.Set<T> left, java.util.Collection<T> right)
Create a Set as a union of a Set and a Collection.static <T> java.util.Set<T>
plus(java.util.Set<T> left, T right)
Create a Set as a union of a Set and an Object.static <T> java.util.SortedSet<T>
plus(java.util.SortedSet<T> left, java.lang.Iterable<T> right)
Create a SortedSet as a union of a SortedSet and an Iterable.static <T> java.util.SortedSet<T>
plus(java.util.SortedSet<T> left, java.util.Collection<T> right)
Create a SortedSet as a union of a SortedSet and a Collection.static <T> java.util.SortedSet<T>
plus(java.util.SortedSet<T> left, T right)
Create a SortedSet as a union of a SortedSet and an Object.static <T> T[]
plus(T[] left, java.lang.Iterable<T> right)
Create an array containing elements from an original array plus those from an Iterable.static <T> T[]
plus(T[] left, java.util.Collection<T> right)
Create an array containing elements from an original array plus those from a Collection.static <T> T[]
plus(T[] left, T right)
Create an array containing elements from an original array plus an additional appended element.static <T> T[]
plus(T[] left, T[] right)
Create an array as a union of two arrays.static <T> T
pop(java.util.List<T> self)
Removes the initial item from the List.static java.lang.Number
power(java.lang.Integer self, java.lang.Integer exponent)
Power of an integer to an integer certain exponent.static java.lang.Number
power(java.lang.Long self, java.lang.Integer exponent)
Power of a long to an integer certain exponent.static java.lang.Number
power(java.lang.Number self, java.lang.Number exponent)
Power of a Number to a certain exponent.static java.lang.Number
power(java.math.BigDecimal self, java.lang.Integer exponent)
Power of a BigDecimal to an integer certain exponent.static java.lang.Number
power(java.math.BigInteger self, java.lang.Integer exponent)
Power of a BigInteger to an integer certain exponent.static java.math.BigInteger
power(java.math.BigInteger self, java.math.BigInteger exponent)
Power of a BigInteger to a BigInteger certain exponent.static java.lang.Character
previous(java.lang.Character self)
Decrement a Character by one.static java.lang.Number
previous(java.lang.Number self)
Decrement a Number by one.protected static java.lang.Object
primitiveArrayGet(java.lang.Object self, int idx)
Implements the getAt(int) method for primitive type arrays.protected static java.util.List
primitiveArrayGet(java.lang.Object self, Range range)
Implements the getAt(Range) method for primitive type arrays.protected static java.util.List
primitiveArrayGet(java.lang.Object self, java.util.Collection indices)
Implements the getAt(Collection) method for primitive type arrays.protected static java.lang.Object
primitiveArrayPut(java.lang.Object self, int idx, java.lang.Object newValue)
Implements the setAt(int idx) method for primitive type arrays.static void
print(Closure self, java.lang.Object value)
Print a value to the standard output stream.static void
print(java.io.PrintStream self, java.lang.Object value)
Print a value formatted Groovy style to the print stream.static void
print(java.io.PrintWriter self, java.lang.Object value)
Print a value formatted Groovy style to the print writer.static void
print(java.lang.Object self, java.io.PrintWriter out)
Print to a console in interactive format.static void
print(java.lang.Object self, java.lang.Object value)
Print a value formatted Groovy style to self if it is a Writer, otherwise to the standard output stream.static void
printf(Closure self, java.lang.String format, java.lang.Object value)
Printf a value to the standard output stream using a format string.static void
printf(Closure self, java.lang.String format, java.lang.Object[] values)
Printf 0 or more values to the standard output stream using a format string.static void
printf(java.lang.Object self, java.lang.String format, java.lang.Object arg)
Prints a formatted string using the specified format string and arguments.static void
printf(java.lang.Object self, java.lang.String format, java.lang.Object[] values)
Printf to the standard output stream.static void
println(Closure self)
Print a linebreak to the standard output stream.static void
println(Closure self, java.lang.Object value)
Print a value (followed by a newline) to the standard output stream.static void
println(java.io.PrintStream self, java.lang.Object value)
Print a value formatted Groovy style (followed by a newline) to the print stream.static void
println(java.io.PrintWriter self, java.lang.Object value)
Print a value formatted Groovy style (followed by a newline) to the print writer.static void
println(java.lang.Object self)
Print a linebreak to the standard output stream.static void
println(java.lang.Object self, java.io.PrintWriter out)
Print to a console in interactive format.static void
println(java.lang.Object self, java.lang.Object value)
Print a value formatted Groovy style (followed by a newline) to self if it is a Writer, otherwise to the standard output stream.static <T> boolean
push(java.util.List<T> self, T value)
Prepends an item to the start of the List.static <K, V> java.util.Map<K,V>
putAll(java.util.Map<K,V> self, java.util.Collection<? extends java.util.Map.Entry<? extends K,? extends V>> entries)
Provides an easy way to append multiple Map.Entry values to a Map.static void
putAt(java.lang.Object self, java.lang.String property, java.lang.Object newValue)
Allows the subscript operator to be used to set dynamically named property values.static void
putAt(java.util.BitSet self, int index, boolean value)
Support subscript-style assignment for a BitSet.static void
putAt(java.util.BitSet self, IntRange range, boolean value)
Support assigning a range of values with a single assignment statement.static <T> void
putAt(java.util.List<T> self, int idx, T value)
A helper method to allow lists to work with subscript operators.static <T> void
putAt(java.util.List<T> self, java.lang.Number idx, T value)
Support subscript operator for list modification.static void
putAt(java.util.List self, EmptyRange range, java.lang.Object value)
A helper method to allow lists to work with subscript operators.static void
putAt(java.util.List self, EmptyRange range, java.util.Collection value)
A helper method to allow lists to work with subscript operators.static void
putAt(java.util.List self, IntRange range, java.lang.Object value)
List subscript assignment operator when given a range as the index.static void
putAt(java.util.List self, IntRange range, java.util.Collection col)
List subscript assignment operator when given a range as the index and the assignment operand is a collection.static void
putAt(java.util.List self, java.util.List splice, java.lang.Object value)
A helper method to allow lists to work with subscript operators.static void
putAt(java.util.List self, java.util.List splice, java.util.List values)
A helper method to allow lists to work with subscript operators.static <K, V> V
putAt(java.util.Map<K,V> self, K key, V value)
A helper method to allow maps to work with subscript operatorsstatic <T> boolean
removeAll(java.util.Collection<T> self, Closure condition)
Modifies this collection by removing the elements that are matched according to the specified closure condition.static boolean
removeAll(java.util.Collection self, java.lang.Object[] items)
Modifies this collection by removing its elements that are contained within the specified object array.static <K, V> boolean
removeAll(java.util.Map<K,V> self, Closure condition)
Modifies this map by removing the elements that are matched according to the specified closure condition.static <E> E
removeAt(java.util.List<E> self, int index)
Modifies this list by removing the element at the specified position in this list.static <E> boolean
removeElement(java.util.Collection<E> self, java.lang.Object o)
Modifies this collection by removing a single instance of the specified element from this collection, if it is present.static <T> T
removeLast(java.util.List<T> self)
Removes the last item from the List.static java.util.List<MetaMethod>
respondsTo(java.lang.Object self, java.lang.String name)
Returns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name regardless of the arguments.static java.util.List<MetaMethod>
respondsTo(java.lang.Object self, java.lang.String name, java.lang.Object[] argTypes)
Returns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name and arguments types.static <T> boolean
retainAll(java.util.Collection<T> self, Closure condition)
Modifies this collection so that it retains only its elements that are matched according to the specified closure condition.static boolean
retainAll(java.util.Collection self, java.lang.Object[] items)
Modifies this collection so that it retains only its elements that are contained in the specified array.static <K, V> boolean
retainAll(java.util.Map<K,V> self, Closure condition)
Modifies this map so that it retains only its elements that are matched according to the specified closure condition.static <T> java.util.Iterator<T>
reverse(java.util.Iterator<T> self)
Reverses the iterator.static <T> java.util.List<T>
reverse(java.util.List<T> self)
Creates a new List with the identical contents to this list but in reverse order.static <T> java.util.List<T>
reverse(java.util.List<T> self, boolean mutate)
Reverses the elements in a list.static <T> T[]
reverse(T[] self)
Creates a new array containing items which are the same as this array but in reverse order.static <T> T[]
reverse(T[] self, boolean mutate)
Reverse the items in an array.static <T> java.util.List<T>
reverseEach(java.util.List<T> self, Closure closure)
Iterate over each element of the list in the reverse order.static <K, V> java.util.Map<K,V>
reverseEach(java.util.Map<K,V> self, Closure closure)
Allows a Map to be iterated through in reverse order using a closure.static <T> T[]
reverseEach(T[] self, Closure closure)
Iterate over each element of the array in the reverse order.static java.lang.Number
rightShift(java.lang.Number self, java.lang.Number operand)
Implementation of the right shift operator for integral types.static java.lang.Number
rightShiftUnsigned(java.lang.Number self, java.lang.Number operand)
Implementation of the right shift (unsigned) operator for integral types.static long
round(java.lang.Double number)
Round the valuestatic double
round(java.lang.Double number, int precision)
Round the valuestatic int
round(java.lang.Float number)
Round the valuestatic float
round(java.lang.Float number, int precision)
Round the valuestatic java.math.BigDecimal
round(java.math.BigDecimal number)
Round the valuestatic java.math.BigDecimal
round(java.math.BigDecimal number, int precision)
Round the valuestatic java.util.TimerTask
runAfter(java.util.Timer timer, int delay, Closure closure)
Allows a simple syntax for using timers.static void
setMetaClass(GroovyObject self, MetaClass metaClass)
Set the metaclass for a GroovyObject.static void
setMetaClass(java.lang.Class self, MetaClass metaClass)
Sets the metaclass for a given class.static void
setMetaClass(java.lang.Object self, MetaClass metaClass)
Set the metaclass for an object.static void
shuffle(java.util.List<?> self)
Randomly reorders the elements of the specified list.static void
shuffle(java.util.List<?> self, java.util.Random rnd)
Randomly reorders the elements of the specified list using the specified random instance as the source of randomness.static <T> void
shuffle(T[] self)
Randomly reorders the elements of the specified array.static <T> void
shuffle(T[] self, java.util.Random rnd)
Randomly reorders the elements of the specified array using the specified random instance as the source of randomness.static <T> java.util.List<T>
shuffled(java.util.List<T> self)
Creates a new list containing the elements of the specified list but in a random order.static <T> java.util.List<T>
shuffled(java.util.List<T> self, java.util.Random rnd)
Creates a new list containing the elements of the specified list but in a random order using the specified random instance as the source of randomness.static <T> T[]
shuffled(T[] self)
Creates a new array containing the elements of the specified array but in a random order.static <T> T[]
shuffled(T[] self, java.util.Random rnd)
Creates a new array containing the elements of the specified array but in a random order using the specified random instance as the source of randomness.static int
size(boolean[] array)
Allows arrays to behave similar to collections.static int
size(byte[] array)
Allows arrays to behave similar to collections.static int
size(char[] array)
Allows arrays to behave similar to collections.static int
size(double[] array)
Allows arrays to behave similar to collections.static int
size(float[] array)
Allows arrays to behave similar to collections.static int
size(int[] array)
Allows arrays to behave similar to collections.static int
size(long[] array)
Allows arrays to behave similar to collections.static int
size(short[] array)
Allows arrays to behave similar to collections.static int
size(java.lang.Iterable self)
Provide the standard Groovysize()
method forIterable
.static int
size(java.lang.Object[] self)
Provide the standard Groovysize()
method for an array.static int
size(java.util.Iterator self)
Provide the standard Groovysize()
method forIterator
.static <T> java.util.List<T>
sort(java.lang.Iterable<T> self)
Sorts the Collection.static <T> java.util.List<T>
sort(java.lang.Iterable<T> self, boolean mutate)
Sorts the Iterable.static <T> java.util.List<T>
sort(java.lang.Iterable<T> self, boolean mutate, Closure closure)
Sorts this Iterable using the given Closure to determine the correct ordering.static <T> java.util.List<T>
sort(java.lang.Iterable<T> self, boolean mutate, java.util.Comparator<? super T> comparator)
Sorts the Iterable using the given Comparator.static <T> java.util.List<T>
sort(java.lang.Iterable<T> self, Closure closure)
Sorts this Iterable using the given Closure to determine the correct ordering.static <T> java.util.Iterator<T>
sort(java.util.Iterator<T> self)
Sorts the given iterator items into a sorted iterator.static <T> java.util.Iterator<T>
sort(java.util.Iterator<T> self, Closure closure)
Sorts the given iterator items into a sorted iterator using the Closure to determine the correct ordering.static <T> java.util.Iterator<T>
sort(java.util.Iterator<T> self, java.util.Comparator<? super T> comparator)
Sorts the given iterator items into a sorted iterator using the comparator.static <K, V> java.util.Map<K,V>
sort(java.util.Map<K,V> self)
Sorts the elements from the given map into a new ordered Map using the natural ordering of the keys to determine the ordering.static <K, V> java.util.Map<K,V>
sort(java.util.Map<K,V> self, Closure closure)
Sorts the elements from the given map into a new ordered map using the closure as a comparator to determine the ordering.static <K, V> java.util.Map<K,V>
sort(java.util.Map<K,V> self, java.util.Comparator<? super K> comparator)
Sorts the elements from the given map into a new ordered Map using the specified key comparator to determine the ordering.static <K, V> java.util.SortedMap<K,V>
sort(java.util.SortedMap<K,V> self)
Avoids doing unnecessary work when sorting an already sorted map (i.e.static <T> java.util.SortedSet<T>
sort(java.util.SortedSet<T> self)
Avoids doing unnecessary work when sorting an already sorted set (i.e.static <T> T[]
sort(T[] self)
Modifies this array so that its elements are in sorted order.static <T> T[]
sort(T[] self, boolean mutate)
Sorts the given array into sorted order.static <T> T[]
sort(T[] self, boolean mutate, Closure closure)
Modifies this array so that its elements are in sorted order using the Closure to determine the correct ordering.static <T> T[]
sort(T[] self, boolean mutate, java.util.Comparator<? super T> comparator)
Modifies this array so that its elements are in sorted order as determined by the given comparator.static <T> T[]
sort(T[] self, Closure closure)
Sorts the elements from this array into a newly created array using the Closure to determine the correct ordering.static <T> T[]
sort(T[] self, java.util.Comparator<? super T> comparator)
Sorts the given array into sorted order using the given comparator.static java.util.Collection
split(java.lang.Object self, Closure closure)
Splits all items into two lists based on the closure condition.static <T> java.util.Collection<java.util.Collection<T>>
split(java.util.Collection<T> self, Closure closure)
Splits all items into two collections based on the closure condition.static <T> java.util.List<java.util.List<T>>
split(java.util.List<T> self, Closure closure)
Splits all items into two collections based on the closure condition.static <T> java.util.List<java.util.Set<T>>
split(java.util.Set<T> self, Closure closure)
Splits all items into two collections based on the closure condition.static <T> java.util.Collection<java.util.Collection<T>>
split(T[] self, Closure closure)
Splits all items into two collections based on the closure condition.static SpreadMap
spread(java.util.Map self)
Synonym fortoSpreadMap(java.util.Map)
.static java.lang.String
sprintf(java.lang.Object self, java.lang.String format, java.lang.Object arg)
Returns a formatted string using the specified format string and arguments.static java.lang.String
sprintf(java.lang.Object self, java.lang.String format, java.lang.Object[] values)
Sprintf to a string.static void
step(java.lang.Number self, java.lang.Number to, java.lang.Number stepNumber, Closure closure)
Iterates from this number up to the given number using a step increment.static <K, V> java.util.Map<K,V>
subMap(java.util.Map<K,V> map, java.util.Collection<K> keys)
Creates a sub-Map containing the given keys.static <K, V> java.util.Map<K,V>
subMap(java.util.Map<K,V> map, K[] keys)
Creates a sub-Map containing the given keys.static <T> java.util.Set<java.util.List<T>>
subsequences(java.util.List<T> self)
Finds all non-null subsequences of a list.static byte
sum(byte[] self)
Sums the items in an array.static byte
sum(byte[] self, byte initialValue)
Sums the items in an array, adding the result to some initial value.static char
sum(char[] self)
Sums the items in an array.static char
sum(char[] self, char initialValue)
Sums the items in an array, adding the result to some initial value.static double
sum(double[] self)
Sums the items in an array.static double
sum(double[] self, double initialValue)
Sums the items in an array, adding the result to some initial value.static float
sum(float[] self)
Sums the items in an array.static float
sum(float[] self, float initialValue)
Sums the items in an array, adding the result to some initial value.static int
sum(int[] self)
Sums the items in an array.static int
sum(int[] self, int initialValue)
Sums the items in an array, adding the result to some initial value.static long
sum(long[] self)
Sums the items in an array.static long
sum(long[] self, long initialValue)
Sums the items in an array, adding the result to some initial value.static short
sum(short[] self)
Sums the items in an array.static short
sum(short[] self, short initialValue)
Sums the items in an array, adding the result to some initial value.static java.lang.Object
sum(java.lang.Iterable<?> self)
Sums the items in an Iterable.static java.lang.Object
sum(java.lang.Iterable<?> self, java.lang.Object initialValue)
Sums the items in an Iterable, adding the result to some initial value.static <T> java.lang.Object
sum(java.lang.Iterable<T> self, Closure closure)
Sums the result of applying a closure to each item of an Iterable.static <T> java.lang.Object
sum(java.lang.Iterable<T> self, java.lang.Object initialValue, Closure closure)
Sums the result of applying a closure to each item of an Iterable to some initial value.static java.lang.Object
sum(java.lang.Object[] self)
Sums the items in an array.static java.lang.Object
sum(java.lang.Object[] self, java.lang.Object initialValue)
Sums the items in an array, adding the result to some initial value.static java.lang.Object
sum(java.util.Collection self)
Deprecated.Use the Iterable version of sum insteadstatic java.lang.Object
sum(java.util.Collection self, Closure closure)
Deprecated.Use the Iterable version of sum insteadstatic java.lang.Object
sum(java.util.Collection self, java.lang.Object initialValue)
Deprecated.Use the Iterable version of sum insteadstatic java.lang.Object
sum(java.util.Collection self, java.lang.Object initialValue, Closure closure)
Deprecated.Use the Iterable version of sum insteadstatic java.lang.Object
sum(java.util.Iterator<?> self, java.lang.Object initialValue)
Sums the items from an Iterator, adding the result to some initial value.static java.lang.Object
sum(java.util.Iterator<java.lang.Object> self)
Sums the items from an Iterator.static <T> java.lang.Object
sum(java.util.Iterator<T> self, Closure closure)
Sums the result of applying a closure to each item returned from an iterator.static <T> java.lang.Object
sum(java.util.Iterator<T> self, java.lang.Object initialValue, Closure closure)
Sums the result of applying a closure to each item of an Iterator to some initial value.static <T> java.lang.Object
sum(T[] self, Closure closure)
Sums the result of applying a closure to each item of an array.static <T> java.lang.Object
sum(T[] self, java.lang.Object initialValue, Closure closure)
Sums the result of applying a closure to each item of an array to some initial value.static boolean[]
swap(boolean[] self, int i, int j)
Swaps two elements at the specified positions.static byte[]
swap(byte[] self, int i, int j)
Swaps two elements at the specified positions.static char[]
swap(char[] self, int i, int j)
Swaps two elements at the specified positions.static double[]
swap(double[] self, int i, int j)
Swaps two elements at the specified positions.static float[]
swap(float[] self, int i, int j)
Swaps two elements at the specified positions.static int[]
swap(int[] self, int i, int j)
Swaps two elements at the specified positions.static long[]
swap(long[] self, int i, int j)
Swaps two elements at the specified positions.static short[]
swap(short[] self, int i, int j)
Swaps two elements at the specified positions.static <T> java.util.List<T>
swap(java.util.List<T> self, int i, int j)
Swaps two elements at the specified positions.static <T> T[]
swap(T[] self, int i, int j)
Swaps two elements at the specified positions.static <T> java.util.Collection<T>
tail(java.lang.Iterable<T> self)
Returns the items from the Iterable excluding the first item.static <T> java.util.Iterator<T>
tail(java.util.Iterator<T> self)
Returns the original iterator after throwing away the first element.static <T> java.util.List<T>
tail(java.util.List<T> self)
Returns the items from the List excluding the first item.static <T> java.util.SortedSet<T>
tail(java.util.SortedSet<T> self)
Returns the items from the SortedSet excluding the first item.static <T> T[]
tail(T[] self)
Returns the items from the array excluding the first item.static <T> java.util.List<java.util.List<T>>
tails(java.lang.Iterable<T> self)
Calculates the tail values of this Iterable: the first value will be this list of all items from the iterable and the final one will be an empty list, with the intervening values the results of successive applications of tail on the items.static <T> java.util.Collection<T>
take(java.lang.Iterable<T> self, int num)
Returns the firstnum
elements from the head of this Iterable.static <T> java.util.Iterator<T>
take(java.util.Iterator<T> self, int num)
Returns an iterator of up to the firstnum
elements from this iterator.static <T> java.util.List<T>
take(java.util.List<T> self, int num)
Returns the firstnum
elements from the head of this List.static <K, V> java.util.Map<K,V>
take(java.util.Map<K,V> self, int num)
Returns a new map containing the firstnum
elements from the head of this map.static <T> java.util.SortedSet<T>
take(java.util.SortedSet<T> self, int num)
Returns the firstnum
elements from the head of this SortedSet.static <T> T[]
take(T[] self, int num)
Returns the firstnum
elements from the head of this array.static <T> java.util.Collection<T>
takeRight(java.lang.Iterable<T> self, int num)
Returns the lastnum
elements from the tail of this Iterable.static <T> java.util.List<T>
takeRight(java.util.List<T> self, int num)
Returns the lastnum
elements from the tail of this List.static <T> java.util.SortedSet<T>
takeRight(java.util.SortedSet<T> self, int num)
Returns the lastnum
elements from the tail of this SortedSet.static <T> T[]
takeRight(T[] self, int num)
Returns the lastnum
elements from the tail of this array.static <T> java.util.Collection<T>
takeWhile(java.lang.Iterable<T> self, Closure condition)
Returns a Collection containing the longest prefix of the elements from this Iterable where each element passed to the given closure evaluates to true.static <T> java.util.Iterator<T>
takeWhile(java.util.Iterator<T> self, Closure condition)
Returns the longest prefix of elements in this iterator where each element passed to the given condition closure evaluates to true.static <T> java.util.List<T>
takeWhile(java.util.List<T> self, Closure condition)
Returns the longest prefix of this list where each element passed to the given closure condition evaluates to true.static <K, V> java.util.Map<K,V>
takeWhile(java.util.Map<K,V> self, Closure condition)
Returns the longest prefix of this Map where each entry (or key/value pair) when passed to the given closure evaluates to true.static <T> java.util.SortedSet<T>
takeWhile(java.util.SortedSet<T> self, Closure condition)
Returns the longest prefix of this SortedSet where each element passed to the given closure condition evaluates to true.static <T> T[]
takeWhile(T[] self, Closure condition)
Returns the longest prefix of this array where each element passed to the given closure evaluates to true.static <T, U> U
tap(U self, Closure<T> closure)
Allows the closure to be called for the object reference self (similar towith
and always returns self.static void
times(java.lang.Number self, Closure closure)
Executes the closure this many times, starting from zero.static java.lang.String
toArrayString(java.lang.Object[] self)
Returns the string representation of the given array.static java.math.BigDecimal
toBigDecimal(java.lang.Number self)
Transform a Number into a BigDecimalstatic java.math.BigInteger
toBigInteger(java.lang.Number self)
Transform this Number into a BigInteger.static java.lang.Boolean
toBoolean(java.lang.Boolean self)
Identity conversion which returns Boolean.TRUE for a true Boolean and Boolean.FALSE for a false Boolean.static java.lang.Double
toDouble(java.lang.Number self)
Transform a Number into a Doublestatic java.lang.Float
toFloat(java.lang.Number self)
Transform a Number into a Floatstatic java.lang.Integer
toInteger(java.lang.Number self)
Transform a Number into an Integerstatic java.util.List<java.lang.Boolean>
toList(boolean[] array)
Converts this array to a List of the same size, with each element added to the list.static java.util.List<java.lang.Byte>
toList(byte[] array)
Converts this array to a List of the same size, with each element added to the list.static java.util.List<java.lang.Character>
toList(char[] array)
Converts this array to a List of the same size, with each element added to the list.static java.util.List<java.lang.Double>
toList(double[] array)
Converts this array to a List of the same size, with each element added to the list.static java.util.List<java.lang.Float>
toList(float[] array)
Converts this array to a List of the same size, with each element added to the list.static java.util.List<java.lang.Integer>
toList(int[] array)
Converts this array to a List of the same size, with each element added to the list.static java.util.List<java.lang.Long>
toList(long[] array)
Converts this array to a List of the same size, with each element added to the list.static java.util.List<java.lang.Short>
toList(short[] array)
Converts this array to a List of the same size, with each element added to the list.static <T> java.util.List<T>
toList(java.lang.Iterable<T> self)
Convert an Iterable to a List.static <T> java.util.List<T>
toList(java.util.Collection<T> self)
Deprecated.Use the Iterable version of toList insteadstatic <T> java.util.List<T>
toList(java.util.Enumeration<T> self)
Convert an enumeration to a List.static <T> java.util.List<T>
toList(java.util.Iterator<T> self)
Convert an iterator to a List.static <T> java.util.List<T>
toList(T[] array)
Allows conversion of arrays into a mutable List.static java.lang.String
toListString(java.util.Collection self)
Returns the string representation of the given list.static java.lang.String
toListString(java.util.Collection self, int maxSize)
Returns the string representation of the given list.static java.lang.Long
toLong(java.lang.Number self)
Transform a Number into a Longstatic char
toLowerCase(java.lang.Character self)
Converts the character to lowercase.static java.lang.String
toMapString(java.util.Map self)
Returns the string representation of this map.static java.lang.String
toMapString(java.util.Map self, int maxSize)
Returns the string representation of this map.static java.util.Set<java.lang.Boolean>
toSet(boolean[] array)
Converts this array to a Set, with each unique element added to the set.static java.util.Set<java.lang.Byte>
toSet(byte[] array)
Converts this array to a Set, with each unique element added to the set.static java.util.Set<java.lang.Character>
toSet(char[] array)
Converts this array to a Set, with each unique element added to the set.static java.util.Set<java.lang.Double>
toSet(double[] array)
Converts this array to a Set, with each unique element added to the set.static java.util.Set<java.lang.Float>
toSet(float[] array)
Converts this array to a Set, with each unique element added to the set.static java.util.Set<java.lang.Integer>
toSet(int[] array)
Converts this array to a Set, with each unique element added to the set.static java.util.Set<java.lang.Long>
toSet(long[] array)
Converts this array to a Set, with each unique element added to the set.static java.util.Set<java.lang.Short>
toSet(short[] array)
Converts this array to a Set, with each unique element added to the set.static <T> java.util.Set<T>
toSet(java.lang.Iterable<T> self)
Convert an Iterable to a Set.static <T> java.util.Set<T>
toSet(java.util.Collection<T> self)
Convert a Collection to a Set.static <T> java.util.Set<T>
toSet(java.util.Enumeration<T> self)
Convert an enumeration to a Set.static <T> java.util.Set<T>
toSet(java.util.Iterator<T> self)
Convert an iterator to a Set.static <T> java.util.List<T>
toSorted(java.lang.Iterable<T> self)
Sorts the Iterable.static <T> java.util.List<T>
toSorted(java.lang.Iterable<T> self, Closure closure)
Sorts this Iterable using the given Closure to determine the correct ordering.static <T> java.util.List<T>
toSorted(java.lang.Iterable<T> self, java.util.Comparator<T> comparator)
Sorts the Iterable using the given Comparator.static <T> java.util.Iterator<T>
toSorted(java.util.Iterator<T> self)
Sorts the Iterator.static <T> java.util.Iterator<T>
toSorted(java.util.Iterator<T> self, Closure closure)
Sorts the given iterator items into a sorted iterator using the Closure to determine the correct ordering.static <T> java.util.Iterator<T>
toSorted(java.util.Iterator<T> self, java.util.Comparator<T> comparator)
Sorts the given iterator items using the comparator.static <K, V> java.util.Map<K,V>
toSorted(java.util.Map<K,V> self)
Sorts the elements from the given map into a new ordered map using aNumberAwareComparator
on map entry values to determine the resulting order.static <K, V> java.util.Map<K,V>
toSorted(java.util.Map<K,V> self, Closure condition)
Sorts the elements from the given map into a new ordered map using the supplied Closure condition as a comparator to determine the ordering.static <K, V> java.util.Map<K,V>
toSorted(java.util.Map<K,V> self, java.util.Comparator<java.util.Map.Entry<K,V>> comparator)
Sorts the elements from the given map into a new ordered map using the supplied comparator to determine the ordering.static <K, V> java.util.Map<K,V>
toSorted(java.util.SortedMap<K,V> self)
Avoids doing unnecessary work when sorting an already sorted mapstatic <T> java.util.Set<T>
toSorted(java.util.SortedSet<T> self)
Avoids doing unnecessary work when sorting an already sorted setstatic <T> T[]
toSorted(T[] self)
Returns a sorted version of the given array using the supplied comparator.static <T> T[]
toSorted(T[] self, Closure condition)
Sorts the elements from this array into a newly created array using the Closure to determine the correct ordering.static <T> T[]
toSorted(T[] self, java.util.Comparator<T> comparator)
Returns a sorted version of the given array using the supplied comparator to determine the resulting order.static SpreadMap
toSpreadMap(java.lang.Iterable self)
Creates a spreadable map from this iterable.static SpreadMap
toSpreadMap(java.lang.Object[] self)
Creates a spreadable map from this array.static SpreadMap
toSpreadMap(java.util.List self)
Creates a spreadable map from this list.static SpreadMap
toSpreadMap(java.util.Map self)
Returns a newSpreadMap
from this map.static java.lang.String
toString(boolean[] self)
Returns the string representation of the given array.static java.lang.String
toString(byte[] self)
Returns the string representation of the given array.static java.lang.String
toString(char[] self)
Returns the string representation of the given array.static java.lang.String
toString(double[] self)
Returns the string representation of the given array.static java.lang.String
toString(float[] self)
Returns the string representation of the given array.static java.lang.String
toString(int[] self)
Returns the string representation of the given array.static java.lang.String
toString(long[] self)
Returns the string representation of the given array.static java.lang.String
toString(short[] self)
Returns the string representation of the given array.static java.lang.String
toString(java.lang.Object value)
Create a String representation of this object.static java.lang.String
toString(java.lang.Object[] self)
Returns the string representation of this array's contents.static java.lang.String
toString(java.util.AbstractCollection self)
Returns the string representation of the given collection.static java.lang.String
toString(java.util.AbstractMap self)
Returns the string representation of the given map.static <T> java.util.Collection<T>
toUnique(java.lang.Iterable<T> self)
Returns a Collection containing the items from the Iterable but with duplicates removed using the natural ordering of the items to determine uniqueness.static <T> java.util.Collection<T>
toUnique(java.lang.Iterable<T> self, Closure condition)
Returns a Collection containing the items from the Iterable but with duplicates removed.static <T> java.util.Collection<T>
toUnique(java.lang.Iterable<T> self, java.util.Comparator<T> comparator)
Returns a Collection containing the items from the Iterable but with duplicates removed.static <T> java.util.Iterator<T>
toUnique(java.util.Iterator<T> self)
Returns an iterator equivalent to this iterator with all duplicated items removed by using the natural ordering of the items.static <T> java.util.Iterator<T>
toUnique(java.util.Iterator<T> self, Closure condition)
Returns an iterator equivalent to this iterator but with all duplicated items removed where duplicate (equal) items are deduced by calling the supplied Closure condition.static <T> java.util.Iterator<T>
toUnique(java.util.Iterator<T> self, java.util.Comparator<T> comparator)
Returns an iterator equivalent to this iterator with all duplicated items removed by using the supplied comparator.static <T> java.util.List<T>
toUnique(java.util.List<T> self)
Returns a List containing the items from the List but with duplicates removed using the natural ordering of the items to determine uniqueness.static <T> java.util.List<T>
toUnique(java.util.List<T> self, Closure condition)
Returns a List containing the items from the List but with duplicates removed.static <T> java.util.List<T>
toUnique(java.util.List<T> self, java.util.Comparator<T> comparator)
Returns a List containing the items from the List but with duplicates removed.static <T> T[]
toUnique(T[] self)
Returns a new Array containing the items from the original Array but with duplicates removed using the natural ordering of the items in the array.static <T> T[]
toUnique(T[] self, Closure condition)
Returns a new Array containing the items from the original Array but with duplicates removed with the supplied comparator determining which items are unique.static <T> T[]
toUnique(T[] self, java.util.Comparator<T> comparator)
Returns a new Array containing the items from the original Array but with duplicates removed with the supplied comparator determining which items are unique.static char
toUpperCase(java.lang.Character self)
Converts the character to uppercase.static double[][]
transpose(double[][] self)
A transpose method for 2D double arrays.static int[][]
transpose(int[][] self)
A transpose method for 2D int arrays.static long[][]
transpose(long[][] self)
A transpose method for 2D long arrays.static java.util.List
transpose(java.util.List self)
Adds GroovyCollections#transpose(List) as a method on lists.static double
trunc(java.lang.Double number)
Truncate the valuestatic double
trunc(java.lang.Double number, int precision)
Truncate the valuestatic float
trunc(java.lang.Float number)
Truncate the valuestatic float
trunc(java.lang.Float number, int precision)
Truncate the valuestatic java.math.BigDecimal
trunc(java.math.BigDecimal number)
Truncate the valuestatic java.math.BigDecimal
trunc(java.math.BigDecimal number, int precision)
Truncate the valuestatic java.lang.Number
unaryMinus(java.lang.Number left)
Negates the number.static java.lang.Number
unaryPlus(java.lang.Number left)
Returns the number, effectively being a noop for numbers.static <T> java.util.Collection<T>
unique(java.util.Collection<T> self)
Modifies this collection to remove all duplicated items, using Groovy's default number-aware comparator.static <T> java.util.Collection<T>
unique(java.util.Collection<T> self, boolean mutate)
Remove all duplicates from a given Collection using Groovy's default number-aware comparator.static <T> java.util.Collection<T>
unique(java.util.Collection<T> self, boolean mutate, Closure closure)
A convenience method for making a collection unique using a Closure to determine duplicate (equal) items.static <T> java.util.Collection<T>
unique(java.util.Collection<T> self, boolean mutate, java.util.Comparator<T> comparator)
Remove all duplicates from a given Collection.static <T> java.util.Collection<T>
unique(java.util.Collection<T> self, Closure closure)
A convenience method for making a collection unique using a Closure to determine duplicate (equal) items.static <T> java.util.Collection<T>
unique(java.util.Collection<T> self, java.util.Comparator<T> comparator)
Remove all duplicates from a given Collection.static <T> java.util.Iterator<T>
unique(java.util.Iterator<T> self)
Returns an iterator equivalent to this iterator with all duplicated items removed by using Groovy's default number-aware comparator.static <T> java.util.Iterator<T>
unique(java.util.Iterator<T> self, Closure condition)
Returns an iterator equivalent to this iterator but with all duplicated items removed by using a Closure to determine duplicate (equal) items.static <T> java.util.Iterator<T>
unique(java.util.Iterator<T> self, java.util.Comparator<T> comparator)
Returns an iterator equivalent to this iterator with all duplicated items removed by using the supplied comparator.static <T> java.util.List<T>
unique(java.util.List<T> self)
Modifies this List to remove all duplicated items, using Groovy's default number-aware comparator.static <T> java.util.List<T>
unique(java.util.List<T> self, boolean mutate)
Remove all duplicates from a given List using Groovy's default number-aware comparator.static <T> java.util.List<T>
unique(java.util.List<T> self, boolean mutate, Closure closure)
A convenience method for making a List unique using a Closure to determine duplicate (equal) items.static <T> java.util.List<T>
unique(java.util.List<T> self, boolean mutate, java.util.Comparator<T> comparator)
Remove all duplicates from a given List.static <T> java.util.List<T>
unique(java.util.List<T> self, Closure closure)
A convenience method for making a List unique using a Closure to determine duplicate (equal) items.static <T> java.util.List<T>
unique(java.util.List<T> self, java.util.Comparator<T> comparator)
Remove all duplicates from a given List.static void
upto(double self, java.lang.Number to, Closure closure)
Iterates from this number up to the given number, inclusive, incrementing by one each time.static void
upto(float self, java.lang.Number to, Closure closure)
Iterates from this number up to the given number, inclusive, incrementing by one each time.static void
upto(long self, java.lang.Number to, Closure closure)
Iterates from this number up to the given number, inclusive, incrementing by one each time.static void
upto(java.lang.Double self, java.lang.Number to, Closure closure)
Iterates from this number up to the given number, inclusive, incrementing by one each time.static void
upto(java.lang.Float self, java.lang.Number to, Closure closure)
Iterates from this number up to the given number, inclusive, incrementing by one each time.static void
upto(java.lang.Long self, java.lang.Number to, Closure closure)
Iterates from this number up to the given number, inclusive, incrementing by one each time.static void
upto(java.lang.Number self, java.lang.Number to, Closure closure)
Iterates from this number up to the given number, inclusive, incrementing by one each time.static void
upto(java.math.BigDecimal self, java.lang.Number to, Closure closure)
Iterates from this number up to the given number, inclusive, incrementing by one each time.static void
upto(java.math.BigInteger self, java.lang.Number to, Closure closure)
Iterates from this number up to the given number, inclusive, incrementing by one each time.static <T> T
use(java.lang.Object self, java.lang.Class categoryClass, Closure<T> closure)
Scoped use methodstatic java.lang.Object
use(java.lang.Object self, java.lang.Object[] array)
Allows you to use a list of categories, specifying the list as varargs.static <T> T
use(java.lang.Object self, java.util.List<java.lang.Class> categoryClassList, Closure<T> closure)
Scoped use method with list of categories.static <T, U extends T, V extends T>
Twith(U self, boolean returning, Closure<T> closure)
Allows the closure to be called for the object reference self.static <T, U> T
with(U self, Closure<T> closure)
Allows the closure to be called for the object reference self.static <T> ListWithDefault<T>
withDefault(java.util.List<T> self, Closure<T> init)
An alias forwithLazyDefault
which decorates a list allowing it to grow when called with index values outside the normal list bounds.static <K, V> java.util.Map<K,V>
withDefault(java.util.Map<K,V> self, Closure<V> init)
Wraps a map using the decorator pattern with a wrapper that intercepts all calls toget(key)
.static <T> java.util.List<T>
withDefault$$bridge(java.util.List<T> self, Closure<T> init)
Deprecated.static <T> ListWithDefault<T>
withEagerDefault(java.util.List<T> self, Closure<T> init)
Decorates a list allowing it to grow when called with a non-existent index value.static <T> java.util.List<T>
withEagerDefault$$bridge(java.util.List<T> self, Closure<T> init)
Deprecated.static <E> java.util.List<Tuple2<E,java.lang.Integer>>
withIndex(java.lang.Iterable<E> self)
Zips an Iterable with indices in (value, index) order.static <E> java.util.List<Tuple2<E,java.lang.Integer>>
withIndex(java.lang.Iterable<E> self, int offset)
Zips an Iterable with indices in (value, index) order.static <E> java.util.Iterator<Tuple2<E,java.lang.Integer>>
withIndex(java.util.Iterator<E> self)
Zips an iterator with indices in (value, index) order.static <E> java.util.Iterator<Tuple2<E,java.lang.Integer>>
withIndex(java.util.Iterator<E> self, int offset)
Zips an iterator with indices in (value, index) order.static <T> ListWithDefault<T>
withLazyDefault(java.util.List<T> self, Closure<T> init)
Decorates a list allowing it to grow when called with a non-existent index value.static <T> java.util.List<T>
withLazyDefault$$bridge(java.util.List<T> self, Closure<T> init)
Deprecated.static java.lang.Object
withTraits(java.lang.Object self, java.lang.Class<?>... traits)
Dynamically wraps an instance into something which implements the supplied trait classes.static java.lang.Boolean
xor(java.lang.Boolean left, java.lang.Boolean right)
Exclusive disjunction of two boolean operatorsstatic java.lang.Number
xor(java.lang.Number left, java.lang.Number right)
Bitwise XOR together two Numbers.static java.util.BitSet
xor(java.util.BitSet left, java.util.BitSet right)
Bitwise XOR together two BitSets.Methods inherited from class org.codehaus.groovy.runtime.DefaultGroovyMethodsSupport
cloneSimilarCollection, cloneSimilarMap, closeQuietly, closeWithWarning, createSimilarArray, createSimilarCollection, createSimilarCollection, createSimilarCollection, createSimilarList, createSimilarMap, createSimilarOrDefaultCollection, createSimilarQueue, createSimilarSet, normaliseIndex, sameType, subListBorders, subListBorders, writeUTF16BomIfRequired, writeUTF16BomIfRequired, writeUTF16BomIfRequired, writeUTF16BomIfRequired
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
ADDITIONAL_CLASSES
public static final java.lang.Class[] ADDITIONAL_CLASSES -
DGM_LIKE_CLASSES
public static final java.lang.Class[] DGM_LIKE_CLASSES
-
-
Constructor Details
-
DefaultGroovyMethods
public DefaultGroovyMethods()
-
-
Method Details
-
is
public static boolean is(java.lang.Object self, java.lang.Object other)Identity check. Since == is overridden in Groovy with the meaning of equality we need some fallback to check for object identity. Invoke using the 'is' method, like so:def same = this.is(that)
- Parameters:
self
- an objectother
- an object to compare identity with- Returns:
- true if self and other are both references to the same instance, false otherwise
- Since:
- 1.0
-
identity
public static <T, U> T identity(U self, @DelegatesTo(value=Target.class,target="self",strategy=1) Closure<T> closure)Allows the closure to be called for the object reference self. Synonym for 'with()'.- Parameters:
self
- the object to have a closure act uponclosure
- the closure to call on the object- Returns:
- result of calling the closure
- Since:
- 1.0
- See Also:
with(Object, Closure)
-
with
public static <T, U> T with(U self, @DelegatesTo(value=Target.class,target="self",strategy=1) Closure<T> closure)Allows the closure to be called for the object reference self.Any method invoked inside the closure will first be invoked on the self reference. For instance, the following method calls to the append() method are invoked on the StringBuilder instance:
def b = new StringBuilder().with { append('foo') append('bar') return it } assert b.toString() == 'foobar'
This is commonly used to simplify object creation, such as this example:def p = new Person().with { firstName = 'John' lastName = 'Doe' return it }
The other typical usage, uses the self object while creating some value:def fullName = person.with{ "$firstName $lastName" }
- Parameters:
self
- the object to have a closure act uponclosure
- the closure to call on the object- Returns:
- result of calling the closure
- Since:
- 1.5.0
- See Also:
with(Object, boolean, Closure)
,tap(Object, Closure)
-
with
public static <T, U extends T, V extends T> T with(U self, boolean returning, @DelegatesTo(value=Target.class,target="self",strategy=1) Closure<T> closure)Allows the closure to be called for the object reference self. Any method invoked inside the closure will first be invoked on the self reference. For example, the following method calls to the append() method are invoked on the StringBuilder instance and then, because 'returning' is true, the self instance is returned:def b = new StringBuilder().with(true) { append('foo') append('bar') } assert b.toString() == 'foobar'
The returning parameter is commonly set to true when using with to simplify object creation, such as this example:def p = new Person().with(true) { firstName = 'John' lastName = 'Doe' }
Alternatively, 'tap' is an alias for 'with(true)', so that method can be used instead. The other main use case for with is when returning a value calculated using self as shown here:def fullName = person.with(false){ "$firstName $lastName" }
Alternatively, 'with' is an alias for 'with(false)', so the boolean parameter can be omitted instead.- Parameters:
self
- the object to have a closure act uponreturning
- if true, return the self object; otherwise, the result of calling the closureclosure
- the closure to call on the object- Returns:
- the self object or the result of calling the closure depending on 'returning'
- Since:
- 2.5.0
- See Also:
with(Object, Closure)
,tap(Object, Closure)
-
tap
public static <T, U> U tap(U self, @DelegatesTo(value=Target.class,target="self",strategy=1) Closure<T> closure)Allows the closure to be called for the object reference self (similar towith
and always returns self.Any method invoked inside the closure will first be invoked on the self reference. For instance, the following method calls to the append() method are invoked on the StringBuilder instance:
def b = new StringBuilder().tap { append('foo') append('bar') } assert b.toString() == 'foobar'
This is commonly used to simplify object creation, such as this example:def p = new Person().tap { firstName = 'John' lastName = 'Doe' }
- Parameters:
self
- the object to have a closure act uponclosure
- the closure to call on the object- Returns:
- self
- Since:
- 2.5.0
- See Also:
with(Object, boolean, Closure)
,with(Object, Closure)
-
getAt
public static java.lang.Object getAt(java.lang.Object self, java.lang.String property)Allows the subscript operator to be used to lookup dynamic property values.bean[somePropertyNameExpression]
. The normal property notation of groovy is neater and more concise but only works with compile-time known property names.- Parameters:
self
- the object to act uponproperty
- the property name of interest- Returns:
- the property value
- Since:
- 1.0
-
putAt
public static void putAt(java.lang.Object self, java.lang.String property, java.lang.Object newValue)Allows the subscript operator to be used to set dynamically named property values.bean[somePropertyNameExpression] = foo
. The normal property notation of groovy is neater and more concise but only works with property names which are known at compile time.- Parameters:
self
- the object to act uponproperty
- the name of the property to setnewValue
- the value to set- Since:
- 1.0
-
dump
public static java.lang.String dump(java.lang.Object self)Generates a detailed dump string of an object showing its class, hashCode and fields.- Parameters:
self
- an object- Returns:
- the dump representation
- Since:
- 1.0
-
getMetaPropertyValues
Retrieves the list ofMetaProperty
objects for 'self' and wraps it in a list ofPropertyValue
objects that additionally provide the value for each property of 'self'.- Parameters:
self
- the receiver object- Returns:
- list of
PropertyValue
objects - Since:
- 1.0
- See Also:
Expando.getMetaPropertyValues()
-
getProperties
public static java.util.Map getProperties(java.lang.Object self)Convenience method that callsgetMetaPropertyValues(java.lang.Object)
(self) and provides the data in form of simple key/value pairs, i.e. without type() information.- Parameters:
self
- the receiver object- Returns:
- meta properties as Map of key/value pairs
- Since:
- 1.0
-
use
Scoped use method- Parameters:
self
- any ObjectcategoryClass
- a category class to useclosure
- the closure to invoke with the category in place- Returns:
- the value returned from the closure
- Since:
- 1.0
-
mixin
Extend object with category methods. All methods for given class and all super classes will be added to the object.- Parameters:
self
- any ClasscategoryClasses
- a category classes to use- Since:
- 1.6.0
-
mixin
public static void mixin(java.lang.Class self, java.util.List<java.lang.Class> categoryClasses)Extend class globally with category methods. All methods for given class and all super classes will be added to the class.- Parameters:
self
- any ClasscategoryClasses
- a category classes to use- Since:
- 1.6.0
-
mixin
public static void mixin(java.lang.Class self, java.lang.Class categoryClass)Extend class globally with category methods.- Parameters:
self
- any ClasscategoryClass
- a category class to use- Since:
- 1.6.0
-
mixin
public static void mixin(java.lang.Class self, java.lang.Class[] categoryClass)Extend class globally with category methods.- Parameters:
self
- any ClasscategoryClass
- a category class to use- Since:
- 1.6.0
-
mixin
Extend class globally with category methods.- Parameters:
self
- any ClasscategoryClass
- a category class to use- Since:
- 1.6.0
-
mixin
Extend class globally with category methods.- Parameters:
self
- any ClasscategoryClass
- a category class to use- Since:
- 1.6.0
-
getLocation
public static java.net.URL getLocation(java.lang.Class self)Gets the url of the jar file/source file containing the specified class- Parameters:
self
- the class- Returns:
- the url of the jar,
null
if the specified class is from JDK - Since:
- 2.5.0
-
use
public static <T> T use(java.lang.Object self, java.util.List<java.lang.Class> categoryClassList, Closure<T> closure)Scoped use method with list of categories.- Parameters:
self
- any ObjectcategoryClassList
- a list of category classesclosure
- the closure to invoke with the categories in place- Returns:
- the value returned from the closure
- Since:
- 1.0
-
addShutdownHook
Allows the usage of addShutdownHook without getting the runtime first.- Parameters:
self
- the object the method is called on (ignored)closure
- the shutdown hook action- Since:
- 1.5.0
-
use
public static java.lang.Object use(java.lang.Object self, java.lang.Object[] array)Allows you to use a list of categories, specifying the list as varargs.use(CategoryClass1, CategoryClass2) { ... }
This method saves having to wrap the category classes in a list.- Parameters:
self
- any Objectarray
- a list of category classes and a Closure- Returns:
- the value returned from the closure
- Since:
- 1.0
-
print
public static void print(java.lang.Object self, java.lang.Object value)Print a value formatted Groovy style to self if it is a Writer, otherwise to the standard output stream.- Parameters:
self
- any Objectvalue
- the value to print- Since:
- 1.0
-
print
public static void print(java.io.PrintWriter self, java.lang.Object value)Print a value formatted Groovy style to the print writer.- Parameters:
self
- a PrintWritervalue
- the value to print- Since:
- 1.0
-
print
public static void print(java.io.PrintStream self, java.lang.Object value)Print a value formatted Groovy style to the print stream.- Parameters:
self
- a PrintStreamvalue
- the value to print- Since:
- 1.6.0
-
print
Print a value to the standard output stream. This method delegates to the owner to execute the method.- Parameters:
self
- a generated closurevalue
- the value to print- Since:
- 1.0
-
println
public static void println(java.lang.Object self)Print a linebreak to the standard output stream.- Parameters:
self
- any Object- Since:
- 1.0
-
println
Print a linebreak to the standard output stream. This method delegates to the owner to execute the method.- Parameters:
self
- a closure- Since:
- 1.0
-
println
public static void println(java.lang.Object self, java.lang.Object value)Print a value formatted Groovy style (followed by a newline) to self if it is a Writer, otherwise to the standard output stream.- Parameters:
self
- any Objectvalue
- the value to print- Since:
- 1.0
-
println
public static void println(java.io.PrintWriter self, java.lang.Object value)Print a value formatted Groovy style (followed by a newline) to the print writer.- Parameters:
self
- a PrintWritervalue
- the value to print- Since:
- 1.0
-
println
public static void println(java.io.PrintStream self, java.lang.Object value)Print a value formatted Groovy style (followed by a newline) to the print stream.- Parameters:
self
- any Objectvalue
- the value to print- Since:
- 1.6.0
-
println
Print a value (followed by a newline) to the standard output stream. This method delegates to the owner to execute the method.- Parameters:
self
- a closurevalue
- the value to print- Since:
- 1.0
-
printf
public static void printf(java.lang.Object self, java.lang.String format, java.lang.Object[] values)Printf to the standard output stream.- Parameters:
self
- any Objectformat
- a format stringvalues
- values referenced by the format specifiers in the format string- Since:
- 1.0
-
printf
Printf 0 or more values to the standard output stream using a format string. This method delegates to the owner to execute the method.- Parameters:
self
- a generated closureformat
- a format stringvalues
- values referenced by the format specifiers in the format string- Since:
- 3.0.0
-
printf
Printf a value to the standard output stream using a format string. This method delegates to the owner to execute the method.- Parameters:
self
- a generated closureformat
- a format stringvalue
- value referenced by the format specifier in the format string- Since:
- 3.0.0
-
sprintf
public static java.lang.String sprintf(java.lang.Object self, java.lang.String format, java.lang.Object[] values)Sprintf to a string.- Parameters:
self
- any Objectformat
- a format stringvalues
- values referenced by the format specifiers in the format string- Returns:
- the resulting formatted string
- Since:
- 1.5.0
-
printf
public static void printf(java.lang.Object self, java.lang.String format, java.lang.Object arg)Prints a formatted string using the specified format string and arguments.Examples:
printf ( "Hello, %s!\n" , [ "world" ] as String[] ) printf ( "Hello, %s!\n" , [ "Groovy" ]) printf ( "%d + %d = %d\n" , [ 1 , 2 , 1+2 ] as Integer[] ) printf ( "%d + %d = %d\n" , [ 3 , 3 , 3+3 ]) ( 1..5 ).each { printf ( "-- %d\n" , [ it ] as Integer[] ) } ( 1..5 ).each { printf ( "-- %d\n" , [ it ] as int[] ) } ( 0x41..0x45 ).each { printf ( "-- %c\n" , [ it ] as char[] ) } ( 07..011 ).each { printf ( "-- %d\n" , [ it ] as byte[] ) } ( 7..11 ).each { printf ( "-- %d\n" , [ it ] as short[] ) } ( 7..11 ).each { printf ( "-- %d\n" , [ it ] as long[] ) } ( 7..11 ).each { printf ( "-- %5.2f\n" , [ it ] as float[] ) } ( 7..11 ).each { printf ( "-- %5.2g\n" , [ it ] as double[] ) }
- Parameters:
self
- any Objectformat
- A format stringarg
- Argument which is referenced by the format specifiers in the format string. The type ofarg
should be one of Object[], List, int[], short[], byte[], char[], boolean[], long[], float[], or double[].- Since:
- 1.0
-
sprintf
public static java.lang.String sprintf(java.lang.Object self, java.lang.String format, java.lang.Object arg)Returns a formatted string using the specified format string and arguments.- Parameters:
self
- any Objectformat
- A format stringarg
- Argument which is referenced by the format specifiers in the format string. The type ofarg
should be one of Object[], List, int[], short[], byte[], char[], boolean[], long[], float[], or double[].- Returns:
- the resulting printf'd string
- Since:
- 1.5.0
-
inspect
public static java.lang.String inspect(java.lang.Object self)Inspects returns the String that matches what would be typed into a terminal to create this object.- Parameters:
self
- any Object- Returns:
- a String that matches what would be typed into a terminal to
create this object. e.g. [1, 'hello'].inspect()
->
[1, "hello"] - Since:
- 1.0
-
print
public static void print(java.lang.Object self, java.io.PrintWriter out)Print to a console in interactive format.- Parameters:
self
- any Objectout
- the PrintWriter used for printing- Since:
- 1.0
-
println
public static void println(java.lang.Object self, java.io.PrintWriter out)Print to a console in interactive format.- Parameters:
self
- any Objectout
- the PrintWriter used for printing- Since:
- 1.0
-
invokeMethod
public static java.lang.Object invokeMethod(java.lang.Object object, java.lang.String method, java.lang.Object arguments)Provide a dynamic method invocation method which can be overloaded in classes to implement dynamic proxies easily.- Parameters:
object
- any Objectmethod
- the name of the method to callarguments
- the arguments to use- Returns:
- the result of the method call
- Since:
- 1.0
-
isCase
public static boolean isCase(java.lang.Object caseValue, java.lang.Object switchValue)Method for overloading the behavior of the 'case' method in switch statements. The default implementation handles arrays types but otherwise simply delegates to Object#equals, but this may be overridden for other types. In this example:switch( a ) { case b: //some code }
"some code" is called whenb.isCase( a )
returnstrue
.- Parameters:
caseValue
- the case valueswitchValue
- the switch value- Returns:
- true if the switchValue is deemed to be equal to the caseValue
- Since:
- 1.0
-
isCase
public static boolean isCase(java.lang.Class caseValue, java.lang.Object switchValue)Special 'Case' implementation for Class, which allows testing whether some switch value is assignable from the given case class. If the switch value is an object,isCase
will return true if the switch value is assignment compatible with the class (case value), i.e. is aninstanceof
the class, for example:def someList = [] switch (someList) { case List: assert true, 'is a list' break case Map: assert false, 'is not a Map' break default: assert false, 'should never get here' break }
If the switch value is a class,isCase
will return true if the switch value is assignable from the given class (case value), i.e. the case class is the same as, or a superclass, or a super-interface of the switch class, for example:switch (ArrayList) { case List: assert true, 'is a list' break case Map: assert false, 'is not a Map' break default: assert false, 'should never get here' break }
- Parameters:
caseValue
- the case valueswitchValue
- the switch value- Returns:
- true if the switchValue is deemed to be assignable from the given class
- Since:
- 1.0
-
isCase
public static boolean isCase(java.util.Collection caseValue, java.lang.Object switchValue)'Case' implementation for collections which tests if the 'switch' operand is contained in any of the 'case' values. For example:switch( 3 ) { case [1,3,5]: assert true break default: assert false }
- Parameters:
caseValue
- the case valueswitchValue
- the switch value- Returns:
- true if the caseValue is deemed to contain the switchValue
- Since:
- 1.0
- See Also:
Collection.contains(java.lang.Object)
-
isCase
public static boolean isCase(java.util.Map caseValue, java.lang.Object switchValue)'Case' implementation for maps which tests the groovy truth value obtained using the 'switch' operand as key. For example:switch( 'foo' ) { case [foo:true, bar:false]: assert true break default: assert false }
- Parameters:
caseValue
- the case valueswitchValue
- the switch value- Returns:
- the groovy truth value from caseValue corresponding to the switchValue key
- Since:
- 1.7.6
-
isCase
public static boolean isCase(java.lang.Number caseValue, java.lang.Number switchValue)Special 'case' implementation for all numbers, which delegates to thecompareTo()
method for comparing numbers of different types.- Parameters:
caseValue
- the case valueswitchValue
- the switch value- Returns:
- true if the numbers are deemed equal
- Since:
- 1.5.0
-
unique
public static <T> java.util.Iterator<T> unique(java.util.Iterator<T> self)Returns an iterator equivalent to this iterator with all duplicated items removed by using Groovy's default number-aware comparator. The original iterator will become exhausted of elements after determining the unique values. A new iterator for the unique values will be returned.- Parameters:
self
- an Iterator- Returns:
- a new Iterator of the unique items from the original iterator
- Since:
- 1.5.5
-
unique
public static <T> java.util.Collection<T> unique(java.util.Collection<T> self)Modifies this collection to remove all duplicated items, using Groovy's default number-aware comparator.assert [1,3] == [1,3,3].unique()
- Parameters:
self
- a collection- Returns:
- the now modified collection
- Since:
- 1.0
- See Also:
unique(Collection, boolean)
-
unique
public static <T> java.util.List<T> unique(java.util.List<T> self)Modifies this List to remove all duplicated items, using Groovy's default number-aware comparator.assert [1,3] == [1,3,3].unique()
- Parameters:
self
- a List- Returns:
- the now modified List
- Since:
- 2.4.0
- See Also:
unique(Collection, boolean)
-
unique
public static <T> java.util.Collection<T> unique(java.util.Collection<T> self, boolean mutate)Remove all duplicates from a given Collection using Groovy's default number-aware comparator. If mutate is true, it works by modifying the original object (and also returning it). If mutate is false, a new collection is returned leaving the original unchanged.assert [1,3] == [1,3,3].unique()
def orig = [1, 3, 2, 3] def uniq = orig.unique(false) assert orig == [1, 3, 2, 3] assert uniq == [1, 3, 2]
- Parameters:
self
- a collectionmutate
- false will cause a new list containing unique items from the collection to be created, true will mutate collections in place- Returns:
- the now modified collection
- Since:
- 1.8.1
-
unique
public static <T> java.util.List<T> unique(java.util.List<T> self, boolean mutate)Remove all duplicates from a given List using Groovy's default number-aware comparator. If mutate is true, it works by modifying the original object (and also returning it). If mutate is false, a new collection is returned leaving the original unchanged.assert [1,3] == [1,3,3].unique()
def orig = [1, 3, 2, 3] def uniq = orig.unique(false) assert orig == [1, 3, 2, 3] assert uniq == [1, 3, 2]
- Parameters:
self
- a Listmutate
- false will cause a new List containing unique items from the List to be created, true will mutate List in place- Returns:
- the now modified List
- Since:
- 2.4.0
-
numberAwareCompareTo
public static int numberAwareCompareTo(java.lang.Comparable self, java.lang.Comparable other)Provides a method that compares two comparables using Groovy's default number aware comparator.- Parameters:
self
- a Comparableother
- another Comparable- Returns:
- a -ve number, 0 or a +ve number according to Groovy's compareTo contract
- Since:
- 1.6.0
-
unique
Returns an iterator equivalent to this iterator but with all duplicated items removed by using a Closure to determine duplicate (equal) items. The original iterator will be fully processed after the call.If the closure takes a single parameter, the argument passed will be each element, and the closure should return a value used for comparison (either using
Comparable.compareTo(java.lang.Object)
orObject.equals(java.lang.Object)
). If the closure takes two parameters, two items from the Iterator will be passed as arguments, and the closure should return an int value (with 0 indicating the items are not unique).- Parameters:
self
- an Iteratorcondition
- a Closure used to determine unique items- Returns:
- the modified Iterator
- Since:
- 1.5.5
-
unique
A convenience method for making a collection unique using a Closure to determine duplicate (equal) items.If the closure takes a single parameter, the argument passed will be each element, and the closure should return a value used for comparison (either using
Comparable.compareTo(java.lang.Object)
orObject.equals(java.lang.Object)
). If the closure takes two parameters, two items from the collection will be passed as arguments, and the closure should return an int value (with 0 indicating the items are not unique).assert [1,4] == [1,3,4,5].unique { it % 2 }
assert [2,3,4] == [2,3,3,4].unique { a, b
->
a<=>
b }- Parameters:
self
- a Collectionclosure
- a 1 or 2 arg Closure used to determine unique items- Returns:
- self without any duplicates
- Since:
- 1.0
- See Also:
unique(Collection, boolean, Closure)
-
unique
A convenience method for making a List unique using a Closure to determine duplicate (equal) items.If the closure takes a single parameter, the argument passed will be each element, and the closure should return a value used for comparison (either using
Comparable.compareTo(java.lang.Object)
orObject.equals(java.lang.Object)
). If the closure takes two parameters, two items from the List will be passed as arguments, and the closure should return an int value (with 0 indicating the items are not unique).assert [1,4] == [1,3,4,5].unique { it % 2 }
assert [2,3,4] == [2,3,3,4].unique { a, b
->
a<=>
b }- Parameters:
self
- a Listclosure
- a 1 or 2 arg Closure used to determine unique items- Returns:
- self without any duplicates
- Since:
- 2.4.0
- See Also:
unique(Collection, boolean, Closure)
-
unique
public static <T> java.util.Collection<T> unique(java.util.Collection<T> self, boolean mutate, Closure closure)A convenience method for making a collection unique using a Closure to determine duplicate (equal) items. If mutate is true, it works on the receiver object and returns it. If mutate is false, a new collection is returned.If the closure takes a single parameter, each element from the Collection will be passed to the closure. The closure should return a value used for comparison (either using
Comparable.compareTo(java.lang.Object)
orObject.equals(java.lang.Object)
). If the closure takes two parameters, two items from the collection will be passed as arguments, and the closure should return an int value (with 0 indicating the items are not unique).def orig = [1, 3, 4, 5] def uniq = orig.unique(false) { it % 2 } assert orig == [1, 3, 4, 5] assert uniq == [1, 4]
def orig = [2, 3, 3, 4] def uniq = orig.unique(false) { a, b
->
a<=>
b } assert orig == [2, 3, 3, 4] assert uniq == [2, 3, 4]- Parameters:
self
- a Collectionmutate
- false will always cause a new list to be created, true will mutate lists in placeclosure
- a 1 or 2 arg Closure used to determine unique items- Returns:
- self without any duplicates
- Since:
- 1.8.1
-
unique
public static <T> java.util.List<T> unique(java.util.List<T> self, boolean mutate, Closure closure)A convenience method for making a List unique using a Closure to determine duplicate (equal) items. If mutate is true, it works on the receiver object and returns it. If mutate is false, a new collection is returned.If the closure takes a single parameter, each element from the List will be passed to the closure. The closure should return a value used for comparison (either using
Comparable.compareTo(java.lang.Object)
orObject.equals(java.lang.Object)
). If the closure takes two parameters, two items from the collection will be passed as arguments, and the closure should return an int value (with 0 indicating the items are not unique).def orig = [1, 3, 4, 5] def uniq = orig.unique(false) { it % 2 } assert orig == [1, 3, 4, 5] assert uniq == [1, 4]
def orig = [2, 3, 3, 4] def uniq = orig.unique(false) { a, b
->
a<=>
b } assert orig == [2, 3, 3, 4] assert uniq == [2, 3, 4]- Parameters:
self
- a Listmutate
- false will always cause a new list to be created, true will mutate lists in placeclosure
- a 1 or 2 arg Closure used to determine unique items- Returns:
- self without any duplicates
- Since:
- 2.4.0
-
unique
public static <T> java.util.Iterator<T> unique(java.util.Iterator<T> self, java.util.Comparator<T> comparator)Returns an iterator equivalent to this iterator with all duplicated items removed by using the supplied comparator. The original iterator will be exhausted upon returning.- Parameters:
self
- an Iteratorcomparator
- a Comparator- Returns:
- the modified Iterator
- Since:
- 1.5.5
-
unique
public static <T> java.util.Collection<T> unique(java.util.Collection<T> self, java.util.Comparator<T> comparator)Remove all duplicates from a given Collection. Works on the original object (and also returns it). The order of members in the Collection are compared by the given Comparator. For each duplicate, the first member which is returned by the given Collection's iterator is retained, but all other ones are removed. The given Collection's original order is preserved.class Person { def fname, lname String toString() { return fname + " " + lname } } class PersonComparator implements Comparator { int compare(Object o1, Object o2) { Person p1 = (Person) o1 Person p2 = (Person) o2 if (p1.lname != p2.lname) return p1.lname.compareTo(p2.lname) else return p1.fname.compareTo(p2.fname) } boolean equals(Object obj) { return this.equals(obj) } } Person a = new Person(fname:"John", lname:"Taylor") Person b = new Person(fname:"Clark", lname:"Taylor") Person c = new Person(fname:"Tom", lname:"Cruz") Person d = new Person(fname:"Clark", lname:"Taylor") def list = [a, b, c, d] List list2 = list.unique(new PersonComparator()) assert( list2 == list
&&
list == [a, b, c] )- Parameters:
self
- a Collectioncomparator
- a Comparator- Returns:
- self the now modified collection without duplicates
- Since:
- 1.0
- See Also:
unique(java.util.Collection, boolean, java.util.Comparator)
-
unique
public static <T> java.util.List<T> unique(java.util.List<T> self, java.util.Comparator<T> comparator)Remove all duplicates from a given List. Works on the original object (and also returns it). The order of members in the List are compared by the given Comparator. For each duplicate, the first member which is returned by the given List's iterator is retained, but all other ones are removed. The given List's original order is preserved.class Person { def fname, lname String toString() { return fname + " " + lname } } class PersonComparator implements Comparator { int compare(Object o1, Object o2) { Person p1 = (Person) o1 Person p2 = (Person) o2 if (p1.lname != p2.lname) return p1.lname.compareTo(p2.lname) else return p1.fname.compareTo(p2.fname) } boolean equals(Object obj) { return this.equals(obj) } } Person a = new Person(fname:"John", lname:"Taylor") Person b = new Person(fname:"Clark", lname:"Taylor") Person c = new Person(fname:"Tom", lname:"Cruz") Person d = new Person(fname:"Clark", lname:"Taylor") def list = [a, b, c, d] List list2 = list.unique(new PersonComparator()) assert( list2 == list
&&
list == [a, b, c] )- Parameters:
self
- a Listcomparator
- a Comparator- Returns:
- self the now modified List without duplicates
- Since:
- 2.4.0
- See Also:
unique(java.util.Collection, boolean, java.util.Comparator)
-
unique
public static <T> java.util.Collection<T> unique(java.util.Collection<T> self, boolean mutate, java.util.Comparator<T> comparator)Remove all duplicates from a given Collection. If mutate is true, it works on the original object (and also returns it). If mutate is false, a new collection is returned. The order of members in the Collection are compared by the given Comparator. For each duplicate, the first member which is returned by the given Collection's iterator is retained, but all other ones are removed. The given Collection's original order is preserved.class Person { def fname, lname String toString() { return fname + " " + lname } } class PersonComparator implements Comparator { int compare(Object o1, Object o2) { Person p1 = (Person) o1 Person p2 = (Person) o2 if (p1.lname != p2.lname) return p1.lname.compareTo(p2.lname) else return p1.fname.compareTo(p2.fname) } boolean equals(Object obj) { return this.equals(obj) } } Person a = new Person(fname:"John", lname:"Taylor") Person b = new Person(fname:"Clark", lname:"Taylor") Person c = new Person(fname:"Tom", lname:"Cruz") Person d = new Person(fname:"Clark", lname:"Taylor") def list = [a, b, c, d] List list2 = list.unique(false, new PersonComparator()) assert( list2 != list
&&
list2 == [a, b, c] )- Parameters:
self
- a Collectionmutate
- false will always cause a new collection to be created, true will mutate collections in placecomparator
- a Comparator- Returns:
- self the collection without duplicates
- Since:
- 1.8.1
-
unique
public static <T> java.util.List<T> unique(java.util.List<T> self, boolean mutate, java.util.Comparator<T> comparator)Remove all duplicates from a given List. If mutate is true, it works on the original object (and also returns it). If mutate is false, a new List is returned. The order of members in the List are compared by the given Comparator. For each duplicate, the first member which is returned by the given List's iterator is retained, but all other ones are removed. The given List's original order is preserved.class Person { def fname, lname String toString() { return fname + " " + lname } } class PersonComparator implements Comparator { int compare(Object o1, Object o2) { Person p1 = (Person) o1 Person p2 = (Person) o2 if (p1.lname != p2.lname) return p1.lname.compareTo(p2.lname) else return p1.fname.compareTo(p2.fname) } boolean equals(Object obj) { return this.equals(obj) } } Person a = new Person(fname:"John", lname:"Taylor") Person b = new Person(fname:"Clark", lname:"Taylor") Person c = new Person(fname:"Tom", lname:"Cruz") Person d = new Person(fname:"Clark", lname:"Taylor") def list = [a, b, c, d] List list2 = list.unique(false, new PersonComparator()) assert( list2 != list
&&
list2 == [a, b, c] )- Parameters:
self
- a Listmutate
- false will always cause a new List to be created, true will mutate List in placecomparator
- a Comparator- Returns:
- self the List without duplicates
- Since:
- 2.4.0
-
toUnique
Returns an iterator equivalent to this iterator but with all duplicated items removed where duplicate (equal) items are deduced by calling the supplied Closure condition.If the supplied Closure takes a single parameter, the argument passed will be each element, and the closure should return a value used for comparison (either using
Comparable.compareTo(java.lang.Object)
orObject.equals(java.lang.Object)
). If the closure takes two parameters, two items from the Iterator will be passed as arguments, and the closure should return an int value (with 0 indicating the items are not unique).def items = "Hello".toList() + [null, null] + "there".toList() def toLower = { it == null ? null : it.toLowerCase() } def noDups = items.iterator().toUnique(toLower).toList() assert noDups == ['H', 'e', 'l', 'o', null, 't', 'r']
assert [1,4] == [1,3,4,5].toUnique { it % 2 }
assert [2,3,4] == [2,3,3,4].toUnique { a, b
->
a<=>
b }- Parameters:
self
- an Iteratorcondition
- a Closure used to determine unique items- Returns:
- an Iterator with no duplicate items
- Since:
- 2.4.0
-
toUnique
public static <T> java.util.Iterator<T> toUnique(java.util.Iterator<T> self, java.util.Comparator<T> comparator)Returns an iterator equivalent to this iterator with all duplicated items removed by using the supplied comparator.- Parameters:
self
- an Iteratorcomparator
- a Comparator used to determine unique (equal) items Ifnull
, the Comparable natural ordering of the elements will be used.- Returns:
- an Iterator with no duplicate items
- Since:
- 2.4.0
-
toUnique
public static <T> java.util.Iterator<T> toUnique(java.util.Iterator<T> self)Returns an iterator equivalent to this iterator with all duplicated items removed by using the natural ordering of the items.- Parameters:
self
- an Iterator- Returns:
- an Iterator with no duplicate items
- Since:
- 2.4.0
-
toUnique
public static <T> java.util.Collection<T> toUnique(java.lang.Iterable<T> self, java.util.Comparator<T> comparator)Returns a Collection containing the items from the Iterable but with duplicates removed. The items in the Iterable are compared by the given Comparator. For each duplicate, the first member which is returned from the Iterable is retained, but all other ones are removed.class Person { def fname, lname String toString() { return fname + " " + lname } } class PersonComparator implements Comparator { int compare(Object o1, Object o2) { Person p1 = (Person) o1 Person p2 = (Person) o2 if (p1.lname != p2.lname) return p1.lname.compareTo(p2.lname) else return p1.fname.compareTo(p2.fname) } boolean equals(Object obj) { return this.equals(obj) } } Person a = new Person(fname:"John", lname:"Taylor") Person b = new Person(fname:"Clark", lname:"Taylor") Person c = new Person(fname:"Tom", lname:"Cruz") Person d = new Person(fname:"Clark", lname:"Taylor") def list = [a, b, c, d] List list2 = list.toUnique(new PersonComparator()) assert list2 == [a, b, c]
&&
list == [a, b, c, d]- Parameters:
self
- an Iterablecomparator
- a Comparator used to determine unique (equal) items Ifnull
, the Comparable natural ordering of the elements will be used.- Returns:
- the Collection of non-duplicate items
- Since:
- 2.4.0
-
toUnique
public static <T> java.util.List<T> toUnique(java.util.List<T> self, java.util.Comparator<T> comparator)Returns a List containing the items from the List but with duplicates removed. The items in the List are compared by the given Comparator. For each duplicate, the first member which is returned from the List is retained, but all other ones are removed.class Person { def fname, lname String toString() { return fname + " " + lname } } class PersonComparator implements Comparator { int compare(Object o1, Object o2) { Person p1 = (Person) o1 Person p2 = (Person) o2 if (p1.lname != p2.lname) return p1.lname.compareTo(p2.lname) else return p1.fname.compareTo(p2.fname) } boolean equals(Object obj) { return this.equals(obj) } } Person a = new Person(fname:"John", lname:"Taylor") Person b = new Person(fname:"Clark", lname:"Taylor") Person c = new Person(fname:"Tom", lname:"Cruz") Person d = new Person(fname:"Clark", lname:"Taylor") def list = [a, b, c, d] List list2 = list.toUnique(new PersonComparator()) assert list2 == [a, b, c]
&&
list == [a, b, c, d]- Parameters:
self
- a Listcomparator
- a Comparator used to determine unique (equal) items Ifnull
, the Comparable natural ordering of the elements will be used.- Returns:
- the List of non-duplicate items
- Since:
- 2.4.0
-
toUnique
public static <T> java.util.Collection<T> toUnique(java.lang.Iterable<T> self)Returns a Collection containing the items from the Iterable but with duplicates removed using the natural ordering of the items to determine uniqueness.String[] letters = ['c', 'a', 't', 's', 'a', 't', 'h', 'a', 't'] String[] expected = ['c', 'a', 't', 's', 'h'] assert letters.toUnique() == expected
- Parameters:
self
- an Iterable- Returns:
- the Collection of non-duplicate items
- Since:
- 2.4.0
-
toUnique
public static <T> java.util.List<T> toUnique(java.util.List<T> self)Returns a List containing the items from the List but with duplicates removed using the natural ordering of the items to determine uniqueness.def letters = ['c', 'a', 't', 's', 'a', 't', 'h', 'a', 't'] def expected = ['c', 'a', 't', 's', 'h'] assert letters.toUnique() == expected
- Parameters:
self
- a List- Returns:
- the List of non-duplicate items
- Since:
- 2.4.0
-
toUnique
Returns a Collection containing the items from the Iterable but with duplicates removed. The items in the Iterable are compared by the given Closure condition. For each duplicate, the first member which is returned from the Iterable is retained, but all other ones are removed.If the closure takes a single parameter, each element from the Iterable will be passed to the closure. The closure should return a value used for comparison (either using
Comparable.compareTo(java.lang.Object)
orObject.equals(java.lang.Object)
). If the closure takes two parameters, two items from the Iterable will be passed as arguments, and the closure should return an int value (with 0 indicating the items are not unique).class Person { def fname, lname String toString() { return fname + " " + lname } } Person a = new Person(fname:"John", lname:"Taylor") Person b = new Person(fname:"Clark", lname:"Taylor") Person c = new Person(fname:"Tom", lname:"Cruz") Person d = new Person(fname:"Clark", lname:"Taylor") def list = [a, b, c, d] def list2 = list.toUnique{ p1, p2
->
p1.lname != p2.lname ? p1.lname <=> p2.lname : p1.fname <=> p2.fname } assert( list2 == [a, b, c]&&
list == [a, b, c, d] ) def list3 = list.toUnique{ it.toString() } assert( list3 == [a, b, c]&&
list == [a, b, c, d] )- Parameters:
self
- an Iterablecondition
- a Closure used to determine unique items- Returns:
- a new Collection
- Since:
- 2.4.0
- See Also:
toUnique(Iterable, Comparator)
-
toUnique
Returns a List containing the items from the List but with duplicates removed. The items in the List are compared by the given Closure condition. For each duplicate, the first member which is returned from the Iterable is retained, but all other ones are removed.If the closure takes a single parameter, each element from the Iterable will be passed to the closure. The closure should return a value used for comparison (either using
Comparable.compareTo(java.lang.Object)
orObject.equals(java.lang.Object)
). If the closure takes two parameters, two items from the Iterable will be passed as arguments, and the closure should return an int value (with 0 indicating the items are not unique).class Person { def fname, lname String toString() { return fname + " " + lname } } Person a = new Person(fname:"John", lname:"Taylor") Person b = new Person(fname:"Clark", lname:"Taylor") Person c = new Person(fname:"Tom", lname:"Cruz") Person d = new Person(fname:"Clark", lname:"Taylor") def list = [a, b, c, d] def list2 = list.toUnique{ p1, p2
->
p1.lname != p2.lname ? p1.lname <=> p2.lname : p1.fname <=> p2.fname } assert( list2 == [a, b, c]&&
list == [a, b, c, d] ) def list3 = list.toUnique{ it.toString() } assert( list3 == [a, b, c]&&
list == [a, b, c, d] )- Parameters:
self
- a Listcondition
- a Closure used to determine unique items- Returns:
- a new List
- Since:
- 2.4.0
- See Also:
toUnique(Iterable, Comparator)
-
toUnique
public static <T> T[] toUnique(T[] self, java.util.Comparator<T> comparator)Returns a new Array containing the items from the original Array but with duplicates removed with the supplied comparator determining which items are unique.String[] letters = ['c', 'a', 't', 's', 'A', 't', 'h', 'a', 'T'] String[] lower = ['c', 'a', 't', 's', 'h'] class LowerComparator implements Comparator { int compare(let1, let2) { let1.toLowerCase()
<=>
let2.toLowerCase() } } assert letters.toUnique(new LowerComparator()) == lower- Parameters:
self
- an arraycomparator
- a Comparator used to determine unique (equal) items Ifnull
, the Comparable natural ordering of the elements will be used.- Returns:
- the unique items from the array
-
toUnique
public static <T> T[] toUnique(T[] self)Returns a new Array containing the items from the original Array but with duplicates removed using the natural ordering of the items in the array.String[] letters = ['c', 'a', 't', 's', 'a', 't', 'h', 'a', 't'] String[] expected = ['c', 'a', 't', 's', 'h'] def result = letters.toUnique() assert result == expected assert result.class.componentType == String
- Parameters:
self
- an array- Returns:
- the unique items from the array
-
toUnique
Returns a new Array containing the items from the original Array but with duplicates removed with the supplied comparator determining which items are unique.String[] letters = ['c', 'a', 't', 's', 'A', 't', 'h', 'a', 'T'] String[] expected = ['c', 'a', 't', 's', 'h'] assert letters.toUnique{ p1, p2
->
p1.toLowerCase()<=>
p2.toLowerCase() } == expected assert letters.toUnique{ it.toLowerCase() } == expected- Parameters:
self
- an arraycondition
- a Closure used to determine unique items- Returns:
- the unique items from the array
-
each
Iterates through an array passing each array entry to the given closure.String[] letters = ['a', 'b', 'c'] String result = '' letters.each{ result += it } assert result == 'abc'
- Parameters:
self
- the array over which we iterateclosure
- the closure applied on each array entry- Returns:
- the self array
- Since:
- 2.5.0
-
each
Iterates through an aggregate type or data structure, passing each item to the given closure. Custom types may utilize this method by simply providing an "iterator()" method. The items returned from the resulting iterator will be passed to the closure.String result = '' ['a', 'b', 'c'].each{ result += it } assert result == 'abc'
- Parameters:
self
- the object over which we iterateclosure
- the closure applied on each element found- Returns:
- the self Object
- Since:
- 1.0
-
eachWithIndex
Iterates through an array, passing each array element and the element's index (a counter starting at zero) to the given closure.String[] letters = ['a', 'b', 'c'] String result = '' letters.eachWithIndex{ letter, index
->
result += "$index:$letter" } assert result == '0:a1:b2:c'- Parameters:
self
- an arrayclosure
- a Closure to operate on each array entry- Returns:
- the self array
- Since:
- 2.5.0
-
eachWithIndex
Iterates through an aggregate type or data structure, passing each item and the item's index (a counter starting at zero) to the given closure.String result = '' ['a', 'b', 'c'].eachWithIndex{ letter, index
->
result += "$index:$letter" } assert result == '0:a1:b2:c'- Parameters:
self
- an Objectclosure
- a Closure to operate on each item- Returns:
- the self Object
- Since:
- 1.0
-
eachWithIndex
Iterates through an iterable type, passing each item and the item's index (a counter starting at zero) to the given closure.- Parameters:
self
- an Iterableclosure
- a Closure to operate on each item- Returns:
- the self Iterable
- Since:
- 2.3.0
-
eachWithIndex
Iterates through an iterator type, passing each item and the item's index (a counter starting at zero) to the given closure.- Parameters:
self
- an Iteratorclosure
- a Closure to operate on each item- Returns:
- the self Iterator (now exhausted)
- Since:
- 2.3.0
-
eachWithIndex
public static <T> java.util.Collection<T> eachWithIndex(java.util.Collection<T> self, Closure closure)Iterates through a Collection, passing each item and the item's index (a counter starting at zero) to the given closure.- Parameters:
self
- a Collectionclosure
- a Closure to operate on each item- Returns:
- the self Collection
- Since:
- 2.4.0
-
eachWithIndex
Iterates through a List, passing each item and the item's index (a counter starting at zero) to the given closure.- Parameters:
self
- a Listclosure
- a Closure to operate on each item- Returns:
- the self List
- Since:
- 2.4.0
-
eachWithIndex
Iterates through a Set, passing each item and the item's index (a counter starting at zero) to the given closure.- Parameters:
self
- a Setclosure
- a Closure to operate on each item- Returns:
- the self Set
- Since:
- 2.4.0
-
eachWithIndex
public static <T> java.util.SortedSet<T> eachWithIndex(java.util.SortedSet<T> self, Closure closure)Iterates through a SortedSet, passing each item and the item's index (a counter starting at zero) to the given closure.- Parameters:
self
- a SortedSetclosure
- a Closure to operate on each item- Returns:
- the self SortedSet
- Since:
- 2.4.0
-
each
Iterates through an Iterable, passing each item to the given closure.- Parameters:
self
- the Iterable over which we iterateclosure
- the closure applied on each element found- Returns:
- the self Iterable
-
each
Iterates through an Iterator, passing each item to the given closure.- Parameters:
self
- the Iterator over which we iterateclosure
- the closure applied on each element found- Returns:
- the self Iterator
- Since:
- 2.4.0
-
each
Iterates through a Collection, passing each item to the given closure.- Parameters:
self
- the Collection over which we iterateclosure
- the closure applied on each element found- Returns:
- the self Collection
- Since:
- 2.4.0
-
each
Iterates through a List, passing each item to the given closure.- Parameters:
self
- the List over which we iterateclosure
- the closure applied on each element found- Returns:
- the self List
- Since:
- 2.4.0
-
each
Iterates through a Set, passing each item to the given closure.- Parameters:
self
- the Set over which we iterateclosure
- the closure applied on each element found- Returns:
- the self Set
- Since:
- 2.4.0
-
each
Iterates through a SortedSet, passing each item to the given closure.- Parameters:
self
- the SortedSet over which we iterateclosure
- the closure applied on each element found- Returns:
- the self SortedSet
- Since:
- 2.4.0
-
each
Allows a Map to be iterated through using a closure. If the closure takes one parameter then it will be passed the Map.Entry otherwise if the closure takes two parameters then it will be passed the key and the value.def result = "" [a:1, b:3].each { key, value
->
result += "$key$value" } assert result == "a1b3"def result = "" [a:1, b:3].each { entry
In general, the order in which the map contents are processed cannot be guaranteed. In practise, specialized forms of Map, e.g. a TreeMap will have its contents processed according to the natural ordering of the map.->
result += entry } assert result == "a=1b=3"- Parameters:
self
- the map over which we iterateclosure
- the 1 or 2 arg closure applied on each entry of the map- Returns:
- returns the self parameter
- Since:
- 1.5.0
-
reverseEach
Allows a Map to be iterated through in reverse order using a closure. In general, the order in which the map contents are processed cannot be guaranteed. In practise, specialized forms of Map, e.g. a TreeMap will have its contents processed according to the reverse of the natural ordering of the map.- Parameters:
self
- the map over which we iterateclosure
- the 1 or 2 arg closure applied on each entry of the map- Returns:
- returns the self parameter
- Since:
- 1.7.2
- See Also:
each(Map, Closure)
-
eachWithIndex
Allows a Map to be iterated through using a closure. If the closure takes two parameters then it will be passed the Map.Entry and the item's index (a counter starting at zero) otherwise if the closure takes three parameters then it will be passed the key, the value, and the index.def result = "" [a:1, b:3].eachWithIndex { key, value, index
->
result += "$index($key$value)" } assert result == "0(a1)1(b3)"def result = "" [a:1, b:3].eachWithIndex { entry, index
->
result += "$index($entry)" } assert result == "0(a=1)1(b=3)"- Parameters:
self
- the map over which we iterateclosure
- a 2 or 3 arg Closure to operate on each item- Returns:
- the self Object
- Since:
- 1.5.0
-
reverseEach
Iterate over each element of the list in the reverse order.def result = [] [1,2,3].reverseEach { result << it } assert result == [3,2,1]
- Parameters:
self
- a Listclosure
- a closure to which each item is passed.- Returns:
- the original list
- Since:
- 1.5.0
-
reverseEach
Iterate over each element of the array in the reverse order.- Parameters:
self
- an arrayclosure
- a closure to which each item is passed- Returns:
- the original array
- Since:
- 1.5.2
-
every
Used to determine if the given predicate closure is valid (i.e. returnstrue
for all items in this data structure). A simple example for a list:def list = [3,4,5] def greaterThanTwo = list.every { it
>
2 }- Parameters:
self
- the object over which we iteratepredicate
- the closure predicate used for matching- Returns:
- true if every iteration of the object matches the closure predicate
- Since:
- 1.0
-
every
Used to determine if the given predicate closure is valid (i.e. returnstrue
for all items in this iterator). A simple example for a list:def list = [3,4,5] def greaterThanTwo = list.iterator().every { it
>
2 }- Parameters:
self
- the iterator over which we iteratepredicate
- the closure predicate used for matching- Returns:
- true if every iteration of the object matches the closure predicate
- Since:
- 2.3.0
-
every
Used to determine if the given predicate closure is valid (i.e. returnstrue
for all items in this Array).- Parameters:
self
- an Arraypredicate
- the closure predicate used for matching- Returns:
- true if every element of the Array matches the closure predicate
- Since:
- 2.5.0
-
every
Used to determine if the given predicate closure is valid (i.e. returnstrue
for all items in this iterable). A simple example for a list:def list = [3,4,5] def greaterThanTwo = list.every { it
>
2 }- Parameters:
self
- the iterable over which we iteratepredicate
- the closure predicate used for matching- Returns:
- true if every iteration of the object matches the closure predicate
- Since:
- 2.3.0
-
every
Iterates over the entries of a map, and checks whether a predicate is valid for all entries. If the closure takes one parameter then it will be passed the Map.Entry otherwise if the closure takes two parameters then it will be passed the key and the value.def map = [a:1, b:2.0, c:2L] assert !map.every { key, value
->
value instanceof Integer } assert map.every { entry->
entry.value instanceof Number }- Parameters:
self
- the map over which we iteratepredicate
- the 1 or 2 arg Closure predicate used for matching- Returns:
- true if every entry of the map matches the closure predicate
- Since:
- 1.5.0
-
every
public static boolean every(java.lang.Object self)Iterates over every element of a collection, and checks whether all elements aretrue
according to the Groovy Truth. Equivalent toself.every({element
->
element})assert [true, true].every() assert [1, 1].every() assert ![1, 0].every()
- Parameters:
self
- the object over which we iterate- Returns:
- true if every item in the collection matches satisfies Groovy truth
- Since:
- 1.5.0
-
any
Iterates over the contents of an object or collection, and checks whether a predicate is valid for at least one element.assert [1, 2, 3].any { it == 2 } assert ![1, 2, 3].any { it
>
3 }- Parameters:
self
- the object over which we iteratepredicate
- the closure predicate used for matching- Returns:
- true if any iteration for the object matches the closure predicate
- Since:
- 1.0
-
any
Iterates over the contents of an iterator, and checks whether a predicate is valid for at least one element.assert [1, 2, 3].iterator().any { it == 2 } assert ![1, 2, 3].iterator().any { it
>
3 }- Parameters:
self
- the iterator over which we iteratepredicate
- the closure predicate used for matching- Returns:
- true if any iteration for the object matches the closure predicate
- Since:
- 1.0
-
any
Iterates over the contents of an iterable, and checks whether a predicate is valid for at least one element.assert [1, 2, 3].any { it == 2 } assert ![1, 2, 3].any { it
>
3 }- Parameters:
self
- the iterable over which we iteratepredicate
- the closure predicate used for matching- Returns:
- true if any iteration for the object matches the closure predicate
- Since:
- 1.0
-
any
Iterates over the contents of an Array, and checks whether a predicate is valid for at least one element.- Parameters:
self
- the array over which we iteratepredicate
- the closure predicate used for matching- Returns:
- true if any iteration for the object matches the closure predicate
- Since:
- 2.5.0
-
any
Iterates over the entries of a map, and checks whether a predicate is valid for at least one entry. If the closure takes one parameter then it will be passed the Map.Entry otherwise if the closure takes two parameters then it will be passed the key and the value.assert [2:3, 4:5, 5:10].any { key, value
->
key * 2 == value } assert ![2:3, 4:5, 5:10].any { entry->
entry.key == entry.value * 2 }- Parameters:
self
- the map over which we iteratepredicate
- the 1 or 2 arg closure predicate used for matching- Returns:
- true if any entry in the map matches the closure predicate
- Since:
- 1.5.0
-
any
public static boolean any(java.lang.Object self)Iterates over the elements of a collection, and checks whether at least one element is true according to the Groovy Truth. Equivalent to self.any({element->
element})assert [false, true].any() assert [0, 1].any() assert ![0, 0].any()
- Parameters:
self
- the object over which we iterate- Returns:
- true if any item in the collection matches the closure predicate
- Since:
- 1.5.0
-
grep
public static java.util.Collection grep(java.lang.Object self, java.lang.Object filter)Iterates over the collection of items which this Object represents and returns each item that matches the given filter - calling the
method used by switch statements. This method can be used with different kinds of filters like regular expressions, classes, ranges etc. Example:isCase(java.lang.Object, java.lang.Object)
def list = ['a', 'b', 'aa', 'bc', 3, 4.5] assert list.grep( ~/a+/ ) == ['a', 'aa'] assert list.grep( ~/../ ) == ['aa', 'bc'] assert list.grep( Number ) == [ 3, 4.5 ] assert list.grep{ it.toString().size() == 1 } == [ 'a', 'b', 3 ]
- Parameters:
self
- the object over which we iteratefilter
- the filter to perform on the object (using theisCase(java.lang.Object, java.lang.Object)
method)- Returns:
- a collection of objects which match the filter
- Since:
- 1.5.6
-
grep
public static <T> java.util.Collection<T> grep(java.util.Collection<T> self, java.lang.Object filter)Iterates over the collection of items and returns each item that matches the given filter - calling the
method used by switch statements. method can be used with different kinds of filters like regular expressions, classes, ranges etc. Example:isCase(java.lang.Object, java.lang.Object)
def list = ['a', 'b', 'aa', 'bc', 3, 4.5] assert list.grep( ~/a+/ ) == ['a', 'aa'] assert list.grep( ~/../ ) == ['aa', 'bc'] assert list.grep( Number ) == [ 3, 4.5 ] assert list.grep{ it.toString().size() == 1 } == [ 'a', 'b', 3 ]
- Parameters:
self
- a collectionfilter
- the filter to perform on each element of the collection (using theisCase(java.lang.Object, java.lang.Object)
method)- Returns:
- a collection of objects which match the filter
- Since:
- 2.0
-
grep
public static <T> java.util.List<T> grep(java.util.List<T> self, java.lang.Object filter)Iterates over the collection of items and returns each item that matches the given filter - calling the
method used by switch statements. This method can be used with different kinds of filters like regular expressions, classes, ranges etc. Example:isCase(java.lang.Object, java.lang.Object)
def list = ['a', 'b', 'aa', 'bc', 3, 4.5] assert list.grep( ~/a+/ ) == ['a', 'aa'] assert list.grep( ~/../ ) == ['aa', 'bc'] assert list.grep( Number ) == [ 3, 4.5 ] assert list.grep{ it.toString().size() == 1 } == [ 'a', 'b', 3 ]
- Parameters:
self
- a Listfilter
- the filter to perform on each element of the collection (using theisCase(java.lang.Object, java.lang.Object)
method)- Returns:
- a List of objects which match the filter
- Since:
- 2.4.0
-
grep
public static <T> java.util.Set<T> grep(java.util.Set<T> self, java.lang.Object filter)Iterates over the collection of items and returns each item that matches the given filter - calling the
method used by switch statements. This method can be used with different kinds of filters like regular expressions, classes, ranges etc. Example:isCase(java.lang.Object, java.lang.Object)
def set = ['a', 'b', 'aa', 'bc', 3, 4.5] as Set assert set.grep( ~/a+/ ) == ['a', 'aa'] as Set assert set.grep( ~/../ ) == ['aa', 'bc'] as Set assert set.grep( Number ) == [ 3, 4.5 ] as Set assert set.grep{ it.toString().size() == 1 } == [ 'a', 'b', 3 ] as Set
- Parameters:
self
- a Setfilter
- the filter to perform on each element of the collection (using theisCase(java.lang.Object, java.lang.Object)
method)- Returns:
- a Set of objects which match the filter
- Since:
- 2.4.0
-
grep
public static <T> java.util.Collection<T> grep(T[] self, java.lang.Object filter)Iterates over the array of items and returns a collection of items that match the given filter - calling the
method used by switch statements. This method can be used with different kinds of filters like regular expressions, classes, ranges etc. Example:isCase(java.lang.Object, java.lang.Object)
def items = ['a', 'b', 'aa', 'bc', 3, 4.5] as Object[] assert items.grep( ~/a+/ ) == ['a', 'aa'] assert items.grep( ~/../ ) == ['aa', 'bc'] assert items.grep( Number ) == [ 3, 4.5 ] assert items.grep{ it.toString().size() == 1 } == [ 'a', 'b', 3 ]
- Parameters:
self
- an arrayfilter
- the filter to perform on each element of the array (using theisCase(java.lang.Object, java.lang.Object)
method)- Returns:
- a collection of objects which match the filter
- Since:
- 2.0
-
grep
public static java.util.Collection grep(java.lang.Object self)Iterates over the collection of items which this Object represents and returns each item that matches using the IDENTITY Closure as a filter - effectively returning all elements which satisfy Groovy truth.Example:
def items = [1, 2, 0, false, true, '', 'foo', [], [4, 5], null] assert items.grep() == [1, 2, true, 'foo', [4, 5]]
- Parameters:
self
- the object over which we iterate- Returns:
- a collection of objects which match the filter
- Since:
- 1.8.1
- See Also:
Closure.IDENTITY
-
grep
public static <T> java.util.Collection<T> grep(java.util.Collection<T> self)Iterates over the collection returning each element that matches using the IDENTITY Closure as a filter - effectively returning all elements which satisfy Groovy truth.Example:
def items = [1, 2, 0, false, true, '', 'foo', [], [4, 5], null] assert items.grep() == [1, 2, true, 'foo', [4, 5]]
- Parameters:
self
- a Collection- Returns:
- a collection of elements satisfy Groovy truth
- Since:
- 2.0
- See Also:
Closure.IDENTITY
-
grep
public static <T> java.util.List<T> grep(java.util.List<T> self)Iterates over the collection returning each element that matches using the IDENTITY Closure as a filter - effectively returning all elements which satisfy Groovy truth.Example:
def items = [1, 2, 0, false, true, '', 'foo', [], [4, 5], null] assert items.grep() == [1, 2, true, 'foo', [4, 5]]
- Parameters:
self
- a List- Returns:
- a List of elements satisfy Groovy truth
- Since:
- 2.4.0
- See Also:
Closure.IDENTITY
-
grep
public static <T> java.util.Set<T> grep(java.util.Set<T> self)Iterates over the collection returning each element that matches using the IDENTITY Closure as a filter - effectively returning all elements which satisfy Groovy truth.Example:
def items = [1, 2, 0, false, true, '', 'foo', [], [4, 5], null] as Set assert items.grep() == [1, 2, true, 'foo', [4, 5]] as Set
- Parameters:
self
- a Set- Returns:
- a Set of elements satisfy Groovy truth
- Since:
- 2.4.0
- See Also:
Closure.IDENTITY
-
grep
public static <T> java.util.Collection<T> grep(T[] self)Iterates over the array returning each element that matches using the IDENTITY Closure as a filter - effectively returning all elements which satisfy Groovy truth.Example:
def items = [1, 2, 0, false, true, '', 'foo', [], [4, 5], null] as Object[] assert items.grep() == [1, 2, true, 'foo', [4, 5]]
- Parameters:
self
- an array- Returns:
- a collection of elements which satisfy Groovy truth
- Since:
- 2.0
- See Also:
Closure.IDENTITY
-
count
public static java.lang.Number count(java.util.Iterator self, java.lang.Object value)Counts the number of occurrences of the given value from the items within this Iterator. Comparison is done using Groovy's == operator (usingcompareTo(value) == 0
orequals(value)
). The iterator will become exhausted of elements after determining the count value.- Parameters:
self
- the Iterator from which we count the number of matching occurrencesvalue
- the value being searched for- Returns:
- the number of occurrences
- Since:
- 1.5.0
-
count
Counts the number of occurrences which satisfy the given closure from the items within this Iterator. The iterator will become exhausted of elements after determining the count value.Example usage:
assert [2,4,2,1,3,5,2,4,3].toSet().iterator().count{ it % 2 == 0 } == 2
- Parameters:
self
- the Iterator from which we count the number of matching occurrencesclosure
- a closure condition- Returns:
- the number of occurrences
- Since:
- 1.8.0
-
count
@Deprecated public static java.lang.Number count(java.util.Collection self, java.lang.Object value)Deprecated.use count(Iterable, Closure)- Since:
- 1.0
-
count
public static java.lang.Number count(java.lang.Iterable self, java.lang.Object value)Counts the number of occurrences of the given value inside this Iterable. Comparison is done using Groovy's == operator (usingcompareTo(value) == 0
orequals(value)
).Example usage:
assert [2,4,2,1,3,5,2,4,3].count(4) == 2
- Parameters:
self
- the Iterable within which we count the number of occurrencesvalue
- the value being searched for- Returns:
- the number of occurrences
- Since:
- 2.2.0
-
count
Deprecated.use count(Iterable, Closure)- Since:
- 1.8.0
-
count
Counts the number of occurrences which satisfy the given closure from inside this Iterable.Example usage:
assert [2,4,2,1,3,5,2,4,3].count{ it % 2 == 0 } == 5
- Parameters:
self
- the Iterable within which we count the number of occurrencesclosure
- a closure condition- Returns:
- the number of occurrences
- Since:
- 2.2.0
-
count
Counts the number of occurrences which satisfy the given closure from inside this map. If the closure takes one parameter then it will be passed the Map.Entry. Otherwise, the closure should take two parameters and will be passed the key and value.Example usage:
assert [a:1, b:1, c:2, d:2].count{ k,v
->
k == 'a'||
v == 2 } == 3- Parameters:
self
- the map within which we count the number of occurrencesclosure
- a 1 or 2 arg Closure condition applying on the entries- Returns:
- the number of occurrences
- Since:
- 1.8.0
-
count
public static java.lang.Number count(java.lang.Object[] self, java.lang.Object value)Counts the number of occurrences of the given value inside this array. Comparison is done using Groovy's == operator (usingcompareTo(value) == 0
orequals(value)
).- Parameters:
self
- the array within which we count the number of occurrencesvalue
- the value being searched for- Returns:
- the number of occurrences
- Since:
- 1.6.4
-
count
Counts the number of occurrences which satisfy the given closure from inside this array.- Parameters:
self
- the array within which we count the number of occurrencesclosure
- a closure condition- Returns:
- the number of occurrences
- Since:
- 1.8.0
-
count
public static java.lang.Number count(int[] self, java.lang.Object value)Counts the number of occurrences of the given value inside this array. Comparison is done using Groovy's == operator (usingcompareTo(value) == 0
orequals(value)
).- Parameters:
self
- the array within which we count the number of occurrencesvalue
- the value being searched for- Returns:
- the number of occurrences
- Since:
- 1.6.4
-
count
public static java.lang.Number count(long[] self, java.lang.Object value)Counts the number of occurrences of the given value inside this array. Comparison is done using Groovy's == operator (usingcompareTo(value) == 0
orequals(value)
).- Parameters:
self
- the array within which we count the number of occurrencesvalue
- the value being searched for- Returns:
- the number of occurrences
- Since:
- 1.6.4
-
count
public static java.lang.Number count(short[] self, java.lang.Object value)Counts the number of occurrences of the given value inside this array. Comparison is done using Groovy's == operator (usingcompareTo(value) == 0
orequals(value)
).- Parameters:
self
- the array within which we count the number of occurrencesvalue
- the value being searched for- Returns:
- the number of occurrences
- Since:
- 1.6.4
-
count
public static java.lang.Number count(char[] self, java.lang.Object value)Counts the number of occurrences of the given value inside this array. Comparison is done using Groovy's == operator (usingcompareTo(value) == 0
orequals(value)
).- Parameters:
self
- the array within which we count the number of occurrencesvalue
- the value being searched for- Returns:
- the number of occurrences
- Since:
- 1.6.4
-
count
public static java.lang.Number count(boolean[] self, java.lang.Object value)Counts the number of occurrences of the given value inside this array. Comparison is done using Groovy's == operator (usingcompareTo(value) == 0
orequals(value)
).- Parameters:
self
- the array within which we count the number of occurrencesvalue
- the value being searched for- Returns:
- the number of occurrences
- Since:
- 1.6.4
-
count
public static java.lang.Number count(double[] self, java.lang.Object value)Counts the number of occurrences of the given value inside this array. Comparison is done using Groovy's == operator (usingcompareTo(value) == 0
orequals(value)
).- Parameters:
self
- the array within which we count the number of occurrencesvalue
- the value being searched for- Returns:
- the number of occurrences
- Since:
- 1.6.4
-
count
public static java.lang.Number count(float[] self, java.lang.Object value)Counts the number of occurrences of the given value inside this array. Comparison is done using Groovy's == operator (usingcompareTo(value) == 0
orequals(value)
).- Parameters:
self
- the array within which we count the number of occurrencesvalue
- the value being searched for- Returns:
- the number of occurrences
- Since:
- 1.6.4
-
count
public static java.lang.Number count(byte[] self, java.lang.Object value)Counts the number of occurrences of the given value inside this array. Comparison is done using Groovy's == operator (usingcompareTo(value) == 0
orequals(value)
).- Parameters:
self
- the array within which we count the number of occurrencesvalue
- the value being searched for- Returns:
- the number of occurrences
- Since:
- 1.6.4
-
toList
@Deprecated public static <T> java.util.List<T> toList(java.util.Collection<T> self)Deprecated.Use the Iterable version of toList instead- Since:
- 1.0
- See Also:
toList(Iterable)
-
toList
public static <T> java.util.List<T> toList(java.util.Iterator<T> self)Convert an iterator to a List. The iterator will become exhausted of elements after making this conversion.- Parameters:
self
- an iterator- Returns:
- a List
- Since:
- 1.5.0
-
toList
public static <T> java.util.List<T> toList(java.lang.Iterable<T> self)Convert an Iterable to a List. The Iterable's iterator will become exhausted of elements after making this conversion.Example usage:
def x = [1,2,3] as HashSet assert x.class == HashSet assert x.toList() instanceof List
- Parameters:
self
- an Iterable- Returns:
- a List
- Since:
- 1.8.7
-
toList
public static <T> java.util.List<T> toList(java.util.Enumeration<T> self)Convert an enumeration to a List.- Parameters:
self
- an enumeration- Returns:
- a List
- Since:
- 1.5.0
-
collate
public static <T> java.util.List<java.util.List<T>> collate(java.lang.Iterable<T> self, int size)Collates this iterable into sub-lists of lengthsize
. Example:def list = [ 1, 2, 3, 4, 5, 6, 7 ] def coll = list.collate( 3 ) assert coll == [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7 ] ]
- Parameters:
self
- an Iterablesize
- the length of each sub-list in the returned list- Returns:
- a List containing the data collated into sub-lists
- Since:
- 2.4.0
-
collate
public static <T> java.util.List<java.util.List<T>> collate(T[] self, int size)Collates an array.- Parameters:
self
- an arraysize
- the length of each sub-list in the returned list- Returns:
- a List containing the array values collated into sub-lists
- Since:
- 2.5.0
- See Also:
collate(Iterable, int)
-
collate
@Deprecated public static <T> java.util.List<java.util.List<T>> collate(java.util.List<T> self, int size)Deprecated.use the Iterable variant instead- Since:
- 1.8.6
- See Also:
collate(Iterable, int)
-
collate
public static <T> java.util.List<java.util.List<T>> collate(java.lang.Iterable<T> self, int size, int step)Collates this iterable into sub-lists of lengthsize
stepping through the codestep
elements for each subList. Example:def list = [ 1, 2, 3, 4 ] def coll = list.collate( 3, 1 ) assert coll == [ [ 1, 2, 3 ], [ 2, 3, 4 ], [ 3, 4 ], [ 4 ] ]
- Parameters:
self
- an Iterablesize
- the length of each sub-list in the returned liststep
- the number of elements to step through for each sub-list- Returns:
- a List containing the data collated into sub-lists
- Since:
- 2.4.0
-
collate
public static <T> java.util.List<java.util.List<T>> collate(T[] self, int size, int step)Collates an array into sub-lists.- Parameters:
self
- an arraysize
- the length of each sub-list in the returned liststep
- the number of elements to step through for each sub-list- Returns:
- a List containing the array elements collated into sub-lists
- Since:
- 2.5.0
- See Also:
collate(Iterable, int, int)
-
collate
@Deprecated public static <T> java.util.List<java.util.List<T>> collate(java.util.List<T> self, int size, int step)Deprecated.use the Iterable variant instead- Since:
- 1.8.6
- See Also:
collate(Iterable, int, int)
-
collate
public static <T> java.util.List<java.util.List<T>> collate(java.lang.Iterable<T> self, int size, boolean keepRemainder)Collates this iterable into sub-lists of lengthsize
. Any remaining elements in the iterable after the subdivision will be dropped ifkeepRemainder
is false. Example:def list = [ 1, 2, 3, 4, 5, 6, 7 ] def coll = list.collate( 3, false ) assert coll == [ [ 1, 2, 3 ], [ 4, 5, 6 ] ]
- Parameters:
self
- an Iterablesize
- the length of each sub-list in the returned listkeepRemainder
- if true, any remaining elements are returned as sub-lists. Otherwise they are discarded- Returns:
- a List containing the data collated into sub-lists
- Since:
- 2.4.0
-
collate
public static <T> java.util.List<java.util.List<T>> collate(T[] self, int size, boolean keepRemainder)Collates this array into sub-lists.- Parameters:
self
- an arraysize
- the length of each sub-list in the returned listkeepRemainder
- if true, any remaining elements are returned as sub-lists. Otherwise they are discarded- Returns:
- a List containing the array elements collated into sub-lists
- Since:
- 2.5.0
- See Also:
collate(Iterable, int, boolean)
-
collate
@Deprecated public static <T> java.util.List<java.util.List<T>> collate(java.util.List<T> self, int size, boolean keepRemainder)Deprecated.use the Iterable variant instead- Since:
- 1.8.6
- See Also:
collate(Iterable, int, boolean)
-
collate
public static <T> java.util.List<java.util.List<T>> collate(java.lang.Iterable<T> self, int size, int step, boolean keepRemainder)Collates this iterable into sub-lists of lengthsize
stepping through the codestep
elements for each sub-list. Any remaining elements in the iterable after the subdivision will be dropped ifkeepRemainder
is false. Example:def list = [ 1, 2, 3, 4 ] assert list.collate( 2, 2, true ) == [ [ 1, 2 ], [ 3, 4 ] ] assert list.collate( 3, 1, true ) == [ [ 1, 2, 3 ], [ 2, 3, 4 ], [ 3, 4 ], [ 4 ] ] assert list.collate( 3, 1, false ) == [ [ 1, 2, 3 ], [ 2, 3, 4 ] ]
- Parameters:
self
- an Iterablesize
- the length of each sub-list in the returned liststep
- the number of elements to step through for each sub-listkeepRemainder
- if true, any remaining elements are returned as sub-lists. Otherwise they are discarded- Returns:
- a List containing the data collated into sub-lists
- Throws:
java.lang.IllegalArgumentException
- if the step is zero.- Since:
- 2.4.0
-
collate
public static <T> java.util.List<java.util.List<T>> collate(T[] self, int size, int step, boolean keepRemainder)Collates this array into into sub-lists.- Parameters:
self
- an arraysize
- the length of each sub-list in the returned liststep
- the number of elements to step through for each sub-listkeepRemainder
- if true, any remaining elements are returned as sub-lists. Otherwise they are discarded- Returns:
- a List containing the array elements collated into sub-lists
- Since:
- 2.5.0
-
collate
@Deprecated public static <T> java.util.List<java.util.List<T>> collate(java.util.List<T> self, int size, int step, boolean keepRemainder)Deprecated.use the Iterable variant instead- Since:
- 1.8.6
- See Also:
collate(Iterable, int, int, boolean)
-
collect
public static java.util.Collection collect(java.lang.Object self)Iterates through this aggregate Object transforming each item into a new value using Closure.IDENTITY as a transformer, basically returning a list of items copied from the original object.assert [1,2,3] == [1,2,3].iterator().collect()
- Parameters:
self
- an aggregate Object with an Iterator returning its items- Returns:
- a Collection of the transformed values
- Since:
- 1.8.5
- See Also:
Closure.IDENTITY
-
collect
Iterates through this aggregate Object transforming each item into a new value using thetransform
closure, returning a list of transformed values. Example:def list = [1, 'a', 1.23, true ] def types = list.collect { it.class } assert types == [Integer, String, BigDecimal, Boolean]
- Parameters:
self
- an aggregate Object with an Iterator returning its itemstransform
- the closure used to transform each item of the aggregate object- Returns:
- a List of the transformed values
- Since:
- 1.0
-
collect
public static <T> java.util.Collection<T> collect(java.lang.Object self, java.util.Collection<T> collector, Closure<? extends T> transform)Iterates through this aggregate Object transforming each item into a new value using thetransform
closure and adding it to the suppliedcollector
.- Parameters:
self
- an aggregate Object with an Iterator returning its itemscollector
- the Collection to which the transformed values are addedtransform
- the closure used to transform each item of the aggregate object- Returns:
- the collector with all transformed values added to it
- Since:
- 1.0
-
collect
Iterates through this Array transforming each item into a new value using thetransform
closure, returning a list of transformed values.- Parameters:
self
- an Arraytransform
- the closure used to transform each item of the Array- Returns:
- a List of the transformed values
- Since:
- 2.5.0
-
collect
public static <S, T> java.util.Collection<T> collect(S[] self, java.util.Collection<T> collector, Closure<? extends T> transform)Iterates through this Array transforming each item into a new value using thetransform
closure and adding it to the suppliedcollector
.Integer[] nums = [1,2,3] List
answer = [] nums.collect(answer) { it * 2 } assert [2,4,6] == answer - Parameters:
self
- an Arraycollector
- the Collection to which the transformed values are addedtransform
- the closure used to transform each item- Returns:
- the collector with all transformed values added to it
- Since:
- 2.5.0
-
collect
Iterates through this Iterator transforming each item into a new value using thetransform
closure, returning a list of transformed values.- Parameters:
self
- an Iteratortransform
- the closure used to transform each item- Returns:
- a List of the transformed values
- Since:
- 2.5.0
-
collect
public static <S, T> java.util.Collection<T> collect(java.util.Iterator<S> self, java.util.Collection<T> collector, Closure<? extends T> transform)Iterates through this Iterator transforming each item into a new value using thetransform
closure and adding it to the suppliedcollector
.- Parameters:
self
- an Iteratorcollector
- the Collection to which the transformed values are addedtransform
- the closure used to transform each item- Returns:
- the collector with all transformed values added to it
- Since:
- 2.5.0
-
collect
@Deprecated public static <T> java.util.List<T> collect(java.util.Collection<T> self)Deprecated.use the Iterable version insteadIterates through this collection transforming each entry into a new value using Closure.IDENTITY as a transformer, basically returning a list of items copied from the original collection.assert [1,2,3] == [1,2,3].collect()
- Parameters:
self
- a collection- Returns:
- a List of the transformed values
- Since:
- 1.8.5
- See Also:
Closure.IDENTITY
-
collect
@Deprecated public static <S, T> java.util.List<T> collect(java.util.Collection<S> self, Closure<T> transform)Deprecated.use the Iterable version insteadIterates through this collection transforming each entry into a new value using thetransform
closure returning a list of transformed values.- Parameters:
self
- a collectiontransform
- the closure used to transform each item of the collection- Returns:
- a List of the transformed values
- Since:
- 1.0
-
collect
@Deprecated public static <S, T> java.util.Collection<T> collect(java.util.Collection<S> self, java.util.Collection<T> collector, Closure<? extends T> transform)Deprecated.use the Iterable version insteadIterates through this collection transforming each value into a new value using thetransform
closure and adding it to the suppliedcollector
.assert [1,2,3] as HashSet == [2,4,5,6].collect(new HashSet()) { (int)(it / 2) }
- Parameters:
self
- a collectioncollector
- the Collection to which the transformed values are addedtransform
- the closure used to transform each item of the collection- Returns:
- the collector with all transformed values added to it
- Since:
- 1.0
-
collect
public static <T> java.util.List<T> collect(java.lang.Iterable<T> self)Iterates through this collection transforming each entry into a new value using Closure.IDENTITY as a transformer, basically returning a list of items copied from the original collection.assert [1,2,3] == [1,2,3].collect()
- Parameters:
self
- an Iterable- Returns:
- a List of the transformed values
- Since:
- 2.5.0
- See Also:
Closure.IDENTITY
-
collect
Iterates through this Iterable transforming each entry into a new value using thetransform
closure returning a list of transformed values.assert [2,4,6] == [1,2,3].collect { it * 2 }
- Parameters:
self
- an Iterabletransform
- the closure used to transform each item of the collection- Returns:
- a List of the transformed values
- Since:
- 2.5.0
-
collect
public static <S, T> java.util.Collection<T> collect(java.lang.Iterable<S> self, java.util.Collection<T> collector, Closure<? extends T> transform)Iterates through this collection transforming each value into a new value using thetransform
closure and adding it to the suppliedcollector
.assert [1,2,3] as HashSet == [2,4,5,6].collect(new HashSet()) { (int)(it / 2) }
- Parameters:
self
- an Iterablecollector
- the Collection to which the transformed values are addedtransform
- the closure used to transform each item- Returns:
- the collector with all transformed values added to it
- Since:
- 2.5.0
-
collectAll
Deprecated.Use collectNested insteadDeprecated alias for collectNested- See Also:
collectNested(Collection, Closure)
-
collectNested
Recursively iterates through this collection transforming each non-Collection value into a new value using the closure as a transformer. Returns a potentially nested list of transformed values.assert [2,[4,6],[8],[]] == [1,[2,3],[4],[]].collectNested { it * 2 }
- Parameters:
self
- a collectiontransform
- the closure used to transform each item of the collection- Returns:
- the resultant collection
- Since:
- 1.8.1
-
collectNested
Recursively iterates through this Iterable transforming each non-Collection value into a new value using the closure as a transformer. Returns a potentially nested list of transformed values.assert [2,[4,6],[8],[]] == [1,[2,3],[4],[]].collectNested { it * 2 }
- Parameters:
self
- an Iterabletransform
- the closure used to transform each item of the Iterable- Returns:
- the resultant list
- Since:
- 2.2.0
-
collectAll
@Deprecated public static java.util.Collection collectAll(java.util.Collection self, java.util.Collection collector, Closure transform)Deprecated.Use collectNested insteadDeprecated alias for collectNested -
collectNested
@Deprecated public static java.util.Collection collectNested(java.util.Collection self, java.util.Collection collector, Closure transform)Deprecated.Use the Iterable version of collectNested instead- Since:
- 1.8.1
- See Also:
collectNested(Iterable, Collection, Closure)
-
collectNested
public static java.util.Collection collectNested(java.lang.Iterable self, java.util.Collection collector, Closure transform)Recursively iterates through this Iterable transforming each non-Collection value into a new value using thetransform
closure. Returns a potentially nested collection of transformed values.def x = [1,[2,3],[4],[]].collectNested(new Vector()) { it * 2 } assert x == [2,[4,6],[8],[]] assert x instanceof Vector
- Parameters:
self
- an Iterablecollector
- an initial Collection to which the transformed values are addedtransform
- the closure used to transform each element of the Iterable- Returns:
- the collector with all transformed values added to it
- Since:
- 2.2.0
-
collectMany
@Deprecated public static <T, E> java.util.List<T> collectMany(java.util.Collection<E> self, Closure<? extends java.util.Collection<? extends T>> projection)Deprecated.Use the Iterable version of collectMany instead- Since:
- 1.8.1
- See Also:
collectMany(Iterable, Closure)
-
collectMany
@Deprecated public static <T, E> java.util.Collection<T> collectMany(java.util.Collection<E> self, java.util.Collection<T> collector, Closure<? extends java.util.Collection<? extends T>> projection)Deprecated.Use the Iterable version of collectMany instead- Since:
- 1.8.5
- See Also:
collectMany(Iterable, Collection, Closure)
-
collectMany
public static <T, E> java.util.List<T> collectMany(java.lang.Iterable<E> self, Closure<? extends java.util.Collection<? extends T>> projection)Projects each item from a source Iterable to a collection and concatenates (flattens) the resulting collections into a single list.def nums = 1..10 def squaresAndCubesOfEvens = nums.collectMany{ it % 2 ? [] : [it**2, it**3] } assert squaresAndCubesOfEvens == [4, 8, 16, 64, 36, 216, 64, 512, 100, 1000] def animals = ['CAT', 'DOG', 'ELEPHANT'] as Set def smallAnimals = animals.collectMany{ it.size()
>
3 ? [] : [it.toLowerCase()] } assert smallAnimals == ['cat', 'dog'] def orig = nums as Set def origPlusIncrements = orig.collectMany{ [it, it+1] } assert origPlusIncrements.size() == orig.size() * 2 assert origPlusIncrements.unique().size() == orig.size() + 1- Parameters:
self
- an Iterableprojection
- a projecting Closure returning a collection of items- Returns:
- a list created from the projected collections concatenated (flattened) together
- Since:
- 2.2.0
- See Also:
sum(java.lang.Iterable, groovy.lang.Closure)
-
collectMany
public static <T, E> java.util.Collection<T> collectMany(java.lang.Iterable<E> self, java.util.Collection<T> collector, Closure<? extends java.util.Collection<? extends T>> projection)Projects each item from a source collection to a result collection and concatenates (flattens) the resulting collections adding them into thecollector
.def animals = ['CAT', 'DOG', 'ELEPHANT'] as Set def smallAnimals = animals.collectMany(['ant', 'bee']){ it.size()
>
3 ? [] : [it.toLowerCase()] } assert smallAnimals == ['ant', 'bee', 'cat', 'dog'] def nums = 1..5 def origPlusIncrements = nums.collectMany([] as Set){ [it, it+1] } assert origPlusIncrements.size() == nums.size() + 1- Parameters:
self
- an Iterablecollector
- an initial collection to add the projected items toprojection
- a projecting Closure returning a collection of items- Returns:
- the collector with the projected collections concatenated (flattened) into it
- Since:
- 2.2.0
-
collectMany
public static <T, K, V> java.util.Collection<T> collectMany(java.util.Map<K,V> self, java.util.Collection<T> collector, Closure<? extends java.util.Collection<? extends T>> projection)Projects each item from a source map to a result collection and concatenates (flattens) the resulting collections adding them into thecollector
.def map = [bread:3, milk:5, butter:2] def result = map.collectMany(['x']){ k, v
->
if (k.startsWith('b')) k.toList() } assert result == ['x', 'b', 'r', 'e', 'a', 'd', 'b', 'u', 't', 't', 'e', 'r']- Parameters:
self
- a mapcollector
- an initial collection to add the projected items toprojection
- a projecting Closure returning a collection of items- Returns:
- the collector with the projected collections concatenated (flattened) to it
- Since:
- 1.8.8
-
collectMany
public static <T, K, V> java.util.List<T> collectMany(java.util.Map<K,V> self, Closure<? extends java.util.Collection<? extends T>> projection)Projects each item from a source map to a result collection and concatenates (flattens) the resulting collections adding them into a collection.def map = [bread:3, milk:5, butter:2] def result = map.collectMany{ k, v
->
k.startsWith('b') ? k.toList() : [] } assert result == ['b', 'r', 'e', 'a', 'd', 'b', 'u', 't', 't', 'e', 'r']- Parameters:
self
- a mapprojection
- a projecting Closure returning a collection of items- Returns:
- a list created from the projected collections concatenated (flattened) together
- Since:
- 1.8.8
-
collectMany$$bridge
@Deprecated public static <T, K, V> java.util.Collection<T> collectMany$$bridge(java.util.Map<K,V> self, Closure<? extends java.util.Collection<? extends T>> projection)Deprecated. -
collectMany
public static <T, E> java.util.List<T> collectMany(E[] self, Closure<? extends java.util.Collection<? extends T>> projection)Projects each item from a source array to a collection and concatenates (flattens) the resulting collections into a single list.def nums = [1, 2, 3, 4, 5, 6] as Object[] def squaresAndCubesOfEvens = nums.collectMany{ it % 2 ? [] : [it**2, it**3] } assert squaresAndCubesOfEvens == [4, 8, 16, 64, 36, 216]
- Parameters:
self
- an arrayprojection
- a projecting Closure returning a collection of items- Returns:
- a list created from the projected collections concatenated (flattened) together
- Since:
- 1.8.1
- See Also:
sum(Object[], groovy.lang.Closure)
-
collectMany
public static <T, E> java.util.Collection<T> collectMany(E[] self, java.util.Collection<T> collector, Closure<? extends java.util.Collection<? extends T>> projection)Projects each item from a source array to a collection and concatenates (flattens) the resulting collections into a single list.def nums = [1, 2, 3, 4, 5, 6] as Object[] def squaresAndCubesOfEvens = nums.collectMany{ it % 2 ? [] : [it**2, it**3] } assert squaresAndCubesOfEvens == [4, 8, 16, 64, 36, 216]
- Parameters:
self
- an arraycollector
- an initial collection to add the projected items toprojection
- a projecting Closure returning a collection of items- Returns:
- the collector with the projected collections concatenated (flattened) to it
- Since:
- 1.8.1
- See Also:
sum(Object[], groovy.lang.Closure)
-
collectMany
public static <T, E> java.util.Collection<T> collectMany(java.util.Iterator<E> self, java.util.Collection<T> collector, Closure<? extends java.util.Collection<? extends T>> projection)Projects each item from a source iterator to a collection and concatenates (flattens) the resulting collections into a single list.def numsIter = [1, 2, 3, 4, 5, 6].iterator() def squaresAndCubesOfEvens = numsIter.collectMany{ if (it % 2 == 0) [it**2, it**3] } assert squaresAndCubesOfEvens == [4, 8, 16, 64, 36, 216]
- Parameters:
self
- an iteratorcollector
- an initial collection to add the projected items toprojection
- a projecting Closure returning a collection of items- Returns:
- the collector with the projected collections concatenated (flattened) to it
- Since:
- 1.8.1
- See Also:
sum(Iterator, groovy.lang.Closure)
-
collectMany
public static <T, E> java.util.List<T> collectMany(java.util.Iterator<E> self, Closure<? extends java.util.Collection<? extends T>> projection)Projects each item from a source iterator to a collection and concatenates (flattens) the resulting collections into a single list.def numsIter = [1, 2, 3, 4, 5, 6].iterator() def squaresAndCubesOfEvens = numsIter.collectMany{ it % 2 ? [] : [it**2, it**3] } assert squaresAndCubesOfEvens == [4, 8, 16, 64, 36, 216]
- Parameters:
self
- an iteratorprojection
- a projecting Closure returning a collection of items- Returns:
- a list created from the projected collections concatenated (flattened) together
- Since:
- 1.8.1
- See Also:
collectMany(Iterator, Collection, groovy.lang.Closure)
-
collect
public static <T, K, V> java.util.Collection<T> collect(java.util.Map<K,V> self, java.util.Collection<T> collector, Closure<? extends T> transform)Iterates through this Map transforming each map entry into a new value using thetransform
closure returning thecollector
with all transformed values added to it.assert [a:1, b:2].collect( [] as HashSet ) { key, value
->
key*value } == ["a", "bb"] as Set assert [3:20, 2:30].collect( [] as HashSet ) { entry->
entry.key * entry.value } == [60] as Set- Parameters:
self
- a Mapcollector
- the Collection to which transformed values are addedtransform
- the transformation closure which can take one (Map.Entry) or two (key, value) parameters- Returns:
- the collector with all transformed values added to it
- Since:
- 1.0
-
collect
public static <T, K, V> java.util.List<T> collect(java.util.Map<K,V> self, Closure<T> transform)Iterates through this Map transforming each map entry into a new value using thetransform
closure returning a list of transformed values.assert [a:1, b:2].collect { key, value
->
key*value } == ["a", "bb"] assert [3:20, 2:30].collect { entry->
entry.key * entry.value } == [60, 60]- Parameters:
self
- a Maptransform
- the transformation closure which can take one (Map.Entry) or two (key, value) parameters- Returns:
- the resultant list of transformed values
- Since:
- 1.0
-
collectEntries
public static <K, V, X, Y> java.util.Map<K,V> collectEntries(java.util.Map<X,Y> self, java.util.Map<K,V> collector, Closure<?> transform)Iterates through this Map transforming each map entry using thetransform
closure returning a map of the transformed entries.assert [a:1, b:2].collectEntries( [:] ) { k, v
Note: When using the list-style of result, the behavior is '->
[v, k] } == [1:'a', 2:'b'] assert [a:1, b:2].collectEntries( [30:'C'] ) { key, value->
[(value*10): key.toUpperCase()] } == [10:'A', 20:'B', 30:'C']def (key, value) = listResultFromClosure
'. While we strongly discourage using a list of size other than 2, Groovy's normal semantics apply in this case; throwing away elements after the second one and using null for the key or value for the case of a shortened list. If your collector Map doesn't support null keys or values, you might get a runtime error, e.g. NullPointerException or IllegalArgumentException.- Parameters:
self
- a Mapcollector
- the Map into which the transformed entries are puttransform
- the closure used for transforming, which can take one (Map.Entry) or two (key, value) parameters and should return a Map.Entry, a Map or a two-element list containing the resulting key and value- Returns:
- the collector with all transformed values added to it
- Since:
- 1.7.9
- See Also:
collect(Map, Collection, Closure)
-
collectEntries
public static <K, V, X, Y> java.util.Map<K,V> collectEntries(java.util.Map<X,Y> self, Closure<?> transform)Iterates through this Map transforming each entry using thetransform
closure and returning a map of the transformed entries.assert [a:1, b:2].collectEntries { key, value
Note: When using the list-style of result, the behavior is '->
[value, key] } == [1:'a', 2:'b'] assert [a:1, b:2].collectEntries { key, value->
[(value*10): key.toUpperCase()] } == [10:'A', 20:'B']def (key, value) = listResultFromClosure
'. While we strongly discourage using a list of size other than 2, Groovy's normal semantics apply in this case; throwing away elements after the second one and using null for the key or value for the case of a shortened list. If your Map doesn't support null keys or values, you might get a runtime error, e.g. NullPointerException or IllegalArgumentException.- Parameters:
self
- a Maptransform
- the closure used for transforming, which can take one (Map.Entry) or two (key, value) parameters and should return a Map.Entry, a Map or a two-element list containing the resulting key and value- Returns:
- a Map of the transformed entries
- Since:
- 1.7.9
- See Also:
collect(Map, Collection, Closure)
-
collectEntries
@Deprecated public static <K, V> java.util.Map<K,V> collectEntries(java.util.Collection<?> self, Closure<?> transform)Deprecated.Use the Iterable version of collectEntries instead- Since:
- 1.7.9
- See Also:
collectEntries(Iterable, Closure)
-
collectEntries
public static <K, V, E> java.util.Map<K,V> collectEntries(java.util.Iterator<E> self, Closure<?> transform)A variant of collectEntries for Iterators.- Parameters:
self
- an Iteratortransform
- the closure used for transforming, which has an item from self as the parameter and should return a Map.Entry, a Map or a two-element list containing the resulting key and value- Returns:
- a Map of the transformed entries
- Since:
- 1.8.7
- See Also:
collectEntries(Iterable, Closure)
-
collectEntries
public static <K, V, E> java.util.Map<K,V> collectEntries(java.lang.Iterable<E> self, Closure<?> transform)Iterates through this Iterable transforming each item using thetransform
closure and returning a map of the resulting transformed entries.def letters = "abc" // collect letters with index using list style assert (0..2).collectEntries { index
Note: When using the list-style of result, the behavior is '->
[index, letters[index]] } == [0:'a', 1:'b', 2:'c'] // collect letters with index using map style assert (0..2).collectEntries { index->
[(index): letters[index]] } == [0:'a', 1:'b', 2:'c']def (key, value) = listResultFromClosure
'. While we strongly discourage using a list of size other than 2, Groovy's normal semantics apply in this case; throwing away elements after the second one and using null for the key or value for the case of a shortened list.- Parameters:
self
- an Iterabletransform
- the closure used for transforming, which has an item from self as the parameter and should return a Map.Entry, a Map or a two-element list containing the resulting key and value- Returns:
- a Map of the transformed entries
- Since:
- 1.8.7
- See Also:
collectEntries(Iterator, Closure)
-
collectEntries
@Deprecated public static <K, V> java.util.Map<K,V> collectEntries(java.util.Collection<?> self)Deprecated.Use the Iterable version of collectEntries instead- Since:
- 1.8.5
- See Also:
collectEntries(Iterable)
-
collectEntries
public static <K, V> java.util.Map<K,V> collectEntries(java.util.Iterator<?> self)A variant of collectEntries for Iterators using the identity closure as the transform.- Parameters:
self
- an Iterator- Returns:
- a Map of the transformed entries
- Since:
- 1.8.7
- See Also:
collectEntries(Iterable)
-
collectEntries
public static <K, V> java.util.Map<K,V> collectEntries(java.lang.Iterable<?> self)A variant of collectEntries for Iterable objects using the identity closure as the transform. The source Iterable should contain a list of[key, value]
tuples orMap.Entry
objects.def nums = [1, 10, 100, 1000] def tuples = nums.collect{ [it, it.toString().size()] } assert tuples == [[1, 1], [10, 2], [100, 3], [1000, 4]] def map = tuples.collectEntries() assert map == [1:1, 10:2, 100:3, 1000:4]
- Parameters:
self
- an Iterable- Returns:
- a Map of the transformed entries
- Since:
- 1.8.7
- See Also:
collectEntries(Iterator)
-
collectEntries
@Deprecated public static <K, V> java.util.Map<K,V> collectEntries(java.util.Collection<?> self, java.util.Map<K,V> collector, Closure<?> transform)Deprecated.Use the Iterable version of collectEntries instead- Since:
- 1.7.9
- See Also:
collectEntries(Iterable, Map, Closure)
-
collectEntries
public static <K, V, E> java.util.Map<K,V> collectEntries(java.util.Iterator<E> self, java.util.Map<K,V> collector, Closure<?> transform)A variant of collectEntries for Iterators using a supplied map as the destination of transformed entries.- Parameters:
self
- an Iteratorcollector
- the Map into which the transformed entries are puttransform
- the closure used for transforming, which has an item from self as the parameter and should return a Map.Entry, a Map or a two-element list containing the resulting key and value- Returns:
- the collector with all transformed values added to it
- Since:
- 1.8.7
-
collectEntries
public static <K, V, E> java.util.Map<K,V> collectEntries(java.lang.Iterable<E> self, java.util.Map<K,V> collector, Closure<?> transform)Iterates through this Iterable transforming each item using the closure as a transformer into a map entry, returning the supplied map with all of the transformed entries added to it.def letters = "abc" // collect letters with index assert (0..2).collectEntries( [:] ) { index
Note: When using the list-style of result, the behavior is '->
[index, letters[index]] } == [0:'a', 1:'b', 2:'c'] assert (0..2).collectEntries( [4:'d'] ) { index->
[(index+1): letters[index]] } == [1:'a', 2:'b', 3:'c', 4:'d']def (key, value) = listResultFromClosure
'. While we strongly discourage using a list of size other than 2, Groovy's normal semantics apply in this case; throwing away elements after the second one and using null for the key or value for the case of a shortened list. If your collector Map doesn't support null keys or values, you might get a runtime error, e.g. NullPointerException or IllegalArgumentException.- Parameters:
self
- an Iterablecollector
- the Map into which the transformed entries are puttransform
- the closure used for transforming, which has an item from self as the parameter and should return a Map.Entry, a Map or a two-element list containing the resulting key and value- Returns:
- the collector with all transformed values added to it
- Since:
- 1.8.7
- See Also:
collectEntries(Iterator, Map, Closure)
-
collectEntries
@Deprecated public static <K, V> java.util.Map<K,V> collectEntries(java.util.Collection<?> self, java.util.Map<K,V> collector)Deprecated.Use the Iterable version of collectEntries instead- Since:
- 1.8.5
- See Also:
collectEntries(Iterable, Map)
-
collectEntries
public static <K, V> java.util.Map<K,V> collectEntries(java.util.Iterator<?> self, java.util.Map<K,V> collector)A variant of collectEntries for Iterators using the identity closure as the transform and a supplied map as the destination of transformed entries.- Parameters:
self
- an Iteratorcollector
- the Map into which the transformed entries are put- Returns:
- the collector with all transformed values added to it
- Since:
- 1.8.7
- See Also:
collectEntries(Iterable, Map)
-
collectEntries
public static <K, V> java.util.Map<K,V> collectEntries(java.lang.Iterable<?> self, java.util.Map<K,V> collector)A variant of collectEntries for Iterables using the identity closure as the transform and a supplied map as the destination of transformed entries.- Parameters:
self
- an Iterablecollector
- the Map into which the transformed entries are put- Returns:
- the collector with all transformed values added to it
- Since:
- 1.8.7
- See Also:
collectEntries(Iterator, Map)
-
collectEntries
public static <K, V, E> java.util.Map<K,V> collectEntries(E[] self, java.util.Map<K,V> collector, Closure<?> transform)Iterates through this array transforming each item using thetransform
closure and returning a map of the resulting transformed entries.def letters = "abc" def nums = [0, 1, 2] as Integer[] // collect letters with index assert nums.collectEntries( [:] ) { index
Note: When using the list-style of result, the behavior is '->
[index, letters[index]] } == [0:'a', 1:'b', 2:'c'] assert nums.collectEntries( [4:'d'] ) { index->
[(index+1): letters[index]] } == [1:'a', 2:'b', 3:'c', 4:'d']def (key, value) = listResultFromClosure
'. While we strongly discourage using a list of size other than 2, Groovy's normal semantics apply in this case; throwing away elements after the second one and using null for the key or value for the case of a shortened list. If your collector Map doesn't support null keys or values, you might get a runtime error, e.g. NullPointerException or IllegalArgumentException.- Parameters:
self
- an arraycollector
- the Map into which the transformed entries are puttransform
- the closure used for transforming, which has an item from self as the parameter and should return a Map.Entry, a Map or a two-element list containing the resulting key and value- Returns:
- the collector with all transformed values added to it
- Since:
- 1.7.9
- See Also:
collect(Map, Collection, Closure)
-
collectEntries
public static <K, V, E> java.util.Map<K,V> collectEntries(E[] self, java.util.Map<K,V> collector)A variant of collectEntries using the identity closure as the transform.- Parameters:
self
- an arraycollector
- the Map into which the transformed entries are put- Returns:
- the collector with all transformed values added to it
- Since:
- 1.8.5
- See Also:
collectEntries(Object[], Map, Closure)
-
collectEntries
Iterates through this array transforming each item using thetransform
closure and returning a map of the resulting transformed entries.def letters = "abc" def nums = [0, 1, 2] as Integer[] // collect letters with index using list style assert nums.collectEntries { index
Note: When using the list-style of result, the behavior is '->
[index, letters[index]] } == [0:'a', 1:'b', 2:'c'] // collect letters with index using map style assert nums.collectEntries { index->
[(index): letters[index]] } == [0:'a', 1:'b', 2:'c']def (key, value) = listResultFromClosure
'. While we strongly discourage using a list of size other than 2, Groovy's normal semantics apply in this case; throwing away elements after the second one and using null for the key or value for the case of a shortened list.- Parameters:
self
- a Collectiontransform
- the closure used for transforming, which has an item from self as the parameter and should return a Map.Entry, a Map or a two-element list containing the resulting key and value- Returns:
- a Map of the transformed entries
- Since:
- 1.7.9
- See Also:
collectEntries(Iterator, Map, Closure)
-
collectEntries
public static <K, V, E> java.util.Map<K,V> collectEntries(E[] self)A variant of collectEntries using the identity closure as the transform.- Parameters:
self
- an array- Returns:
- the collector with all transformed values added to it
- Since:
- 1.8.5
- See Also:
collectEntries(Object[], Closure)
-
find
Finds the first value matching the closure condition.def numbers = [1, 2, 3] def result = numbers.find { it
>
1} assert result == 2- Parameters:
self
- an Object with an iterator returning its valuesclosure
- a closure condition- Returns:
- the first Object found or null if none was found
- Since:
- 1.0
-
find
public static java.lang.Object find(java.lang.Object self)Finds the first item matching the IDENTITY Closure (i.e. matching Groovy truth).Example:
def items = [null, 0, 0.0, false, '', [], 42, 43] assert items.find() == 42
- Parameters:
self
- an Object with an Iterator returning its values- Returns:
- the first Object found or null if none was found
- Since:
- 1.8.1
- See Also:
Closure.IDENTITY
-
find
Finds the first value matching the closure condition. Example:def list = [1,2,3] assert 2 == list.find { it
>
1 }- Parameters:
self
- a Collectionclosure
- a closure condition- Returns:
- the first Object found, in the order of the collections iterator, or null if no element matches
- Since:
- 1.0
-
find
Finds the first element in the array that matches the given closure condition. Example:def list = [1,2,3] as Integer[] assert 2 == list.find { it
>
1 } assert null == list.find { it>
5 }- Parameters:
self
- an Arraycondition
- a closure condition- Returns:
- the first element from the array that matches the condition or null if no element matches
- Since:
- 2.0
-
find
public static <T> T find(java.util.Collection<T> self)Finds the first item matching the IDENTITY Closure (i.e. matching Groovy truth).Example:
def items = [null, 0, 0.0, false, '', [], 42, 43] assert items.find() == 42
- Parameters:
self
- a Collection- Returns:
- the first Object found or null if none was found
- Since:
- 1.8.1
- See Also:
Closure.IDENTITY
-
findResult
Treats the object as iterable, iterating through the values it represents and returns the first non-null result obtained from calling the closure, otherwise returns null.int[] numbers = [1, 2, 3] assert numbers.findResult { if(it
>
1) return it } == 2 assert numbers.findResult { if(it>
4) return it } == null- Parameters:
self
- an Object with an iterator returning its valuescondition
- a closure that returns a non-null value to indicate that processing should stop and the value should be returned- Returns:
- the first non-null result of the closure
- Since:
- 1.7.5
-
findResult
public static java.lang.Object findResult(java.lang.Object self, java.lang.Object defaultResult, Closure condition)Treats the object as iterable, iterating through the values it represents and returns the first non-null result obtained from calling the closure, otherwise returns the defaultResult.int[] numbers = [1, 2, 3] assert numbers.findResult(5) { if(it
>
1) return it } == 2 assert numbers.findResult(5) { if(it>
4) return it } == 5- Parameters:
self
- an Object with an iterator returning its valuesdefaultResult
- an Object that should be returned if all closure results are nullcondition
- a closure that returns a non-null value to indicate that processing should stop and the value should be returned- Returns:
- the first non-null result of the closure, otherwise the default value
- Since:
- 1.7.5
-
findResult
@Deprecated public static <S, T, U extends T, V extends T> T findResult(java.util.Collection<S> self, U defaultResult, Closure<V> condition)Deprecated.use the Iterable version insteadIterates through the collection calling the given closure for each item but stopping once the first non-null result is found and returning that result. If all are null, the defaultResult is returned.- Parameters:
self
- a CollectiondefaultResult
- an Object that should be returned if all closure results are nullcondition
- a closure that returns a non-null value to indicate that processing should stop and the value should be returned- Returns:
- the first non-null result from calling the closure, or the defaultValue
- Since:
- 1.7.5
-
findResult
Deprecated.use the Iterable version insteadIterates through the collection calling the given closure for each item but stopping once the first non-null result is found and returning that result. If all results are null, null is returned.- Parameters:
self
- a Collectioncondition
- a closure that returns a non-null value to indicate that processing should stop and the value should be returned- Returns:
- the first non-null result from calling the closure, or null
- Since:
- 1.7.5
-
findResult
public static <S, T, U extends T, V extends T> T findResult(java.util.Iterator<S> self, U defaultResult, Closure<V> condition)Iterates through the Iterator calling the given closure condition for each item but stopping once the first non-null result is found and returning that result. If all are null, the defaultResult is returned.Examples:
def iter = [1,2,3].iterator() assert "Found 2" == iter.findResult("default") { it
>
1 ? "Found $it" : null } assert "default" == iter.findResult("default") { it>
3 ? "Found $it" : null }- Parameters:
self
- an IteratordefaultResult
- an Object that should be returned if all closure results are nullcondition
- a closure that returns a non-null value to indicate that processing should stop and the value should be returned- Returns:
- the first non-null result from calling the closure, or the defaultValue
- Since:
- 2.5.0
-
findResult
Iterates through the Iterator calling the given closure condition for each item but stopping once the first non-null result is found and returning that result. If all results are null, null is returned.- Parameters:
self
- an Iteratorcondition
- a closure that returns a non-null value to indicate that processing should stop and the value should be returned- Returns:
- the first non-null result from calling the closure, or null
- Since:
- 2.5.0
-
findResult
public static <S, T, U extends T, V extends T> T findResult(java.lang.Iterable<S> self, U defaultResult, Closure<V> condition)Iterates through the Iterable calling the given closure condition for each item but stopping once the first non-null result is found and returning that result. If all are null, the defaultResult is returned.Examples:
def list = [1,2,3] assert "Found 2" == list.findResult("default") { it
>
1 ? "Found $it" : null } assert "default" == list.findResult("default") { it>
3 ? "Found $it" : null }- Parameters:
self
- an IterabledefaultResult
- an Object that should be returned if all closure results are nullcondition
- a closure that returns a non-null value to indicate that processing should stop and the value should be returned- Returns:
- the first non-null result from calling the closure, or the defaultValue
- Since:
- 2.5.0
-
findResult
Iterates through the Iterable calling the given closure condition for each item but stopping once the first non-null result is found and returning that result. If all results are null, null is returned.- Parameters:
self
- an Iterablecondition
- a closure that returns a non-null value to indicate that processing should stop and the value should be returned- Returns:
- the first non-null result from calling the closure, or null
- Since:
- 2.5.0
-
findResult
public static <S, T, U extends T, V extends T> T findResult(S[] self, U defaultResult, Closure<V> condition)Iterates through the Array calling the given closure condition for each item but stopping once the first non-null result is found and returning that result. If all are null, the defaultResult is returned.- Parameters:
self
- an ArraydefaultResult
- an Object that should be returned if all closure results are nullcondition
- a closure that returns a non-null value to indicate that processing should stop and the value should be returned- Returns:
- the first non-null result from calling the closure, or the defaultValue
- Since:
- 2.5.0
-
findResult
Iterates through the Array calling the given closure condition for each item but stopping once the first non-null result is found and returning that result. If all results are null, null is returned.- Parameters:
self
- an Arraycondition
- a closure that returns a non-null value to indicate that processing should stop and the value should be returned- Returns:
- the first non-null result from calling the closure, or null
- Since:
- 2.5.0
-
findResult
Returns the first non-null closure result found by passing each map entry to the closure, otherwise null is returned. If the closure takes two parameters, the entry key and value are passed. If the closure takes one parameter, the Map.Entry object is passed.assert "Found b:3" == [a:1, b:3].findResult { if (it.value == 3) return "Found ${it.key}:${it.value}" } assert null == [a:1, b:3].findResult { if (it.value == 9) return "Found ${it.key}:${it.value}" } assert "Found a:1" == [a:1, b:3].findResult { k, v
->
if (k.size() + v == 2) return "Found $k:$v" }- Parameters:
self
- a Mapcondition
- a 1 or 2 arg Closure that returns a non-null value when processing should stop and a value should be returned- Returns:
- the first non-null result collected by calling the closure, or null if no such result was found
- Since:
- 1.7.5
-
findResult
public static <T, U extends T, V extends T, A, B> T findResult(java.util.Map<A,B> self, U defaultResult, Closure<V> condition)Returns the first non-null closure result found by passing each map entry to the closure, otherwise the defaultResult is returned. If the closure takes two parameters, the entry key and value are passed. If the closure takes one parameter, the Map.Entry object is passed.assert "Found b:3" == [a:1, b:3].findResult("default") { if (it.value == 3) return "Found ${it.key}:${it.value}" } assert "default" == [a:1, b:3].findResult("default") { if (it.value == 9) return "Found ${it.key}:${it.value}" } assert "Found a:1" == [a:1, b:3].findResult("default") { k, v
->
if (k.size() + v == 2) return "Found $k:$v" }- Parameters:
self
- a MapdefaultResult
- an Object that should be returned if all closure results are nullcondition
- a 1 or 2 arg Closure that returns a non-null value when processing should stop and a value should be returned- Returns:
- the first non-null result collected by calling the closure, or the defaultResult if no such result was found
- Since:
- 1.7.5
-
findResults
@Deprecated public static <T, U> java.util.Collection<T> findResults(java.util.Collection<U> self, Closure<T> filteringTransform)Deprecated.Use the Iterable version of findResults instead- Since:
- 1.8.1
- See Also:
findResults(Iterable, Closure)
-
findResults
public static <T, U> java.util.Collection<T> findResults(java.lang.Iterable<U> self, Closure<T> filteringTransform)Iterates through the Iterable transforming items using the supplied closure and collecting any non-null results.Example:
def list = [1,2,3] def result = list.findResults { it
>
1 ? "Found $it" : null } assert result == ["Found 2", "Found 3"]- Parameters:
self
- an IterablefilteringTransform
- a Closure that should return either a non-null transformed value or null for items which should be discarded- Returns:
- the list of non-null transformed values
- Since:
- 2.2.0
-
findResults
public static <T, U> java.util.Collection<T> findResults(java.util.Iterator<U> self, Closure<T> filteringTransform)Iterates through the Iterator transforming items using the supplied closure and collecting any non-null results.- Parameters:
self
- an IteratorfilteringTransform
- a Closure that should return either a non-null transformed value or null for items which should be discarded- Returns:
- the list of non-null transformed values
- Since:
- 2.5.0
-
findResults
Iterates through the Array transforming items using the supplied closure and collecting any non-null results.- Parameters:
self
- an ArrayfilteringTransform
- a Closure that should return either a non-null transformed value or null for items which should be discarded- Returns:
- the list of non-null transformed values
- Since:
- 2.5.0
-
findResults
public static <T, K, V> java.util.Collection<T> findResults(java.util.Map<K,V> self, Closure<T> filteringTransform)Iterates through the map transforming items using the supplied closure and collecting any non-null results. If the closure takes two parameters, the entry key and value are passed. If the closure takes one parameter, the Map.Entry object is passed.Example:
def map = [a:1, b:2, hi:2, cat:3, dog:2] def result = map.findResults { k, v
->
k.size() == v ? "Found $k:$v" : null } assert result == ["Found a:1", "Found hi:2", "Found cat:3"]- Parameters:
self
- a MapfilteringTransform
- a 1 or 2 arg Closure that should return either a non-null transformed value or null for items which should be discarded- Returns:
- the list of non-null transformed values
- Since:
- 1.8.1
-
find
Finds the first entry matching the closure condition. If the closure takes two parameters, the entry key and value are passed. If the closure takes one parameter, the Map.Entry object is passed.assert [a:1, b:3].find { it.value == 3 }.key == "b"
- Parameters:
self
- a Mapclosure
- a 1 or 2 arg Closure condition- Returns:
- the first Object found
- Since:
- 1.0
-
findAll
Finds all values matching the closure condition.assert ([2,4] as Set) == ([1,2,3,4] as Set).findAll { it % 2 == 0 }
- Parameters:
self
- a Setclosure
- a closure condition- Returns:
- a Set of matching values
- Since:
- 2.4.0
-
findAll
Finds all values matching the closure condition.assert [2,4] == [1,2,3,4].findAll { it % 2 == 0 }
- Parameters:
self
- a Listclosure
- a closure condition- Returns:
- a List of matching values
- Since:
- 2.4.0
-
findAll
Finds all values matching the closure condition.assert [2,4] == [1,2,3,4].findAll { it % 2 == 0 }
- Parameters:
self
- a Collectionclosure
- a closure condition- Returns:
- a Collection of matching values
- Since:
- 1.5.6
-
findAll
Finds all elements of the array matching the given Closure condition.def items = [1,2,3,4] as Integer[] assert [2,4] == items.findAll { it % 2 == 0 }
- Parameters:
self
- an arraycondition
- a closure condition- Returns:
- a list of matching values
- Since:
- 2.0
-
findAll
public static <T> java.util.Set<T> findAll(java.util.Set<T> self)Finds the items matching the IDENTITY Closure (i.e. matching Groovy truth).Example:
def items = [1, 2, 0, false, true, '', 'foo', [], [4, 5], null] as Set assert items.findAll() == [1, 2, true, 'foo', [4, 5]] as Set
- Parameters:
self
- a Set- Returns:
- a Set of the values found
- Since:
- 2.4.0
- See Also:
Closure.IDENTITY
-
findAll
public static <T> java.util.List<T> findAll(java.util.List<T> self)Finds the items matching the IDENTITY Closure (i.e. matching Groovy truth).Example:
def items = [1, 2, 0, false, true, '', 'foo', [], [4, 5], null] assert items.findAll() == [1, 2, true, 'foo', [4, 5]]
- Parameters:
self
- a List- Returns:
- a List of the values found
- Since:
- 2.4.0
- See Also:
Closure.IDENTITY
-
findAll
public static <T> java.util.Collection<T> findAll(java.util.Collection<T> self)Finds the items matching the IDENTITY Closure (i.e. matching Groovy truth).Example:
def items = [1, 2, 0, false, true, '', 'foo', [], [4, 5], null] assert items.findAll() == [1, 2, true, 'foo', [4, 5]]
- Parameters:
self
- a Collection- Returns:
- a Collection of the values found
- Since:
- 1.8.1
- See Also:
Closure.IDENTITY
-
findAll
public static <T> java.util.Collection<T> findAll(T[] self)Finds the elements of the array matching the IDENTITY Closure (i.e. matching Groovy truth).Example:
def items = [1, 2, 0, false, true, '', 'foo', [], [4, 5], null] as Object[] assert items.findAll() == [1, 2, true, 'foo', [4, 5]]
- Parameters:
self
- an array- Returns:
- a collection of the elements found
- Since:
- 2.0
- See Also:
Closure.IDENTITY
-
findAll
Finds all items matching the closure condition.- Parameters:
self
- an Object with an Iterator returning its valuesclosure
- a closure condition- Returns:
- a List of the values found
- Since:
- 1.6.0
-
findAll
public static java.util.Collection findAll(java.lang.Object self)Finds all items matching the IDENTITY Closure (i.e. matching Groovy truth).Example:
def items = [1, 2, 0, false, true, '', 'foo', [], [4, 5], null] assert items.findAll() == [1, 2, true, 'foo', [4, 5]]
- Parameters:
self
- an Object with an Iterator returning its values- Returns:
- a List of the values found
- Since:
- 1.8.1
- See Also:
Closure.IDENTITY
-
contains
public static boolean contains(java.lang.Iterable self, java.lang.Object item)Returns true if this iterable contains the item.- Parameters:
self
- an Iterable to be checked for containmentitem
- an Object to be checked for containment in this iterable- Returns:
- true if this iterable contains the item
- Since:
- 2.4.0
- See Also:
Collection.contains(Object)
-
containsAll
public static boolean containsAll(java.lang.Iterable self, java.lang.Object[] items)Returns true if this iterable contains all of the elements in the specified array.- Parameters:
self
- an Iterable to be checked for containmentitems
- array to be checked for containment in this iterable- Returns:
- true if this collection contains all of the elements in the specified array
- Since:
- 2.4.0
- See Also:
Collection.containsAll(Collection)
-
containsAll
@Deprecated public static boolean containsAll(java.util.Collection self, java.lang.Object[] items)Deprecated.use the Iterable variant instead- Since:
- 1.7.2
- See Also:
containsAll(Iterable, Object[])
-
removeAll
public static boolean removeAll(java.util.Collection self, java.lang.Object[] items)Modifies this collection by removing its elements that are contained within the specified object array. See alsofindAll
andgrep
when wanting to produce a new list containing items which don't match some criteria while leaving the original collection unchanged.- Parameters:
self
- a Collection to be modifieditems
- array containing elements to be removed from this collection- Returns:
- true if this collection changed as a result of the call
- Since:
- 1.7.2
- See Also:
Collection.removeAll(Collection)
-
retainAll
public static boolean retainAll(java.util.Collection self, java.lang.Object[] items)Modifies this collection so that it retains only its elements that are contained in the specified array. In other words, removes from this collection all of its elements that are not contained in the specified array. See alsogrep
andfindAll
when wanting to produce a new list containing items which match some specified items but leaving the original collection unchanged.- Parameters:
self
- a Collection to be modifieditems
- array containing elements to be retained from this collection- Returns:
- true if this collection changed as a result of the call
- Since:
- 1.7.2
- See Also:
Collection.retainAll(Collection)
-
retainAll
Modifies this collection so that it retains only its elements that are matched according to the specified closure condition. In other words, removes from this collection all of its elements that don't match.def list = ['a', 'b'] list.retainAll { it == 'b' } assert list == ['b']
See alsofindAll
andgrep
when wanting to produce a new list containing items which match some criteria but leaving the original collection unchanged.- Parameters:
self
- a Collection to be modifiedcondition
- a closure condition- Returns:
- true if this collection changed as a result of the call
- Since:
- 1.7.2
- See Also:
Iterator.remove()
-
retainAll
Modifies this map so that it retains only its elements that are matched according to the specified closure condition. In other words, removes from this map all of its elements that don't match. If the closure takes one parameter then it will be passed theMap.Entry
. Otherwise the closure should take two parameters, which will be the key and the value.def map = [a:1, b:2] map.retainAll { k,v
See also->
k == 'b' } assert map == [b:2]findAll
when wanting to produce a new map containing items which match some criteria but leaving the original map unchanged.- Parameters:
self
- a Map to be modifiedcondition
- a 1 or 2 arg Closure condition applying on the entries- Returns:
- true if this map changed as a result of the call
- Since:
- 2.5.0
-
removeAll
Modifies this collection by removing the elements that are matched according to the specified closure condition.def list = ['a', 'b'] list.removeAll { it == 'b' } assert list == ['a']
See alsofindAll
andgrep
when wanting to produce a new list containing items which match some criteria but leaving the original collection unchanged.- Parameters:
self
- a Collection to be modifiedcondition
- a closure condition- Returns:
- true if this collection changed as a result of the call
- Since:
- 1.7.2
- See Also:
Iterator.remove()
-
removeAll
Modifies this map by removing the elements that are matched according to the specified closure condition. If the closure takes one parameter then it will be passed theMap.Entry
. Otherwise the closure should take two parameters, which will be the key and the value.def map = [a:1, b:2] map.removeAll { k,v
See also->
k == 'b' } assert map == [a:1]findAll
when wanting to produce a new map containing items which match some criteria but leaving the original map unchanged.- Parameters:
self
- a Map to be modifiedcondition
- a 1 or 2 arg Closure condition applying on the entries- Returns:
- true if this map changed as a result of the call
- Since:
- 2.5.0
-
addAll
public static <T> boolean addAll(java.util.Collection<T> self, T[] items)Modifies the collection by adding all of the elements in the specified array to the collection. The behavior of this operation is undefined if the specified array is modified while the operation is in progress. See alsoplus
or the '+' operator if wanting to produce a new collection containing additional items but while leaving the original collection unchanged.- Parameters:
self
- a Collection to be modifieditems
- array containing elements to be added to this collection- Returns:
- true if this collection changed as a result of the call
- Since:
- 1.7.2
- See Also:
Collection.addAll(Collection)
-
addAll
public static <T> boolean addAll(java.util.List<T> self, int index, T[] items)Modifies this list by inserting all of the elements in the specified array into the list at the specified position. Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices). The new elements will appear in this list in the order that they occur in the array. The behavior of this operation is undefined if the specified array is modified while the operation is in progress. See alsoplus
for similar functionality with copy semantics, i.e. which produces a new list after adding the additional items at the specified position but leaves the original list unchanged.- Parameters:
self
- a list to be modifieditems
- array containing elements to be added to this collectionindex
- index at which to insert the first element from the specified array- Returns:
- true if this collection changed as a result of the call
- Since:
- 1.7.2
- See Also:
List.addAll(int, Collection)
-
split
Splits all items into two lists based on the closure condition. The first list contains all items matching the closure expression. The second list all those that don't.- Parameters:
self
- an Object with an Iterator returning its valuesclosure
- a closure condition- Returns:
- a List whose first item is the accepted values and whose second item is the rejected values
- Since:
- 1.6.0
-
split
public static <T> java.util.Collection<java.util.Collection<T>> split(java.util.Collection<T> self, Closure closure)Splits all items into two collections based on the closure condition. The first list contains all items which match the closure expression. The second list all those that don't.Example usage:
assert [[2,4],[1,3]] == [1,2,3,4].split { it % 2 == 0 }
- Parameters:
self
- a Collection of valuesclosure
- a closure condition- Returns:
- a List whose first item is the accepted values and whose second item is the rejected values
- Since:
- 1.6.0
-
split
Splits all items into two collections based on the closure condition. The first list contains all items which match the closure expression. The second list all those that don't.- Parameters:
self
- an Arrayclosure
- a closure condition- Returns:
- a List whose first item is the accepted values and whose second item is the rejected values
- Since:
- 2.5.0
-
split
Splits all items into two collections based on the closure condition. The first list contains all items which match the closure expression. The second list all those that don't.Example usage:
assert [[2,4],[1,3]] == [1,2,3,4].split { it % 2 == 0 }
- Parameters:
self
- a List of valuesclosure
- a closure condition- Returns:
- a List whose first item is the accepted values and whose second item is the rejected values
- Since:
- 2.4.0
-
split
Splits all items into two collections based on the closure condition. The first list contains all items which match the closure expression. The second list all those that don't.Example usage:
assert [[2,4] as Set, [1,3] as Set] == ([1,2,3,4] as Set).split { it % 2 == 0 }
- Parameters:
self
- a Set of valuesclosure
- a closure condition- Returns:
- a List whose first item is the accepted values and whose second item is the rejected values
- Since:
- 2.4.0
-
combinations
@Deprecated public static java.util.List combinations(java.util.Collection self)Deprecated.Use the Iterable version of combinations instead- Since:
- 1.5.0
- See Also:
combinations(Iterable)
-
combinations
public static java.util.List combinations(java.lang.Iterable self)Adds GroovyCollections#combinations(Iterable) as a method on Iterables.Example usage:
assert [['a', 'b'],[1, 2, 3]].combinations() == [['a', 1], ['b', 1], ['a', 2], ['b', 2], ['a', 3], ['b', 3]]
- Parameters:
self
- an Iterable of collections- Returns:
- a List of the combinations found
- Since:
- 2.2.0
- See Also:
GroovyCollections.combinations(java.lang.Iterable)
-
combinations
Adds GroovyCollections#combinations(Iterable, Closure) as a method on collections.Example usage:
assert [[2, 3],[4, 5, 6]].combinations {x,y
->
x*y } == [8, 12, 10, 15, 12, 18]- Parameters:
self
- a Collection of listsfunction
- a closure to be called on each combination- Returns:
- a List of the results of applying the closure to each combinations found
- Since:
- 2.2.0
- See Also:
GroovyCollections.combinations(Iterable)
-
eachCombination
Applies a function on each combination of the input lists.Example usage:
[[2, 3],[4, 5, 6]].eachCombination { println "Found $it" }
- Parameters:
self
- a Collection of listsfunction
- a closure to be called on each combination- Since:
- 2.2.0
- See Also:
GroovyCollections.combinations(Iterable)
-
subsequences
public static <T> java.util.Set<java.util.List<T>> subsequences(java.util.List<T> self)Finds all non-null subsequences of a list.Example usage:
def result = [1, 2, 3].subsequences() assert result == [[1, 2, 3], [1, 3], [2, 3], [1, 2], [1], [2], [3]] as Set
- Parameters:
self
- the List of items- Returns:
- the subsequences from the list
- Since:
- 1.7.0
-
permutations
public static <T> java.util.Set<java.util.List<T>> permutations(java.lang.Iterable<T> self)Finds all permutations of an iterable.Example usage:
def result = [1, 2, 3].permutations() assert result == [[3, 2, 1], [3, 1, 2], [1, 3, 2], [2, 3, 1], [2, 1, 3], [1, 2, 3]] as Set
- Parameters:
self
- the Iterable of items- Returns:
- the permutations from the list
- Since:
- 1.7.0
-
permutations
public static <T, V> java.util.List<V> permutations(java.lang.Iterable<T> self, Closure<V> function)Finds all permutations of an iterable, applies a function to each permutation and collects the result into a list.Example usage:
Set result = [1, 2, 3].permutations { it.collect { v
->
2*v }} assert result == [[6, 4, 2], [6, 2, 4], [2, 6, 4], [4, 6, 2], [4, 2, 6], [2, 4, 6]] as Set- Parameters:
self
- the Iterable of itemsfunction
- the function to apply on each permutation- Returns:
- the list of results of the application of the function on each permutation
- Since:
- 2.2.0
-
permutations
@Deprecated public static <T, V> java.util.List<V> permutations(java.util.List<T> self, Closure<V> function)Deprecated.Use the Iterable version of permutations instead- Since:
- 2.2.0
- See Also:
permutations(Iterable, Closure)
-
eachPermutation
@Deprecated public static <T> java.util.Iterator<java.util.List<T>> eachPermutation(java.util.Collection<T> self, Closure closure)Deprecated.Use the Iterable version of eachPermutation instead- Since:
- 1.7.0
- See Also:
eachPermutation(Iterable, Closure)
-
eachPermutation
public static <T> java.util.Iterator<java.util.List<T>> eachPermutation(java.lang.Iterable<T> self, Closure closure)Iterates over all permutations of a collection, running a closure for each iteration.Example usage:
def permutations = [] [1, 2, 3].eachPermutation{ permutations << it } assert permutations == [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
- Parameters:
self
- the Collection of itemsclosure
- the closure to call for each permutation- Returns:
- the permutations from the list
- Since:
- 1.7.0
-
transpose
public static java.util.List transpose(java.util.List self)Adds GroovyCollections#transpose(List) as a method on lists. A Transpose Function takes a collection of columns and returns a collection of rows. The first row consists of the first element from each column. Successive rows are constructed similarly.Example usage:
def result = [['a', 'b'], [1, 2]].transpose() assert result == [['a', 1], ['b', 2]]
def result = [['a', 'b'], [1, 2], [3, 4]].transpose() assert result == [['a', 1, 3], ['b', 2, 4]]
- Parameters:
self
- a List of lists- Returns:
- a List of the transposed lists
- Since:
- 1.5.0
- See Also:
GroovyCollections.transpose(java.util.List)
-
transpose
public static int[][] transpose(int[][] self)A transpose method for 2D int arrays.Example usage:
int[][] nums = [[10, 15, 20], [30, 35, 40]] int[][] expected = [[10, 30], [15, 35], [20, 40]] assert nums.transpose() == expected
- Parameters:
self
- a 2D int array- Returns:
- the transposed 2D int array
- Since:
- 3.0.8
-
transpose
public static long[][] transpose(long[][] self)A transpose method for 2D long arrays.- Parameters:
self
- a 2D long array- Returns:
- the transposed 2D long array
- Since:
- 3.0.8
-
transpose
public static double[][] transpose(double[][] self)A transpose method for 2D double arrays.- Parameters:
self
- a 2D double array- Returns:
- the transposed 2D double array
- Since:
- 3.0.8
-
findAll
Finds all entries matching the closure condition. If the closure takes one parameter then it will be passed the Map.Entry. Otherwise if the closure should take two parameters, which will be the key and the value.If the
self
map is one of TreeMap, LinkedHashMap, Hashtable or Properties, the returned Map will preserve that type, otherwise a HashMap will be returned.Example usage:
def result = [a:1, b:2, c:4, d:5].findAll { it.value % 2 == 0 } assert result.every { it instanceof Map.Entry } assert result*.key == ["b", "c"] assert result*.value == [2, 4]
- Parameters:
self
- a Mapclosure
- a 1 or 2 arg Closure condition applying on the entries- Returns:
- a new subMap
- Since:
- 1.0
-
groupBy
@Deprecated public static <K, T> java.util.Map<K,java.util.List<T>> groupBy(java.util.Collection<T> self, Closure<K> closure)Deprecated.Use the Iterable version of groupBy instead- Since:
- 1.0
- See Also:
groupBy(Iterable, Closure)
-
groupBy
public static <K, T> java.util.Map<K,java.util.List<T>> groupBy(java.lang.Iterable<T> self, Closure<K> closure)Sorts all Iterable members into groups determined by the supplied mapping closure. The closure should return the key that this item should be grouped by. The returned LinkedHashMap will have an entry for each distinct key returned from the closure, with each value being a list of items for that group.Example usage:
assert [0:[2,4,6], 1:[1,3,5]] == [1,2,3,4,5,6].groupBy { it % 2 }
- Parameters:
self
- a collection to groupclosure
- a closure mapping entries on keys- Returns:
- a new Map grouped by keys
- Since:
- 2.2.0
-
groupBy
Sorts all array members into groups determined by the supplied mapping closure. The closure should return the key that this item should be grouped by. The returned LinkedHashMap will have an entry for each distinct key returned from the closure, with each value being a list of items for that group.Example usage:
Integer[] items = [1,2,3,4,5,6] assert [0:[2,4,6], 1:[1,3,5]] == items.groupBy { it % 2 }
- Parameters:
self
- an array to groupclosure
- a closure mapping entries on keys- Returns:
- a new Map grouped by keys
- Since:
- 2.2.0
- See Also:
groupBy(Iterable, Closure)
-
groupBy
@Deprecated public static java.util.Map groupBy(java.util.Collection self, java.lang.Object... closures)Deprecated.Use the Iterable version of groupBy instead- Since:
- 1.8.1
- See Also:
groupBy(Iterable, Object...)
-
groupBy
public static java.util.Map groupBy(java.lang.Iterable self, java.lang.Object... closures)Sorts all Iterable members into (sub)groups determined by the supplied mapping closures. Each closure should return the key that this item should be grouped by. The returned LinkedHashMap will have an entry for each distinct 'key path' returned from the closures, with each value being a list of items for that 'group path'. Example usage:def result = [1,2,3,4,5,6].groupBy({ it % 2 }, { it
Another example:<
4 }) assert result == [1:[(true):[1, 3], (false):[5]], 0:[(true):[2], (false):[4, 6]]]def sql = groovy.sql.Sql.newInstance(/* ... */) def data = sql.rows("SELECT * FROM a_table").groupBy({ it.column1 }, { it.column2 }, { it.column3 }) if (data.val1.val2.val3) { // there exists a record where: // a_table.column1 == val1 // a_table.column2 == val2, and // a_table.column3 == val3 } else { // there is no such record }
If an empty array of closures is supplied the IDENTITY Closure will be used.- Parameters:
self
- a collection to groupclosures
- an array of closures, each mapping entries on keys- Returns:
- a new Map grouped by keys on each criterion
- Since:
- 2.2.0
- See Also:
Closure.IDENTITY
-
groupBy
public static java.util.Map groupBy(java.lang.Object[] self, java.lang.Object... closures)Sorts all array members into (sub)groups determined by the supplied mapping closures as per the Iterable variant of this method.- Parameters:
self
- an array to groupclosures
- an array of closures, each mapping entries on keys- Returns:
- a new Map grouped by keys on each criterion
- Since:
- 2.2.0
- See Also:
groupBy(Iterable, Object...)
,Closure.IDENTITY
-
groupBy
@Deprecated public static java.util.Map groupBy(java.util.Collection self, java.util.List<Closure> closures)Deprecated.Use the Iterable version of groupBy instead- Since:
- 1.8.1
- See Also:
groupBy(Iterable, List)
-
groupBy
Sorts all Iterable members into (sub)groups determined by the supplied mapping closures. Each closure should return the key that this item should be grouped by. The returned LinkedHashMap will have an entry for each distinct 'key path' returned from the closures, with each value being a list of items for that 'group path'. Example usage:def result = [1,2,3,4,5,6].groupBy([{ it % 2 }, { it
Another example:<
4 }]) assert result == [1:[(true):[1, 3], (false):[5]], 0:[(true):[2], (false):[4, 6]]]def sql = groovy.sql.Sql.newInstance(/* ... */) def data = sql.rows("SELECT * FROM a_table").groupBy([{ it.column1 }, { it.column2 }, { it.column3 }]) if (data.val1.val2.val3) { // there exists a record where: // a_table.column1 == val1 // a_table.column2 == val2, and // a_table.column3 == val3 } else { // there is no such record }
If an empty list of closures is supplied the IDENTITY Closure will be used.- Parameters:
self
- a collection to groupclosures
- a list of closures, each mapping entries on keys- Returns:
- a new Map grouped by keys on each criterion
- Since:
- 2.2.0
- See Also:
Closure.IDENTITY
-
groupBy
Sorts all array members into (sub)groups determined by the supplied mapping closures as per the list variant of this method.- Parameters:
self
- an array to groupclosures
- a list of closures, each mapping entries on keys- Returns:
- a new Map grouped by keys on each criterion
- Since:
- 2.2.0
- See Also:
Closure.IDENTITY
,groupBy(Iterable, List)
-
countBy
@Deprecated public static <K> java.util.Map<K,java.lang.Integer> countBy(java.util.Collection self, Closure<K> closure)Deprecated.Use the Iterable version of countBy instead- Since:
- 1.8.0
- See Also:
countBy(Iterable, Closure)
-
countBy
public static <K, E> java.util.Map<K,java.lang.Integer> countBy(java.lang.Iterable<E> self, Closure<K> closure)Sorts all collection members into groups determined by the supplied mapping closure and counts the group size. The closure should return the key that each item should be grouped by. The returned Map will have an entry for each distinct key returned from the closure, with each value being the frequency of items occurring for that group.Example usage:
assert [0:2, 1:3] == [1,2,3,4,5].countBy { it % 2 }
- Parameters:
self
- a collection to group and countclosure
- a closure mapping items to the frequency keys- Returns:
- a new Map grouped by keys with frequency counts
- Since:
- 2.2.0
-
countBy
Sorts all array members into groups determined by the supplied mapping closure and counts the group size. The closure should return the key that each item should be grouped by. The returned Map will have an entry for each distinct key returned from the closure, with each value being the frequency of items occurring for that group.Example usage:
assert ([1,2,2,2,3] as Object[]).countBy{ it % 2 } == [1:2, 0:3]
- Parameters:
self
- an array to group and countclosure
- a closure mapping items to the frequency keys- Returns:
- a new Map grouped by keys with frequency counts
- Since:
- 1.8.0
- See Also:
countBy(Iterator, Closure)
-
countBy
public static <K, E> java.util.Map<K,java.lang.Integer> countBy(java.util.Iterator<E> self, Closure<K> closure)Sorts all iterator items into groups determined by the supplied mapping closure and counts the group size. The closure should return the key that each item should be grouped by. The returned Map will have an entry for each distinct key returned from the closure, with each value being the frequency of items occurring for that group.Example usage:
assert [1,2,2,2,3].toSet().iterator().countBy{ it % 2 } == [1:2, 0:1]
- Parameters:
self
- an iterator to group and countclosure
- a closure mapping items to the frequency keys- Returns:
- a new Map grouped by keys with frequency counts
- Since:
- 1.8.0
-
groupEntriesBy
public static <G, K, V> java.util.Map<G,java.util.List<java.util.Map.Entry<K,V>>> groupEntriesBy(java.util.Map<K,V> self, Closure<G> closure)Groups all map entries into groups determined by the supplied mapping closure. The closure will be passed a Map.Entry or key and value (depending on the number of parameters the closure accepts) and should return the key that each item should be grouped under. The resulting map will have an entry for each 'group' key returned by the closure, with values being the list of map entries that belong to each group. (If instead of a list of map entries, you want an actual map use {code}groupBy{code}.)def result = [a:1,b:2,c:3,d:4,e:5,f:6].groupEntriesBy { it.value % 2 } assert result[0]*.key == ["b", "d", "f"] assert result[1]*.value == [1, 3, 5]
- Parameters:
self
- a map to groupclosure
- a 1 or 2 arg Closure mapping entries on keys- Returns:
- a new Map grouped by keys
- Since:
- 1.5.2
-
groupBy
public static <G, K, V> java.util.Map<G,java.util.Map<K,V>> groupBy(java.util.Map<K,V> self, Closure<G> closure)Groups the members of a map into sub maps determined by the supplied mapping closure. The closure will be passed a Map.Entry or key and value (depending on the number of parameters the closure accepts) and should return the key that each item should be grouped under. The resulting map will have an entry for each 'group' key returned by the closure, with values being the map members from the original map that belong to each group. (If instead of a map, you want a list of map entries use {code}groupEntriesBy{code}.)If the
self
map is one of TreeMap, Hashtable or Properties, the returned Map will preserve that type, otherwise a LinkedHashMap will be returned.def result = [a:1,b:2,c:3,d:4,e:5,f:6].groupBy { it.value % 2 } assert result == [0:[b:2, d:4, f:6], 1:[a:1, c:3, e:5]]
- Parameters:
self
- a map to groupclosure
- a closure mapping entries on keys- Returns:
- a new Map grouped by keys
- Since:
- 1.0
-
groupBy
public static java.util.Map<java.lang.Object,java.util.Map> groupBy(java.util.Map self, java.lang.Object... closures)Groups the members of a map into sub maps determined by the supplied mapping closures. Each closure will be passed a Map.Entry or key and value (depending on the number of parameters the closure accepts) and should return the key that each item should be grouped under. The resulting map will have an entry for each 'group path' returned by all closures, with values being the map members from the original map that belong to each such 'group path'. If theself
map is one of TreeMap, Hashtable, or Properties, the returned Map will preserve that type, otherwise a LinkedHashMap will be returned.def result = [a:1,b:2,c:3,d:4,e:5,f:6].groupBy({ it.value % 2 }, { it.key.next() }) assert result == [1:[b:[a:1], d:[c:3], f:[e:5]], 0:[c:[b:2], e:[d:4], g:[f:6]]]
If an empty array of closures is supplied the IDENTITY Closure will be used.- Parameters:
self
- a map to groupclosures
- an array of closures that map entries on keys- Returns:
- a new map grouped by keys on each criterion
- Since:
- 1.8.1
- See Also:
Closure.IDENTITY
-
groupBy
public static java.util.Map<java.lang.Object,java.util.Map> groupBy(java.util.Map self, java.util.List<Closure> closures)Groups the members of a map into sub maps determined by the supplied mapping closures. Each closure will be passed a Map.Entry or key and value (depending on the number of parameters the closure accepts) and should return the key that each item should be grouped under. The resulting map will have an entry for each 'group path' returned by all closures, with values being the map members from the original map that belong to each such 'group path'. If theself
map is one of TreeMap, Hashtable, or Properties, the returned Map will preserve that type, otherwise a LinkedHashMap will be returned.def result = [a:1,b:2,c:3,d:4,e:5,f:6].groupBy([{ it.value % 2 }, { it.key.next() }]) assert result == [1:[b:[a:1], d:[c:3], f:[e:5]], 0:[c:[b:2], e:[d:4], g:[f:6]]]
If an empty list of closures is supplied the IDENTITY Closure will be used.- Parameters:
self
- a map to groupclosures
- a list of closures that map entries on keys- Returns:
- a new map grouped by keys on each criterion
- Since:
- 1.8.1
- See Also:
Closure.IDENTITY
-
countBy
public static <K, U, V> java.util.Map<K,java.lang.Integer> countBy(java.util.Map<U,V> self, Closure<K> closure)Groups the members of a map into groups determined by the supplied mapping closure and counts the frequency of the created groups. The closure will be passed a Map.Entry or key and value (depending on the number of parameters the closure accepts) and should return the key that each item should be grouped under. The resulting map will have an entry for each 'group' key returned by the closure, with values being the frequency counts for that 'group'.def result = [a:1,b:2,c:3,d:4,e:5].countBy { it.value % 2 } assert result == [0:2, 1:3]
- Parameters:
self
- a map to group and countclosure
- a closure mapping entries to frequency count keys- Returns:
- a new Map grouped by keys with frequency counts
- Since:
- 1.8.0
-
groupAnswer
protected static <K, T> void groupAnswer(java.util.Map<K,java.util.List<T>> answer, T element, K value)Groups the current element according to the value- Parameters:
answer
- the map containing the resultselement
- the element to be placedvalue
- the value according to which the element will be placed- Since:
- 1.5.0
-
callClosureForMapEntry
protected static <T, K, V> T callClosureForMapEntry(Closure<T> closure, java.util.Map.Entry<K,V> entry) -
callClosureForLine
-
callClosureForMapEntryAndCounter
protected static <T, K, V> T callClosureForMapEntryAndCounter(Closure<T> closure, java.util.Map.Entry<K,V> entry, int counter) -
inject
Performs the same function as the version of inject that takes an initial value, but uses the head of the Collection as the initial value, and iterates over the tail.assert 1 * 2 * 3 * 4 == [ 1, 2, 3, 4 ].inject { acc, val
->
acc * val } assert ['b'] == [['a','b'], ['b','c'], ['d','b']].inject { acc, val->
acc.intersect( val ) } LinkedHashSet set = [ 't', 'i', 'm' ] assert 'tim' == set.inject { a, b->
a + b }- Parameters:
self
- a Collectionclosure
- a closure- Returns:
- the result of the last closure call
- Throws:
java.util.NoSuchElementException
- if the collection is empty.- Since:
- 1.8.7
- See Also:
inject(Collection, Object, Closure)
-
inject
public static <E, T, U extends T, V extends T> T inject(java.util.Collection<E> self, U initialValue, Closure<V> closure)Iterates through the given Collection, passing in the initial value to the 2-arg closure along with the first item. The result is passed back (injected) into the closure along with the second item. The new result is injected back into the closure along with the third item and so on until the entire collection has been used. Also known as foldLeft or reduce in functional parlance. Examples:assert 1*1*2*3*4 == [1,2,3,4].inject(1) { acc, val
Visual representation of the last example above:->
acc * val } assert 0+1+2+3+4 == [1,2,3,4].inject(0) { acc, val->
acc + val } assert 'The quick brown fox' == ['quick', 'brown', 'fox'].inject('The') { acc, val->
acc + ' ' + val } assert 'bat' == ['rat', 'bat', 'cat'].inject('zzz') { min, next->
next<
min ? next : min } def max = { a, b->
[a, b].max() } def animals = ['bat', 'rat', 'cat'] assert 'rat' == animals.inject('aaa', max)initVal animals[0] v v max('aaa', 'bat')
=>
'bat' animals[1] v v max('bat', 'rat')=>
'rat' animals[2] v v max('rat', 'cat')=>
'rat'- Parameters:
self
- a CollectioninitialValue
- some initial valueclosure
- a closure- Returns:
- the result of the last closure call
- Since:
- 1.0
-
inject
public static <K, V, T, U extends T, W extends T> T inject(java.util.Map<K,V> self, U initialValue, Closure<W> closure)Iterates through the given Map, passing in the initial value to the 2-arg Closure along with the first item (or 3-arg Closure along with the first key and value). The result is passed back (injected) into the closure along with the second item. The new result is injected back into the closure along with the third item and so on until the entire collection has been used. Also known as foldLeft or reduce in functional parlance. Examples:def map = [a:1, b:2, c:3] assert map.inject([]) { list, k, v
->
list + [k] * v } == ['a', 'b', 'b', 'c', 'c', 'c']- Parameters:
self
- a MapinitialValue
- some initial valueclosure
- a 2 or 3 arg Closure- Returns:
- the result of the last closure call
- Since:
- 1.8.1
-
inject
public static <E, T, U extends T, V extends T> T inject(java.util.Iterator<E> self, U initialValue, Closure<V> closure)Iterates through the given Iterator, passing in the initial value to the closure along with the first item. The result is passed back (injected) into the closure along with the second item. The new result is injected back into the closure along with the third item and so on until the Iterator has been expired of values. Also known as foldLeft in functional parlance.- Parameters:
self
- an IteratorinitialValue
- some initial valueclosure
- a closure- Returns:
- the result of the last closure call
- Since:
- 1.5.0
- See Also:
inject(Collection, Object, Closure)
-
inject
Iterates through the given Object, passing in the first value to the closure along with the first item. The result is passed back (injected) into the closure along with the second item. The new result is injected back into the closure along with the third item and so on until further iteration of the object is not possible. Also known as foldLeft in functional parlance.- Parameters:
self
- an Objectclosure
- a closure- Returns:
- the result of the last closure call
- Throws:
java.util.NoSuchElementException
- if the collection is empty.- Since:
- 1.8.7
- See Also:
inject(Collection, Object, Closure)
-
inject
public static <T, U extends T, V extends T> T inject(java.lang.Object self, U initialValue, Closure<V> closure)Iterates through the given Object, passing in the initial value to the closure along with the first item. The result is passed back (injected) into the closure along with the second item. The new result is injected back into the closure along with the third item and so on until further iteration of the object is not possible. Also known as foldLeft in functional parlance.- Parameters:
self
- an ObjectinitialValue
- some initial valueclosure
- a closure- Returns:
- the result of the last closure call
- Since:
- 1.5.0
- See Also:
inject(Collection, Object, Closure)
-
inject
Iterates through the given array as with inject(Object[],initialValue,closure), but using the first element of the array as the initialValue, and then iterating the remaining elements of the array.- Parameters:
self
- an Object[]closure
- a closure- Returns:
- the result of the last closure call
- Throws:
java.util.NoSuchElementException
- if the array is empty.- Since:
- 1.8.7
- See Also:
inject(Object[], Object, Closure)
-
inject
public static <E, T, U extends T, V extends T> T inject(E[] self, U initialValue, Closure<V> closure)Iterates through the given array, passing in the initial value to the closure along with the first item. The result is passed back (injected) into the closure along with the second item. The new result is injected back into the closure along with the third item and so on until all elements of the array have been used. Also known as foldLeft in functional parlance.- Parameters:
self
- an Object[]initialValue
- some initial valueclosure
- a closure- Returns:
- the result of the last closure call
- Since:
- 1.5.0
- See Also:
inject(Collection, Object, Closure)
-
sum
@Deprecated public static java.lang.Object sum(java.util.Collection self)Deprecated.Use the Iterable version of sum instead- Since:
- 1.0
- See Also:
sum(Iterable)
-
sum
public static java.lang.Object sum(java.lang.Iterable<?> self)Sums the items in an Iterable. This is equivalent to invoking the "plus" method on all items in the Iterable.assert 1+2+3+4 == [1,2,3,4].sum()
- Parameters:
self
- Iterable of values to add together- Returns:
- The sum of all of the items
- Since:
- 2.2.0
- See Also:
sum(Iterator)
-
sum
public static java.lang.Object sum(java.lang.Object[] self)Sums the items in an array. This is equivalent to invoking the "plus" method on all items in the array.- Parameters:
self
- The array of values to add together- Returns:
- The sum of all of the items
- Since:
- 1.7.1
- See Also:
sum(java.util.Iterator)
-
sum
public static java.lang.Object sum(java.util.Iterator<java.lang.Object> self)Sums the items from an Iterator. This is equivalent to invoking the "plus" method on all items from the Iterator. The iterator will become exhausted of elements after determining the sum value.- Parameters:
self
- an Iterator for the values to add together- Returns:
- The sum of all of the items
- Since:
- 1.5.5
-
sum
public static byte sum(byte[] self)Sums the items in an array.assert (1+2+3+4 as byte) == ([1,2,3,4] as byte[]).sum()
- Parameters:
self
- The array of values to add together- Returns:
- The sum of all of the items
- Since:
- 2.4.2
-
sum
public static short sum(short[] self)Sums the items in an array.assert (1+2+3+4 as short) == ([1,2,3,4] as short[]).sum()
- Parameters:
self
- The array of values to add together- Returns:
- The sum of all of the items
- Since:
- 2.4.2
-
sum
public static int sum(int[] self)Sums the items in an array.assert 1+2+3+4 == ([1,2,3,4] as int[]).sum()
- Parameters:
self
- The array of values to add together- Returns:
- The sum of all of the items
- Since:
- 2.4.2
-
sum
public static long sum(long[] self)Sums the items in an array.assert (1+2+3+4 as long) == ([1,2,3,4] as long[]).sum()
- Parameters:
self
- The array of values to add together- Returns:
- The sum of all of the items
- Since:
- 2.4.2
-
sum
public static char sum(char[] self)Sums the items in an array.assert (1+2+3+4 as char) == ([1,2,3,4] as char[]).sum()
- Parameters:
self
- The array of values to add together- Returns:
- The sum of all of the items
- Since:
- 2.4.2
-
sum
public static float sum(float[] self)Sums the items in an array.assert (1+2+3+4 as float) == ([1,2,3,4] as float[]).sum()
- Parameters:
self
- The array of values to add together- Returns:
- The sum of all of the items
- Since:
- 2.4.2
-
sum
public static double sum(double[] self)Sums the items in an array.assert (1+2+3+4 as double) == ([1,2,3,4] as double[]).sum()
- Parameters:
self
- The array of values to add together- Returns:
- The sum of all of the items
- Since:
- 2.4.2
-
sum
@Deprecated public static java.lang.Object sum(java.util.Collection self, java.lang.Object initialValue)Deprecated.Use the Iterable version of sum instead- Since:
- 1.5.0
- See Also:
sum(Iterable, Object)
-
sum
public static java.lang.Object sum(java.lang.Iterable<?> self, java.lang.Object initialValue)Sums the items in an Iterable, adding the result to some initial value.assert 5+1+2+3+4 == [1,2,3,4].sum(5)
- Parameters:
self
- an Iterable of values to suminitialValue
- the items in the collection will be summed to this initial value- Returns:
- The sum of all of the items.
- Since:
- 2.2.0
- See Also:
sum(Iterator, Object)
-
sum
public static java.lang.Object sum(java.lang.Object[] self, java.lang.Object initialValue)Sums the items in an array, adding the result to some initial value.- Parameters:
self
- an array of values to suminitialValue
- the items in the array will be summed to this initial value- Returns:
- The sum of all of the items.
- Since:
- 1.7.1
-
sum
public static java.lang.Object sum(java.util.Iterator<?> self, java.lang.Object initialValue)Sums the items from an Iterator, adding the result to some initial value. This is equivalent to invoking the "plus" method on all items from the Iterator. The iterator will become exhausted of elements after determining the sum value.- Parameters:
self
- an Iterator for the values to add togetherinitialValue
- the items in the collection will be summed to this initial value- Returns:
- The sum of all of the items
- Since:
- 1.5.5
-
sum
public static byte sum(byte[] self, byte initialValue)Sums the items in an array, adding the result to some initial value.assert (5+1+2+3+4 as byte) == ([1,2,3,4] as byte[]).sum(5 as byte)
- Parameters:
self
- an array of values to suminitialValue
- the items in the array will be summed to this initial value- Returns:
- The sum of all of the items.
- Since:
- 2.4.2
-
sum
public static short sum(short[] self, short initialValue)Sums the items in an array, adding the result to some initial value.assert (5+1+2+3+4 as short) == ([1,2,3,4] as short[]).sum(5 as short)
- Parameters:
self
- an array of values to suminitialValue
- the items in the array will be summed to this initial value- Returns:
- The sum of all of the items.
- Since:
- 2.4.2
-
sum
public static int sum(int[] self, int initialValue)Sums the items in an array, adding the result to some initial value.assert 5+1+2+3+4 == ([1,2,3,4] as int[]).sum(5)
- Parameters:
self
- an array of values to suminitialValue
- the items in the array will be summed to this initial value- Returns:
- The sum of all of the items.
- Since:
- 2.4.2
-
sum
public static long sum(long[] self, long initialValue)Sums the items in an array, adding the result to some initial value.assert (5+1+2+3+4 as long) == ([1,2,3,4] as long[]).sum(5)
- Parameters:
self
- an array of values to suminitialValue
- the items in the array will be summed to this initial value- Returns:
- The sum of all of the items.
- Since:
- 2.4.2
-
sum
public static char sum(char[] self, char initialValue)Sums the items in an array, adding the result to some initial value.assert (5+1+2+3+4 as char) == ([1,2,3,4] as char[]).sum(5 as char)
- Parameters:
self
- an array of values to suminitialValue
- the items in the array will be summed to this initial value- Returns:
- The sum of all of the items.
- Since:
- 2.4.2
-
sum
public static float sum(float[] self, float initialValue)Sums the items in an array, adding the result to some initial value.assert (5+1+2+3+4 as float) == ([1,2,3,4] as float[]).sum(5)
- Parameters:
self
- an array of values to suminitialValue
- the items in the array will be summed to this initial value- Returns:
- The sum of all of the items.
- Since:
- 2.4.2
-
sum
public static double sum(double[] self, double initialValue)Sums the items in an array, adding the result to some initial value.assert (5+1+2+3+4 as double) == ([1,2,3,4] as double[]).sum(5)
- Parameters:
self
- an array of values to suminitialValue
- the items in the array will be summed to this initial value- Returns:
- The sum of all of the items.
- Since:
- 2.4.2
-
sum
Deprecated.Use the Iterable version of sum instead- Since:
- 1.0
- See Also:
sum(Iterable, Closure)
-
sum
Sums the result of applying a closure to each item of an Iterable.coll.sum(closure)
is equivalent to:coll.collect(closure).sum()
.assert 4+6+10+12 == [2,3,5,6].sum { it * 2 }
- Parameters:
self
- an Iterableclosure
- a single parameter closure that returns a (typically) numeric value.- Returns:
- The sum of the values returned by applying the closure to each item of the Iterable.
- Since:
- 2.2.0
-
sum
Sums the result of applying a closure to each item of an array.array.sum(closure)
is equivalent to:array.collect(closure).sum()
.- Parameters:
self
- An arrayclosure
- a single parameter closure that returns a (typically) numeric value.- Returns:
- The sum of the values returned by applying the closure to each item of the array.
- Since:
- 1.7.1
-
sum
Sums the result of applying a closure to each item returned from an iterator.iter.sum(closure)
is equivalent to:iter.collect(closure).sum()
. The iterator will become exhausted of elements after determining the sum value.- Parameters:
self
- An Iteratorclosure
- a single parameter closure that returns a (typically) numeric value.- Returns:
- The sum of the values returned by applying the closure to each item from the Iterator.
- Since:
- 1.7.1
-
sum
@Deprecated public static java.lang.Object sum(java.util.Collection self, java.lang.Object initialValue, Closure closure)Deprecated.Use the Iterable version of sum instead- Since:
- 1.5.0
- See Also:
sum(Iterable, Object, Closure)
-
sum
public static <T> java.lang.Object sum(java.lang.Iterable<T> self, java.lang.Object initialValue, Closure closure)Sums the result of applying a closure to each item of an Iterable to some initial value.iter.sum(initVal, closure)
is equivalent to:iter.collect(closure).sum(initVal)
.assert 50+4+6+10+12 == [2,3,5,6].sum(50) { it * 2 }
- Parameters:
self
- an Iterableclosure
- a single parameter closure that returns a (typically) numeric value.initialValue
- the closure results will be summed to this initial value- Returns:
- The sum of the values returned by applying the closure to each item of the collection.
- Since:
- 1.5.0
-
sum
Sums the result of applying a closure to each item of an array to some initial value.array.sum(initVal, closure)
is equivalent to:array.collect(closure).sum(initVal)
.- Parameters:
self
- an arrayclosure
- a single parameter closure that returns a (typically) numeric value.initialValue
- the closure results will be summed to this initial value- Returns:
- The sum of the values returned by applying the closure to each item of the array.
- Since:
- 1.7.1
-
sum
public static <T> java.lang.Object sum(java.util.Iterator<T> self, java.lang.Object initialValue, Closure closure)Sums the result of applying a closure to each item of an Iterator to some initial value.iter.sum(initVal, closure)
is equivalent to:iter.collect(closure).sum(initVal)
. The iterator will become exhausted of elements after determining the sum value.- Parameters:
self
- an Iteratorclosure
- a single parameter closure that returns a (typically) numeric value.initialValue
- the closure results will be summed to this initial value- Returns:
- The sum of the values returned by applying the closure to each item from the Iterator.
- Since:
- 1.7.1
-
average
public static java.lang.Object average(java.lang.Iterable<?> self)Averages the items in an Iterable. This is equivalent to invoking the "plus" method on all items in the Iterable and then dividing by the total count using the "div" method for the resulting sum.assert 3 == [1, 2, 6].average()
- Parameters:
self
- Iterable of values to average- Returns:
- The average of all of the items
- Since:
- 3.0.0
- See Also:
average(Iterator)
-
average
public static java.lang.Object average(java.lang.Object[] self)Averages the items in an array. This is equivalent to invoking the "plus" method on all items in the array and then dividing by the total count using the "div" method for the resulting sum.assert 3 == ([1, 2, 6] as Integer[]).average()
- Parameters:
self
- The array of values to average- Returns:
- The average of all of the items
- Since:
- 3.0.0
- See Also:
sum(java.lang.Object[])
-
average
public static java.lang.Object average(java.util.Iterator<?> self)Averages the items from an Iterator. This is equivalent to invoking the "plus" method on all items in the array and then dividing by the total count using the "div" method for the resulting sum. The iterator will become exhausted of elements after determining the average value. While most frequently used with aggregates of numbers,average
will work with any class supportingplus
anddiv
, e.g.:class Stars { int numStars = 0 String toString() { '*' * numStars } Stars plus(Stars other) { new Stars(numStars: numStars + other.numStars) } Stars div(Number divisor) { int newSize = numStars.intdiv(divisor) new Stars(numStars: newSize) } } def stars = [new Stars(numStars: 1), new Stars(numStars: 3)] assert stars*.toString() == ['*', '***'] assert stars.average().toString() == '**'
- Parameters:
self
- an Iterator for the values to average- Returns:
- The average of all of the items
- Since:
- 3.0.0
-
average
public static java.math.BigDecimal average(byte[] self)Calculates the average of the bytes in the array.assert 5.0G == ([2,4,6,8] as byte[]).average()
- Parameters:
self
- The array of values to calculate the average of- Returns:
- The average of the items
- Since:
- 3.0.0
-
average
public static java.math.BigDecimal average(short[] self)Calculates the average of the shorts in the array.assert 5.0G == ([2,4,6,8] as short[]).average()
- Parameters:
self
- The array of values to calculate the average of- Returns:
- The average of the items
- Since:
- 3.0.0
-
average
public static java.math.BigDecimal average(int[] self)Calculates the average of the ints in the array.assert 5.0G == ([2,4,6,8] as int[]).average()
- Parameters:
self
- The array of values to calculate the average of- Returns:
- The average of the items
- Since:
- 3.0.0
-
average
public static java.math.BigDecimal average(long[] self)Calculates the average of the longs in the array.assert 5.0G == ([2,4,6,8] as long[]).average()
- Parameters:
self
- The array of values to calculate the average of- Returns:
- The average of the items
- Since:
- 3.0.0
-
average
public static double average(float[] self)Calculates the average of the floats in the array.assert 5.0d == ([2,4,6,8] as float[]).average()
- Parameters:
self
- The array of values to calculate the average of- Returns:
- The average of the items
- Since:
- 3.0.0
-
average
public static double average(double[] self)Calculates the average of the doubles in the array.assert 5.0d == ([2,4,6,8] as double[]).average()
- Parameters:
self
- The array of values to calculate the average of- Returns:
- The average of the items
- Since:
- 3.0.0
-
average
Averages the result of applying a closure to each item of an Iterable.iter.average(closure)
is equivalent to:iter.collect(closure).average()
.assert 20 == [1, 3].average { it * 10 } assert 3 == ['to', 'from'].average { it.size() }
- Parameters:
self
- an Iterableclosure
- a single parameter closure that returns a (typically) numeric value.- Returns:
- The average of the values returned by applying the closure to each item of the Iterable.
- Since:
- 3.0.0
-
average
Averages the result of applying a closure to each item of an array.array.average(closure)
is equivalent to:array.collect(closure).average()
.def (nums, strings) = [[1, 3] as Integer[], ['to', 'from'] as String[]] assert 20 == nums.average { it * 10 } assert 3 == strings.average { it.size() } assert 3 == strings.average (String::size)
- Parameters:
self
- An arrayclosure
- a single parameter closure that returns a (typically) numeric value.- Returns:
- The average of the values returned by applying the closure to each item of the array.
- Since:
- 3.0.0
-
average
Averages the result of applying a closure to each item returned from an iterator.iter.average(closure)
is equivalent to:iter.collect(closure).average()
. The iterator will become exhausted of elements after determining the average value.- Parameters:
self
- An Iteratorclosure
- a single parameter closure that returns a (typically) numeric value.- Returns:
- The average of the values returned by applying the closure to each item from the Iterator.
- Since:
- 3.0.0
-
join
@Deprecated public static java.lang.String join(java.util.Collection self, java.lang.String separator)Deprecated.Use the Iterable version of join instead- Since:
- 1.0
- See Also:
join(Iterable, String)
-
join
public static java.lang.String join(java.util.Iterator<?> self, java.lang.String separator)Concatenates thetoString()
representation of each item from the iterator, with the given String as a separator between each item. The iterator will become exhausted of elements after determining the resulting conjoined value.- Parameters:
self
- an Iterator of itemsseparator
- a String separator- Returns:
- the joined String
- Since:
- 1.5.5
-
join
public static java.lang.String join(java.lang.Iterable<?> self, java.lang.String separator)Concatenates thetoString()
representation of each item in this Iterable, with the given String as a separator between each item.assert "1, 2, 3" == [1,2,3].join(", ")
- Parameters:
self
- an Iterable of objectsseparator
- a String separator- Returns:
- the joined String
- Since:
- 1.0
-
join
public static <T> java.lang.String join(T[] self, java.lang.String separator)Concatenates thetoString()
representation of each items in this array, with the given String as a separator between each item.- Parameters:
self
- an array of Objectseparator
- a String separator- Returns:
- the joined String
- Since:
- 1.0
-
join
public static java.lang.String join(boolean[] self, java.lang.String separator)Concatenates the string representation of each items in this array, with the given String as a separator between each item.- Parameters:
self
- an array of booleanseparator
- a String separator- Returns:
- the joined String
- Since:
- 2.4.1
-
join
public static java.lang.String join(byte[] self, java.lang.String separator)Concatenates the string representation of each items in this array, with the given String as a separator between each item.- Parameters:
self
- an array of byteseparator
- a String separator- Returns:
- the joined String
- Since:
- 2.4.1
-
join
public static java.lang.String join(char[] self, java.lang.String separator)Concatenates the string representation of each items in this array, with the given String as a separator between each item.- Parameters:
self
- an array of charseparator
- a String separator- Returns:
- the joined String
- Since:
- 2.4.1
-
join
public static java.lang.String join(double[] self, java.lang.String separator)Concatenates the string representation of each items in this array, with the given String as a separator between each item.- Parameters:
self
- an array of doubleseparator
- a String separator- Returns:
- the joined String
- Since:
- 2.4.1
-
join
public static java.lang.String join(float[] self, java.lang.String separator)Concatenates the string representation of each items in this array, with the given String as a separator between each item.- Parameters:
self
- an array of floatseparator
- a String separator- Returns:
- the joined String
- Since:
- 2.4.1
-
join
public static java.lang.String join(int[] self, java.lang.String separator)Concatenates the string representation of each items in this array, with the given String as a separator between each item.- Parameters:
self
- an array of intseparator
- a String separator- Returns:
- the joined String
- Since:
- 2.4.1
-
join
public static java.lang.String join(long[] self, java.lang.String separator)Concatenates the string representation of each items in this array, with the given String as a separator between each item.- Parameters:
self
- an array of longseparator
- a String separator- Returns:
- the joined String
- Since:
- 2.4.1
-
join
public static java.lang.String join(short[] self, java.lang.String separator)Concatenates the string representation of each items in this array, with the given String as a separator between each item.- Parameters:
self
- an array of shortseparator
- a String separator- Returns:
- the joined String
- Since:
- 2.4.1
-
min
@Deprecated public static <T> T min(java.util.Collection<T> self)Deprecated.Use the Iterable version of min instead- Since:
- 1.0
- See Also:
min(Iterable)
-
min
public static <T> T min(java.lang.Iterable<T> self)Adds min() method to Collection objects.assert 2 == [4,2,5].min()
- Parameters:
self
- a Collection- Returns:
- the minimum value
- Since:
- 1.0
- See Also:
min(Iterator)
-
min
public static <T> T min(java.util.Iterator<T> self)Adds min() method to Iterator objects. The iterator will become exhausted of elements after determining the minimum value.- Parameters:
self
- an Iterator- Returns:
- the minimum value
- Since:
- 1.5.5
- See Also:
min(Iterable)
-
min
public static <T> T min(T[] self)Adds min() method to Object arrays.- Parameters:
self
- an array- Returns:
- the minimum value
- Since:
- 1.5.5
- See Also:
min(Iterator)
-
min
@Deprecated public static <T> T min(java.util.Collection<T> self, java.util.Comparator<T> comparator)Deprecated.Use the Iterable version of min instead- Since:
- 1.0
- See Also:
min(Iterable, Comparator)
-
min
public static int min(int[] self)Adds min() method to int arrays. Example usage:int[] nums = [10, 20, 30] assert 10 == nums.min()
- Parameters:
self
- an int array- Returns:
- the minimum value
- Since:
- 3.0.8
- See Also:
min(Object[])
-
min
public static long min(long[] self)Adds min() method to long arrays.- Parameters:
self
- a long array- Returns:
- the minimum value
- Since:
- 3.0.8
- See Also:
min(Object[])
-
min
public static double min(double[] self)Adds min() method to double arrays.- Parameters:
self
- a double array- Returns:
- the minimum value
- Since:
- 3.0.8
- See Also:
min(Object[])
-
min
public static <T> T min(java.lang.Iterable<T> self, java.util.Comparator<T> comparator)Selects the minimum value found in the Iterable using the given comparator.assert "hi" == ["hello","hi","hey"].min( { a, b
->
a.length()<=>
b.length() } as Comparator )- Parameters:
self
- an Iterablecomparator
- a Comparator- Returns:
- the minimum value or null for an empty Iterable
- Since:
- 2.2.0
- See Also:
min(Iterator, java.util.Comparator)
-
min
public static <T> T min(java.util.Iterator<T> self, java.util.Comparator<T> comparator)Selects the minimum value found from the Iterator using the given comparator.- Parameters:
self
- an Iteratorcomparator
- a Comparator- Returns:
- the minimum value
- Since:
- 1.5.5
-
min
public static <T> T min(T[] self, java.util.Comparator<T> comparator)Selects the minimum value found from the Object array using the given comparator.- Parameters:
self
- an arraycomparator
- a Comparator- Returns:
- the minimum value
- Since:
- 1.5.5
- See Also:
min(Iterator, java.util.Comparator)
-
min
Deprecated.Use the Iterable version of min instead- Since:
- 1.0
- See Also:
min(Iterable, Closure)
-
min
Selects the item in the iterable which when passed as a parameter to the supplied closure returns the minimum value. A null return value represents the least possible return value. If more than one item has the minimum value, an arbitrary choice is made between the items having the minimum value.If the closure has two parameters it is used like a traditional Comparator. I.e. it should compare its two parameters for order, returning a negative integer, zero, or a positive integer when the first parameter is less than, equal to, or greater than the second respectively. Otherwise, the Closure is assumed to take a single parameter and return a Comparable (typically an Integer) which is then used for further comparison.
assert "hi" == ["hello","hi","hey"].min { it.length() }
def lastDigit = { a, b
->
a % 10<=>
b % 10 } assert [19, 55, 91].min(lastDigit) == 91def pets = ['dog', 'cat', 'anaconda'] def shortestName = pets.min{ it.size() } // one of 'dog' or 'cat' assert shortestName.size() == 3
- Parameters:
self
- an Iterableclosure
- a 1 or 2 arg Closure used to determine the correct ordering- Returns:
- an item from the Iterable having the minimum value returned by calling the supplied closure with that item as parameter or null for an empty Iterable
- Since:
- 1.0
- See Also:
min(Iterator)
-
min
Selects an entry in the map having the minimum calculated value as determined by the supplied closure. If more than one entry has the minimum value, an arbitrary choice is made between the entries having the minimum value.If the closure has two parameters it is used like a traditional Comparator. I.e. it should compare its two parameters for order, returning a negative integer, zero, or a positive integer when the first parameter is less than, equal to, or greater than the second respectively. Otherwise, the Closure is assumed to take a single parameter and return a Comparable (typically an Integer) which is then used for further comparison.
def zoo = [monkeys:6, lions:5, tigers:7] def leastCommonEntry = zoo.min{ it.value } assert leastCommonEntry.value == 5 def mostCommonEntry = zoo.min{ a, b
Edge case for multiple min values:->
b.value<=>
a.value } // double negative! assert mostCommonEntry.value == 7def zoo = [monkeys:6, lions:5, tigers:7] def lastCharOfName = { e
->
e.key[-1] } def ans = zoo.min(lastCharOfName) // some random entry assert lastCharOfName(ans) == 's'- Parameters:
self
- a Mapclosure
- a 1 or 2 arg Closure used to determine the correct ordering- Returns:
- the Map.Entry having the minimum value as determined by the closure
- Since:
- 1.7.6
-
max
Selects an entry in the map having the maximum calculated value as determined by the supplied closure. If more than one entry has the maximum value, an arbitrary choice is made between the entries having the maximum value.If the closure has two parameters it is used like a traditional Comparator. I.e. it should compare its two parameters for order, returning a negative integer, zero, or a positive integer when the first parameter is less than, equal to, or greater than the second respectively. Otherwise, the Closure is assumed to take a single parameter and return a Comparable (typically an Integer) which is then used for further comparison. An example:
def zoo = [monkeys:6, lions:5, tigers:7] def mostCommonEntry = zoo.max{ it.value } assert mostCommonEntry.value == 7 def leastCommonEntry = zoo.max{ a, b
Edge case for multiple max values:->
b.value<=>
a.value } // double negative! assert leastCommonEntry.value == 5def zoo = [monkeys:6, lions:5, tigers:7] def lengthOfNamePlusNumber = { e
->
e.key.size() + e.value } def ans = zoo.max(lengthOfNamePlusNumber) // one of [monkeys:6, tigers:7] assert lengthOfNamePlusNumber(ans) == 13- Parameters:
self
- a Mapclosure
- a 1 or 2 arg Closure used to determine the correct ordering- Returns:
- the Map.Entry having the maximum value as determined by the closure
- Since:
- 1.7.6
-
min
Selects the minimum value found from the Iterator using the closure to determine the correct ordering. The iterator will become exhausted of elements after this operation.If the closure has two parameters it is used like a traditional Comparator. I.e. it should compare its two parameters for order, returning a negative integer, zero, or a positive integer when the first parameter is less than, equal to, or greater than the second respectively. Otherwise, the Closure is assumed to take a single parameter and return a Comparable (typically an Integer) which is then used for further comparison.
- Parameters:
self
- an Iteratorclosure
- a Closure used to determine the correct ordering- Returns:
- the minimum value
- Since:
- 1.5.5
-
min
Selects the minimum value found from the Object array using the closure to determine the correct ordering.If the closure has two parameters it is used like a traditional Comparator. I.e. it should compare its two parameters for order, returning a negative integer, zero, or a positive integer when the first parameter is less than, equal to, or greater than the second respectively. Otherwise, the Closure is assumed to take a single parameter and return a Comparable (typically an Integer) which is then used for further comparison.
- Parameters:
self
- an arrayclosure
- a Closure used to determine the correct ordering- Returns:
- the minimum value
- Since:
- 1.5.5
- See Also:
min(Iterator, groovy.lang.Closure)
-
max
@Deprecated public static <T> T max(java.util.Collection<T> self)Deprecated.Use the Iterable version of max instead- Since:
- 1.0
- See Also:
max(Iterable)
-
max
public static <T> T max(java.lang.Iterable<T> self)Adds max() method to Iterable objects.assert 5 == [2,3,1,5,4].max()
- Parameters:
self
- an Iterable- Returns:
- the maximum value
- Since:
- 2.2.0
- See Also:
max(Iterator)
-
max
public static <T> T max(java.util.Iterator<T> self)Adds max() method to Iterator objects. The iterator will become exhausted of elements after determining the maximum value.- Parameters:
self
- an Iterator- Returns:
- the maximum value
- Since:
- 1.5.5
-
max
public static <T> T max(T[] self)Adds max() method to Object arrays.- Parameters:
self
- an array- Returns:
- the maximum value
- Since:
- 1.5.5
- See Also:
max(Iterator)
-
max
Deprecated.Use the Iterable version of max instead- Since:
- 1.0
- See Also:
max(Iterable, Closure)
-
max
public static int max(int[] self)Adds max() method to int arrays.- Parameters:
self
- an int array- Returns:
- the maximum value
- Since:
- 3.0.8
- See Also:
max(Object[])
-
max
public static long max(long[] self)Adds max() method to long arrays.- Parameters:
self
- a long array- Returns:
- the maximum value
- Since:
- 3.0.8
- See Also:
max(Object[])
-
max
public static double max(double[] self)Adds max() method to double arrays. Example usage:double[] nums = [1.1d, 2.2d, 3.3d] assert 3.3d == nums.max()
- Parameters:
self
- a double array- Returns:
- the maximum value
- Since:
- 3.0.8
- See Also:
max(Object[])
-
max
Selects the item in the iterable which when passed as a parameter to the supplied closure returns the maximum value. A null return value represents the least possible return value, so any item for which the supplied closure returns null, won't be selected (unless all items return null). If more than one item has the maximum value, an arbitrary choice is made between the items having the maximum value.If the closure has two parameters it is used like a traditional Comparator. I.e. it should compare its two parameters for order, returning a negative integer, zero, or a positive integer when the first parameter is less than, equal to, or greater than the second respectively. Otherwise, the Closure is assumed to take a single parameter and return a Comparable (typically an Integer) which is then used for further comparison.
assert "hello" == ["hello","hi","hey"].max { it.length() }
assert "hello" == ["hello","hi","hey"].max { a, b
->
a.length()<=>
b.length() }def pets = ['dog', 'elephant', 'anaconda'] def longestName = pets.max{ it.size() } // one of 'elephant' or 'anaconda' assert longestName.size() == 8
- Parameters:
self
- an Iterableclosure
- a 1 or 2 arg Closure used to determine the correct ordering- Returns:
- an item from the Iterable having the maximum value returned by calling the supplied closure with that item as parameter or null for an empty Iterable
- Since:
- 2.2.0
-
max
Selects the maximum value found from the Iterator using the closure to determine the correct ordering. The iterator will become exhausted of elements after this operation.If the closure has two parameters it is used like a traditional Comparator. I.e. it should compare its two parameters for order, returning a negative integer, zero, or a positive integer when the first parameter is less than, equal to, or greater than the second respectively. Otherwise, the Closure is assumed to take a single parameter and return a Comparable (typically an Integer) which is then used for further comparison.
- Parameters:
self
- an Iteratorclosure
- a Closure used to determine the correct ordering- Returns:
- the maximum value
- Since:
- 1.5.5
-
max
Selects the maximum value found from the Object array using the closure to determine the correct ordering.If the closure has two parameters it is used like a traditional Comparator. I.e. it should compare its two parameters for order, returning a negative integer, zero, or a positive integer when the first parameter is less than, equal to, or greater than the second respectively. Otherwise, the Closure is assumed to take a single parameter and return a Comparable (typically an Integer) which is then used for further comparison.
- Parameters:
self
- an arrayclosure
- a Closure used to determine the correct ordering- Returns:
- the maximum value
- Since:
- 1.5.5
- See Also:
max(Iterator, groovy.lang.Closure)
-
max
@Deprecated public static <T> T max(java.util.Collection<T> self, java.util.Comparator<T> comparator)Deprecated.Use the Iterable version of max instead- Since:
- 1.0
- See Also:
max(Iterable, Comparator)
-
max
public static <T> T max(java.lang.Iterable<T> self, java.util.Comparator<T> comparator)Selects the maximum value found in the Iterable using the given comparator.assert "hello" == ["hello","hi","hey"].max( { a, b
->
a.length()<=>
b.length() } as Comparator )- Parameters:
self
- an Iterablecomparator
- a Comparator- Returns:
- the maximum value or null for an empty Iterable
- Since:
- 2.2.0
- See Also:
max(Iterator, Comparator)
-
max
public static <T> T max(java.util.Iterator<T> self, java.util.Comparator<T> comparator)Selects the maximum value found from the Iterator using the given comparator.- Parameters:
self
- an Iteratorcomparator
- a Comparator- Returns:
- the maximum value
- Since:
- 1.5.5
-
max
public static <T> T max(T[] self, java.util.Comparator<T> comparator)Selects the maximum value found from the Object array using the given comparator.- Parameters:
self
- an arraycomparator
- a Comparator- Returns:
- the maximum value
- Since:
- 1.5.5
- See Also:
max(Iterator, Comparator)
-
getIndices
Returns indices of the collection.Example:
assert 0..2 == [5, 6, 7].indices
- Parameters:
self
- a collection- Returns:
- an index range
- Since:
- 2.4.0
-
getIndices
Returns indices of the array.Example:
String[] letters = ['a', 'b', 'c', 'd']
assert 0..<4 == letters.indices
- Parameters:
self
- an array- Returns:
- an index range
- Since:
- 2.4.0
-
getIndices
Returns indices of the boolean array.- Since:
- 3.0.8
- See Also:
getIndices(Object[])
-
getIndices
Returns indices of the byte array.- Since:
- 3.0.8
- See Also:
getIndices(Object[])
-
getIndices
Returns indices of the char array.- Since:
- 3.0.8
- See Also:
getIndices(Object[])
-
getIndices
Returns indices of the double array.- Since:
- 3.0.8
- See Also:
getIndices(Object[])
-
getIndices
Returns indices of the float array.- Since:
- 3.0.8
- See Also:
getIndices(Object[])
-
getIndices
Returns indices of the int array.- Since:
- 3.0.8
- See Also:
getIndices(Object[])
-
getIndices
Returns indices of the long array.- Since:
- 3.0.8
- See Also:
getIndices(Object[])
-
getIndices
Returns indices of the short array.- Since:
- 3.0.8
- See Also:
getIndices(Object[])
-
size
public static int size(java.util.Iterator self)Provide the standard Groovysize()
method forIterator
. The iterator will become exhausted of elements after determining the size value.- Parameters:
self
- an Iterator- Returns:
- the length of the Iterator
- Since:
- 1.5.5
-
size
public static int size(java.lang.Iterable self)Provide the standard Groovysize()
method forIterable
.def items = [1, 2, 3] def iterable = { [ hasNext:{ !items.isEmpty() }, next:{ items.pop() } ] as Iterator } as Iterable assert iterable.size() == 3
- Parameters:
self
- an Iterable- Returns:
- the length of the Iterable
- Since:
- 2.3.8
-
size
public static int size(java.lang.Object[] self)Provide the standard Groovysize()
method for an array.- Parameters:
self
- an Array of objects- Returns:
- the size (length) of the Array
- Since:
- 1.0
-
isEmpty
public static boolean isEmpty(java.lang.Iterable self)Check whether anIterable
has elementsdef items = [1] def iterable = { [ hasNext:{ !items.isEmpty() }, next:{ items.pop() } ] as Iterator } as Iterable assert !iterable.isEmpty() iterable.iterator().next() assert iterable.isEmpty()
- Parameters:
self
- an Iterable- Returns:
- true if the iterable has no elements, false otherwise
- Since:
- 2.5.0
-
getAt
Support the range subscript operator for a List.def list = [1, "a", 4.5, true] assert list[1..2] == ["a", 4.5]
- Parameters:
self
- a Listrange
- a Range indicating the items to get- Returns:
- a new list instance based on range borders
- Since:
- 1.0
-
getAt
Select a List of items from an eager or lazy List using a Collection to identify the indices to be selected.def list = [].withDefault { 42 } assert list[1,0,2] == [42, 42, 42]
- Parameters:
self
- a ListWithDefaultindices
- a Collection of indices- Returns:
- a new eager or lazy list of the values at the given indices
-
getAt
Support the range subscript operator for an eager or lazy List.def list = [].withDefault { 42 } assert list[1..2] == [null, 42]
- Parameters:
self
- a ListWithDefaultrange
- a Range indicating the items to get- Returns:
- a new eager or lazy list instance based on range borders
-
getAt
Support the range subscript operator for an eager or lazy List.def list = [true, 1, 3.4].withDefault{ 42 }
assert list[0..<0] == []
- Parameters:
self
- a ListWithDefaultrange
- a Range indicating the items to get- Returns:
- a new list instance based on range borders
-
getAt
Support the range subscript operator for a List.def list = [true, 1, 3.4]
assert list[0..<0] == []
- Parameters:
self
- a Listrange
- a Range indicating the items to get- Returns:
- a new list instance based on range borders
- Since:
- 1.0
-
getAt
public static <T> java.util.List<T> getAt(java.util.List<T> self, java.util.Collection indices)Select a List of items from a List using a Collection to identify the indices to be selected.def list = [true, 1, 3.4, false] assert list[1,0,2] == [1, true, 3.4]
- Parameters:
self
- a Listindices
- a Collection of indices- Returns:
- a new list of the values at the given indices
- Since:
- 1.0
-
getAt
public static <T> java.util.List<T> getAt(T[] self, java.util.Collection indices)Select a List of items from an array using a Collection to identify the indices to be selected.- Parameters:
self
- an arrayindices
- a Collection of indices- Returns:
- a new list of the values at the given indices
- Since:
- 1.0
-
subMap
public static <K, V> java.util.Map<K,V> subMap(java.util.Map<K,V> map, java.util.Collection<K> keys)Creates a sub-Map containing the given keys. This method is similar to List.subList() but uses keys rather than index ranges.assert [1:10, 2:20, 4:40].subMap( [2, 4] ) == [2:20, 4:40]
- Parameters:
map
- a Mapkeys
- a Collection of keys- Returns:
- a new Map containing the given keys
- Since:
- 1.0
-
subMap
public static <K, V> java.util.Map<K,V> subMap(java.util.Map<K,V> map, K[] keys)Creates a sub-Map containing the given keys. This method is similar to List.subList() but uses keys rather than index ranges. The original map is unaltered.def orig = [1:10, 2:20, 3:30, 4:40] assert orig.subMap([1, 3] as int[]) == [1:10, 3:30] assert orig.subMap([2, 4] as Integer[]) == [2:20, 4:40] assert orig.size() == 4
- Parameters:
map
- a Mapkeys
- an array of keys- Returns:
- a new Map containing the given keys
- Since:
- 2.1.0
-
get
public static <K, V> V get(java.util.Map<K,V> map, K key, V defaultValue)Looks up an item in a Map for the given key and returns the value - unless there is no entry for the given key in which case add the default value to the map and return that.def map=[:] map.get("a", []) << 5 assert map == [a:[5]]
- Parameters:
map
- a Mapkey
- the key to lookup the value ofdefaultValue
- the value to return and add to the map for this key if there is no entry for the given key- Returns:
- the value of the given key or the default value, added to the map if the key did not exist
- Since:
- 1.0
-
getAt
Support the range subscript operator for an Array- Parameters:
array
- an Array of Objectsrange
- a Range- Returns:
- a range of a list from the range's from index up to but not including the range's to value
- Since:
- 1.0
-
getAt
- Parameters:
array
- an Array of Objectsrange
- an IntRange- Returns:
- a range of a list from the range's from index up to but not including the range's to value
- Since:
- 1.0
-
getAt
- Parameters:
array
- an Array of Objectsrange
- an EmptyRange- Returns:
- an empty Range
- Since:
- 1.5.0
-
getAt
- Parameters:
array
- an Array of Objectsrange
- an ObjectRange- Returns:
- a range of a list from the range's from index up to but not including the range's to value
- Since:
- 1.0
-
toList
public static <T> java.util.List<T> toList(T[] array)Allows conversion of arrays into a mutable List.- Parameters:
array
- an Array of Objects- Returns:
- the array as a List
- Since:
- 1.0
-
getAt
public static <T> T getAt(java.util.List<T> self, int idx)Support the subscript operator for a List.def list = [2, "a", 5.3] assert list[1] == "a"
- Parameters:
self
- a Listidx
- an index- Returns:
- the value at the given index
- Since:
- 1.0
-
getAt
public static <T> T getAt(java.util.List<T> self, java.lang.Number idx)Support subscript operator for list access. -
getAt
public static <T> T getAt(java.util.Iterator<T> self, int idx)Support the subscript operator for an Iterator. The iterator will be partially exhausted up until the idx entry after returning if a +ve or 0 idx is used, or fully exhausted if a -ve idx is used or no corresponding entry was found. Typical usage:def iter = [2, "a", 5.3].iterator() assert iter[1] == "a"
A more elaborate example:def items = [2, "a", 5.3] def iter = items.iterator() assert iter[-1] == 5.3 // iter exhausted, so reset iter = items.iterator() assert iter[1] == "a" // iter partially exhausted so now idx starts after "a" assert iter[0] == 5.3
- Parameters:
self
- an Iteratoridx
- an index value (-self.size() <= idx < self.size())- Returns:
- the value at the given index (after normalisation) or null if no corresponding value was found
- Since:
- 1.7.2
-
getAt
public static <T> T getAt(java.lang.Iterable<T> self, int idx)Support the subscript operator for an Iterable. Typical usage:// custom Iterable example: class MyIterable implements Iterable { Iterator iterator() { [1, 2, 3].iterator() } } def myIterable = new MyIterable() assert myIterable[1] == 2 // Set example: def set = [1,2,3] as LinkedHashSet assert set[1] == 2
- Parameters:
self
- an Iterableidx
- an index value (-self.size() <= idx < self.size()) but using -ve index values will be inefficient- Returns:
- the value at the given index (after normalisation) or null if no corresponding value was found
- Since:
- 2.1.0
-
putAt
public static <T> void putAt(java.util.List<T> self, int idx, T value)A helper method to allow lists to work with subscript operators.def list = [2, 3] list[0] = 1 assert list == [1, 3]
- Parameters:
self
- a Listidx
- an indexvalue
- the value to put at the given index- Since:
- 1.0
-
putAt
public static <T> void putAt(java.util.List<T> self, java.lang.Number idx, T value)Support subscript operator for list modification. -
putAt
A helper method to allow lists to work with subscript operators.def list = ["a", true]
list[1..<1] = 5
assert list == ["a", 5, true]- Parameters:
self
- a Listrange
- the (in this case empty) subset of the list to setvalue
- the values to put at the given sublist or a Collection of values- Since:
- 1.0
-
putAt
A helper method to allow lists to work with subscript operators.def list = ["a", true]
list[1..<1] = [4, 3, 2]
assert list == ["a", 4, 3, 2, true]- Parameters:
self
- a Listrange
- the (in this case empty) subset of the list to setvalue
- the Collection of values- Since:
- 1.0
- See Also:
putAt(java.util.List, groovy.lang.EmptyRange, java.lang.Object)
-
putAt
List subscript assignment operator when given a range as the index and the assignment operand is a collection. Example:def myList = [4, 3, 5, 1, 2, 8, 10] myList[3..5] = ["a", true] assert myList == [4, 3, 5, "a", true, 10]
Items in the given range are replaced with items from the collection.- Parameters:
self
- a Listrange
- the subset of the list to setcol
- the collection of values to put at the given sublist- Since:
- 1.5.0
-
putAt
List subscript assignment operator when given a range as the index. Example:def myList = [4, 3, 5, 1, 2, 8, 10] myList[3..5] = "b" assert myList == [4, 3, 5, "b", 10]
Items in the given range are replaced with the operand. Thevalue
operand is always treated as a single value.- Parameters:
self
- a Listrange
- the subset of the list to setvalue
- the value to put at the given sublist- Since:
- 1.0
-
putAt
public static void putAt(java.util.List self, java.util.List splice, java.util.List values)A helper method to allow lists to work with subscript operators.def list = ["a", true, 42, 9.4] list[1, 4] = ["x", false] assert list == ["a", "x", 42, 9.4, false]
- Parameters:
self
- a Listsplice
- the subset of the list to setvalues
- the value to put at the given sublist- Since:
- 1.0
-
putAt
public static void putAt(java.util.List self, java.util.List splice, java.lang.Object value)A helper method to allow lists to work with subscript operators.def list = ["a", true, 42, 9.4] list[1, 3] = 5 assert list == ["a", 5, 42, 5]
- Parameters:
self
- a Listsplice
- the subset of the list to setvalue
- the value to put at the given sublist- Since:
- 1.0
-
getSubList
@Deprecated protected static java.util.List getSubList(java.util.List self, java.util.List splice)Deprecated. -
getAt
public static <K, V> V getAt(java.util.Map<K,V> self, java.lang.Object key)Support the subscript operator for a Map.def map = [a:10] assert map["a"] == 10
- Parameters:
self
- a Mapkey
- an Object as a key for the map- Returns:
- the value corresponding to the given key
- Since:
- 1.0
-
plus
public static <K, V> java.util.Map<K,V> plus(java.util.Map<K,V> left, java.util.Map<K,V> right)Returns a newMap
containing all entries fromleft
andright
, giving precedence toright
. Any keys appearing in both Maps will appear in the resultant map with values from theright
operand. If theleft
map is one of TreeMap, LinkedHashMap, Hashtable or Properties, the returned Map will preserve that type, otherwise a HashMap will be returned.Roughly equivalent to
Map m = new HashMap(); m.putAll(left); m.putAll(right); return m;
but with some additional logic to preserve theleft
Map type for common cases as described above.assert [a:10, b:20] + [a:5, c:7] == [a:5, b:20, c:7]
- Parameters:
left
- a Mapright
- a Map- Returns:
- a new Map containing all entries from left and right
- Since:
- 1.5.0
-
putAt
public static <K, V> V putAt(java.util.Map<K,V> self, K key, V value)A helper method to allow maps to work with subscript operators- Parameters:
self
- a Mapkey
- an Object as a key for the mapvalue
- the value to put into the map- Returns:
- the value corresponding to the given key
- Since:
- 1.0
-
getAt
public static java.util.List getAt(java.util.Collection coll, java.lang.String property)Support the subscript operator for Collection.assert [String, Long, Integer] == ["a",5L,2]["class"]
- Parameters:
coll
- a Collectionproperty
- a String- Returns:
- a List
- Since:
- 1.0
-
asImmutable
public static <K, V> java.util.Map<K,V> asImmutable(java.util.Map<K,V> self)A convenience method for creating an immutable Map.- Parameters:
self
- a Map- Returns:
- an unmodifiable view of a copy of the original, i.e. an effectively immutable copy
- Since:
- 1.0
- See Also:
asImmutable(java.util.List)
,asUnmodifiable(java.util.Map)
-
asImmutable
public static <K, V> java.util.SortedMap<K,V> asImmutable(java.util.SortedMap<K,V> self)A convenience method for creating an immutable SortedMap.- Parameters:
self
- a SortedMap- Returns:
- an unmodifiable view of a copy of the original, i.e. an effectively immutable copy
- Since:
- 1.0
- See Also:
asImmutable(java.util.List)
,asUnmodifiable(java.util.SortedMap)
-
asImmutable
public static <T> java.util.List<T> asImmutable(java.util.List<T> self)A convenience method for creating an immutable List.def mutable = [1,2,3] def immutable = mutable.asImmutable() try { immutable << 4 assert false } catch (UnsupportedOperationException) { assert true } mutable << 4 assert mutable.size() == 4 assert immutable.size() == 3
- Parameters:
self
- a List- Returns:
- an unmodifiable view of a copy of the original, i.e. an effectively immutable copy
- Since:
- 1.0
- See Also:
asUnmodifiable(java.util.List)
-
asImmutable
public static <T> java.util.Set<T> asImmutable(java.util.Set<T> self)A convenience method for creating an immutable Set.- Parameters:
self
- a Set- Returns:
- an unmodifiable view of a copy of the original, i.e. an effectively immutable copy
- Since:
- 1.0
- See Also:
asImmutable(java.util.List)
,asUnmodifiable(java.util.Set)
-
asImmutable
public static <T> java.util.SortedSet<T> asImmutable(java.util.SortedSet<T> self)A convenience method for creating an immutable SortedSet.- Parameters:
self
- a SortedSet- Returns:
- an unmodifiable view of a copy of the original, i.e. an effectively immutable copy
- Since:
- 1.0
- See Also:
asImmutable(java.util.List)
,asUnmodifiable(java.util.SortedSet)
-
asImmutable
public static <T> java.util.Collection<T> asImmutable(java.util.Collection<T> self)A convenience method for creating an immutable Collection.- Parameters:
self
- a Collection- Returns:
- an unmodifiable view of a copy of the original, i.e. an effectively immutable copy
- Since:
- 1.5.0
- See Also:
asImmutable(java.util.List)
,asUnmodifiable(java.util.Collection)
-
asUnmodifiable
public static <K, V> java.util.Map<K,V> asUnmodifiable(java.util.Map<K,V> self)Creates an unmodifiable view of a Map.- Parameters:
self
- a Map- Returns:
- an unmodifiable view of the Map
- Since:
- 2.5.0
- See Also:
Collections.unmodifiableMap(java.util.Map)
,asUnmodifiable(java.util.List)
-
asUnmodifiable
public static <K, V> java.util.SortedMap<K,V> asUnmodifiable(java.util.SortedMap<K,V> self)Creates an unmodifiable view of a SortedMap.- Parameters:
self
- a SortedMap- Returns:
- an unmodifiable view of the SortedMap
- Since:
- 2.5.0
- See Also:
Collections.unmodifiableSortedMap(java.util.SortedMap)
,asUnmodifiable(java.util.List)
-
asUnmodifiable
public static <T> java.util.List<T> asUnmodifiable(java.util.List<T> self)Creates an unmodifiable view of a List.def mutable = [1,2,3] def unmodifiable = mutable.asUnmodifiable() try { unmodifiable << 4 assert false } catch (UnsupportedOperationException) { assert true } mutable << 4 assert unmodifiable.size() == 4
- Parameters:
self
- a List- Returns:
- an unmodifiable view of the List
- Since:
- 2.5.0
- See Also:
Collections.unmodifiableList(java.util.List)
-
asUnmodifiable
public static <T> java.util.Set<T> asUnmodifiable(java.util.Set<T> self)Creates an unmodifiable view of a Set.- Parameters:
self
- a Set- Returns:
- an unmodifiable view of the Set
- Since:
- 2.5.0
- See Also:
Collections.unmodifiableSet(java.util.Set)
,asUnmodifiable(java.util.List)
-
asUnmodifiable
public static <T> java.util.SortedSet<T> asUnmodifiable(java.util.SortedSet<T> self)Creates an unmodifiable view of a SortedSet.- Parameters:
self
- a SortedSet- Returns:
- an unmodifiable view of the SortedSet
- Since:
- 2.5.0
- See Also:
Collections.unmodifiableSortedSet(java.util.SortedSet)
,asUnmodifiable(java.util.List)
-
asUnmodifiable
public static <T> java.util.Collection<T> asUnmodifiable(java.util.Collection<T> self)Creates an unmodifiable view of a Collection.- Parameters:
self
- a Collection- Returns:
- an unmodifiable view of the Collection
- Since:
- 2.5.0
- See Also:
Collections.unmodifiableCollection(java.util.Collection)
,asUnmodifiable(java.util.List)
-
asSynchronized
public static <K, V> java.util.Map<K,V> asSynchronized(java.util.Map<K,V> self)A convenience method for creating a synchronized Map.- Parameters:
self
- a Map- Returns:
- a synchronized Map
- Since:
- 1.0
- See Also:
Collections.synchronizedMap(java.util.Map)
-
asSynchronized
public static <K, V> java.util.SortedMap<K,V> asSynchronized(java.util.SortedMap<K,V> self)A convenience method for creating a synchronized SortedMap.- Parameters:
self
- a SortedMap- Returns:
- a synchronized SortedMap
- Since:
- 1.0
- See Also:
Collections.synchronizedSortedMap(java.util.SortedMap)
-
asSynchronized
public static <T> java.util.Collection<T> asSynchronized(java.util.Collection<T> self)A convenience method for creating a synchronized Collection.- Parameters:
self
- a Collection- Returns:
- a synchronized Collection
- Since:
- 1.0
- See Also:
Collections.synchronizedCollection(java.util.Collection)
-
asSynchronized
public static <T> java.util.List<T> asSynchronized(java.util.List<T> self)A convenience method for creating a synchronized List.- Parameters:
self
- a List- Returns:
- a synchronized List
- Since:
- 1.0
- See Also:
Collections.synchronizedList(java.util.List)
-
asSynchronized
public static <T> java.util.Set<T> asSynchronized(java.util.Set<T> self)A convenience method for creating a synchronized Set.- Parameters:
self
- a Set- Returns:
- a synchronized Set
- Since:
- 1.0
- See Also:
Collections.synchronizedSet(java.util.Set)
-
asSynchronized
public static <T> java.util.SortedSet<T> asSynchronized(java.util.SortedSet<T> self)A convenience method for creating a synchronized SortedSet.- Parameters:
self
- a SortedSet- Returns:
- a synchronized SortedSet
- Since:
- 1.0
- See Also:
Collections.synchronizedSortedSet(java.util.SortedSet)
-
spread
Synonym fortoSpreadMap(java.util.Map)
.- Parameters:
self
- a map- Returns:
- a newly created SpreadMap
- Since:
- 1.0
-
toSpreadMap
Returns a newSpreadMap
from this map.The example below shows the various possible use cases:
def fn(Map m) { return m.a + m.b + m.c + m.d } assert fn(a:1, b:2, c:3, d:4) == 10 assert fn(a:1, *:[b:2, c:3], d:4) == 10 assert fn([a:1, b:2, c:3, d:4].toSpreadMap()) == 10 assert fn((['a', 1, 'b', 2, 'c', 3, 'd', 4] as Object[]).toSpreadMap()) == 10 assert fn(['a', 1, 'b', 2, 'c', 3, 'd', 4].toSpreadMap()) == 10 assert fn(['abcd'.toList(), 1..4].transpose().flatten().toSpreadMap()) == 10
Note that toSpreadMap() is not normally used explicitly but under the covers by Groovy.- Parameters:
self
- a map to be converted into a SpreadMap- Returns:
- a newly created SpreadMap if this map is not null and its size is positive.
- Since:
- 1.0
- See Also:
SpreadMap(java.util.Map)
-
toSpreadMap
Creates a spreadable map from this array.- Parameters:
self
- an object array- Returns:
- a newly created SpreadMap
- Since:
- 1.0
- See Also:
SpreadMap(java.lang.Object[])
,toSpreadMap(java.util.Map)
-
toSpreadMap
Creates a spreadable map from this list.- Parameters:
self
- a list- Returns:
- a newly created SpreadMap
- Since:
- 1.8.0
- See Also:
SpreadMap(java.util.List)
,toSpreadMap(java.util.Map)
-
toSpreadMap
Creates a spreadable map from this iterable.- Parameters:
self
- an iterable- Returns:
- a newly created SpreadMap
- Since:
- 2.4.0
- See Also:
SpreadMap(java.util.List)
,toSpreadMap(java.util.Map)
-
withDefault
Wraps a map using the decorator pattern with a wrapper that intercepts all calls toget(key)
. If an unknown key is found, a default value will be stored into the Map before being returned. The default value stored will be the result of calling the supplied Closure with the key as the parameter to the Closure. Example usage:def map = [a:1, b:2].withDefault{ k
->
k.toCharacter().isLowerCase() ? 10 : -10 } def expected = [a:1, b:2, c:10, D:-10] assert expected.every{ e->
e.value == map[e.key] } def constMap = [:].withDefault{ 42 } assert constMap.foo == 42 assert constMap.size() == 1- Parameters:
self
- a Mapinit
- a Closure which is passed the unknown key- Returns:
- the wrapped Map
- Since:
- 1.7.1
-
withDefault
An alias forwithLazyDefault
which decorates a list allowing it to grow when called with index values outside the normal list bounds.- Parameters:
self
- a Listinit
- a Closure with the target index as parameter which generates the default value- Returns:
- the decorated List
- Since:
- 1.8.7
- See Also:
withLazyDefault(java.util.List, groovy.lang.Closure)
,withEagerDefault(java.util.List, groovy.lang.Closure)
-
withDefault$$bridge
@Deprecated public static <T> java.util.List<T> withDefault$$bridge(java.util.List<T> self, Closure<T> init)Deprecated. -
withLazyDefault
Decorates a list allowing it to grow when called with a non-existent index value. When called with such values, the list is grown in size and a default value is placed in the list by calling a suppliedinit
Closure. Subsequent retrieval operations if finding a null value in the list assume it was set as null from an earlier growing operation and again call theinit
Closure to populate the retrieved value; consequently the list can't be used to store null values.How it works: The decorated list intercepts all calls to
getAt(index)
andget(index)
. If an index greater than or equal to the currentsize()
is used, the list will grow automatically up to the specified index. Gaps will be filled bynull
. If a default value should also be used to fill gaps instead ofnull
, usewithEagerDefault
. IfgetAt(index)
orget(index)
are called and a null value is found, it is assumed that the null value was a consequence of an earlier grow list operation and theinit
Closure is called to populate the value.Example usage:
def list = [0, 1].withLazyDefault{ 42 } assert list[0] == 0 assert list[1] == 1 assert list[3] == 42 // default value assert list == [0, 1, null, 42] // gap filled with null // illustrate using the index when generating default values def list2 = [5].withLazyDefault{ index
->
index * index } assert list2[3] == 9 assert list2 == [5, null, null, 9] assert list2[2] == 4 assert list2 == [5, null, 4, 9] // illustrate what happens with null values list2[2] = null assert list2[2] == 4- Parameters:
self
- a Listinit
- a Closure with the target index as parameter which generates the default value- Returns:
- the decorated List
- Since:
- 1.8.7
-
withLazyDefault$$bridge
@Deprecated public static <T> java.util.List<T> withLazyDefault$$bridge(java.util.List<T> self, Closure<T> init)Deprecated. -
withEagerDefault
Decorates a list allowing it to grow when called with a non-existent index value. When called with such values, the list is grown in size and a default value is placed in the list by calling a suppliedinit
Closure. Null values can be stored in the list.How it works: The decorated list intercepts all calls to
getAt(index)
andget(index)
. If an index greater than or equal to the currentsize()
is used, the list will grow automatically up to the specified index. Gaps will be filled by calling theinit
Closure. If generating a default value is a costly operation consider usingwithLazyDefault
.Example usage:
def list = [0, 1].withEagerDefault{ 42 } assert list[0] == 0 assert list[1] == 1 assert list[3] == 42 // default value assert list == [0, 1, 42, 42] // gap filled with default value // illustrate using the index when generating default values def list2 = [5].withEagerDefault{ index
->
index * index } assert list2[3] == 9 assert list2 == [5, 1, 4, 9] // illustrate what happens with null values list2[2] = null assert list2[2] == null assert list2 == [5, 1, null, 9]- Parameters:
self
- a Listinit
- a Closure with the target index as parameter which generates the default value- Returns:
- the wrapped List
- Since:
- 1.8.7
-
withEagerDefault$$bridge
@Deprecated public static <T> java.util.List<T> withEagerDefault$$bridge(java.util.List<T> self, Closure<T> init)Deprecated. -
withIndex
public static <E> java.util.List<Tuple2<E,java.lang.Integer>> withIndex(java.lang.Iterable<E> self)Zips an Iterable with indices in (value, index) order. Example usage:assert [["a", 0], ["b", 1]] == ["a", "b"].withIndex() assert ["0: a", "1: b"] == ["a", "b"].withIndex().collect { str, idx
->
"$idx: $str" }- Parameters:
self
- an Iterable- Returns:
- a zipped list with indices
- Since:
- 2.4.0
- See Also:
indexed(Iterable)
-
indexed
public static <E> java.util.Map<java.lang.Integer,E> indexed(java.lang.Iterable<E> self)Zips an Iterable with indices in (index, value) order. Example usage:assert [0: "a", 1: "b"] == ["a", "b"].indexed() assert ["0: a", "1: b"] == ["a", "b"].indexed().collect { idx, str
->
"$idx: $str" }- Parameters:
self
- an Iterable- Returns:
- a zipped map with indices
- Since:
- 2.4.0
- See Also:
withIndex(Iterable)
-
withIndex
public static <E> java.util.List<Tuple2<E,java.lang.Integer>> withIndex(java.lang.Iterable<E> self, int offset)Zips an Iterable with indices in (value, index) order. Example usage:assert [["a", 5], ["b", 6]] == ["a", "b"].withIndex(5) assert ["1: a", "2: b"] == ["a", "b"].withIndex(1).collect { str, idx
->
"$idx: $str" }- Parameters:
self
- an Iterableoffset
- an index to start from- Returns:
- a zipped list with indices
- Since:
- 2.4.0
- See Also:
indexed(Iterable, int)
-
indexed
public static <E> java.util.Map<java.lang.Integer,E> indexed(java.lang.Iterable<E> self, int offset)Zips an Iterable with indices in (index, value) order. Example usage:assert [5: "a", 6: "b"] == ["a", "b"].indexed(5) assert ["1: a", "2: b"] == ["a", "b"].indexed(1).collect { idx, str
->
"$idx: $str" }- Parameters:
self
- an Iterableoffset
- an index to start from- Returns:
- a Map (since the keys/indices are unique) containing the elements from the iterable zipped with indices
- Since:
- 2.4.0
- See Also:
withIndex(Iterable, int)
-
indexed
public static java.util.Map<java.lang.Integer,java.lang.Integer> indexed(int[] self)Zips an int[] with indices in (index, value) order starting from index 0.- Since:
- 3.0.8
- See Also:
indexed(int[], int)
-
indexed
public static java.util.Map<java.lang.Integer,java.lang.Integer> indexed(int[] self, int offset)Zips an int[] with indices in (index, value) order. Example usage:int[] nums = [10, 20, 30] assert [5: 10, 6: 20, 7: 30] == nums.indexed(5) assert ["1: 10", "2: 20", "3: 30"] == nums.indexed(1).collect { idx, str
->
"$idx: $str" }- Parameters:
self
- an Iterableoffset
- an index to start from- Returns:
- a Map (since the keys/indices are unique) containing the elements from the iterable zipped with indices
- Since:
- 3.0.8
- See Also:
indexed(Iterable, int)
-
indexed
public static java.util.Map<java.lang.Integer,java.lang.Long> indexed(long[] self)Zips a long[] with indices in (index, value) order starting from index 0.- Since:
- 3.0.8
- See Also:
indexed(long[], int)
-
indexed
public static java.util.Map<java.lang.Integer,java.lang.Long> indexed(long[] self, int offset)Zips a long[] with indices in (index, value) order.- Parameters:
self
- a long[]offset
- an index to start from- Returns:
- a Map (since the keys/indices are unique) containing the elements from the iterable zipped with indices
- Since:
- 3.0.8
- See Also:
indexed(Iterable, int)
-
indexed
public static java.util.Map<java.lang.Integer,java.lang.Double> indexed(double[] self)Zips a double[] with indices in (index, value) order starting from index 0.- Since:
- 3.0.8
- See Also:
indexed(double[], int)
-
indexed
public static java.util.Map<java.lang.Integer,java.lang.Double> indexed(double[] self, int offset)Zips a double[] with indices in (index, value) order.- Parameters:
self
- a double[]offset
- an index to start from- Returns:
- a Map (since the keys/indices are unique) containing the elements from the iterable zipped with indices
- Since:
- 3.0.8
- See Also:
indexed(Iterable, int)
-
withIndex
public static <E> java.util.Iterator<Tuple2<E,java.lang.Integer>> withIndex(java.util.Iterator<E> self)Zips an iterator with indices in (value, index) order. Example usage:assert [["a", 0], ["b", 1]] == ["a", "b"].iterator().withIndex().toList() assert ["0: a", "1: b"] == ["a", "b"].iterator().withIndex().collect { str, idx
->
"$idx: $str" }.toList()- Parameters:
self
- an iterator- Returns:
- a zipped iterator with indices
- Since:
- 2.4.0
- See Also:
indexed(Iterator)
-
indexed
public static <E> java.util.Iterator<Tuple2<java.lang.Integer,E>> indexed(java.util.Iterator<E> self)Zips an iterator with indices in (index, value) order. Example usage:assert [[0, "a"], [1, "b"]] == ["a", "b"].iterator().indexed().collect{ tuple
->
[tuple.first, tuple.second] } assert ["0: a", "1: b"] == ["a", "b"].iterator().indexed().collect { idx, str->
"$idx: $str" }.toList()- Parameters:
self
- an iterator- Returns:
- a zipped iterator with indices
- Since:
- 2.4.0
- See Also:
withIndex(Iterator)
-
withIndex
public static <E> java.util.Iterator<Tuple2<E,java.lang.Integer>> withIndex(java.util.Iterator<E> self, int offset)Zips an iterator with indices in (value, index) order. Example usage:assert [["a", 5], ["b", 6]] == ["a", "b"].iterator().withIndex(5).toList() assert ["1: a", "2: b"] == ["a", "b"].iterator().withIndex(1).collect { str, idx
->
"$idx: $str" }.toList()- Parameters:
self
- an iteratoroffset
- an index to start from- Returns:
- a zipped iterator with indices
- Since:
- 2.4.0
- See Also:
indexed(Iterator, int)
-
indexed
public static <E> java.util.Iterator<Tuple2<java.lang.Integer,E>> indexed(java.util.Iterator<E> self, int offset)Zips an iterator with indices in (index, value) order. Example usage:assert [[5, "a"], [6, "b"]] == ["a", "b"].iterator().indexed(5).toList() assert ["a: 1", "b: 2"] == ["a", "b"].iterator().indexed(1).collect { idx, str
->
"$str: $idx" }.toList()- Parameters:
self
- an iteratoroffset
- an index to start from- Returns:
- a zipped iterator with indices
- Since:
- 2.4.0
- See Also:
withIndex(Iterator, int)
-
sort
public static <T> java.util.List<T> sort(java.lang.Iterable<T> self)Sorts the Collection. Assumes that the collection items are comparable and uses their natural ordering to determine the resulting order. If the Collection is a List, it is sorted in place and returned. Otherwise, the elements are first placed into a new list which is then sorted and returned - leaving the original Collection unchanged.assert [1,2,3] == [3,1,2].sort()
- Parameters:
self
- the Iterable to be sorted- Returns:
- the sorted Iterable as a List
- Since:
- 2.2.0
- See Also:
sort(Iterable, boolean)
-
sort
public static <T> java.util.List<T> sort(java.lang.Iterable<T> self, boolean mutate)Sorts the Iterable. Assumes that the Iterable items are comparable and uses their natural ordering to determine the resulting order. If the Iterable is a List and mutate is true, it is sorted in place and returned. Otherwise, the elements are first placed into a new list which is then sorted and returned - leaving the original Iterable unchanged.assert [1,2,3] == [3,1,2].sort()
def orig = [1, 3, 2] def sorted = orig.sort(false) assert orig == [1, 3, 2] assert sorted == [1, 2, 3]
- Parameters:
self
- the iterable to be sortedmutate
- false will always cause a new list to be created, true will mutate lists in place- Returns:
- the sorted iterable as a List
- Since:
- 2.2.0
-
sort
Sorts the elements from the given map into a new ordered map using the closure as a comparator to determine the ordering. The original map is unchanged.def map = [a:5, b:3, c:6, d:4].sort { a, b
->
a.value<=>
b.value } assert map == [b:3, d:4, a:5, c:6]- Parameters:
self
- the original unsorted mapclosure
- a Closure used as a comparator- Returns:
- the sorted map
- Since:
- 1.6.0
-
sort
public static <K, V> java.util.Map<K,V> sort(java.util.Map<K,V> self, java.util.Comparator<? super K> comparator)Sorts the elements from the given map into a new ordered Map using the specified key comparator to determine the ordering. The original map is unchanged.def map = [ba:3, cz:6, ab:5].sort({ a, b
->
a[-1]<=>
b[-1] } as Comparator) assert map*.value == [3, 5, 6]- Parameters:
self
- the original unsorted mapcomparator
- a Comparator- Returns:
- the sorted map
- Since:
- 1.7.2
-
sort
public static <K, V> java.util.Map<K,V> sort(java.util.Map<K,V> self)Sorts the elements from the given map into a new ordered Map using the natural ordering of the keys to determine the ordering. The original map is unchanged.map = [ba:3, cz:6, ab:5].sort() assert map*.value == [5, 3, 6]
- Parameters:
self
- the original unsorted map- Returns:
- the sorted map
- Since:
- 1.7.2
-
sort
public static <T> T[] sort(T[] self)Modifies this array so that its elements are in sorted order. The array items are assumed to be comparable.- Parameters:
self
- the array to be sorted- Returns:
- the sorted array
- Since:
- 1.5.5
-
sort
public static <T> T[] sort(T[] self, boolean mutate)Sorts the given array into sorted order. The array items are assumed to be comparable. If mutate is true, the array is sorted in place and returned. Otherwise, a new sorted array is returned and the original array remains unchanged.def orig = ["hello","hi","Hey"] as String[] def sorted = orig.sort(false) assert orig == ["hello","hi","Hey"] as String[] assert sorted == ["Hey","hello","hi"] as String[] orig.sort(true) assert orig == ["Hey","hello","hi"] as String[]
- Parameters:
self
- the array to be sortedmutate
- false will always cause a new array to be created, true will mutate the array in place- Returns:
- the sorted array
- Since:
- 1.8.1
-
sort
public static <T> java.util.Iterator<T> sort(java.util.Iterator<T> self)Sorts the given iterator items into a sorted iterator. The items are assumed to be comparable. The original iterator will become exhausted of elements after completing this method call. A new iterator is produced that traverses the items in sorted order.- Parameters:
self
- the Iterator to be sorted- Returns:
- the sorted items as an Iterator
- Since:
- 1.5.5
-
sort
public static <T> java.util.Iterator<T> sort(java.util.Iterator<T> self, java.util.Comparator<? super T> comparator)Sorts the given iterator items into a sorted iterator using the comparator. The original iterator will become exhausted of elements after completing this method call. A new iterator is produced that traverses the items in sorted order.- Parameters:
self
- the Iterator to be sortedcomparator
- a Comparator used for comparing items- Returns:
- the sorted items as an Iterator
- Since:
- 1.5.5
-
sort
public static <T> java.util.List<T> sort(java.lang.Iterable<T> self, boolean mutate, java.util.Comparator<? super T> comparator)Sorts the Iterable using the given Comparator. If the Iterable is a List and mutate is true, it is sorted in place and returned. Otherwise, the elements are first placed into a new list which is then sorted and returned - leaving the original Iterable unchanged.assert ["hi","hey","hello"] == ["hello","hi","hey"].sort(false, { a, b
->
a.length()<=>
b.length() } as Comparator )def orig = ["hello","hi","Hey"] def sorted = orig.sort(false, String.CASE_INSENSITIVE_ORDER) assert orig == ["hello","hi","Hey"] assert sorted == ["hello","Hey","hi"]
- Parameters:
self
- the Iterable to be sortedmutate
- false will always cause a new list to be created, true will mutate lists in placecomparator
- a Comparator used for the comparison- Returns:
- a sorted List
- Since:
- 2.2.0
-
sort
public static <T> T[] sort(T[] self, java.util.Comparator<? super T> comparator)Sorts the given array into sorted order using the given comparator.- Parameters:
self
- the array to be sortedcomparator
- a Comparator used for the comparison- Returns:
- the sorted array
- Since:
- 1.5.5
-
sort
public static <T> T[] sort(T[] self, boolean mutate, java.util.Comparator<? super T> comparator)Modifies this array so that its elements are in sorted order as determined by the given comparator. If mutate is true, the array is sorted in place and returned. Otherwise, a new sorted array is returned and the original array remains unchanged.def orig = ["hello","hi","Hey"] as String[] def sorted = orig.sort(false, String.CASE_INSENSITIVE_ORDER) assert orig == ["hello","hi","Hey"] as String[] assert sorted == ["hello","Hey","hi"] as String[] orig.sort(true, String.CASE_INSENSITIVE_ORDER) assert orig == ["hello","Hey","hi"] as String[]
- Parameters:
self
- the array containing elements to be sortedmutate
- false will always cause a new array to be created, true will mutate arrays in placecomparator
- a Comparator used for the comparison- Returns:
- a sorted array
- Since:
- 1.8.1
-
sort
Sorts the given iterator items into a sorted iterator using the Closure to determine the correct ordering. The original iterator will be fully processed after the method call.If the closure has two parameters it is used like a traditional Comparator. I.e. it should compare its two parameters for order, returning a negative integer, zero, or a positive integer when the first parameter is less than, equal to, or greater than the second respectively. Otherwise, the Closure is assumed to take a single parameter and return a Comparable (typically an Integer) which is then used for further comparison.
- Parameters:
self
- the Iterator to be sortedclosure
- a Closure used to determine the correct ordering- Returns:
- the sorted items as an Iterator
- Since:
- 1.5.5
-
sort
Sorts the elements from this array into a newly created array using the Closure to determine the correct ordering.If the closure has two parameters it is used like a traditional Comparator. I.e. it should compare its two parameters for order, returning a negative integer, zero, or a positive integer when the first parameter is less than, equal to, or greater than the second respectively. Otherwise, the Closure is assumed to take a single parameter and return a Comparable (typically an Integer) which is then used for further comparison.
- Parameters:
self
- the array containing the elements to be sortedclosure
- a Closure used to determine the correct ordering- Returns:
- the sorted array
- Since:
- 1.5.5
-
sort
Modifies this array so that its elements are in sorted order using the Closure to determine the correct ordering. If mutate is false, a new array is returned and the original array remains unchanged. Otherwise, the original array is sorted in place and returned.If the closure has two parameters it is used like a traditional Comparator. I.e. it should compare its two parameters for order, returning a negative integer, zero, or a positive integer when the first parameter is less than, equal to, or greater than the second respectively. Otherwise, the Closure is assumed to take a single parameter and return a Comparable (typically an Integer) which is then used for further comparison.
def orig = ["hello","hi","Hey"] as String[] def sorted = orig.sort(false) { it.size() } assert orig == ["hello","hi","Hey"] as String[] assert sorted == ["hi","Hey","hello"] as String[] orig.sort(true) { it.size() } assert orig == ["hi","Hey","hello"] as String[]
- Parameters:
self
- the array to be sortedmutate
- false will always cause a new array to be created, true will mutate arrays in placeclosure
- a Closure used to determine the correct ordering- Returns:
- the sorted array
- Since:
- 1.8.1
-
sort
Sorts this Iterable using the given Closure to determine the correct ordering. If the Iterable is a List, it is sorted in place and returned. Otherwise, the elements are first placed into a new list which is then sorted and returned - leaving the original Iterable unchanged.If the Closure has two parameters it is used like a traditional Comparator. I.e. it should compare its two parameters for order, returning a negative integer, zero, or a positive integer when the first parameter is less than, equal to, or greater than the second respectively. Otherwise, the Closure is assumed to take a single parameter and return a Comparable (typically an Integer) which is then used for further comparison.
assert ["hi","hey","hello"] == ["hello","hi","hey"].sort { it.length() }
assert ["hi","hey","hello"] == ["hello","hi","hey"].sort { a, b
->
a.length()<=>
b.length() }- Parameters:
self
- the Iterable to be sortedclosure
- a 1 or 2 arg Closure used to determine the correct ordering- Returns:
- a newly created sorted List
- Since:
- 2.2.0
- See Also:
sort(Iterable, boolean, Closure)
-
sort
public static <T> java.util.List<T> sort(java.lang.Iterable<T> self, boolean mutate, Closure closure)Sorts this Iterable using the given Closure to determine the correct ordering. If the Iterable is a List and mutate is true, it is sorted in place and returned. Otherwise, the elements are first placed into a new list which is then sorted and returned - leaving the original Iterable unchanged.If the closure has two parameters it is used like a traditional Comparator. I.e. it should compare its two parameters for order, returning a negative integer, zero, or a positive integer when the first parameter is less than, equal to, or greater than the second respectively. Otherwise, the Closure is assumed to take a single parameter and return a Comparable (typically an Integer) which is then used for further comparison.
assert ["hi","hey","hello"] == ["hello","hi","hey"].sort { it.length() }
assert ["hi","hey","hello"] == ["hello","hi","hey"].sort { a, b
->
a.length()<=>
b.length() }def orig = ["hello","hi","Hey"] def sorted = orig.sort(false) { it.toUpperCase() } assert orig == ["hello","hi","Hey"] assert sorted == ["hello","Hey","hi"]
- Parameters:
self
- the Iterable to be sortedmutate
- false will always cause a new list to be created, true will mutate lists in placeclosure
- a 1 or 2 arg Closure used to determine the correct ordering- Returns:
- a newly created sorted List
- Since:
- 2.2.0
-
sort
public static <T> java.util.SortedSet<T> sort(java.util.SortedSet<T> self)Avoids doing unnecessary work when sorting an already sorted set (i.e. an identity function for an already sorted set).- Parameters:
self
- an already sorted set- Returns:
- the set
- Since:
- 1.0
-
sort
public static <K, V> java.util.SortedMap<K,V> sort(java.util.SortedMap<K,V> self)Avoids doing unnecessary work when sorting an already sorted map (i.e. an identity function for an already sorted map).- Parameters:
self
- an already sorted map- Returns:
- the map
- Since:
- 1.8.1
-
toSorted
public static <T> java.util.List<T> toSorted(java.lang.Iterable<T> self)Sorts the Iterable. Assumes that the Iterable elements are comparable and uses aNumberAwareComparator
to determine the resulting order.NumberAwareComparator
has special treatment for numbers but otherwise uses the natural ordering of the Iterable elements. The elements are first placed into a new list which is then sorted and returned - leaving the original Iterable unchanged.def orig = [1, 3, 2] def sorted = orig.toSorted() assert orig == [1, 3, 2] assert sorted == [1, 2, 3]
- Parameters:
self
- the Iterable to be sorted- Returns:
- the sorted iterable as a List
- Since:
- 2.4.0
- See Also:
toSorted(Iterable, Comparator)
-
toSorted
public static <T> java.util.List<T> toSorted(java.lang.Iterable<T> self, java.util.Comparator<T> comparator)Sorts the Iterable using the given Comparator. The elements are first placed into a new list which is then sorted and returned - leaving the original Iterable unchanged.def orig = ["hello","hi","Hey"] def sorted = orig.toSorted(String.CASE_INSENSITIVE_ORDER) assert orig == ["hello","hi","Hey"] assert sorted == ["hello","Hey","hi"]
- Parameters:
self
- the Iterable to be sortedcomparator
- a Comparator used for the comparison- Returns:
- a sorted List
- Since:
- 2.4.0
-
toSorted
Sorts this Iterable using the given Closure to determine the correct ordering. The elements are first placed into a new list which is then sorted and returned - leaving the original Iterable unchanged.If the Closure has two parameters it is used like a traditional Comparator. I.e. it should compare its two parameters for order, returning a negative integer, zero, or a positive integer when the first parameter is less than, equal to, or greater than the second respectively. Otherwise, the Closure is assumed to take a single parameter and return a Comparable (typically an Integer) which is then used for further comparison.
assert ["hi","hey","hello"] == ["hello","hi","hey"].sort { it.length() }
assert ["hi","hey","hello"] == ["hello","hi","hey"].sort { a, b
->
a.length()<=>
b.length() }- Parameters:
self
- the Iterable to be sortedclosure
- a 1 or 2 arg Closure used to determine the correct ordering- Returns:
- a newly created sorted List
- Since:
- 2.4.0
- See Also:
toSorted(Iterable, Comparator)
-
toSorted
public static <T> java.util.Iterator<T> toSorted(java.util.Iterator<T> self)Sorts the Iterator. Assumes that the Iterator elements are comparable and uses aNumberAwareComparator
to determine the resulting order.NumberAwareComparator
has special treatment for numbers but otherwise uses the natural ordering of the Iterator elements. A new iterator is produced that traverses the items in sorted order.- Parameters:
self
- the Iterator to be sorted- Returns:
- the sort
-