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.
Modifier and Type | Field and Description |
---|---|
static Class[] |
additionals |
static Class[] |
DGM_LIKE_CLASSES |
Constructor and Description |
---|
DefaultGroovyMethods() |
Modifier and Type | Method and Description |
---|---|
static double |
abs(Double number)
Get the absolute value
|
static float |
abs(Float number)
Get the absolute value
|
static long |
abs(Long number)
Get the absolute value
|
static int |
abs(Number number)
Get the absolute value
|
static Socket |
accept(ServerSocket serverSocket,
boolean runInANewThread,
Closure closure)
Deprecated.
|
static Socket |
accept(ServerSocket serverSocket,
Closure closure)
Deprecated.
|
static <T> boolean |
addAll(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(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(Object self,
Closure closure)
Allows the usage of addShutdownHook without getting the runtime first.
|
static BitSet |
and(BitSet left,
BitSet right)
Bitwise AND together two BitSets.
|
static Boolean |
and(Boolean left,
Boolean right)
Logical conjunction of two boolean operators.
|
static Number |
and(Number left,
Number right)
Bitwise AND together two Numbers.
|
static <T> boolean |
any(Iterable<T> self,
Closure closure)
Iterates over the contents of an iterable, and checks whether a
predicate is valid for at least one element.
|
static <T> boolean |
any(Iterator<T> self,
Closure closure)
Iterates over the contents of an iterator, and checks whether a
predicate is valid for at least one element.
|
static <K,V> boolean |
any(Map<K,V> self,
Closure<?> closure)
Iterates over the entries of a map, and checks whether a predicate is
valid for at least one entry.
|
static boolean |
any(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(Object self,
Closure closure)
Iterates over the contents of an object or collection, and checks whether a
predicate is valid for at least one element.
|
static void |
append(File file,
byte[] bytes)
Deprecated.
|
static void |
append(File self,
InputStream stream)
Deprecated.
|
static void |
append(File file,
Object text)
Deprecated.
|
static void |
append(File file,
Object text,
String charset)
Deprecated.
|
static boolean |
asBoolean(Boolean bool)
Coerce an Boolean instance to a boolean value.
|
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(Character character)
Coerce a character to a boolean value.
|
static boolean |
asBoolean(CharSequence string)
Deprecated.
|
static boolean |
asBoolean(Collection collection)
Coerce a collection instance to a boolean value.
|
static boolean |
asBoolean(double[] array)
Coerces a double array to a boolean value.
|
static boolean |
asBoolean(Enumeration enumeration)
Coerce an enumeration instance 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(Iterator iterator)
Coerce an iterator instance to a boolean value.
|
static boolean |
asBoolean(long[] array)
Coerces a long array to a boolean value.
|
static boolean |
asBoolean(Map map)
Coerce a map instance to a boolean value.
|
static boolean |
asBoolean(Matcher matcher)
Deprecated.
|
static boolean |
asBoolean(Number number)
Coerce a number to a boolean value.
|
static boolean |
asBoolean(Object object)
Coerce an object instance to a boolean value.
|
static boolean |
asBoolean(Object[] array)
Coerce an Object array to a boolean value.
|
static boolean |
asBoolean(short[] array)
Coerces a short array to a boolean value.
|
static <T> Collection<T> |
asImmutable(Collection<? extends T> self)
A convenience method for creating an immutable Collection.
|
static <T> List<T> |
asImmutable(List<? extends T> self)
A convenience method for creating an immutable list
|
static <K,V> Map<K,V> |
asImmutable(Map<? extends K,? extends V> self)
A convenience method for creating an immutable map.
|
static <T> Set<T> |
asImmutable(Set<? extends T> self)
A convenience method for creating an immutable list.
|
static <K,V> SortedMap<K,V> |
asImmutable(SortedMap<K,? extends V> self)
A convenience method for creating an immutable sorted map.
|
static <T> SortedSet<T> |
asImmutable(SortedSet<T> self)
A convenience method for creating an immutable sorted set.
|
static <T> List<T> |
asList(Collection<T> self)
Deprecated.
Use the Iterable version of asList instead
|
static <T> List<T> |
asList(Iterable<T> self)
Converts this Iterable to a List.
|
static <T> Collection<T> |
asSynchronized(Collection<T> self)
A convenience method for creating a synchronized Collection.
|
static <T> List<T> |
asSynchronized(List<T> self)
A convenience method for creating a synchronized List.
|
static <K,V> Map<K,V> |
asSynchronized(Map<K,V> self)
A convenience method for creating a synchronized Map.
|
static <T> Set<T> |
asSynchronized(Set<T> self)
A convenience method for creating a synchronized Set.
|
static <K,V> SortedMap<K,V> |
asSynchronized(SortedMap<K,V> self)
A convenience method for creating a synchronized SortedMap.
|
static <T> SortedSet<T> |
asSynchronized(SortedSet<T> self)
A convenience method for creating a synchronized SortedSet.
|
static <T> T |
asType(CharSequence self,
Class<T> c)
Deprecated.
|
static <T> T |
asType(Closure cl,
Class<T> clazz)
Coerces the closure to an implementation of the given class.
|
static <T> T |
asType(Collection col,
Class<T> clazz)
Converts the given collection to another type.
|
static <T> T |
asType(File f,
Class<T> c)
Deprecated.
|
static <T> T |
asType(GString self,
Class<T> c)
Deprecated.
|
static <T> T |
asType(Map map,
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> T |
asType(Number self,
Class<T> c)
Transform this number to a the given type, using the 'as' operator.
|
static <T> T |
asType(Object[] ary,
Class<T> clazz)
Converts the given array to either a List, Set, or
SortedSet.
|
static <T> T |
asType(Object obj,
Class<T> type)
Converts a given object to a type.
|
static <T> T |
asType(String self,
Class<T> c)
Deprecated.
|
static File |
asWritable(File file)
Deprecated.
|
static File |
asWritable(File file,
String encoding)
Deprecated.
|
static BitSet |
bitwiseNegate(BitSet self)
Bitwise NEGATE a BitSet.
|
static Pattern |
bitwiseNegate(CharSequence self)
Deprecated.
|
static Number |
bitwiseNegate(Number left)
Bitwise NEGATE a Number.
|
static Pattern |
bitwiseNegate(String self)
Deprecated.
|
protected static <T> T |
callClosureForLine(Closure<T> closure,
String line,
int counter) |
protected static <T> T |
callClosureForMapEntry(Closure<T> closure,
Map.Entry entry) |
protected static <T> T |
callClosureForMapEntryAndCounter(Closure<T> closure,
Map.Entry entry,
int counter) |
static CharSequence |
capitalize(CharSequence self)
Deprecated.
|
static String |
capitalize(String self)
Deprecated.
|
static CharSequence |
center(CharSequence self,
Number numberOfChars)
Deprecated.
|
static CharSequence |
center(CharSequence self,
Number numberOfChars,
CharSequence padding)
Deprecated.
|
static String |
center(String self,
Number numberOfChars)
Deprecated.
|
static String |
center(String self,
Number numberOfChars,
String padding)
Deprecated.
|
static <T> List<List<T>> |
collate(List<T> self,
int size)
Collates this list into sub-lists of length
size . |
static <T> List<List<T>> |
collate(List<T> self,
int size,
boolean keepRemainder)
Collates this list into sub-lists of length
size . |
static <T> List<List<T>> |
collate(List<T> self,
int size,
int step)
Collates this list into sub-lists of length
size stepping through the code step
elements for each subList. |
static <T> List<List<T>> |
collate(List<T> self,
int size,
int step,
boolean keepRemainder)
Collates this list into sub-lists of length
size stepping through the code step
elements for each sub-list. |
static <T,E> Collection<T> |
collect(Collection<E> self,
Collection<T> collector,
Closure<? extends T> transform)
Iterates through this collection transforming each value into a new value using the
transform closure
and adding it to the supplied collector . |
static <S,T> List<T> |
collect(Collection<S> self,
Closure<T> transform)
Iterates through this collection transforming each entry into a new value using the
transform closure
returning a list of transformed values. |
static <T> List<T> |
collect(Collection<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 <T,K,V> List<T> |
collect(Map<K,V> self,
Closure<T> transform)
Iterates through this Map transforming each map entry into a new value using the
transform closure
returning a list of transformed values. |
static <T,K,V> Collection<T> |
collect(Map<K,V> self,
Collection<T> collector,
Closure<? extends T> transform)
Iterates through this Map transforming each map entry into a new value using the
transform closure
returning the collector with all transformed values added to it. |
static Collection |
collect(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> List<T> |
collect(Object self,
Closure<T> transform)
Iterates through this aggregate Object transforming each item into a new value using the
transform closure, returning a list of transformed values. |
static <T> Collection<T> |
collect(Object self,
Collection<T> collector,
Closure<? extends T> transform)
Iterates through this aggregate Object transforming each item into a new value using the
transform closure
and adding it to the supplied collector . |
static List |
collectAll(Collection self,
Closure transform)
Deprecated.
Use collectNested instead
|
static Collection |
collectAll(Collection self,
Collection collector,
Closure transform)
Deprecated.
Use collectNested instead
|
static <K,V> Map<K,V> |
collectEntries(Collection<?> self)
Deprecated.
Use the Iterable version of collectEntries instead
|
static <K,V> Map<K,V> |
collectEntries(Collection<?> self,
Closure<?> transform)
Deprecated.
Use the Iterable version of collectEntries instead
|
static <K,V> Map<K,V> |
collectEntries(Collection<?> self,
Map<K,V> collector)
Deprecated.
Use the Iterable version of collectEntries instead
|
static <K,V> Map<K,V> |
collectEntries(Collection<?> self,
Map<K,V> collector,
Closure<?> transform)
Deprecated.
Use the Iterable version of collectEntries instead
|
static <K,V,E> Map<K,V> |
collectEntries(E[] self,
Closure<?> transform)
Iterates through this array transforming each item using the
transform closure
and returning a map of the resulting transformed entries. |
static <K,V,E> Map<K,V> |
collectEntries(E[] self,
Map<K,V> collector,
Closure<?> transform)
Iterates through this array transforming each item using the
transform closure
and returning a map of the resulting transformed entries. |
static <K,V> Map<K,V> |
collectEntries(Iterable<?> self)
A variant of collectEntries for Iterable objects using the identity closure as the transform.
|
static <K,V> Map<K,V> |
collectEntries(Iterable<?> self,
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> Map<K,V> |
collectEntries(Iterable<E> self,
Closure<?> transform)
Iterates through this Iterable transforming each item using the
transform closure
and returning a map of the resulting transformed entries. |
static <K,V,E> Map<K,V> |
collectEntries(Iterable<E> self,
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> Map<K,V> |
collectEntries(Iterator<?> self)
A variant of collectEntries for Iterators using the identity closure as the transform.
|
static <K,V> Map<K,V> |
collectEntries(Iterator<?> self,
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> Map<K,V> |
collectEntries(Iterator<E> self,
Closure<?> transform)
A variant of collectEntries for Iterators.
|
static <K,V,E> Map<K,V> |
collectEntries(Iterator<E> self,
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> Map<?,?> |
collectEntries(Map<K,V> self,
Closure<?> transform)
Iterates through this Map transforming each entry using the
transform closure
and returning a map of the transformed entries. |
static <K,V,S,T> Map<K,V> |
collectEntries(Map<S,T> self,
Map<K,V> collector,
Closure<?> transform)
Iterates through this Map transforming each map entry using the
transform closure
returning a map of the transformed entries. |
static <K,V> Map<K,V> |
collectEntries(Object[] self)
A variant of collectEntries using the identity closure as the transform.
|
static <K,V> Map<K,V> |
collectEntries(Object[] self,
Map<K,V> collector)
A variant of collectEntries using the identity closure as the transform.
|
static <T,E> List<T> |
collectMany(Collection<E> self,
Closure<Collection<? extends T>> projection)
Deprecated.
Use the Iterable version of collectMany instead
|
static <T,E> Collection<T> |
collectMany(Collection<E> self,
Collection<T> collector,
Closure<Collection<? extends T>> projection)
Deprecated.
Use the Iterable version of collectMany instead
|
static <T,E> List<T> |
collectMany(E[] self,
Closure<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> List<T> |
collectMany(Iterable<E> self,
Closure<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> Collection<T> |
collectMany(Iterable<E> self,
Collection<T> collector,
Closure<Collection<? extends T>> projection)
Projects each item from a source collection to a result collection and concatenates (flattens) the resulting
collections adding them into the
collector . |
static <T,E> List<T> |
collectMany(Iterator<E> self,
Closure<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> Collection<T> |
collectMany(Map<K,V> self,
Closure<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> Collection<T> |
collectMany(Map<K,V> self,
Collection<T> collector,
Closure<Collection<? extends T>> projection)
Projects each item from a source map to a result collection and concatenates (flattens) the resulting
collections adding them into the
collector . |
static List |
collectNested(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 Collection |
collectNested(Collection self,
Collection collector,
Closure transform)
Deprecated.
Use the Iterable version of collectNested instead
|
static List |
collectNested(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 Collection |
collectNested(Iterable self,
Collection collector,
Closure transform)
Recursively iterates through this Iterable transforming each non-Collection value
into a new value using the
transform closure. |
static List |
combinations(Collection self)
Deprecated.
Use the Iterable version of combinations instead
|
static List |
combinations(Iterable self)
Adds GroovyCollections#combinations(Iterable) as a method on Iterables.
|
static List |
combinations(Iterable self,
Closure<?> function)
Adds GroovyCollections#combinations(Iterable, Closure) as a method on collections.
|
static int |
compareTo(Character left,
Character right)
Compare two Characters.
|
static int |
compareTo(Character left,
Number right)
Compare a Character and a Number.
|
static int |
compareTo(Number left,
Character right)
Compare a Number and a Character.
|
static int |
compareTo(Number left,
Number right)
Compare two Numbers.
|
static boolean |
contains(boolean[] self,
Object value)
Checks whether the array contains the given value.
|
static boolean |
contains(byte[] self,
Object value)
Checks whether the array contains the given value.
|
static boolean |
contains(char[] self,
Object value)
Checks whether the array contains the given value.
|
static boolean |
contains(CharSequence self,
CharSequence text)
Deprecated.
|
static boolean |
contains(double[] self,
Object value)
Checks whether the array contains the given value.
|
static boolean |
contains(float[] self,
Object value)
Checks whether the array contains the given value.
|
static boolean |
contains(int[] self,
Object value)
Checks whether the array contains the given value.
|
static boolean |
contains(long[] self,
Object value)
Checks whether the array contains the given value.
|
static boolean |
contains(Object[] self,
Object value)
Checks whether the array contains the given value.
|
static boolean |
contains(short[] self,
Object value)
Checks whether the array contains the given value.
|
static boolean |
contains(String self,
String text)
Deprecated.
|
static boolean |
containsAll(Collection self,
Object[] items)
Returns true if this collection contains all of the elements
in the specified array.
|
static Number |
count(boolean[] self,
Object value)
Counts the number of occurrences of the given value inside this array.
|
static Number |
count(byte[] self,
Object value)
Counts the number of occurrences of the given value inside this array.
|
static Number |
count(char[] self,
Object value)
Counts the number of occurrences of the given value inside this array.
|
static int |
count(CharSequence self,
CharSequence text)
Deprecated.
|
static Number |
count(Collection self,
Closure closure)
Deprecated.
use count(Iterable, Closure)
|
static Number |
count(Collection self,
Object value)
Deprecated.
use count(Iterable, Closure)
|
static Number |
count(double[] self,
Object value)
Counts the number of occurrences of the given value inside this array.
|
static Number |
count(float[] self,
Object value)
Counts the number of occurrences of the given value inside this array.
|
static Number |
count(int[] self,
Object value)
Counts the number of occurrences of the given value inside this array.
|
static <T> Number |
count(Iterable<T> self,
Closure closure)
Counts the number of occurrences which satisfy the given closure from inside this Iterable.
|
static Number |
count(Iterable self,
Object value)
Counts the number of occurrences of the given value inside this Iterable.
|
static <T> Number |
count(Iterator<T> self,
Closure closure)
Counts the number of occurrences which satisfy the given closure from the
items within this Iterator.
|
static Number |
count(Iterator self,
Object value)
Counts the number of occurrences of the given value from the
items within this Iterator.
|
static Number |
count(long[] self,
Object value)
Counts the number of occurrences of the given value inside this array.
|
static <K,V> Number |
count(Map<K,V> self,
Closure<?> closure)
Counts the number of occurrences which satisfy the given closure from inside this map.
|
static Number |
count(Object[] self,
Object value)
Counts the number of occurrences of the given value inside this array.
|
static Number |
count(short[] self,
Object value)
Counts the number of occurrences of the given value inside this array.
|
static int |
count(String self,
String text)
Deprecated.
|
static <T> Number |
count(T[] self,
Closure closure)
Counts the number of occurrences which satisfy the given closure from inside this array.
|
static <K> Map<K,Integer> |
countBy(Collection self,
Closure<K> closure)
Deprecated.
Use the Iterable version of countBy instead
|
static <K,E> Map<K,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> Map<K,Integer> |
countBy(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,E> Map<K,Integer> |
countBy(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> Map<K,Integer> |
countBy(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.
|
protected static StringBufferWriter |
createStringBufferWriter(StringBuffer self)
Deprecated.
|
protected static StringWriter |
createStringWriter(String self)
Deprecated.
|
static boolean |
deleteDir(File self)
Deprecated.
|
static CharSequence |
denormalize(CharSequence self)
Deprecated.
|
static String |
denormalize(String self)
Deprecated.
|
static boolean |
disjoint(Collection left,
Collection right)
Returns
true if the intersection of two collections is empty. |
static Number |
div(Character left,
Character right)
Divide one Character by another.
|
static Number |
div(Character left,
Number right)
Divide a Character by a Number.
|
static Number |
div(Number left,
Character right)
Divide a Number by a Character.
|
static void |
downto(BigDecimal self,
Number to,
Closure closure)
Iterates from this number down to the given number, inclusive,
decrementing by one each time.
|
static void |
downto(BigInteger self,
Number to,
Closure closure)
Iterates from this number down to the given number, inclusive,
decrementing by one each time.
|
static void |
downto(double self,
Number to,
Closure closure)
Iterates from this number down to the given number, inclusive,
decrementing by one each time.
|
static void |
downto(Double self,
Number to,
Closure closure)
Iterates from this number down to the given number, inclusive,
decrementing by one each time.
|
static void |
downto(float self,
Number to,
Closure closure)
Iterates from this number down to the given number, inclusive,
decrementing by one each time.
|
static void |
downto(Float self,
Number to,
Closure closure)
Iterates from this number down to the given number, inclusive,
decrementing by one each time.
|
static void |
downto(long self,
Number to,
Closure closure)
Iterates from this number down to the given number, inclusive,
decrementing by one each time.
|
static void |
downto(Long self,
Number to,
Closure closure)
Iterates from this number down to the given number, inclusive,
decrementing by one each time.
|
static void |
downto(Number self,
Number to,
Closure closure)
Iterates from this number down to the given number, inclusive,
decrementing by one each time.
|
static CharSequence |
drop(CharSequence self,
int num)
Deprecated.
|
static <T> List<T> |
drop(Iterable<T> self,
int num)
Drops the given number of elements from the head of this Iterable.
|
static <T> Iterator<T> |
drop(Iterator<T> self,
int num)
Drops the given number of elements from the head of this iterator if they are available.
|
static <T> List<T> |
drop(List<T> self,
int num)
Drops the given number of elements from the head of this list
if they are available.
|
static <K,V> Map<K,V> |
drop(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> T[] |
drop(T[] self,
int num)
Drops the given number of elements from the head of this array
if they are available.
|
static <T> List<T> |
dropWhile(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> Iterator<T> |
dropWhile(Iterator<T> self,
Closure<?> condition)
Creates an Iterator that returns a suffix of the elements from an original Iterator.
|
static <T> List<T> |
dropWhile(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> Map<K,V> |
dropWhile(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> 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 String |
dump(Object self)
Generates a detailed dump string of an object showing its class,
hashCode and fields.
|
static <T> Iterable<T> |
each(Iterable<T> self,
Closure closure) |
static <K,V> Map<K,V> |
each(Map<K,V> self,
Closure closure)
Allows a Map to be iterated through using a 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(Byte[] self,
Closure closure)
Traverse through each byte of this Byte array.
|
static void |
eachByte(File self,
Closure closure)
Deprecated.
|
static void |
eachByte(File self,
int bufferLen,
Closure closure)
Deprecated.
|
static void |
eachByte(InputStream is,
Closure closure)
Deprecated.
|
static void |
eachByte(InputStream is,
int bufferLen,
Closure closure)
Deprecated.
|
static void |
eachByte(URL url,
Closure closure)
Deprecated.
|
static void |
eachByte(URL url,
int bufferLen,
Closure closure)
Deprecated.
|
static void |
eachCombination(Iterable self,
Closure<?> function)
Applies a function on each combination of the input lists.
|
static void |
eachDir(File self,
Closure closure)
Deprecated.
|
static void |
eachDirMatch(File self,
Object nameFilter,
Closure closure)
Deprecated.
|
static void |
eachDirRecurse(File self,
Closure closure)
Deprecated.
|
static void |
eachFile(File self,
Closure closure)
Deprecated.
|
static void |
eachFile(File self,
FileType fileType,
Closure closure)
Deprecated.
|
static void |
eachFileMatch(File self,
FileType fileType,
Object nameFilter,
Closure closure)
Deprecated.
|
static void |
eachFileMatch(File self,
Object nameFilter,
Closure closure)
Deprecated.
|
static void |
eachFileRecurse(File self,
Closure closure)
Deprecated.
|
static void |
eachFileRecurse(File self,
FileType fileType,
Closure closure)
Deprecated.
|
static <T> T |
eachLine(CharSequence self,
Closure<T> closure)
Deprecated.
|
static <T> T |
eachLine(CharSequence self,
int firstLine,
Closure<T> closure)
Deprecated.
|
static <T> T |
eachLine(File self,
Closure<T> closure)
Deprecated.
|
static <T> T |
eachLine(File self,
int firstLine,
Closure<T> closure)
Deprecated.
|
static <T> T |
eachLine(File self,
String charset,
Closure<T> closure)
Deprecated.
|
static <T> T |
eachLine(File self,
String charset,
int firstLine,
Closure<T> closure)
Deprecated.
|
static <T> T |
eachLine(InputStream stream,
Closure<T> closure)
Deprecated.
|
static <T> T |
eachLine(InputStream stream,
int firstLine,
Closure<T> closure)
Deprecated.
|
static <T> T |
eachLine(InputStream stream,
String charset,
Closure<T> closure)
Deprecated.
|
static <T> T |
eachLine(InputStream stream,
String charset,
int firstLine,
Closure<T> closure)
Deprecated.
|
static <T> T |
eachLine(Reader self,
Closure<T> closure)
Deprecated.
|
static <T> T |
eachLine(Reader self,
int firstLine,
Closure<T> closure)
Deprecated.
|
static <T> T |
eachLine(String self,
Closure<T> closure)
Deprecated.
|
static <T> T |
eachLine(String self,
int firstLine,
Closure<T> closure)
Deprecated.
|
static <T> T |
eachLine(URL url,
Closure<T> closure)
Deprecated.
|
static <T> T |
eachLine(URL url,
int firstLine,
Closure<T> closure)
Deprecated.
|
static <T> T |
eachLine(URL url,
String charset,
Closure<T> closure)
Deprecated.
|
static <T> T |
eachLine(URL url,
String charset,
int firstLine,
Closure<T> closure)
Deprecated.
|
static String |
eachMatch(CharSequence self,
CharSequence regex,
Closure closure)
Deprecated.
|
static String |
eachMatch(CharSequence self,
Pattern pattern,
Closure closure)
Deprecated.
|
static String |
eachMatch(String self,
Pattern pattern,
Closure closure)
Deprecated.
|
static String |
eachMatch(String self,
String regex,
Closure closure)
Deprecated.
|
static void |
eachObject(File self,
Closure closure)
Deprecated.
|
static void |
eachObject(ObjectInputStream ois,
Closure closure)
Deprecated.
|
static <T> Iterator<List<T>> |
eachPermutation(Collection<T> self,
Closure closure)
Iterates over all permutations of a collection, running a closure for each iteration.
|
static <T> Iterable<T> |
eachWithIndex(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> Iterator<T> |
eachWithIndex(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 <K,V> Map<K,V> |
eachWithIndex(Map<K,V> self,
Closure closure)
Allows a Map to be iterated through using a 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(List left,
List right)
Compare the contents of two Lists.
|
static boolean |
equals(List left,
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(Map self,
Map other)
Compares two Maps treating coerced numerical values as identical.
|
static boolean |
equals(Object[] left,
List right)
Determines if the contents of this array are equal to the
contents of the given list, in the same order.
|
static <T> boolean |
equals(Set<T> self,
Set<T> other)
Compare the contents of two Sets for equality using Groovy's coercion rules.
|
static <T> boolean |
every(Iterable<T> self,
Closure closure)
Used to determine if the given predicate closure is valid (i.e.&nsbp;returns
true for all items in this iterable). |
static <T> boolean |
every(Iterator<T> self,
Closure closure)
Used to determine if the given predicate closure is valid (i.e.&nsbp;returns
true for all items in this iterator). |
static <K,V> boolean |
every(Map<K,V> self,
Closure closure)
Iterates over the entries of a map, and checks whether a predicate is
valid for all entries.
|
static boolean |
every(Object self)
Iterates over every element of a collection, and checks whether all
elements are
true according to the Groovy Truth. |
static boolean |
every(Object self,
Closure closure)
Used to determine if the given predicate closure is valid (i.e.&nsbp;returns
true for all items in this data structure). |
static Process |
execute(List commands)
Deprecated.
|
static Process |
execute(List commands,
List envp,
File dir)
Deprecated.
|
static Process |
execute(List commands,
String[] envp,
File dir)
Deprecated.
|
static Process |
execute(String self)
Deprecated.
|
static Process |
execute(String[] commandArray)
Deprecated.
|
static Process |
execute(String[] commandArray,
List envp,
File dir)
Deprecated.
|
static Process |
execute(String[] commandArray,
String[] envp,
File dir)
Deprecated.
|
static Process |
execute(String self,
List envp,
File dir)
Deprecated.
|
static Process |
execute(String self,
String[] envp,
File dir)
Deprecated.
|
static CharSequence |
expand(CharSequence self)
Deprecated.
|
static CharSequence |
expand(CharSequence self,
int tabStop)
Deprecated.
|
static String |
expand(String self)
Deprecated.
|
static String |
expand(String self,
int tabStop)
Deprecated.
|
static CharSequence |
expandLine(CharSequence self,
int tabStop)
Deprecated.
|
static String |
expandLine(String self,
int tabStop)
Deprecated.
|
static Writable |
filterLine(File self,
Closure closure)
Deprecated.
|
static Writable |
filterLine(File self,
String charset,
Closure closure)
Deprecated.
|
static void |
filterLine(File self,
Writer writer,
Closure closure)
Deprecated.
|
static void |
filterLine(File self,
Writer writer,
String charset,
Closure closure)
Deprecated.
|
static Writable |
filterLine(InputStream self,
Closure predicate)
Deprecated.
|
static Writable |
filterLine(InputStream self,
String charset,
Closure predicate)
Deprecated.
|
static void |
filterLine(InputStream self,
Writer writer,
Closure predicate)
Deprecated.
|
static void |
filterLine(InputStream self,
Writer writer,
String charset,
Closure predicate)
Deprecated.
|
static Writable |
filterLine(Reader reader,
Closure closure)
Deprecated.
|
static void |
filterLine(Reader reader,
Writer writer,
Closure closure)
Deprecated.
|
static Writable |
filterLine(URL self,
Closure predicate)
Deprecated.
|
static Writable |
filterLine(URL self,
String charset,
Closure predicate)
Deprecated.
|
static void |
filterLine(URL self,
Writer writer,
Closure predicate)
Deprecated.
|
static void |
filterLine(URL self,
Writer writer,
String charset,
Closure predicate)
Deprecated.
|
static CharSequence |
find(CharSequence self,
CharSequence regex)
Deprecated.
|
static CharSequence |
find(CharSequence self,
CharSequence regex,
Closure closure)
Deprecated.
|
static CharSequence |
find(CharSequence self,
Pattern pattern)
Deprecated.
|
static CharSequence |
find(CharSequence self,
Pattern pattern,
Closure closure)
Deprecated.
|
static <T> T |
find(Collection<T> self)
Finds the first item matching the IDENTITY Closure (i.e. matching Groovy truth).
|
static <T> T |
find(Collection<T> self,
Closure closure)
Finds the first value matching the closure condition.
|
static <K,V> Map.Entry<K,V> |
find(Map<K,V> self,
Closure<?> closure)
Finds the first entry matching the closure condition.
|
static Object |
find(Object self)
Finds the first item matching the IDENTITY Closure (i.e. matching Groovy truth).
|
static Object |
find(Object self,
Closure closure)
Finds the first value matching the closure condition
|
static String |
find(String self,
Pattern pattern)
Deprecated.
|
static String |
find(String self,
Pattern pattern,
Closure closure)
Deprecated.
|
static String |
find(String self,
String regex)
Deprecated.
|
static String |
find(String self,
String regex,
Closure closure)
Deprecated.
|
static <T> T |
find(T[] self,
Closure condition)
Finds the first element in the array that matches the given closure condition.
|
static List<CharSequence> |
findAll(CharSequence self,
CharSequence regex)
Deprecated.
|
static <T> List<T> |
findAll(CharSequence self,
CharSequence regex,
Closure<T> closure)
Deprecated.
|
static List<CharSequence> |
findAll(CharSequence self,
Pattern pattern)
Deprecated.
|
static <T> List<T> |
findAll(CharSequence self,
Pattern pattern,
Closure<T> closure)
Deprecated.
|
static <T> Collection<T> |
findAll(Collection<T> self)
Finds the items matching the IDENTITY Closure (i.e. matching Groovy truth).
|
static <T> Collection<T> |
findAll(Collection<T> self,
Closure closure)
Finds all values matching the closure condition.
|
static <K,V> Map<K,V> |
findAll(Map<K,V> self,
Closure closure)
Finds all entries matching the closure condition.
|
static Collection |
findAll(Object self)
Finds all items matching the IDENTITY Closure (i.e. matching Groovy truth).
|
static Collection |
findAll(Object self,
Closure closure)
Finds all items matching the closure condition.
|
static List<String> |
findAll(String self,
Pattern pattern)
Deprecated.
|
static <T> List<T> |
findAll(String self,
Pattern pattern,
Closure<T> closure)
Deprecated.
|
static List<String> |
findAll(String self,
String regex)
Deprecated.
|
static <T> List<T> |
findAll(String self,
String regex,
Closure<T> closure)
Deprecated.
|
static <T> Collection<T> |
findAll(T[] self)
Finds the elements of the array matching the IDENTITY Closure (i.e. matching Groovy truth).
|
static <T> Collection<T> |
findAll(T[] self,
Closure condition)
Finds all elements of the array matching the given Closure condition.
|
static int |
findIndexOf(Object self,
Closure closure)
Iterates over the elements of an iterable collection of items and returns
the index of the first item that matches the condition specified in the closure.
|
static int |
findIndexOf(Object self,
int startIndex,
Closure closure)
Iterates over the elements of an iterable collection of items, starting from a
specified startIndex, and returns the index of the first item that matches the
condition specified in the closure.
|
static List<Number> |
findIndexValues(Object self,
Closure closure)
Iterates over the elements of an iterable collection of items and returns
the index values of the items that match the condition specified in the closure.
|
static List<Number> |
findIndexValues(Object self,
Number startIndex,
Closure closure)
Iterates over the elements of an iterable collection of items, starting from
a specified startIndex, and returns the index values of the items that match
the condition specified in the closure.
|
static int |
findLastIndexOf(Object self,
Closure closure)
Iterates over the elements of an iterable collection of items and returns
the index of the last item that matches the condition specified in the closure.
|
static int |
findLastIndexOf(Object self,
int startIndex,
Closure closure)
Iterates over the elements of an iterable collection of items, starting
from a specified startIndex, and returns the index of the last item that
matches the condition specified in the closure.
|
static <T,U extends T,V extends T,E> |
findResult(Collection<E> self,
U defaultResult,
Closure<V> closure)
Iterates through the collection calling the given closure for each item but stopping once the first non-null
result is found and returning that result.
|
static <T,U> T |
findResult(Collection<U> self,
Closure<T> closure)
Iterates through the collection calling the given closure 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> |
findResult(Map<A,B> self,
U defaultResult,
Closure<V> closure)
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(Map<K,V> self,
Closure<T> closure)
Returns the first non-null closure result found by passing each map entry to the closure, otherwise null is returned.
|
static Object |
findResult(Object self,
Closure closure)
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 Object |
findResult(Object self,
Object defaultResult,
Closure closure)
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 <T,U> Collection<T> |
findResults(Collection<U> self,
Closure<T> filteringTransform)
Deprecated.
Use the Iterable version of findResults instead
|
static <T,U> Collection<T> |
findResults(Iterable<U> self,
Closure<T> filteringTransform)
Iterates through the Iterable transforming items using the supplied closure
and collecting any non-null results.
|
static <T,K,V> Collection<T> |
findResults(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> T |
first(Iterable<T> self)
Returns the first item from the Iterable.
|
static <T> T |
first(List<T> self)
Returns the first item from the List.
|
static <T> T |
first(T[] self)
Returns the first item from the array.
|
static Collection |
flatten(boolean[] self)
Flatten an array.
|
static Collection |
flatten(byte[] self)
Flatten an array.
|
static Collection |
flatten(char[] self)
Flatten an array.
|
static Collection<?> |
flatten(Collection<?> self)
Flatten a collection.
|
static <T> Collection<T> |
flatten(Collection<T> self,
Closure<? extends T> flattenUsing)
Flatten a collection.
|
static Collection |
flatten(double[] self)
Flatten an array.
|
static Collection |
flatten(float[] self)
Flatten an array.
|
static Collection |
flatten(int[] self)
Flatten an array.
|
static Collection<?> |
flatten(Iterable<?> self)
Flatten an Iterable.
|
static <T> Collection<T> |
flatten(Iterable<T> self,
Closure<? extends T> flattenUsing)
Flatten an Iterable.
|
static Collection |
flatten(long[] self)
Flatten an array.
|
static Collection |
flatten(Object[] self)
Flatten an array.
|
static Collection |
flatten(short[] self)
Flatten an array.
|
static <K,V> V |
get(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 boolean |
getAt(BitSet self,
int index)
Support the subscript operator for a Bitset
|
static BitSet |
getAt(BitSet self,
IntRange range)
Support retrieving a subset of a BitSet using a Range
|
static List<Boolean> |
getAt(boolean[] array,
Collection indices)
Support the subscript operator with a collection for a boolean array
|
static List<Boolean> |
getAt(boolean[] array,
IntRange range)
Support the subscript operator with an IntRange for a boolean array
|
static List<Boolean> |
getAt(boolean[] array,
ObjectRange range)
Support the subscript operator with an ObjectRange for a byte array
|
static List<Boolean> |
getAt(boolean[] array,
Range range)
Support the subscript operator with a range for a boolean array
|
static List<Byte> |
getAt(byte[] array,
Collection indices)
Support the subscript operator with a collection for a byte array
|
static List<Byte> |
getAt(byte[] array,
IntRange range)
Support the subscript operator with an IntRange for a byte array
|
static List<Byte> |
getAt(byte[] array,
ObjectRange range)
Support the subscript operator with an ObjectRange for a byte array
|
static List<Byte> |
getAt(byte[] array,
Range range)
Support the subscript operator with a range for a byte array
|
static List<Character> |
getAt(char[] array,
Collection indices)
Support the subscript operator with a collection for a char array
|
static List<Character> |
getAt(char[] array,
IntRange range)
Support the subscript operator with an IntRange for a char array
|
static List<Character> |
getAt(char[] array,
ObjectRange range)
Support the subscript operator with an ObjectRange for a char array
|
static List<Character> |
getAt(char[] array,
Range range)
Support the subscript operator with a range for a char array
|
static CharSequence |
getAt(CharSequence self,
Collection indices)
Deprecated.
|
static CharSequence |
getAt(CharSequence text,
EmptyRange range)
Deprecated.
|
static CharSequence |
getAt(CharSequence text,
int index)
Deprecated.
|
static CharSequence |
getAt(CharSequence text,
IntRange range)
Deprecated.
|
static CharSequence |
getAt(CharSequence text,
Range range)
Deprecated.
|
static List |
getAt(Collection coll,
String property)
Support the subscript operator for Collection.
|
static List<Double> |
getAt(double[] array,
Collection indices)
Support the subscript operator with a collection for a double array
|
static List<Double> |
getAt(double[] array,
IntRange range)
Support the subscript operator with an IntRange for a double array
|
static List<Double> |
getAt(double[] array,
ObjectRange range)
Support the subscript operator with an ObjectRange for a double array
|
static List<Double> |
getAt(double[] array,
Range range)
Support the subscript operator with a range for a double array
|
static List<Float> |
getAt(float[] array,
Collection indices)
Support the subscript operator with a collection for a float array
|
static List<Float> |
getAt(float[] array,
IntRange range)
Support the subscript operator with an IntRange for a float array
|
static List<Float> |
getAt(float[] array,
ObjectRange range)
Support the subscript operator with an ObjectRange for a float array
|
static List<Float> |
getAt(float[] array,
Range range)
Support the subscript operator with a range for a float array
|
static List<Integer> |
getAt(int[] array,
Collection indices)
Support the subscript operator with a collection for an int array
|
static List<Integer> |
getAt(int[] array,
IntRange range)
Support the subscript operator with an IntRange for an int array
|
static List<Integer> |
getAt(int[] array,
ObjectRange range)
Support the subscript operator with an ObjectRange for an int array
|
static List<Integer> |
getAt(int[] array,
Range range)
Support the subscript operator with a range for an int array
|
static <T> T |
getAt(Iterable<T> self,
int idx)
Support the subscript operator for an Iterable.
|
static <T> T |
getAt(Iterator<T> self,
int idx)
Support the subscript operator for an Iterator.
|
static <T> List<T> |
getAt(List<T> self,
Collection indices)
Select a List of items from a List using a Collection to
identify the indices to be selected.
|
static <T> List<T> |
getAt(List<T> self,
EmptyRange range)
Support the range subscript operator for a List.
|
static <T> T |
getAt(List<T> self,
int idx)
Support the subscript operator for a List.
|
static <T> List<T> |
getAt(List<T> self,
Range range)
Support the range subscript operator for a List.
|
static <T> List<T> |
getAt(ListWithDefault<T> self,
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> List<T> |
getAt(ListWithDefault<T> self,
EmptyRange range)
Support the range subscript operator for an eager or lazy List.
|
static <T> List<T> |
getAt(ListWithDefault<T> self,
Range range)
Support the range subscript operator for an eager or lazy List.
|
static List<Long> |
getAt(long[] array,
Collection indices)
Support the subscript operator with a collection for a long array
|
static List<Long> |
getAt(long[] array,
IntRange range)
Support the subscript operator with an IntRange for a long array
|
static List<Long> |
getAt(long[] array,
ObjectRange range)
Support the subscript operator with an ObjectRange for a long array
|
static List<Long> |
getAt(long[] array,
Range range)
Support the subscript operator with a range for a long array
|
static <K,V> V |
getAt(Map<K,V> self,
K key)
Support the subscript operator for a Map.
|
static List |
getAt(Matcher self,
Collection indices)
Deprecated.
|
static Object |
getAt(Matcher matcher,
int idx)
Deprecated.
|
static Object |
getAt(Object self,
String property)
Allows the subscript operator to be used to lookup dynamic property values.
|
static List<Short> |
getAt(short[] array,
Collection indices)
Support the subscript operator with a collection for a short array
|
static List<Short> |
getAt(short[] array,
IntRange range)
Support the subscript operator with an IntRange for a short array
|
static List<Short> |
getAt(short[] array,
ObjectRange range)
Support the subscript operator with an ObjectRange for a short array
|
static List<Short> |
getAt(short[] array,
Range range)
Support the subscript operator with a range for a short array
|
static String |
getAt(String self,
Collection indices)
Deprecated.
|
static String |
getAt(String text,
EmptyRange range)
Deprecated.
|
static String |
getAt(String text,
int index)
Deprecated.
|
static String |
getAt(String text,
IntRange range)
Deprecated.
|
static String |
getAt(String text,
Range range)
Deprecated.
|
static <T> List<T> |
getAt(T[] self,
Collection indices)
Select a List of items from an Object array using a Collection to
identify the indices to be selected.
|
static <T> List<T> |
getAt(T[] array,
EmptyRange range) |
static <T> List<T> |
getAt(T[] array,
IntRange range) |
static <T> List<T> |
getAt(T[] array,
ObjectRange range) |
static <T> List<T> |
getAt(T[] array,
Range range)
Support the range subscript operator for an Array
|
static byte[] |
getBytes(File file)
Deprecated.
|
static byte[] |
getBytes(InputStream is)
Deprecated.
|
static byte[] |
getBytes(URL url)
Deprecated.
|
static char[] |
getChars(CharSequence self)
Deprecated.
|
static char[] |
getChars(String self)
Deprecated.
|
static int |
getCount(Matcher matcher)
Deprecated.
|
static MetaClass |
getMetaClass(Class c)
Adds a "metaClass" property to all class objects so you can use the syntax
String.metaClass.myMethod = { println "foo" } |
static 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(Object obj)
Obtains a MetaClass for an object either from the registry or in the case of
a GroovyObject from the object itself.
|
static List<PropertyValue> |
getMetaPropertyValues(Object self)
Retrieves the list of
MetaProperty objects for 'self' and wraps it
in a list of PropertyValue objects that additionally provide
the value for each property of 'self'. |
static Map |
getProperties(Object self)
Convenience method that calls
getMetaPropertyValues(java.lang.Object) (self)
and provides the data in form of simple key/value pairs, i.e.&nsbp;without
type() information. |
static ClassLoader |
getRootLoader(ClassLoader self)
Iterates through the classloader parents until it finds a loader with a class
named "org.codehaus.groovy.tools.RootLoader".
|
protected static List |
getSubList(List self,
List splice) |
static String |
getText(BufferedReader reader)
Deprecated.
|
static String |
getText(File file)
Deprecated.
|
static String |
getText(File file,
String charset)
Deprecated.
|
static String |
getText(InputStream is)
Deprecated.
|
static String |
getText(InputStream is,
String charset)
Deprecated.
|
static String |
getText(Reader reader)
Deprecated.
|
static String |
getText(URL url)
Deprecated.
|
static String |
getText(URL url,
Map parameters)
Deprecated.
|
static String |
getText(URL url,
Map parameters,
String charset)
Deprecated.
|
static String |
getText(URL url,
String charset)
Deprecated.
|
static <T> Collection<T> |
grep(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> Collection<T> |
grep(Collection<T> self,
Object filter)
Iterates over the collection of items and returns each item that matches
the given filter - calling the
method used by switch statements. |
static Collection |
grep(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 Collection |
grep(Object self,
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. |
static <T> 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> Collection<T> |
grep(T[] self,
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. |
protected static <K,T> void |
groupAnswer(Map<K,List<T>> answer,
T element,
K value)
Groups the current element according to the value
|
static <K,T> Map<K,List<T>> |
groupBy(Collection<T> self,
Closure<K> closure)
Deprecated.
Use the Iterable version of groupBy instead
|
static Map |
groupBy(Collection self,
List<Closure> closures)
Sorts all collection members into (sub)groups determined by the supplied
mapping closures.
|
static Map |
groupBy(Collection self,
Object... closures)
Deprecated.
Use the Iterable version of groupBy instead
|
static <K,T> Map<K,List<T>> |
groupBy(Iterable<T> self,
Closure<K> closure)
Sorts all Iterable members into groups determined by the supplied mapping closure.
|
static Map |
groupBy(Iterable self,
List<Closure> closures)
Sorts all Iterable members into (sub)groups determined by the supplied
mapping closures.
|
static Map |
groupBy(Iterable self,
Object... closures)
Sorts all Iterable members into (sub)groups determined by the supplied
mapping closures.
|
static <G,K,V> Map<G,Map<K,V>> |
groupBy(Map<K,V> self,
Closure<G> closure)
Groups the members of a map into sub maps determined by the
supplied mapping closure.
|
static Map<Object,Map> |
groupBy(Map self,
List<Closure> closures)
Groups the members of a map into sub maps determined by the supplied
mapping closures.
|
static Map<Object,Map> |
groupBy(Map self,
Object... closures)
Groups the members of a map into sub maps determined by the supplied
mapping closures.
|
static Map |
groupBy(Object[] self,
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 Map |
groupBy(Object[] self,
Object... closures)
Sorts all array members into (sub)groups determined by the supplied
mapping closures as per the Iterable variant of this method.
|
static <K,T> Map<K,List<T>> |
groupBy(T[] self,
Closure<K> closure)
Sorts all array members into groups determined by the supplied mapping closure.
|
static <G,K,V> Map<G,List<Map.Entry<K,V>>> |
groupEntriesBy(Map<K,V> self,
Closure<G> closure)
Groups all map entries into groups determined by the
supplied mapping closure.
|
static boolean |
hasGroup(Matcher matcher)
Deprecated.
|
static MetaProperty |
hasProperty(Object self,
String name)
Returns true of the implementing MetaClass has a property of the given name
|
static <T> T |
head(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> T |
identity(Object self,
Closure<T> closure)
Allows the closure to be called for the object reference self.
|
static Boolean |
implies(Boolean left,
Boolean right)
Logical implication of two boolean operators
|
static <E,T,U extends T,V extends T> |
inject(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> |
inject(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,V extends T> |
inject(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> |
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.
|
static <E,T,U extends T,V extends T> |
inject(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 <Key,Value,T,U extends T,V extends T> |
inject(Map<Key,Value> self,
U initialValue,
Closure<V> 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 <T,V extends T> |
inject(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> |
inject(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 String |
inspect(Object self)
Inspects returns the String that matches what would be typed into a
terminal to create this object.
|
static Number |
intdiv(Character left,
Character right)
Integer Divide two Characters.
|
static Number |
intdiv(Character left,
Number right)
Integer Divide a Character by a Number.
|
static Number |
intdiv(Number left,
Character right)
Integer Divide a Number by a Character.
|
static Number |
intdiv(Number left,
Number right)
Integer Divide two Numbers.
|
static <T> Collection<T> |
intersect(Collection<T> left,
Collection<T> right)
Create a Collection composed of the intersection of both collections.
|
static <K,V> Map<K,V> |
intersect(Map<K,V> left,
Map<K,V> right)
Create a Map composed of the intersection of both maps.
|
static Object |
invokeMethod(Object object,
String method,
Object arguments)
Provide a dynamic method invocation method which can be overloaded in
classes to implement dynamic proxies easily.
|
static boolean |
is(Object self,
Object other)
Identity check.
|
static boolean |
isAllWhitespace(CharSequence self)
Deprecated.
|
static boolean |
isAllWhitespace(String self)
Deprecated.
|
static boolean |
isBigDecimal(CharSequence self)
Deprecated.
|
static boolean |
isBigDecimal(String self)
Deprecated.
|
static boolean |
isBigInteger(CharSequence self)
Deprecated.
|
static boolean |
isBigInteger(String self)
Deprecated.
|
static boolean |
isCase(CharSequence caseValue,
Object switchValue)
Deprecated.
|
static boolean |
isCase(Class caseValue,
Object switchValue)
Special 'Case' implementation for Class, which allows testing
for a certain class in a switch statement.
|
static boolean |
isCase(Collection caseValue,
Object switchValue)
'Case' implementation for collections which tests if the 'switch'
operand is contained in any of the 'case' values.
|
static boolean |
isCase(GString caseValue,
Object switchValue)
Deprecated.
|
static boolean |
isCase(Map caseValue,
Object switchValue)
'Case' implementation for maps which tests the groovy truth
value obtained using the 'switch' operand as key.
|
static boolean |
isCase(Number caseValue,
Number switchValue)
Special 'case' implementation for all numbers, which delegates to the
compareTo() method for comparing numbers of different
types. |
static boolean |
isCase(Object caseValue,
Object switchValue)
Method for overloading the behavior of the 'case' method in switch statements.
|
static boolean |
isCase(Pattern caseValue,
Object switchValue)
Deprecated.
|
static boolean |
isCase(String caseValue,
Object switchValue)
Deprecated.
|
static boolean |
isDigit(Character self)
Determines if a character is a digit.
|
static boolean |
isDouble(CharSequence self)
Deprecated.
|
static boolean |
isDouble(String self)
Deprecated.
|
static boolean |
isFloat(CharSequence self)
Deprecated.
|
static boolean |
isFloat(String self)
Deprecated.
|
static boolean |
isInteger(CharSequence self)
Deprecated.
|
static boolean |
isInteger(String self)
Deprecated.
|
static boolean |
isLetter(Character self)
Determines if a character is a letter.
|
static boolean |
isLetterOrDigit(Character self)
Determines if a character is a letter or digit.
|
static boolean |
isLong(CharSequence self)
Deprecated.
|
static boolean |
isLong(String self)
Deprecated.
|
static boolean |
isLowerCase(Character self)
Determine if a Character is lowercase.
|
static boolean |
isNumber(CharSequence self)
Deprecated.
|
static boolean |
isNumber(String self)
Deprecated.
|
static boolean |
isUpperCase(Character self)
Determine if a Character is uppercase.
|
static boolean |
isWhitespace(Character self)
Determines if a character is a whitespace character.
|
static Iterator<Byte> |
iterator(DataInputStream self)
Deprecated.
|
static <T> Iterator<T> |
iterator(Enumeration<T> enumeration)
Allows an Enumeration to behave like an Iterator.
|
static Iterator<Byte> |
iterator(InputStream self)
Deprecated.
|
static <T> Iterator<T> |
iterator(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 Iterator |
iterator(Matcher matcher)
Deprecated.
|
static Iterator |
iterator(Object o)
Attempts to create an Iterator for the given object by first
converting it to a Collection.
|
static Iterator<String> |
iterator(Reader self)
Deprecated.
|
static <T> Iterator<T> |
iterator(T[] a)
Attempts to create an Iterator for the given object by first
converting it to a Collection.
|
static String |
join(Collection self,
String separator)
Deprecated.
Use the Iterable version of join instead
|
static String |
join(Iterable self,
String separator)
Concatenates the
toString() representation of each
item in this Iterable, with the given String as a separator between each item. |
static String |
join(Iterator<Object> self,
String separator)
Concatenates the
toString() representation of each
item from the iterator, with the given String as a separator between
each item. |
static String |
join(Object[] self,
String separator)
Concatenates the
toString() representation of each
items in this array, with the given String as a separator between each
item. |
static <T> T |
last(Iterable<T> self)
Returns the last item from the Iterable.
|
static <T> T |
last(List<T> self)
Returns the last item from the List.
|
static <T> T |
last(T[] self)
Returns the last item from the array.
|
static <T> BlockingQueue<T> |
leftShift(BlockingQueue<T> self,
T value)
Overloads the left shift operator to provide an easy way to append
objects to a BlockingQueue.
|
static StringBuilder |
leftShift(CharSequence self,
Object value)
Deprecated.
|
static <T> Collection<T> |
leftShift(Collection<T> self,
T value)
Overloads the left shift operator to provide an easy way to append
objects to a Collection.
|
static File |
leftShift(File file,
byte[] bytes)
Deprecated.
|
static File |
leftShift(File file,
InputStream data)
Deprecated.
|
static File |
leftShift(File file,
Object text)
Deprecated.
|
static <K,V> Map<K,V> |
leftShift(Map<K,V> self,
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> Map<K,V> |
leftShift(Map<K,V> self,
Map<K,V> other)
Overloads the left shift operator to provide an easy way to put
one maps entries into another map.
|
static Number |
leftShift(Number self,
Number operand)
Implementation of the left shift operator for integral types.
|
static void |
leftShift(ObjectOutputStream self,
Object value)
Deprecated.
|
static OutputStream |
leftShift(OutputStream self,
byte[] value)
Deprecated.
|
static OutputStream |
leftShift(OutputStream self,
InputStream in)
Deprecated.
|
static Writer |
leftShift(OutputStream self,
Object value)
Deprecated.
|
static OutputStream |
leftShift(Socket self,
byte[] value)
Deprecated.
|
static Writer |
leftShift(Socket self,
Object value)
Deprecated.
|
static StringBuffer |
leftShift(StringBuffer self,
Object value)
Deprecated.
|
static StringBuilder |
leftShift(StringBuilder self,
Object value)
Deprecated.
|
static StringBuffer |
leftShift(String self,
Object value)
Deprecated.
|
static Writer |
leftShift(Writer self,
Object value)
Deprecated.
|
static boolean |
matches(CharSequence self,
Pattern pattern)
Deprecated.
|
static boolean |
matches(String self,
Pattern pattern)
Deprecated.
|
static <T> T |
max(Collection<T> self)
Deprecated.
Use the Iterable version of max instead
|
static <T> T |
max(Collection<T> self,
Closure closure)
Deprecated.
Use the Iterable version of max instead
|
static <T> T |
max(Collection<T> self,
Comparator<T> comparator)
Deprecated.
Use the Iterable version of max instead
|
static <T> T |
max(Iterable<T> self)
Adds max() method to Iterable objects.
|
static <T> T |
max(Iterable<T> self,
Closure closure)
Selects an item in the collection having the maximum
value as determined by the supplied closure.
|
static <T> T |
max(Iterable<T> self,
Comparator<T> comparator)
Selects the maximum value found in the Iterable using the given comparator.
|
static <T> T |
max(Iterator<T> self)
Adds max() method to Iterator objects.
|
static <T> T |
max(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(Iterator<T> self,
Comparator<T> comparator)
Selects the maximum value found from the Iterator using the given comparator.
|
static <K,V> Map.Entry<K,V> |
max(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,
Comparator<T> comparator)
Selects the maximum value found from the Object array using the given comparator.
|
static MetaClass |
metaClass(Class self,
Closure closure)
Sets/updates the metaclass for a given class to a closure.
|
static MetaClass |
metaClass(Object self,
Closure closure)
Sets/updates the metaclass for a given object to a closure.
|
static <T> T |
min(Collection<T> self)
Deprecated.
Use the Iterable version of min instead
|
static <T> T |
min(Collection<T> self,
Closure closure)
Deprecated.
Use the Iterable version of min instead
|
static <T> T |
min(Collection<T> self,
Comparator<T> comparator)
Deprecated.
Use the Iterable version of min instead
|
static <T> T |
min(Iterable<T> self)
Adds min() method to Collection objects.
|
static <T> T |
min(Iterable<T> self,
Closure closure)
Selects an item in the collection having the minimum
value as determined by the supplied closure.
|
static <T> T |
min(Iterable<T> self,
Comparator<T> comparator)
Selects the minimum value found in the Iterable using the given comparator.
|
static <T> T |
min(Iterator<T> self)
Adds min() method to Iterator objects.
|
static <T> T |
min(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(Iterator<T> self,
Comparator<T> comparator)
Selects the minimum value found from the Iterator using the given comparator.
|
static <K,V> Map.Entry<K,V> |
min(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,
Comparator<T> comparator)
Selects the minimum value found from the Object array using the given comparator.
|
static Number |
minus(Character left,
Character right)
Subtract one Character from another.
|
static Number |
minus(Character left,
Number right)
Subtract a Number from a Character.
|
static CharSequence |
minus(CharSequence self,
Object target)
Deprecated.
|
static <T> List<T> |
minus(List<T> self,
Collection<?> removeMe)
Create a List composed of the elements of the first list minus
every occurrence of elements of the given Collection.
|
static <T> List<T> |
minus(List<T> self,
Iterable<?> removeMe)
Create a List composed of the elements of the first list minus
every occurrence of elements of the given Iterable.
|
static <T> List<T> |
minus(List<T> self,
Object removeMe)
Create a new List composed of the elements of the first list minus every occurrence of the
given element to remove.
|
static <K,V> Map<K,V> |
minus(Map<K,V> self,
Map removeMe)
Create a Map composed of the entries of the first map minus the
entries of the given map.
|
static Number |
minus(Number left,
Character right)
Subtract a Character from a Number.
|
static <T> Set<T> |
minus(Set<T> self,
Collection<?> removeMe)
Create a Set composed of the elements of the first Set minus the
elements of the given Collection.
|
static <T> Set<T> |
minus(Set<T> self,
Iterable<?> removeMe)
Create a Set composed of the elements of the first Set minus the
elements from the given Iterable.
|
static <T> Set<T> |
minus(Set<T> self,
Object removeMe)
Create a Set composed of the elements of the first Set minus the given element.
|
static String |
minus(String self,
Object target)
Deprecated.
|
static <T> T[] |
minus(T[] self,
Iterable removeMe)
Create an array composed of the elements of the first array minus the
elements of the given Iterable.
|
static <T> T[] |
minus(T[] self,
Object removeMe)
Create a new object array composed of the elements of the first array
minus the element to remove.
|
static <T> T[] |
minus(T[] self,
Object[] removeMe)
Create an array composed of the elements of the first array minus the
elements of the given array.
|
static void |
mixin(Class self,
Class categoryClass)
Extend class globally with category methods.
|
static void |
mixin(Class self,
Class[] categoryClass)
Extend class globally with category methods.
|
static void |
mixin(Class self,
List<Class> categoryClasses)
Extend class globally with category methods.
|
static void |
mixin(MetaClass self,
Class categoryClass)
Extend class globally with category methods.
|
static void |
mixin(MetaClass self,
Class[] categoryClass)
Extend class globally with category methods.
|
static void |
mixin(MetaClass self,
List<Class> categoryClasses)
Extend object with category methods.
|
static Number |
mod(Number left,
Number right)
Performs a division modulus operation.
|
static Number |
multiply(BigDecimal left,
BigInteger right)
Multiply a BigDecimal and a BigInteger.
|
static Number |
multiply(BigDecimal left,
Double right)
Multiply a BigDecimal and a Double.
|
static Number |
multiply(Character left,
Character right)
Multiply two Characters.
|
static Number |
multiply(Character left,
Number right)
Multiply a Character by a Number.
|
static CharSequence |
multiply(CharSequence self,
Number factor)
Deprecated.
|
static <T> List<T> |
multiply(Collection<T> self,
Number factor)
Create a List composed of the elements of this list, repeated
a certain number of times.
|
static Number |
multiply(Number left,
Character right)
Multiply a Number by a Character.
|
static String |
multiply(String self,
Number factor)
Deprecated.
|
static DataInputStream |
newDataInputStream(File file)
Deprecated.
|
static DataOutputStream |
newDataOutputStream(File file)
Deprecated.
|
static BufferedInputStream |
newInputStream(File file)
Deprecated.
|
static BufferedInputStream |
newInputStream(URL url)
Deprecated.
|
static BufferedInputStream |
newInputStream(URL url,
Map parameters)
Deprecated.
|
static <T> T |
newInstance(Class<T> c)
Convenience method to dynamically create a new instance of this
class.
|
static <T> T |
newInstance(Class<T> c,
Object[] args)
Helper to construct a new instance from the given arguments.
|
static ObjectInputStream |
newObjectInputStream(File file)
Deprecated.
|
static ObjectInputStream |
newObjectInputStream(File file,
ClassLoader classLoader)
Deprecated.
|
static ObjectInputStream |
newObjectInputStream(InputStream inputStream)
Deprecated.
|
static ObjectInputStream |
newObjectInputStream(InputStream inputStream,
ClassLoader classLoader)
Deprecated.
|
static ObjectOutputStream |
newObjectOutputStream(File file)
Deprecated.
|
static ObjectOutputStream |
newObjectOutputStream(OutputStream outputStream)
Deprecated.
|
static BufferedOutputStream |
newOutputStream(File file)
Deprecated.
|
static PrintWriter |
newPrintWriter(File file)
Deprecated.
|
static PrintWriter |
newPrintWriter(File file,
String charset)
Deprecated.
|
static PrintWriter |
newPrintWriter(Writer writer)
Deprecated.
|
static BufferedReader |
newReader(File file)
Deprecated.
|
static BufferedReader |
newReader(File file,
String charset)
Deprecated.
|
static BufferedReader |
newReader(InputStream self)
Deprecated.
|
static BufferedReader |
newReader(InputStream self,
String charset)
Deprecated.
|
static BufferedReader |
newReader(URL url)
Deprecated.
|
static BufferedReader |
newReader(URL url,
Map parameters)
Deprecated.
|
static BufferedReader |
newReader(URL url,
Map parameters,
String charset)
Deprecated.
|
static BufferedReader |
newReader(URL url,
String charset)
Deprecated.
|
static BufferedWriter |
newWriter(File file)
Deprecated.
|
static BufferedWriter |
newWriter(File file,
boolean append)
Deprecated.
|
static BufferedWriter |
newWriter(File file,
String charset)
Deprecated.
|
static BufferedWriter |
newWriter(File file,
String charset,
boolean append)
Deprecated.
|
static Character |
next(Character self)
Increment a Character by one.
|
static CharSequence |
next(CharSequence self)
Deprecated.
|
static Number |
next(Number self)
Increment a Number by one.
|
static String |
next(String self)
Deprecated.
|
static CharSequence |
normalize(CharSequence self)
Deprecated.
|
static String |
normalize(String self)
Deprecated.
|
static int |
numberAwareCompareTo(Comparable self,
Comparable other)
Provides a method that compares two comparables using Groovy's
default number aware comparator.
|
static BitSet |
or(BitSet left,
BitSet right)
Bitwise OR together two BitSets.
|
static Boolean |
or(Boolean left,
Boolean right)
Logical disjunction of two boolean operators
|
static Number |
or(Number left,
Number right)
Bitwise OR together two numbers.
|
static CharSequence |
padLeft(CharSequence self,
Number numberOfChars)
Deprecated.
|
static CharSequence |
padLeft(CharSequence self,
Number numberOfChars,
CharSequence padding)
Deprecated.
|
static String |
padLeft(String self,
Number numberOfChars)
Deprecated.
|
static String |
padLeft(String self,
Number numberOfChars,
String padding)
Deprecated.
|
static CharSequence |
padRight(CharSequence self,
Number numberOfChars)
Deprecated.
|
static CharSequence |
padRight(CharSequence self,
Number numberOfChars,
CharSequence padding)
Deprecated.
|
static String |
padRight(String self,
Number numberOfChars)
Deprecated.
|
static String |
padRight(String self,
Number numberOfChars,
String padding)
Deprecated.
|
static <T> Set<List<T>> |
permutations(List<T> self)
Finds all permutations of a collection.
|
static <T,V> List<V> |
permutations(List<T> self,
Closure<V> function)
Finds all permutations of a collection, applies a function to each permutation and collects the result
into a list.
|
static Number |
plus(Character left,
Character right)
Add one Character to another.
|
static Number |
plus(Character left,
Number right)
Add a Character and a Number.
|
static CharSequence |
plus(CharSequence left,
Object value)
Deprecated.
|
static <T> Collection<T> |
plus(Collection<T> left,
Collection<T> right)
Create a Collection as a union of two collections.
|
static <T> Collection<T> |
plus(Collection<T> left,
Iterable<T> right)
Create a Collection as a union of a Collection and an Iterable.
|
static <T> Collection<T> |
plus(Collection<T> left,
T right)
Create a collection as a union of a Collection and an Object.
|
static <T> List<T> |
plus(List<T> self,
int index,
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> List<T> |
plus(List<T> self,
int index,
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> List<T> |
plus(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 <K,V> Map<K,V> |
plus(Map<K,V> self,
Collection<Map.Entry<K,V>> entries)
Returns a new
Map containing all entries from self and entries ,
giving precedence to entries . |
static <K,V> Map<K,V> |
plus(Map<K,V> left,
Map<K,V> right)
Returns a new
Map containing all entries from left and right ,
giving precedence to right . |
static Number |
plus(Number left,
Character right)
Add a Number and a Character.
|
static String |
plus(Number value,
String right)
Deprecated.
|
static String |
plus(StringBuffer left,
String value)
Deprecated.
|
static String |
plus(String left,
Object value)
Deprecated.
|
static <T> T[] |
plus(T[] left,
Collection<T> right)
Create an array containing elements from an original array plus those from a Collection.
|
static <T> T[] |
plus(T[] left,
Iterable<T> right)
Create an array containing elements from an original array plus those from an Iterable.
|
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(List<T> self)
Removes the last item from the List.
|
static Number |
power(BigDecimal self,
Integer exponent)
Power of a BigDecimal to an integer certain exponent.
|
static BigInteger |
power(BigInteger self,
BigInteger exponent)
Power of a BigInteger to an BigInteger certain exponent.
|
static Number |
power(BigInteger self,
Integer exponent)
Power of a BigInteger to an integer certain exponent.
|
static Number |
power(Integer self,
Integer exponent)
Power of an integer to an integer certain exponent.
|
static Number |
power(Long self,
Integer exponent)
Power of a long to an integer certain exponent.
|
static Number |
power(Number self,
Number exponent)
Power of a Number to a certain exponent.
|
static Character |
previous(Character self)
Decrement a Character by one.
|
static CharSequence |
previous(CharSequence self)
Deprecated.
|
static Number |
previous(Number self)
Decrement a Number by one.
|
static String |
previous(String self)
Deprecated.
|
protected static List |
primitiveArrayGet(Object self,
Collection indices)
Implements the getAt(Collection) method for primitive type arrays.
|
protected static Object |
primitiveArrayGet(Object self,
int idx)
Implements the getAt(int) method for primitive type arrays.
|
protected static List |
primitiveArrayGet(Object self,
Range range)
Implements the getAt(Range) method for primitive type arrays.
|
protected static Object |
primitiveArrayPut(Object self,
int idx,
Object newValue)
Implements the setAt(int idx) method for primitive type arrays.
|
static void |
print(Closure self,
Object value)
Print a value to the standard output stream.
|
static void |
print(Object self,
Object value)
Print a value formatted Groovy style to self if it
is a Writer, otherwise to the standard output stream.
|
static void |
print(Object self,
PrintWriter out)
Print to a console in interactive format.
|
static void |
print(PrintStream self,
Object value)
Print a value formatted Groovy style to the print stream.
|
static void |
print(PrintWriter self,
Object value)
Print a value formatted Groovy style to the print writer.
|
static void |
printf(Object self,
String format,
Object arg)
Prints a formatted string using the specified format string and
arguments.
|
static void |
printf(Object self,
String format,
Object[] values)
Printf to a console.
|
static void |
println(Closure self)
Print a linebreak to the standard output stream.
|
static void |
println(Closure self,
Object value)
Print a value (followed by a newline) to the standard output stream.
|
static void |
println(Object self)
Print a linebreak to the standard output stream.
|
static void |
println(Object self,
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 void |
println(Object self,
PrintWriter out)
Print to a console in interactive format.
|
static void |
println(PrintStream self,
Object value)
Print a value formatted Groovy style (followed by a newline) to the print stream.
|
static void |
println(PrintWriter self,
Object value)
Print a value formatted Groovy style (followed by a newline) to the print writer.
|
static <T> boolean |
push(List<T> self,
T value)
Appends an item to the List.
|
static <K,V> Map<K,V> |
putAll(Map<K,V> self,
Collection<Map.Entry<K,V>> entries)
Provides an easy way to append multiple Map.Entry values to a Map.
|
static void |
putAt(BitSet self,
int index,
boolean value)
Support subscript-style assignment for a BitSet.
|
static void |
putAt(BitSet self,
IntRange range,
boolean value)
Support assigning a range of values with a single assignment statement.
|
static <T> void |
putAt(List<T> self,
int idx,
T value)
A helper method to allow lists to work with subscript operators.
|
static void |
putAt(List self,
EmptyRange range,
Collection value)
A helper method to allow lists to work with subscript operators.
|
static void |
putAt(List self,
EmptyRange range,
Object value)
A helper method to allow lists to work with subscript operators.
|
static void |
putAt(List self,
IntRange range,
Collection col)
List subscript assignment operator when given a range as the index and
the assignment operand is a collection.
|
static void |
putAt(List self,
IntRange range,
Object value)
List subscript assignment operator when given a range as the index.
|
static void |
putAt(List self,
List splice,
List values)
A helper method to allow lists to work with subscript operators.
|
static void |
putAt(List self,
List splice,
Object value)
A helper method to allow lists to work with subscript operators.
|
static <K,V> V |
putAt(Map<K,V> self,
K key,
V value)
A helper method to allow maps to work with subscript operators
|
static void |
putAt(Object self,
String property,
Object newValue)
Allows the subscript operator to be used to set dynamically named property values.
|
static void |
putAt(StringBuffer self,
EmptyRange range,
Object value)
Deprecated.
|
static void |
putAt(StringBuffer self,
IntRange range,
Object value)
Deprecated.
|
static byte[] |
readBytes(File file)
Deprecated.
|
static String |
readLine(Reader self)
Deprecated.
|
static List<CharSequence> |
readLines(CharSequence self)
Deprecated.
|
static List<String> |
readLines(File file)
Deprecated.
|
static List<String> |
readLines(File file,
String charset)
Deprecated.
|
static List<String> |
readLines(InputStream stream)
Deprecated.
|
static List<String> |
readLines(InputStream stream,
String charset)
Deprecated.
|
static List<String> |
readLines(Reader reader)
Deprecated.
|
static List<String> |
readLines(String self)
Deprecated.
|
static List<String> |
readLines(URL self)
Deprecated.
|
static List<String> |
readLines(URL self,
String charset)
Deprecated.
|
static <T> boolean |
removeAll(Collection<T> self,
Closure condition)
Modifies this collection by removing the elements that are matched according
to the specified closure condition.
|
static boolean |
removeAll(Collection self,
Object[] items)
Modifies this collection by removing its elements that are contained
within the specified object array.
|
static boolean |
renameTo(File self,
String newPathName)
Deprecated.
|
static CharSequence |
replaceAll(CharSequence self,
CharSequence regex,
CharSequence replacement)
Deprecated.
|
static CharSequence |
replaceAll(CharSequence self,
CharSequence regex,
Closure closure)
Deprecated.
|
static CharSequence |
replaceAll(CharSequence self,
Pattern pattern,
CharSequence replacement)
Deprecated.
|
static String |
replaceAll(CharSequence self,
Pattern pattern,
Closure closure)
Deprecated.
|
static String |
replaceAll(String self,
Pattern pattern,
Closure closure)
Deprecated.
|
static String |
replaceAll(String self,
Pattern pattern,
String replacement)
Deprecated.
|
static String |
replaceAll(String self,
String regex,
Closure closure)
Deprecated.
|
static String |
replaceFirst(CharSequence self,
CharSequence regex,
CharSequence replacement)
Deprecated.
|
static String |
replaceFirst(CharSequence self,
CharSequence regex,
Closure closure)
Deprecated.
|
static CharSequence |
replaceFirst(CharSequence self,
Pattern pattern,
CharSequence replacement)
Deprecated.
|
static String |
replaceFirst(CharSequence self,
Pattern pattern,
Closure closure)
Deprecated.
|
static String |
replaceFirst(String self,
Pattern pattern,
Closure closure)
Deprecated.
|
static String |
replaceFirst(String self,
Pattern pattern,
String replacement)
Deprecated.
|
static String |
replaceFirst(String self,
String regex,
Closure closure)
Deprecated.
|
static List<MetaMethod> |
respondsTo(Object self,
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 List<MetaMethod> |
respondsTo(Object self,
String name,
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(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(Collection self,
Object[] items)
Modifies this collection so that it retains only its elements that are contained
in the specified array.
|
static CharSequence |
reverse(CharSequence self)
Deprecated.
|
static <T> Iterator<T> |
reverse(Iterator<T> self)
Reverses the iterator.
|
static <T> List<T> |
reverse(List<T> self)
Creates a new List with the identical contents to this list
but in reverse order.
|
static <T> List<T> |
reverse(List<T> self,
boolean mutate)
Reverses the elements in a list.
|
static String |
reverse(String self)
Deprecated.
|
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> List<T> |
reverseEach(List<T> self,
Closure closure)
Iterate over each element of the list in the reverse order.
|
static <K,V> Map<K,V> |
reverseEach(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 Number |
rightShift(Number self,
Number operand)
Implementation of the right shift operator for integral types.
|
static Number |
rightShiftUnsigned(Number self,
Number operand)
Implementation of the right shift (unsigned) operator for integral types.
|
static long |
round(Double number)
Round the value
|
static double |
round(Double number,
int precision)
Round the value
|
static int |
round(Float number)
Round the value
|
static float |
round(Float number,
int precision)
Round the value
|
static TimerTask |
runAfter(Timer timer,
int delay,
Closure closure)
Allows a simple syntax for using timers.
|
static void |
setBytes(File file,
byte[] bytes)
Deprecated.
|
static void |
setBytes(OutputStream os,
byte[] bytes)
Deprecated.
|
static void |
setIndex(Matcher matcher,
int idx)
Deprecated.
|
static void |
setMetaClass(Class self,
MetaClass metaClass)
Sets the metaclass for a given class.
|
static void |
setMetaClass(GroovyObject self,
MetaClass metaClass)
Set the metaclass for a GroovyObject.
|
static void |
setMetaClass(Object self,
MetaClass metaClass)
Set the metaclass for an object.
|
static void |
setText(File file,
String text)
Deprecated.
|
static void |
setText(File file,
String text,
String charset)
Deprecated.
|
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(CharSequence text)
Deprecated.
|
static int |
size(double[] array)
Allows arrays to behave similar to collections.
|
static long |
size(File self)
Deprecated.
|
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(Iterable self)
Provide the standard Groovy
size() method for Iterable . |
static int |
size(Iterator self)
Provide the standard Groovy
size() method for Iterator . |
static int |
size(long[] array)
Allows arrays to behave similar to collections.
|
static long |
size(Matcher self)
Deprecated.
|
static int |
size(Object[] self)
Provide the standard Groovy
size() method for an array. |
static int |
size(short[] array)
Allows arrays to behave similar to collections.
|
static int |
size(String text)
Deprecated.
|
static int |
size(StringBuffer buffer)
Deprecated.
|
static <T> List<T> |
sort(Collection<T> self)
Deprecated.
Use the Iterable version of sort instead
|
static <T> List<T> |
sort(Collection<T> self,
boolean mutate)
Deprecated.
Use the Iterable version of sort instead
|
static <T> List<T> |
sort(Collection<T> self,
boolean mutate,
Closure closure)
Deprecated.
Use the Iterable version of sort instead
|
static <T> List<T> |
sort(Collection<T> self,
boolean mutate,
Comparator<T> comparator)
Deprecated.
Use the Iterable version of sort instead
|
static <T> List<T> |
sort(Collection<T> self,
Closure closure)
Sorts this Collection using the given Closure to determine the correct ordering.
|
static <T> List<T> |
sort(Collection<T> self,
Comparator<T> comparator)
Deprecated.
Use the Iterable version of sort instead
|
static <T> List<T> |
sort(Iterable<T> self)
Sorts the Collection.
|
static <T> List<T> |
sort(Iterable<T> self,
boolean mutate)
Sorts the Iterable.
|
static <T> List<T> |
sort(Iterable<T> self,
boolean mutate,
Closure closure)
Sorts this Iterable using the given Closure to determine the correct ordering.
|
static <T> List<T> |
sort(Iterable<T> self,
boolean mutate,
Comparator<T> comparator)
Sorts the Iterable using the given Comparator.
|
static <T> List<T> |
sort(Iterable<T> self,
Closure closure)
Sorts this Iterable using the given Closure to determine the correct ordering.
|
static <T> Iterator<T> |
sort(Iterator<T> self)
Sorts the given iterator items into a sorted iterator.
|
static <T> Iterator<T> |
sort(Iterator<T> self,
Closure closure)
Sorts the given iterator items into a sorted iterator using the Closure to determine the correct ordering.
|
static <T> Iterator<T> |
sort(Iterator<T> self,
Comparator<T> comparator)
Sorts the given iterator items into a sorted iterator using the comparator.
|
static <K,V> Map<K,V> |
sort(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> Map<K,V> |
sort(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> Map<K,V> |
sort(Map<K,V> self,
Comparator<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> SortedMap<K,V> |
sort(SortedMap<K,V> self)
Avoids doing unnecessary work when sorting an already sorted map (i.e.
|
static <T> SortedSet<T> |
sort(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,
Comparator<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,
Comparator<T> comparator)
Sorts the given array into sorted order using the given comparator.
|
static CharSequence[] |
split(CharSequence self)
Deprecated.
|
static <T> Collection<Collection<T>> |
split(Collection<T> self,
Closure closure)
Splits all items into two collections based on the closure condition.
|
static String[] |
split(GString self)
Deprecated.
|
static Collection |
split(Object self,
Closure closure)
Splits all items into two lists based on the closure condition.
|
static String[] |
split(String self)
Deprecated.
|
static <T> T |
splitEachLine(CharSequence self,
CharSequence regex,
Closure<T> closure)
Deprecated.
|
static <T> T |
splitEachLine(CharSequence self,
Pattern pattern,
Closure<T> closure)
Deprecated.
|
static <T> T |
splitEachLine(File self,
Pattern pattern,
Closure<T> closure)
Deprecated.
|
static <T> T |
splitEachLine(File self,
Pattern pattern,
String charset,
Closure<T> closure)
Deprecated.
|
static <T> T |
splitEachLine(File self,
String regex,
Closure<T> closure)
Deprecated.
|
static <T> T |
splitEachLine(File self,
String regex,
String charset,
Closure<T> closure)
Deprecated.
|
static <T> T |
splitEachLine(InputStream stream,
Pattern pattern,
Closure<T> closure)
Deprecated.
|
static <T> T |
splitEachLine(InputStream stream,
Pattern pattern,
String charset,
Closure<T> closure)
Deprecated.
|
static <T> T |
splitEachLine(InputStream stream,
String regex,
Closure<T> closure)
Deprecated.
|
static <T> T |
splitEachLine(InputStream stream,
String regex,
String charset,
Closure<T> closure)
Deprecated.
|
static <T> T |
splitEachLine(Reader self,
Pattern pattern,
Closure<T> closure)
Deprecated.
|
static <T> T |
splitEachLine(Reader self,
String regex,
Closure<T> closure)
Deprecated.
|
static <T> T |
splitEachLine(String self,
Pattern pattern,
Closure<T> closure)
Deprecated.
|
static <T> T |
splitEachLine(String self,
String regex,
Closure<T> closure)
Deprecated.
|
static <T> T |
splitEachLine(URL self,
Pattern pattern,
Closure<T> closure)
Deprecated.
|
static <T> T |
splitEachLine(URL self,
Pattern pattern,
String charset,
Closure<T> closure)
Deprecated.
|
static <T> T |
splitEachLine(URL self,
String regex,
Closure<T> closure)
Deprecated.
|
static <T> T |
splitEachLine(URL self,
String regex,
String charset,
Closure<T> closure)
Deprecated.
|
static SpreadMap |
spread(Map self)
Synonym for
toSpreadMap(java.util.Map) . |
static String |
sprintf(Object self,
String format,
Object arg)
Returns a formatted string using the specified format string and
arguments.
|
static String |
sprintf(Object self,
String format,
Object[] values)
Sprintf to a string.
|
static void |
step(Number self,
Number to,
Number stepNumber,
Closure closure)
Iterates from this number up to the given number using a step increment.
|
static CharSequence |
stripIndent(CharSequence self)
Deprecated.
|
static CharSequence |
stripIndent(CharSequence self,
int numChars)
Deprecated.
|
static String |
stripIndent(String self)
Deprecated.
|
static String |
stripIndent(String self,
int numChars)
Deprecated.
|
static CharSequence |
stripMargin(CharSequence self)
Deprecated.
|
static CharSequence |
stripMargin(CharSequence self,
char marginChar)
Deprecated.
|
static String |
stripMargin(CharSequence self,
CharSequence marginChar)
Deprecated.
|
static String |
stripMargin(String self)
Deprecated.
|
static String |
stripMargin(String self,
char marginChar)
Deprecated.
|
static String |
stripMargin(String self,
String marginChar)
Deprecated.
|
static <K,V> Map<K,V> |
subMap(Map<K,V> map,
Collection<K> keys)
Creates a sub-Map containing the given keys.
|
static <K,V> Map<K,V> |
subMap(Map<K,V> map,
K[] keys)
Creates a sub-Map containing the given keys.
|
static <T> Set<List<T>> |
subsequences(List<T> self)
Finds all non-null subsequences of a list.
|
static Object |
sum(Collection self)
Deprecated.
Use the Iterable version of sum instead
|
static Object |
sum(Collection self,
Closure closure)
Deprecated.
Use the Iterable version of sum instead
|
static Object |
sum(Collection self,
Object initialValue)
Deprecated.
Use the Iterable version of sum instead
|
static Object |
sum(Collection self,
Object initialValue,
Closure closure)
Deprecated.
Use the Iterable version of sum instead
|
static Object |
sum(Iterable self)
Sums the items in an Iterable.
|
static Object |
sum(Iterable self,
Closure closure)
Sums the result of apply a closure to each item of an Iterable.
|
static Object |
sum(Iterable self,
Object initialValue)
Sums the items in an Iterable, adding the result to some initial value.
|
static Object |
sum(Iterable self,
Object initialValue,
Closure closure)
Sums the result of applying a closure to each item of an Iterable to some initial value.
|
static Object |
sum(Iterator<Object> self)
Sums the items from an Iterator.
|
static Object |
sum(Iterator<Object> self,
Closure closure)
Sums the result of apply a closure to each item returned from an iterator.
|
static Object |
sum(Iterator<Object> self,
Object initialValue)
Sums the items from an Iterator, adding the result to some initial value.
|
static Object |
sum(Iterator<Object> self,
Object initialValue,
Closure closure)
Sums the result of applying a closure to each item of an Iterator to some initial value.
|
static Object |
sum(Object[] self)
Sums the items in an array.
|
static Object |
sum(Object[] self,
Closure closure)
Sums the result of apply a closure to each item of an array.
|
static Object |
sum(Object[] self,
Object initialValue)
Sums the items in an array, adding the result to some initial value.
|
static Object |
sum(Object[] self,
Object initialValue,
Closure closure)
Sums the result of applying a closure to each item of an array to some initial value.
|
static <T> List<T> |
tail(List<T> self)
Returns the items from the List excluding the first item.
|
static <T> T[] |
tail(T[] self)
Returns the items from the Object array excluding the first item.
|
static CharSequence |
take(CharSequence self,
int num)
Deprecated.
|
static <T> List<T> |
take(Iterable<T> self,
int num)
Returns the first
num elements from the head of this Iterable. |
static <T> Iterator<T> |
take(Iterator<T> self,
int num)
Returns an iterator of up to the first
num elements from this iterator. |
static <T> List<T> |
take(List<T> self,
int num)
Returns the first
num elements from the head of this list. |
static <K,V> Map<K,V> |
take(Map<K,V> self,
int num)
Returns a new map containing the first
num elements from the head of this map. |
static <T> T[] |
take(T[] self,
int num)
Returns the first
num elements from the head of this array. |
static <T> List<T> |
takeWhile(Iterable<T> self,
Closure condition)
Returns a List containing the longest prefix of the elements from this Iterable
where each element passed to the given closure evaluates to true.
|
static <T> Iterator<T> |
takeWhile(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> List<T> |
takeWhile(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> Map<K,V> |
takeWhile(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> 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 void |
times(Number self,
Closure closure)
Executes the closure this many times, starting from zero.
|
static String |
toArrayString(Object[] self)
Returns the string representation of the given array.
|
static BigDecimal |
toBigDecimal(CharSequence self)
Deprecated.
|
static BigDecimal |
toBigDecimal(Number self)
Transform a Number into a BigDecimal
|
static BigDecimal |
toBigDecimal(String self)
Deprecated.
|
static BigInteger |
toBigInteger(CharSequence self)
Deprecated.
|
static BigInteger |
toBigInteger(Number self)
Transform this Number into a BigInteger.
|
static BigInteger |
toBigInteger(String self)
Deprecated.
|
static Boolean |
toBoolean(Boolean self)
Identity conversion which returns Boolean.TRUE for a true Boolean and Boolean.FALSE for a false Boolean.
|
static Boolean |
toBoolean(String self)
Deprecated.
|
static Character |
toCharacter(String self)
Deprecated.
|
static Double |
toDouble(CharSequence self)
Deprecated.
|
static Double |
toDouble(Number self)
Transform a Number into a Double
|
static Double |
toDouble(String self)
Deprecated.
|
static Float |
toFloat(CharSequence self)
Deprecated.
|
static Float |
toFloat(Number self)
Transform a Number into a Float
|
static Float |
toFloat(String self)
Deprecated.
|
static Integer |
toInteger(CharSequence self)
Deprecated.
|
static Integer |
toInteger(Number self)
Transform a Number into an Integer
|
static Integer |
toInteger(String self)
Deprecated.
|
static List<CharSequence> |
tokenize(CharSequence self)
Deprecated.
|
static List<CharSequence> |
tokenize(CharSequence self,
Character token)
Deprecated.
|
static List<CharSequence> |
tokenize(CharSequence self,
CharSequence token)
Deprecated.
|
static List<String> |
tokenize(String self)
Deprecated.
|
static List<String> |
tokenize(String self,
Character token)
Deprecated.
|
static List<String> |
tokenize(String self,
String token)
Deprecated.
|
static List<Boolean> |
toList(boolean[] array)
Converts this array to a List of the same size, with each element
added to the list.
|
static List<Byte> |
toList(byte[] array)
Converts this array to a List of the same size, with each element
added to the list.
|
static List<Character> |
toList(char[] array)
Converts this array to a List of the same size, with each element
added to the list.
|
static List<CharSequence> |
toList(CharSequence self)
Deprecated.
|
static <T> List<T> |
toList(Collection<T> self)
Convert a Collection to a List.
|
static List<Double> |
toList(double[] array)
Converts this array to a List of the same size, with each element
added to the list.
|
static <T> List<T> |
toList(Enumeration<T> self)
Convert an enumeration to a List.
|
static List<Float> |
toList(float[] array)
Converts this array to a List of the same size, with each element
added to the list.
|
static List<Integer> |
toList(int[] array)
Converts this array to a List of the same size, with each element
added to the list.
|
static <T> List<T> |
toList(Iterable<T> self)
Convert an Iterable to a List.
|
static <T> List<T> |
toList(Iterator<T> self)
Convert an iterator to a List.
|
static List<Long> |
toList(long[] array)
Converts this array to a List of the same size, with each element
added to the list.
|
static List<Short> |
toList(short[] array)
Converts this array to a List of the same size, with each element
added to the list.
|
static List<String> |
toList(String self)
Deprecated.
|
static <T> List<T> |
toList(T[] array)
Allows conversion of arrays into a mutable List.
|
static String |
toListString(Collection self)
Returns the string representation of the given list.
|
static String |
toListString(Collection self,
int maxSize)
Returns the string representation of the given list.
|
static Long |
toLong(CharSequence self)
Deprecated.
|
static Long |
toLong(Number self)
Transform a Number into a Long
|
static Long |
toLong(String self)
Deprecated.
|
static char |
toLowerCase(Character self)
Converts the character to lowercase.
|
static String |
toMapString(Map self)
Returns the string representation of this map.
|
static String |
toMapString(Map self,
int maxSize)
Returns the string representation of this map.
|
static Set<Boolean> |
toSet(boolean[] array)
Converts this array to a Set, with each unique element
added to the set.
|
static Set<Byte> |
toSet(byte[] array)
Converts this array to a Set, with each unique element
added to the set.
|
static Set<Character> |
toSet(char[] array)
Converts this array to a Set, with each unique element
added to the set.
|
static Set<CharSequence> |
toSet(CharSequence self)
Deprecated.
|
static <T> Set<T> |
toSet(Collection<T> self)
Convert a Collection to a Set.
|
static Set<Double> |
toSet(double[] array)
Converts this array to a Set, with each unique element
added to the set.
|
static <T> Set<T> |
toSet(Enumeration<T> self)
Convert an enumeration to a Set.
|
static Set<Float> |
toSet(float[] array)
Converts this array to a Set, with each unique element
added to the set.
|
static Set<Integer> |
toSet(int[] array)
Converts this array to a Set, with each unique element
added to the set.
|
static <T> Set<T> |
toSet(Iterator<T> self)
Convert an iterator to a Set.
|
static Set<Long> |
toSet(long[] array)
Converts this array to a Set, with each unique element
added to the set.
|
static Set<Short> |
toSet(short[] array)
Converts this array to a Set, with each unique element
added to the set.
|
static Set<String> |
toSet(String self)
Deprecated.
|
static Short |
toShort(CharSequence self)
Deprecated.
|
static Short |
toShort(String self)
Deprecated.
|
static SpreadMap |
toSpreadMap(List self)
Creates a spreadable map from this list.
|
static SpreadMap |
toSpreadMap(Map self)
Returns a new
SpreadMap from this map. |
static SpreadMap |
toSpreadMap(Object[] self)
Creates a spreadable map from this array.
|
static String |
toString(AbstractCollection self)
Returns the string representation of the given collection.
|
static String |
toString(AbstractMap self)
Returns the string representation of the given map.
|
static String |
toString(boolean[] self)
Returns the string representation of the given array.
|
static String |
toString(byte[] self)
Returns the string representation of the given array.
|
static String |
toString(char[] self)
Returns the string representation of the given array.
|
static String |
toString(double[] self)
Returns the string representation of the given array.
|
static String |
toString(float[] self)
Returns the string representation of the given array.
|
static String |
toString(int[] self)
Returns the string representation of the given array.
|
static String |
toString(long[] self)
Returns the string representation of the given array.
|
static String |
toString(Object value)
Create a String representation of this object.
|
static String |
toString(Object[] self)
Returns the string representation of this array's contents.
|
static String |
toString(short[] self)
Returns the string representation of the given array.
|
static char |
toUpperCase(Character self)
Converts the character to uppercase.
|
static URI |
toURI(CharSequence self)
Deprecated.
|
static URI |
toURI(String self)
Deprecated.
|
static URL |
toURL(CharSequence self)
Deprecated.
|
static URL |
toURL(String self)
Deprecated.
|
static CharSequence |
tr(CharSequence self,
CharSequence sourceSet,
CharSequence replacementSet)
Deprecated.
|
static String |
tr(String self,
String sourceSet,
String replacementSet)
Deprecated.
|
static void |
transformChar(Reader self,
Writer writer,
Closure closure)
Deprecated.
|
static void |
transformLine(Reader reader,
Writer writer,
Closure closure)
Deprecated.
|
static List |
transpose(List self)
Adds GroovyCollections#transpose(List) as a method on lists.
|
static void |
traverse(File self,
Closure closure)
Deprecated.
|
static void |
traverse(File self,
Map<String,Object> options)
Deprecated.
|
static void |
traverse(File self,
Map<String,Object> options,
Closure closure)
Deprecated.
|
static double |
trunc(Double number)
Truncate the value
|
static double |
trunc(Double number,
int precision)
Truncate the value
|
static float |
trunc(Float number)
Truncate the value
|
static float |
trunc(Float number,
int precision)
Truncate the value
|
static Number |
unaryMinus(Number left)
Negates the number.
|
static Number |
unaryPlus(Number left)
Returns the number, effectively being a noop for numbers.
|
static CharSequence |
unexpand(CharSequence self)
Deprecated.
|
static CharSequence |
unexpand(CharSequence self,
int tabStop)
Deprecated.
|
static String |
unexpand(String self)
Deprecated.
|
static String |
unexpand(String self,
int tabStop)
Deprecated.
|
static CharSequence |
unexpandLine(CharSequence self,
int tabStop)
Deprecated.
|
static String |
unexpandLine(String self,
int tabStop)
Deprecated.
|
static <T> Collection<T> |
unique(Collection<T> self)
Modifies this collection to remove all duplicated items, using the
default comparator.
|
static <T> Collection<T> |
unique(Collection<T> self,
boolean mutate)
Remove all duplicates from a given Collection using the default comparator.
|
static <T> Collection<T> |
unique(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> Collection<T> |
unique(Collection<T> self,
boolean mutate,
Comparator<T> comparator)
Remove all duplicates from a given Collection.
|
static <T> Collection<T> |
unique(Collection<T> self,
Closure closure)
A convenience method for making a collection unique using a Closure
to determine duplicate (equal) items.
|
static <T> Collection<T> |
unique(Collection<T> self,
Comparator<T> comparator)
Remove all duplicates from a given Collection.
|
static <T> Iterator<T> |
unique(Iterator<T> self)
Returns an iterator equivalent to this iterator all duplicated items removed
by using the default comparator.
|
static <T> Iterator<T> |
unique(Iterator<T> self,
Closure closure)
Returns an iterator equivalent to this iterator but with all duplicated items
removed by using a Closure to determine duplicate (equal) items.
|
static <T> Iterator<T> |
unique(Iterator<T> self,
Comparator<T> comparator)
Returns an iterator equivalent to this iterator with all duplicated
items removed by using the supplied comparator.
|
static void |
upto(BigDecimal self,
Number to,
Closure closure)
Iterates from this number up to the given number, inclusive,
incrementing by one each time.
|
static void |
upto(BigInteger self,
Number to,
Closure closure)
Iterates from this number up to the given number, inclusive,
incrementing by one each time.
|
static void |
upto(double self,
Number to,
Closure closure)
Iterates from this number up to the given number, inclusive,
incrementing by one each time.
|
static void |
upto(Double self,
Number to,
Closure closure)
Iterates from this number up to the given number, inclusive,
incrementing by one each time.
|
static void |
upto(float self,
Number to,
Closure closure)
Iterates from this number up to the given number, inclusive,
incrementing by one each time.
|
static void |
upto(Float self,
Number to,
Closure closure)
Iterates from this number up to the given number, inclusive,
incrementing by one each time.
|
static void |
upto(long self,
Number to,
Closure closure)
Iterates from this number up to the given number, inclusive,
incrementing by one each time.
|
static void |
upto(Long self,
Number to,
Closure closure)
Iterates from this number up to the given number, inclusive,
incrementing by one each time.
|
static void |
upto(Number self,
Number to,
Closure closure)
Iterates from this number up to the given number, inclusive,
incrementing by one each time.
|
static <T> T |
use(Object self,
Class categoryClass,
Closure<T> closure)
Scoped use method
|
static <T> T |
use(Object self,
List<Class> categoryClassList,
Closure<T> closure)
Scoped use method with list of categories.
|
static Object |
use(Object self,
Object[] array)
Allows you to use a list of categories, specifying the list as varargs.
|
static <T,U> T |
with(U self,
Closure<T> closure)
Allows the closure to be called for the object reference self.
|
static <T> T |
withDataInputStream(File file,
Closure<T> closure)
Deprecated.
|
static <T> T |
withDataOutputStream(File file,
Closure<T> closure)
Deprecated.
|
static <T> List<T> |
withDefault(List<T> self,
Closure init)
An alias for
withLazyDefault which decorates a list allowing
it to grow when called with index values outside the normal list bounds. |
static <K,V> Map<K,V> |
withDefault(Map<K,V> self,
Closure init)
Wraps a map using the decorator pattern with a wrapper that intercepts all calls
to
get(key) . |
static <T> List<T> |
withEagerDefault(List<T> self,
Closure init)
Decorates a list allowing it to grow when called with a non-existent index value.
|
static Object |
withInputStream(File file,
Closure closure)
Deprecated.
|
static <T> T |
withInputStream(URL url,
Closure<T> closure)
Deprecated.
|
static <T> List<T> |
withLazyDefault(List<T> self,
Closure init)
Decorates a list allowing it to grow when called with a non-existent index value.
|
static <T> T |
withObjectInputStream(File file,
ClassLoader classLoader,
Closure<T> closure)
Deprecated.
|
static <T> T |
withObjectInputStream(File file,
Closure<T> closure)
Deprecated.
|
static <T> T |
withObjectInputStream(InputStream inputStream,
ClassLoader classLoader,
Closure<T> closure)
Deprecated.
|
static <T> T |
withObjectInputStream(InputStream inputStream,
Closure<T> closure)
Deprecated.
|
static <T> T |
withObjectOutputStream(File file,
Closure<T> closure)
Deprecated.
|
static <T> T |
withObjectOutputStream(OutputStream outputStream,
Closure<T> closure)
Deprecated.
|
static <T> T |
withObjectStreams(Socket socket,
Closure<T> closure)
Deprecated.
|
static Object |
withOutputStream(File file,
Closure closure)
Deprecated.
|
static <T> T |
withPrintWriter(File file,
Closure<T> closure)
Deprecated.
|
static <T> T |
withPrintWriter(File file,
String charset,
Closure<T> closure)
Deprecated.
|
static <T> T |
withPrintWriter(Writer writer,
Closure<T> closure)
Deprecated.
|
static <T> T |
withReader(File file,
Closure<T> closure)
Deprecated.
|
static <T> T |
withReader(File file,
String charset,
Closure<T> closure)
Deprecated.
|
static <T> T |
withReader(InputStream in,
Closure<T> closure)
Deprecated.
|
static <T> T |
withReader(InputStream in,
String charset,
Closure<T> closure)
Deprecated.
|
static <T> T |
withReader(Reader reader,
Closure<T> closure)
Deprecated.
|
static <T> T |
withReader(URL url,
Closure<T> closure)
Deprecated.
|
static <T> T |
withReader(URL url,
String charset,
Closure<T> closure)
Deprecated.
|
static <T> T |
withStream(InputStream stream,
Closure<T> closure)
Deprecated.
|
static <T> T |
withStream(OutputStream os,
Closure<T> closure)
Deprecated.
|
static <T> T |
withStreams(Socket socket,
Closure<T> closure)
Deprecated.
|
static Object |
withTraits(Object self,
Class<?>... traits)
Dynamically wraps an instance into something which implements the
supplied trait classes.
|
static <T> T |
withWriter(File file,
Closure<T> closure)
Deprecated.
|
static <T> T |
withWriter(File file,
String charset,
Closure<T> closure)
Deprecated.
|
static <T> T |
withWriter(OutputStream stream,
Closure<T> closure)
Deprecated.
|
static <T> T |
withWriter(OutputStream stream,
String charset,
Closure<T> closure)
Deprecated.
|
static <T> T |
withWriter(Writer writer,
Closure<T> closure)
Deprecated.
|
static <T> T |
withWriterAppend(File file,
Closure<T> closure)
Deprecated.
|
static <T> T |
withWriterAppend(File file,
String charset,
Closure<T> closure)
Deprecated.
|
static void |
write(File file,
String text)
Deprecated.
|
static void |
write(File file,
String text,
String charset)
Deprecated.
|
static void |
write(Writer self,
Writable writable)
Deprecated.
|
static void |
writeLine(BufferedWriter writer,
String line)
Deprecated.
|
static BitSet |
xor(BitSet left,
BitSet right)
Bitwise XOR together two BitSets.
|
static Boolean |
xor(Boolean left,
Boolean right)
Exclusive disjunction of two boolean operators
|
static Number |
xor(Number left,
Number right)
Bitwise XOR together two Numbers.
|
cloneSimilarCollection, cloneSimilarMap, closeQuietly, closeWithWarning, createSimilarArray, createSimilarCollection, createSimilarCollection, createSimilarList, createSimilarMap, createSimilarOrDefaultCollection, createSimilarSet, normaliseIndex, sameType, subListBorders, subListBorders
public static final Class[] additionals
public static final Class[] DGM_LIKE_CLASSES
public static boolean is(Object self, Object other)
def same = this.is(that)
self
- an objectother
- an object to compare identity withpublic static <T> T identity(Object self, Closure<T> closure)
self
- the object to have a closure act uponclosure
- the closure to call on the objectpublic static <T,U> T with(U self, @DelegatesTo(value=DelegatesTo.Target.class,target="self",strategy=1) Closure<T> closure)
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 }
self
- the object to have a closure act uponclosure
- the closure to call on the objectpublic static Object getAt(Object self, String property)
bean[somePropertyNameExpression]
. The normal property notation
of groovy is neater and more concise but only works with compile-time known
property names.self
- the object to act uponproperty
- the property name of interestpublic static void putAt(Object self, String property, Object newValue)
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.self
- the object to act uponproperty
- the name of the property to setnewValue
- the value to setpublic static String dump(Object self)
self
- an objectpublic static List<PropertyValue> getMetaPropertyValues(Object self)
MetaProperty
objects for 'self' and wraps it
in a list of PropertyValue
objects that additionally provide
the value for each property of 'self'.self
- the receiver objectPropertyValue
objectsExpando.getMetaPropertyValues()
public static Map getProperties(Object self)
getMetaPropertyValues(java.lang.Object)
(self)
and provides the data in form of simple key/value pairs, i.e.&nsbp;without
type() information.self
- the receiver objectpublic static <T> T use(Object self, Class categoryClass, Closure<T> closure)
self
- any ObjectcategoryClass
- a category class to useclosure
- the closure to invoke with the category in placepublic static void mixin(MetaClass self, List<Class> categoryClasses)
self
- any ClasscategoryClasses
- a category classes to usepublic static void mixin(Class self, List<Class> categoryClasses)
self
- any ClasscategoryClasses
- a category classes to usepublic static void mixin(Class self, Class categoryClass)
self
- any ClasscategoryClass
- a category class to usepublic static void mixin(Class self, Class[] categoryClass)
self
- any ClasscategoryClass
- a category class to usepublic static void mixin(MetaClass self, Class categoryClass)
self
- any ClasscategoryClass
- a category class to usepublic static void mixin(MetaClass self, Class[] categoryClass)
self
- any ClasscategoryClass
- a category class to usepublic static <T> T use(Object self, List<Class> categoryClassList, Closure<T> closure)
self
- any ObjectcategoryClassList
- a list of category classesclosure
- the closure to invoke with the categories in placepublic static void addShutdownHook(Object self, Closure closure)
self
- the object the method is called on (ignored)closure
- the shutdown hook actionpublic static Object use(Object self, Object[] array)
use(CategoryClass1, CategoryClass2) { ... }
This method saves having to wrap the the category
classes in a list.self
- any Objectarray
- a list of category classes and a Closurepublic static void print(Object self, Object value)
self
- any Objectvalue
- the value to printpublic static void print(PrintWriter self, Object value)
self
- a PrintWritervalue
- the value to printpublic static void print(PrintStream self, Object value)
self
- a PrintStreamvalue
- the value to printpublic static void print(Closure self, Object value)
self
- a generated closurevalue
- the value to printpublic static void println(Object self)
self
- any Objectpublic static void println(Closure self)
self
- a closurepublic static void println(Object self, Object value)
self
- any Objectvalue
- the value to printpublic static void println(PrintWriter self, Object value)
self
- a PrintWritervalue
- the value to printpublic static void println(PrintStream self, Object value)
self
- any Objectvalue
- the value to printpublic static void println(Closure self, Object value)
self
- a closurevalue
- the value to printpublic static void printf(Object self, String format, Object[] values)
self
- any Objectformat
- a format stringvalues
- values referenced by the format specifiers in the format string.public static String sprintf(Object self, String format, Object[] values)
self
- any Objectformat
- a format stringvalues
- values referenced by the format specifiers in the format string.public static void printf(Object self, String format, Object arg)
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[] ) }
self
- any Objectformat
- A format stringarg
- Argument which is referenced by the format specifiers in the format
string. The type of arg
should be one of Object[], List,
int[], short[], byte[], char[], boolean[], long[], float[], or double[].public static String sprintf(Object self, String format, Object arg)
self
- any Objectformat
- A format stringarg
- Argument which is referenced by the format specifiers in the format
string. The type of arg
should be one of Object[], List,
int[], short[], byte[], char[], boolean[], long[], float[], or double[].public static String inspect(Object self)
self
- any Objectpublic static void print(Object self, PrintWriter out)
self
- any Objectout
- the PrintWriter used for printingpublic static void println(Object self, PrintWriter out)
self
- any Objectout
- the PrintWriter used for printingpublic static Object invokeMethod(Object object, String method, Object arguments)
object
- any Objectmethod
- the name of the method to callarguments
- the arguments to usepublic static boolean isCase(Object caseValue, Object switchValue)
switch( a ) { case b: //some code }"some code" is called when
b.isCase( a )
returns
true
.caseValue
- the case valueswitchValue
- the switch valuepublic static boolean isCase(Class caseValue, Object switchValue)
switch( obj ) { case List : // obj is a list break; case Set : // etc }
caseValue
- the case valueswitchValue
- the switch valuepublic static boolean isCase(Collection caseValue, Object switchValue)
switch( 3 ) { case [1,3,5]: assert true break default: assert false }
caseValue
- the case valueswitchValue
- the switch valueCollection.contains(java.lang.Object)
public static boolean isCase(Map caseValue, Object switchValue)
switch( 'foo' ) { case [foo:true, bar:false]: assert true break default: assert false }
caseValue
- the case valueswitchValue
- the switch valuepublic static boolean isCase(Number caseValue, Number switchValue)
compareTo()
method for comparing numbers of different
types.caseValue
- the case valueswitchValue
- the switch valuepublic static <T> Iterator<T> unique(Iterator<T> self)
self
- an Iteratorpublic static <T> Collection<T> unique(Collection<T> self)
assert [1,3] == [1,3,3].unique()
self
- a collectionunique(Collection, boolean)
public static <T> Collection<T> unique(Collection<T> self, boolean mutate)
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]
self
- a collectionmutate
- false will cause a new list containing unique items from the collection to be created, true will mutate collections in placepublic static int numberAwareCompareTo(Comparable self, Comparable other)
self
- a Comparableother
- another Comparablepublic static <T> Iterator<T> unique(Iterator<T> self, Closure closure)
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)
or Object.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).
self
- an Iteratorclosure
- a Closure used to determine unique itemspublic static <T> Collection<T> unique(Collection<T> self, Closure closure)
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)
or Object.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 }
self
- a Collectionclosure
- a 1 or 2 arg Closure used to determine unique itemsunique(Collection, boolean, Closure)
public static <T> Collection<T> unique(Collection<T> self, boolean mutate, Closure closure)
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)
or Object.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]
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 itemspublic static <T> Iterator<T> unique(Iterator<T> self, Comparator<T> comparator)
self
- an Iteratorcomparator
- a Comparatorpublic static <T> Collection<T> unique(Collection<T> self, Comparator<T> comparator)
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] )
self
- a Collectioncomparator
- a Comparatorunique(java.util.Collection, boolean, java.util.Comparator)
public static <T> Collection<T> unique(Collection<T> self, boolean mutate, Comparator<T> comparator)
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] )
self
- a Collectionmutate
- false will always cause a new collection to be created, true will mutate collections in placecomparator
- a Comparatorpublic static <T> T each(T self, Closure closure)
self
- the object over which we iterateclosure
- the closure applied on each element foundpublic static <T> T eachWithIndex(T self, Closure closure)
self
- an Objectclosure
- a Closure to operate on each itempublic static <T> Iterable<T> eachWithIndex(Iterable<T> self, Closure closure)
self
- an Iterableclosure
- a Closure to operate on each itempublic static <T> Iterator<T> eachWithIndex(Iterator<T> self, Closure closure)
self
- an Iterableclosure
- a Closure to operate on each itempublic static <K,V> Map<K,V> each(Map<K,V> self, Closure closure)
def result = "" [a:1, b:3].each { key, value -> result += "$key$value" } assert result == "a1b3"
def result = "" [a:1, b:3].each { entry -> result += entry } assert result == "a=1b=3"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.
self
- the map over which we iterateclosure
- the 1 or 2 arg closure applied on each entry of the mappublic static <K,V> Map<K,V> reverseEach(Map<K,V> self, Closure closure)
self
- the map over which we iterateclosure
- the 1 or 2 arg closure applied on each entry of the mapeach(Map, Closure)
public static <K,V> Map<K,V> eachWithIndex(Map<K,V> self, Closure closure)
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)"
self
- the map over which we iterateclosure
- a 2 or 3 arg Closure to operate on each itempublic static <T> List<T> reverseEach(List<T> self, Closure closure)
def result = [] [1,2,3].reverseEach { result << it } assert result == [3,2,1]
self
- a Listclosure
- a closure to which each item is passed.public static <T> T[] reverseEach(T[] self, Closure closure)
self
- an Object arrayclosure
- a closure to which each item is passedpublic static boolean every(Object self, Closure closure)
true
for all items in this data structure).
A simple example for a list:
def list = [3,4,5] def greaterThanTwo = list.every { it > 2 }
self
- the object over which we iterateclosure
- the closure predicate used for matchingpublic static <T> boolean every(Iterator<T> self, Closure closure)
true
for all items in this iterator).
A simple example for a list:
def list = [3,4,5] def greaterThanTwo = list.iterator().every { it > 2 }
self
- the iterator over which we iterateclosure
- the closure predicate used for matchingpublic static <T> boolean every(Iterable<T> self, Closure closure)
true
for all items in this iterable).
A simple example for a list:
def list = [3,4,5] def greaterThanTwo = list.every { it > 2 }
self
- the iterable over which we iterateclosure
- the closure predicate used for matchingpublic static <K,V> boolean every(Map<K,V> self, Closure closure)
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 }
self
- the map over which we iterateclosure
- the 1 or 2 arg Closure predicate used for matchingpublic static boolean every(Object self)
true
according to the Groovy Truth.
Equivalent to self.every({element -> element})
self
- the object over which we iteratepublic static boolean any(Object self, Closure closure)
self
- the object over which we iterateclosure
- the closure predicate used for matchingpublic static <T> boolean any(Iterator<T> self, Closure closure)
self
- the iterator over which we iterateclosure
- the closure predicate used for matchingpublic static <T> boolean any(Iterable<T> self, Closure closure)
self
- the iterable over which we iterateclosure
- the closure predicate used for matchingpublic static <K,V> boolean any(Map<K,V> self, Closure<?> closure)
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 }
self
- the map over which we iterateclosure
- the 1 or 2 arg closure predicate used for matchingpublic static boolean any(Object self)
self
- the object over which we iteratepublic static Collection grep(Object self, Object filter)
isCase(java.lang.Object, java.lang.Object)
method used by switch statements. This method can be used with different
kinds of filters like regular expressions, classes, ranges etc.
Example:
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 ]
self
- the object over which we iteratefilter
- the filter to perform on the object (using the isCase(java.lang.Object, java.lang.Object)
method)public static <T> Collection<T> grep(Collection<T> self, Object filter)
isCase(java.lang.Object, java.lang.Object)
method used by switch statements. This method can be used with different
kinds of filters like regular expressions, classes, ranges etc.
Example:
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 ]
self
- a collectionfilter
- the filter to perform on each element of the collection (using the isCase(java.lang.Object, java.lang.Object)
method)public static <T> Collection<T> grep(T[] self, Object filter)
isCase(java.lang.Object, java.lang.Object)
method used by switch statements. This method can be used with different
kinds of filters like regular expressions, classes, ranges etc.
Example:
def list = ['a', 'b', 'aa', 'bc', 3, 4.5] as Object[] 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 ]
self
- an arrayfilter
- the filter to perform on each element of the array (using the isCase(java.lang.Object, java.lang.Object)
method)public static Collection grep(Object self)
Example:
def items = [1, 2, 0, false, true, '', 'foo', [], [4, 5], null] assert items.grep() == [1, 2, true, 'foo', [4, 5]]
self
- the object over which we iterateClosure.IDENTITY
public static <T> Collection<T> grep(Collection<T> self)
Example:
def items = [1, 2, 0, false, true, '', 'foo', [], [4, 5], null] assert items.grep() == [1, 2, true, 'foo', [4, 5]]
self
- a CollectionClosure.IDENTITY
public static <T> Collection<T> grep(T[] self)
Example:
def items = [1, 2, 0, false, true, '', 'foo', [], [4, 5], null] as Object[] assert items.grep() == [1, 2, true, 'foo', [4, 5]]
self
- an arrayClosure.IDENTITY
public static Number count(Iterator self, Object value)
compareTo(value) == 0
or equals(value)
).
The iterator will become exhausted of elements after determining the count value.self
- the Iterator from which we count the number of matching occurrencesvalue
- the value being searched forpublic static <T> Number count(Iterator<T> self, Closure closure)
Example usage:
assert [2,4,2,1,3,5,2,4,3].toSet().iterator().count{ it % 2 == 0 } == 2
self
- the Iterator from which we count the number of matching occurrencesclosure
- a closure condition@Deprecated public static Number count(Collection self, Object value)
public static Number count(Iterable self, Object value)
compareTo(value) == 0
or equals(value)
).
Example usage:
assert [2,4,2,1,3,5,2,4,3].count(4) == 2
self
- the Iterable within which we count the number of occurrencesvalue
- the value being searched for@Deprecated public static Number count(Collection self, Closure closure)
public static <T> Number count(Iterable<T> self, Closure closure)
Example usage:
assert [2,4,2,1,3,5,2,4,3].count{ it % 2 == 0 } == 5
self
- the Iterable within which we count the number of occurrencesclosure
- a closure conditionpublic static <K,V> Number count(Map<K,V> self, Closure<?> closure)
Example usage:
assert [a:1, b:1, c:2, d:2].count{ k,v -> k == 'a' || v == 2 } == 3
self
- the map within which we count the number of occurrencesclosure
- a 1 or 2 arg Closure condition applying on the entriespublic static Number count(Object[] self, Object value)
compareTo(value) == 0
or equals(value)
).self
- the array within which we count the number of occurrencesvalue
- the value being searched forpublic static <T> Number count(T[] self, Closure closure)
self
- the array within which we count the number of occurrencesclosure
- a closure conditionpublic static Number count(int[] self, Object value)
compareTo(value) == 0
or equals(value)
).self
- the array within which we count the number of occurrencesvalue
- the value being searched forpublic static Number count(long[] self, Object value)
compareTo(value) == 0
or equals(value)
).self
- the array within which we count the number of occurrencesvalue
- the value being searched forpublic static Number count(short[] self, Object value)
compareTo(value) == 0
or equals(value)
).self
- the array within which we count the number of occurrencesvalue
- the value being searched forpublic static Number count(char[] self, Object value)
compareTo(value) == 0
or equals(value)
).self
- the array within which we count the number of occurrencesvalue
- the value being searched forpublic static Number count(boolean[] self, Object value)
compareTo(value) == 0
or equals(value)
).self
- the array within which we count the number of occurrencesvalue
- the value being searched forpublic static Number count(double[] self, Object value)
compareTo(value) == 0
or equals(value)
).self
- the array within which we count the number of occurrencesvalue
- the value being searched forpublic static Number count(float[] self, Object value)
compareTo(value) == 0
or equals(value)
).self
- the array within which we count the number of occurrencesvalue
- the value being searched forpublic static Number count(byte[] self, Object value)
compareTo(value) == 0
or equals(value)
).self
- the array within which we count the number of occurrencesvalue
- the value being searched forpublic static <T> List<T> toList(Collection<T> self)
Example usage:
def x = [1,2,3] as HashSet assert x.class == HashSet assert x.toList() instanceof List
self
- a collectionpublic static <T> List<T> toList(Iterator<T> self)
self
- an iteratorpublic static <T> List<T> toList(Iterable<T> self)
self
- an Iterablepublic static <T> List<T> toList(Enumeration<T> self)
self
- an enumerationpublic static <T> List<List<T>> collate(List<T> self, int size)
size
.
Example:
def list = [ 1, 2, 3, 4, 5, 6, 7 ] def coll = list.collate( 3 ) assert coll == [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7 ] ]
self
- a Listsize
- the length of each sub-list in the returned listpublic static <T> List<List<T>> collate(List<T> self, int size, int step)
size
stepping through the code step
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 ] ]
self
- a Listsize
- the length of each sub-list in the returned liststep
- the number of elements to step through for each sub-listpublic static <T> List<List<T>> collate(List<T> self, int size, boolean keepRemainder)
size
. Any remaining elements in
the list after the subdivision will be dropped if keepRemainder
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 ] ]
self
- a Listsize
- the length of each sub-list in the returned listkeepRemainder
- if true, any rmeaining elements are returned as sub-lists. Otherwise they are discardedpublic static <T> List<List<T>> collate(List<T> self, int size, int step, boolean keepRemainder)
size
stepping through the code step
elements for each sub-list. Any remaining elements in the list after the subdivision will be dropped if
keepRemainder
is false.
Example:
def list = [ 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 ] ]
self
- a Listsize
- the length of each sub-list in the returned liststep
- the number of elements to step through for each sub-listkeepRemainder
- if true, any rmeaining elements are returned as sub-lists. Otherwise they are discardedpublic static <T> List<T> collect(Object self, Closure<T> transform)
transform
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]
self
- an aggregate Object with an Iterator returning its itemstransform
- the closure used to transform each item of the aggregate objectpublic static Collection collect(Object self)
assert [1,2,3] == [1,2,3].iterator().collect()
self
- an aggregate Object with an Iterator returning its itemsClosure.IDENTITY
public static <T> Collection<T> collect(Object self, Collection<T> collector, Closure<? extends T> transform)
transform
closure
and adding it to the supplied collector
.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 objectpublic static <S,T> List<T> collect(Collection<S> self, Closure<T> transform)
transform
closure
returning a list of transformed values.
assert [2,4,6] == [1,2,3].collect { it * 2 }
self
- a collectiontransform
- the closure used to transform each item of the collectionpublic static <T> List<T> collect(Collection<T> self)
assert [1,2,3] == [1,2,3].collect()
self
- a collectionClosure.IDENTITY
public static <T,E> Collection<T> collect(Collection<E> self, Collection<T> collector, Closure<? extends T> transform)
transform
closure
and adding it to the supplied collector
.
assert [1,2,3] as HashSet == [2,4,5,6].collect(new HashSet()) { (int)(it / 2) }
self
- a collectioncollector
- the Collection to which the transformed values are addedtransform
- the closure used to transform each item of the collectionpublic static List collectAll(Collection self, Closure transform)
collectNested(Collection, Closure)
public static List collectNested(Collection self, Closure transform)
assert [2,[4,6],[8],[]] == [1,[2,3],[4],[]].collectNested { it * 2 }
self
- a collectiontransform
- the closure used to transform each item of the collectionpublic static List collectNested(Iterable self, Closure transform)
assert [2,[4,6],[8],[]] == [1,[2,3],[4],[]].collectNested { it * 2 }
self
- an Iterabletransform
- the closure used to transform each item of the Iterablepublic static Collection collectAll(Collection self, Collection collector, Closure transform)
@Deprecated public static Collection collectNested(Collection self, Collection collector, Closure transform)
collectNested(Iterable, Collection, Closure)
public static Collection collectNested(Iterable self, Collection collector, Closure transform)
transform
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
self
- an Iterablecollector
- an initial Collection to which the transformed values are addedtransform
- the closure used to transform each element of the Iterable@Deprecated public static <T,E> List<T> collectMany(Collection<E> self, Closure<Collection<? extends T>> projection)
collectMany(Iterable, Closure)
@Deprecated public static <T,E> Collection<T> collectMany(Collection<E> self, Collection<T> collector, Closure<Collection<? extends T>> projection)
collectMany(Iterable, Collection, Closure)
public static <T,E> List<T> collectMany(Iterable<E> self, Closure<Collection<? extends T>> projection)
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
self
- an Iterableprojection
- a projecting Closure returning a collection of itemssum(java.util.Collection, groovy.lang.Closure)
public static <T,E> Collection<T> collectMany(Iterable<E> self, Collection<T> collector, Closure<Collection<? extends T>> projection)
collector
.
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
self
- an Iterablecollector
- an initial collection to add the projected items toprojection
- a projecting Closure returning a collection of itemspublic static <T,K,V> Collection<T> collectMany(Map<K,V> self, Collection<T> collector, Closure<Collection<? extends T>> projection)
collector
.
def map = [bread:3, milk:5, butter:2] def result = map.collectMany(['x']){ k, v -> k.startsWith('b') ? k.toList() : [] } assert result == ['x', 'b', 'r', 'e', 'a', 'd', 'b', 'u', 't', 't', 'e', 'r']
self
- a mapcollector
- an initial collection to add the projected items toprojection
- a projecting Closure returning a collection of itemspublic static <T,K,V> Collection<T> collectMany(Map<K,V> self, Closure<Collection<? extends T>> projection)
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']
self
- a mapprojection
- a projecting Closure returning a collection of itemspublic static <T,E> List<T> collectMany(E[] self, Closure<Collection<? extends T>> projection)
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]
self
- an object arrayprojection
- a projecting Closure returning a collection of itemssum(Object[], groovy.lang.Closure)
public static <T,E> List<T> collectMany(Iterator<E> self, Closure<Collection<? extends T>> projection)
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]
self
- an iteratorprojection
- a projecting Closure returning a collection of itemssum(Iterator, groovy.lang.Closure)
public static <T,K,V> Collection<T> collect(Map<K,V> self, Collection<T> collector, Closure<? extends T> transform)
transform
closure
returning the collector
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
self
- a Mapcollector
- the Collection to which transformed values are addedtransform
- the transformation closure which can take one (Map.Entry) or two (key, value) parameterspublic static <T,K,V> List<T> collect(Map<K,V> self, Closure<T> transform)
transform
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]
self
- a Maptransform
- the transformation closure which can take one (Map.Entry) or two (key, value) parameterspublic static <K,V,S,T> Map<K,V> collectEntries(Map<S,T> self, Map<K,V> collector, Closure<?> transform)
transform
closure
returning a map of the transformed entries.
assert [a:1, b:2].collectEntries( [:] ) { k, v -> [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']Note: When using the list-style of result, the behavior is '
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.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 valuecollect(Map, Collection, Closure)
public static <K,V> Map<?,?> collectEntries(Map<K,V> self, Closure<?> transform)
transform
closure
and returning a map of the transformed entries.
assert [a:1, b:2].collectEntries { key, value -> [value, key] } == [1:'a', 2:'b'] assert [a:1, b:2].collectEntries { key, value -> [(value*10): key.toUpperCase()] } == [10:'A', 20:'B']Note: When using the list-style of result, the behavior is '
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.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 valuecollect(Map, Collection, Closure)
@Deprecated public static <K,V> Map<K,V> collectEntries(Collection<?> self, Closure<?> transform)
collectEntries(Iterable, Closure)
public static <K,V,E> Map<K,V> collectEntries(Iterator<E> self, Closure<?> transform)
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 valuecollectEntries(Iterable, Closure)
public static <K,V,E> Map<K,V> collectEntries(Iterable<E> self, Closure<?> transform)
transform
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 -> [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']Note: When using the list-style of result, the behavior is '
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.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 valuecollectEntries(Iterator, Closure)
@Deprecated public static <K,V> Map<K,V> collectEntries(Collection<?> self)
collectEntries(Iterable)
public static <K,V> Map<K,V> collectEntries(Iterator<?> self)
self
- an IteratorcollectEntries(Iterable)
public static <K,V> Map<K,V> collectEntries(Iterable<?> self)
[key, value]
tuples or Map.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]
self
- an IterablecollectEntries(Iterator)
@Deprecated public static <K,V> Map<K,V> collectEntries(Collection<?> self, Map<K,V> collector, Closure<?> transform)
collectEntries(Iterable, Map, Closure)
public static <K,V,E> Map<K,V> collectEntries(Iterator<E> self, Map<K,V> collector, Closure<?> transform)
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 valuepublic static <K,V,E> Map<K,V> collectEntries(Iterable<E> self, Map<K,V> collector, Closure<?> transform)
def letters = "abc" // collect letters with index assert (0..2).collectEntries( [:] ) { index -> [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']Note: When using the list-style of result, the behavior is '
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.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 valuecollectEntries(Iterator, Map, Closure)
@Deprecated public static <K,V> Map<K,V> collectEntries(Collection<?> self, Map<K,V> collector)
collectEntries(Iterable, Map)
public static <K,V> Map<K,V> collectEntries(Iterator<?> self, Map<K,V> collector)
self
- an Iteratorcollector
- the Map into which the transformed entries are putcollectEntries(Iterable, Map)
public static <K,V> Map<K,V> collectEntries(Iterable<?> self, Map<K,V> collector)
self
- an Iterablecollector
- the Map into which the transformed entries are putcollectEntries(Iterator, Map)
public static <K,V,E> Map<K,V> collectEntries(E[] self, Map<K,V> collector, Closure<?> transform)
transform
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 -> [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']Note: When using the list-style of result, the behavior is '
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.self
- an Object 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 valuecollect(Map, Collection, Closure)
public static <K,V> Map<K,V> collectEntries(Object[] self, Map<K,V> collector)
self
- an Object arraycollector
- the Map into which the transformed entries are putcollectEntries(Object[], Map, Closure)
public static <K,V,E> Map<K,V> collectEntries(E[] self, Closure<?> transform)
transform
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 -> [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']Note: When using the list-style of result, the behavior is '
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.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 valuecollectEntries(Iterable, Map, Closure)
public static <K,V> Map<K,V> collectEntries(Object[] self)
self
- an Object arraycollectEntries(Object[], Closure)
public static Object find(Object self, Closure closure)
self
- an Object with an iterator returning its valuesclosure
- a closure conditionpublic static Object find(Object self)
Example:
def items = [null, 0, 0.0, false, '', [], 42, 43] assert items.find() == 42
self
- an Object with an Iterator returning its valuesClosure.IDENTITY
public static Object findResult(Object self, Object defaultResult, Closure closure)
self
- an Object with an iterator returning its valuesdefaultResult
- an Object that should be returned if all closure results are nullclosure
- a closure that returns a non-null value when processing should stoppublic static Object findResult(Object self, Closure closure)
self
- an Object with an iterator returning its valuesclosure
- a closure that returns a non-null value when processing should stoppublic static <T> T find(Collection<T> self, Closure closure)
def list = [1,2,3] assert 2 == list.find { it > 1 }
self
- a Collectionclosure
- a closure conditionpublic static <T> T find(T[] self, Closure condition)
def list = [1,2,3] as Integer[] assert 2 == list.find { it > 1 } assert null == list.find { it > 5 }
self
- an Arraycondition
- a closure conditionpublic static <T> T find(Collection<T> self)
Example:
def items = [null, 0, 0.0, false, '', [], 42, 43] assert items.find() == 42
self
- a CollectionClosure.IDENTITY
public static <T,U extends T,V extends T,E> T findResult(Collection<E> self, U defaultResult, Closure<V> closure)
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 }
self
- a CollectiondefaultResult
- an Object that should be returned if all closure results are nullclosure
- a closure that returns a non-null value when processing should stop and a value should be returnedpublic static <T,U> T findResult(Collection<U> self, Closure<T> closure)
Example:
def list = [1,2,3] assert "Found 2" == list.findResult { it > 1 ? "Found $it" : null }
self
- a Collectionclosure
- a closure that returns a non-null value when processing should stop and a value should be returned@Deprecated public static <T,U> Collection<T> findResults(Collection<U> self, Closure<T> filteringTransform)
findResults(Iterable, Closure)
public static <T,U> Collection<T> findResults(Iterable<U> self, Closure<T> filteringTransform)
Example:
def list = [1,2,3] def result = list.findResults { it > 1 ? "Found $it" : null } assert result == ["Found 2", "Found 3"]
self
- an IterablefilteringTransform
- a Closure that should return either a non-null transformed value or null for items which should be discardedpublic static <T,K,V> Collection<T> findResults(Map<K,V> self, Closure<T> filteringTransform)
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"]
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 discardedpublic static <K,V> Map.Entry<K,V> find(Map<K,V> self, Closure<?> closure)
assert [a:1, b:3].find { it.value == 3 }.key == "b"
self
- a Mapclosure
- a 1 or 2 arg Closure conditionpublic static <T,U extends T,V extends T,A,B> T findResult(Map<A,B> self, U defaultResult, Closure<V> closure)
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" }
self
- a MapdefaultResult
- an Object that should be returned if all closure results are nullclosure
- a 1 or 2 arg Closure that returns a non-null value when processing should stop and a value should be returnedpublic static <T,K,V> T findResult(Map<K,V> self, Closure<T> closure)
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" }
self
- a Mapclosure
- a 1 or 2 arg Closure that returns a non-null value when processing should stop and a value should be returnedpublic static <T> Collection<T> findAll(Collection<T> self, Closure closure)
assert [2,4] == [1,2,3,4].findAll { it % 2 == 0 }
self
- a Collectionclosure
- a closure conditionpublic static <T> Collection<T> findAll(T[] self, Closure condition)
def items = [1,2,3,4] as Integer[] assert [2,4] == items.findAll { it % 2 == 0 }
self
- an arraycondition
- a closure conditionpublic static <T> Collection<T> findAll(Collection<T> self)
Example:
def items = [1, 2, 0, false, true, '', 'foo', [], [4, 5], null] assert items.findAll() == [1, 2, true, 'foo', [4, 5]]
self
- a CollectionClosure.IDENTITY
public static <T> Collection<T> findAll(T[] self)
Example:
def items = [1, 2, 0, false, true, '', 'foo', [], [4, 5], null] as Object[] assert items.findAll() == [1, 2, true, 'foo', [4, 5]]
self
- an arrayClosure.IDENTITY
public static Collection findAll(Object self, Closure closure)
self
- an Object with an Iterator returning its valuesclosure
- a closure conditionpublic static Collection findAll(Object self)
Example:
def items = [1, 2, 0, false, true, '', 'foo', [], [4, 5], null] assert items.findAll() == [1, 2, true, 'foo', [4, 5]]
self
- an Object with an Iterator returning its valuesClosure.IDENTITY
public static boolean containsAll(Collection self, Object[] items)
self
- a Collection to be checked for containmentitems
- array to be checked for containment in this collectionCollection.containsAll(Collection)
public static boolean removeAll(Collection self, Object[] items)
findAll
and grep
when wanting to produce a new list
containing items which don't match some criteria while leaving the original collection unchanged.self
- a Collection to be modifieditems
- array containing elements to be removed from this collectionCollection.removeAll(Collection)
public static boolean retainAll(Collection self, Object[] items)
grep
and findAll
when wanting to produce a new list
containing items which match some specified items but leaving the original collection unchanged.self
- a Collection to be modifieditems
- array containing elements to be retained from this collectionCollection.retainAll(Collection)
public static <T> boolean retainAll(Collection<T> self, Closure condition)
findAll
and grep
when wanting to produce a new list
containing items which match some criteria but leaving the original collection unchanged.self
- a Collection to be modifiedcondition
- a closure conditionIterator.remove()
public static <T> boolean removeAll(Collection<T> self, Closure condition)
findAll
and grep
when wanting to produce a new list
containing items which don't match some criteria while leaving the original collection unchanged.self
- a Collection to be modifiedcondition
- a closure conditionIterator.remove()
public static <T> boolean addAll(Collection<T> self, T[] items)
plus
or the '+' operator if wanting to produce a new collection
containing additional items but while leaving the original collection unchanged.self
- a Collection to be modifieditems
- array containing elements to be added to this collectionCollection.addAll(Collection)
public static <T> boolean addAll(List<T> self, int index, T[] items)
plus
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.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 arrayList.addAll(int, Collection)
public static Collection split(Object self, Closure closure)
self
- an Object with an Iterator returning its valuesclosure
- a closure conditionpublic static <T> Collection<Collection<T>> split(Collection<T> self, Closure closure)
Example usage:
assert [[2,4],[1,3]] == [1,2,3,4].split { it % 2 == 0 }
self
- a Collection of valuesclosure
- a closure condition@Deprecated public static List combinations(Collection self)
combinations(Iterable)
public static List combinations(Iterable self)
Example usage:
assert [['a', 'b'],[1, 2, 3]].combinations() == [['a', 1], ['b', 1], ['a', 2], ['b', 2], ['a', 3], ['b', 3]]
self
- an Iterable of collectionsGroovyCollections.combinations(java.lang.Iterable)
public static List combinations(Iterable self, Closure<?> function)
Example usage:
assert [[2, 3],[4, 5, 6]].combinations {x,y -> x*y } == [8, 12, 10, 15, 12, 18]
self
- a Collection of listsfunction
- a closure to be called on each combinationGroovyCollections.combinations(Iterable)
public static void eachCombination(Iterable self, Closure<?> function)
Example usage:
[[2, 3],[4, 5, 6]].eachCombination { println "Found $it" }
self
- a Collection of listsfunction
- a closure to be called on each combinationGroovyCollections.combinations(Iterable)
public static <T> Set<List<T>> subsequences(List<T> self)
Example usage:
def result = [1, 2, 3].subsequences() assert result == [[1, 2, 3], [1, 3], [2, 3], [1, 2], [1], [2], [3]] as Set
self
- the List of itemspublic static <T> Set<List<T>> permutations(List<T> self)
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
self
- the Collection of itemspublic static <T,V> List<V> permutations(List<T> self, Closure<V> function)
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
self
- the Collection of itemsfunction
- the function to apply on each permutationpublic static <T> Iterator<List<T>> eachPermutation(Collection<T> self, Closure closure)
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]]
self
- the Collection of itemsclosure
- the closure to call for each permutationpublic static List transpose(List self)
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]]
self
- a List of listsGroovyCollections.transpose(java.util.List)
public static <K,V> Map<K,V> findAll(Map<K,V> self, Closure closure)
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]
self
- a Mapclosure
- a 1 or 2 arg Closure condition applying on the entries@Deprecated public static <K,T> Map<K,List<T>> groupBy(Collection<T> self, Closure<K> closure)
groupBy(Iterable, Closure)
public static <K,T> Map<K,List<T>> groupBy(Iterable<T> self, Closure<K> closure)
Example usage:
assert [0:[2,4,6], 1:[1,3,5]] == [1,2,3,4,5,6].groupBy { it % 2 }
self
- a collection to groupclosure
- a closure mapping entries on keyspublic static <K,T> Map<K,List<T>> groupBy(T[] self, Closure<K> closure)
Example usage:
Integer[] items = [1,2,3,4,5,6] assert [0:[2,4,6], 1:[1,3,5]] == items.groupBy { it % 2 }
self
- an array to groupclosure
- a closure mapping entries on keysgroupBy(Iterable, Closure)
@Deprecated public static Map groupBy(Collection self, Object... closures)
groupBy(Iterable, Object...)
public static Map groupBy(Iterable self, Object... closures)
def result = [1,2,3,4,5,6].groupBy({ it % 2 }, { it < 4 }) assert result == [1:[(true):[1, 3], (false):[5]], 0:[(true):[2], (false):[4, 6]]]Another example:
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.
self
- a collection to groupclosures
- an array of closures, each mapping entries on keysClosure.IDENTITY
public static Map groupBy(Object[] self, Object... closures)
self
- an array to groupclosures
- an array of closures, each mapping entries on keysgroupBy(Iterable, Object...)
,
Closure.IDENTITY
public static Map groupBy(Collection self, List<Closure> closures)
def result = [1,2,3,4,5,6].groupBy([{ it % 2 }, { it < 4 }]) assert result == [1:[(true):[1, 3], (false):[5]], 0:[(true):[2], (false):[4, 6]]]Another example:
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.
self
- a collection to groupclosures
- a list of closures, each mapping entries on keysClosure.IDENTITY
public static Map groupBy(Iterable self, List<Closure> closures)
def result = [1,2,3,4,5,6].groupBy([{ it % 2 }, { it < 4 }]) assert result == [1:[(true):[1, 3], (false):[5]], 0:[(true):[2], (false):[4, 6]]]Another example:
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.
self
- a collection to groupclosures
- a list of closures, each mapping entries on keysClosure.IDENTITY
public static Map groupBy(Object[] self, List<Closure> closures)
self
- an array to groupclosures
- a list of closures, each mapping entries on keysClosure.IDENTITY
,
groupBy(Iterable, List)
@Deprecated public static <K> Map<K,Integer> countBy(Collection self, Closure<K> closure)
countBy(Iterable, Closure)
public static <K,E> Map<K,Integer> countBy(Iterable<E> self, Closure<K> closure)
Example usage:
assert [0:2, 1:3] == [1,2,3,4,5].countBy { it % 2 }
self
- a collection to group and countclosure
- a closure mapping items to the frequency keyspublic static <K,E> Map<K,Integer> countBy(E[] self, Closure<K> closure)
Example usage:
assert ([1,2,2,2,3] as Object[]).countBy{ it % 2 } == [1:2, 0:3]
self
- an object array to group and countclosure
- a closure mapping items to the frequency keyscountBy(Collection, Closure)
public static <K,E> Map<K,Integer> countBy(Iterator<E> self, Closure<K> closure)
Example usage:
assert [1,2,2,2,3].toSet().iterator().countBy{ it % 2 } == [1:2, 0:1]
self
- an iterator to group and countclosure
- a closure mapping items to the frequency keyscountBy(Collection, Closure)
public static <G,K,V> Map<G,List<Map.Entry<K,V>>> groupEntriesBy(Map<K,V> self, Closure<G> closure)
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]
self
- a map to groupclosure
- a 1 or 2 arg Closure mapping entries on keyspublic static <G,K,V> Map<G,Map<K,V>> groupBy(Map<K,V> self, Closure<G> closure)
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]]
self
- a map to groupclosure
- a closure mapping entries on keyspublic static Map<Object,Map> groupBy(Map self, Object... closures)
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 }, { 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.
self
- a map to groupclosures
- an array of closures that map entries on keysClosure.IDENTITY
public static Map<Object,Map> groupBy(Map self, List<Closure> closures)
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 }, { 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.
self
- a map to groupclosures
- a list of closures that map entries on keysClosure.IDENTITY
public static <K,U,V> Map<K,Integer> countBy(Map<U,V> self, Closure<K> closure)
def result = [a:1,b:2,c:3,d:4,e:5].countBy { it.value % 2 } assert result == [0:2, 1:3]
self
- a map to group and countclosure
- a closure mapping entries to frequency count keysprotected static <K,T> void groupAnswer(Map<K,List<T>> answer, T element, K value)
answer
- the map containing the resultselement
- the element to be placedvalue
- the value according to which the element will be placedprotected static <T> T callClosureForMapEntry(Closure<T> closure, Map.Entry entry)
protected static <T> T callClosureForLine(Closure<T> closure, String line, int counter)
protected static <T> T callClosureForMapEntryAndCounter(Closure<T> closure, Map.Entry entry, int counter)
public static <T,V extends T> T inject(Collection<T> self, Closure<V> closure)
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 }
self
- a Collectionclosure
- a closureNoSuchElementException
- if the collection is empty.inject(Collection, Object, Closure)
public static <E,T,U extends T,V extends T> T inject(Collection<E> self, U initialValue, Closure<V> closure)
assert 1*1*2*3*4 == [1,2,3,4].inject(1) { acc, val -> 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)Visual representation of the last example above:
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'
self
- a CollectioninitialValue
- some initial valueclosure
- a closurepublic static <Key,Value,T,U extends T,V extends T> T inject(Map<Key,Value> self, U initialValue, Closure<V> closure)
def map = [a:1, b:2, c:3] assert map.inject([]) { list, k, v -> list + [k] * v } == ['a', 'b', 'b', 'c', 'c', 'c']
self
- a MapinitialValue
- some initial valueclosure
- a 2 or 3 arg Closurepublic static <E,T,U extends T,V extends T> T inject(Iterator<E> self, U initialValue, Closure<V> closure)
self
- an IteratorinitialValue
- some initial valueclosure
- a closureinject(Collection, Object, Closure)
public static <T,V extends T> T inject(Object self, Closure<V> closure)
self
- an Objectclosure
- a closureNoSuchElementException
- if the collection is empty.inject(Collection, Object, Closure)
public static <T,U extends T,V extends T> T inject(Object self, U initialValue, Closure<V> closure)
self
- an ObjectinitialValue
- some initial valueclosure
- a closureinject(Collection, Object, Closure)
public static <E,T,V extends T> T inject(E[] self, Closure<V> closure)
self
- an Object[]closure
- a closureNoSuchElementException
- if the array is empty.inject(Object[], Object, Closure)
public static <E,T,U extends T,V extends T> T inject(E[] self, U initialValue, Closure<V> closure)
self
- an Object[]initialValue
- some initial valueclosure
- a closureinject(Collection, Object, Closure)
@Deprecated public static Object sum(Collection self)
sum(Iterable)
public static Object sum(Iterable self)
assert 1+2+3+4 == [1,2,3,4].sum()
self
- Collection of values to add togetherpublic static Object sum(Object[] self)
self
- The array of values to add togethersum(java.util.Collection)
public static Object sum(Iterator<Object> self)
self
- an Iterator for the values to add together@Deprecated public static Object sum(Collection self, Object initialValue)
sum(Iterable, Object)
public static Object sum(Iterable self, Object initialValue)
assert 5+1+2+3+4 == [1,2,3,4].sum(5)
self
- an Iterable of values to suminitialValue
- the items in the collection will be summed to this initial valuepublic static Object sum(Object[] self, Object initialValue)
self
- an array of values to suminitialValue
- the items in the array will be summed to this initial valuepublic static Object sum(Iterator<Object> self, Object initialValue)
self
- an Iterator for the values to add togetherinitialValue
- the items in the collection will be summed to this initial value@Deprecated public static Object sum(Collection self, Closure closure)
sum(Iterable, Closure)
public static Object sum(Iterable self, Closure closure)
coll.sum(closure)
is equivalent to:
coll.collect(closure).sum()
.
assert 4+6+10+12 == [2,3,5,6].sum() { it * 2 }
self
- an Iterableclosure
- a single parameter closure that returns a numeric value.public static Object sum(Object[] self, Closure closure)
array.sum(closure)
is equivalent to:
array.collect(closure).sum()
.self
- An arrayclosure
- a single parameter closure that returns a numeric value.public static Object sum(Iterator<Object> self, Closure closure)
iter.sum(closure)
is equivalent to:
iter.collect(closure).sum()
. The iterator will become
exhausted of elements after determining the sum value.self
- An Iteratorclosure
- a single parameter closure that returns a numeric value.@Deprecated public static Object sum(Collection self, Object initialValue, Closure closure)
sum(Iterable, Object, Closure)
public static Object sum(Iterable self, Object initialValue, Closure closure)
coll.sum(initVal, closure)
is equivalent to:
coll.collect(closure).sum(initVal)
.
assert 50+4+6+10+12 == [2,3,5,6].sum(50) { it * 2 }
self
- an Iterableclosure
- a single parameter closure that returns a numeric value.initialValue
- the closure results will be summed to this initial valuepublic static Object sum(Object[] self, Object initialValue, Closure closure)
array.sum(initVal, closure)
is equivalent to:
array.collect(closure).sum(initVal)
.self
- an arrayclosure
- a single parameter closure that returns a numeric value.initialValue
- the closure results will be summed to this initial valuepublic static Object sum(Iterator<Object> self, Object initialValue, Closure closure)
iter.sum(initVal, closure)
is equivalent to:
iter.collect(closure).sum(initVal)
. The iterator will become
exhausted of elements after determining the sum value.self
- an Iteratorclosure
- a single parameter closure that returns a numeric value.initialValue
- the closure results will be summed to this initial valuepublic static String join(Iterator<Object> self, String separator)
toString()
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.self
- an Iterator of itemsseparator
- a String separator@Deprecated public static String join(Collection self, String separator)
join(Iterable, String)
public static String join(Iterable self, String separator)
toString()
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(", ")
self
- an Iterable of objectsseparator
- a String separatorpublic static String join(Object[] self, String separator)
toString()
representation of each
items in this array, with the given String as a separator between each
item.self
- an array of Objectseparator
- a String separator@Deprecated public static <T> T min(Collection<T> self)
min(Iterable)
public static <T> T min(Iterable<T> self)
assert 2 == [4,2,5].min()
self
- a CollectionGroovyCollections.min(java.util.Collection)
public static <T> T min(Iterator<T> self)
self
- an Iteratormin(java.util.Collection)
public static <T> T min(T[] self)
self
- an Object arraymin(java.util.Collection)
@Deprecated public static <T> T min(Collection<T> self, Comparator<T> comparator)
min(Iterable, Comparator)
public static <T> T min(Iterable<T> self, Comparator<T> comparator)
assert "hi" == ["hello","hi","hey"].min( { a, b -> a.length() <=> b.length() } as Comparator )
self
- an Iterablecomparator
- a Comparatorpublic static <T> T min(Iterator<T> self, Comparator<T> comparator)
self
- an Iteratorcomparator
- a Comparatormin(java.util.Collection, java.util.Comparator)
public static <T> T min(T[] self, Comparator<T> comparator)
self
- an Object arraycomparator
- a Comparatormin(java.util.Collection, java.util.Comparator)
@Deprecated public static <T> T min(Collection<T> self, Closure closure)
min(Iterable, Closure)
public static <T> T min(Iterable<T> self, Closure closure)
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) == 91
def pets = ['dog', 'cat', 'anaconda'] def shortestName = pets.min{ it.size() } // one of 'dog' or 'cat' assert shortestName.size() == 3
self
- an Iterableclosure
- a 1 or 2 arg Closure used to determine the correct orderingpublic static <K,V> Map.Entry<K,V> min(Map<K,V> self, Closure closure)
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 -> b.value <=> a.value } // double negative! assert mostCommonEntry.value == 7Edge case for multiple min values:
def 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'
self
- a Mapclosure
- a 1 or 2 arg Closure used to determine the correct orderingpublic static <K,V> Map.Entry<K,V> max(Map<K,V> self, Closure closure)
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 -> b.value <=> a.value } // double negative! assert leastCommonEntry.value == 5Edge case for multiple max values:
def 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
self
- a Mapclosure
- a 1 or 2 arg Closure used to determine the correct orderingpublic static <T> T min(Iterator<T> self, Closure closure)
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.
self
- an Iteratorclosure
- a Closure used to determine the correct orderingmin(java.util.Collection, groovy.lang.Closure)
public static <T> T min(T[] self, Closure closure)
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.
self
- an Object arrayclosure
- a Closure used to determine the correct orderingmin(java.util.Collection, groovy.lang.Closure)
@Deprecated public static <T> T max(Collection<T> self)
max(Iterable)
public static <T> T max(Iterable<T> self)
assert 5 == [2,3,1,5,4].max()
self
- an IterableGroovyCollections.max(java.lang.Iterable)
public static <T> T max(Iterator<T> self)
self
- an IteratorGroovyCollections.max(java.util.Collection)
public static <T> T max(T[] self)
self
- an Object arraymax(java.util.Collection)
@Deprecated public static <T> T max(Collection<T> self, Closure closure)
max(Iterable, Closure)
public static <T> T max(Iterable<T> self, Closure closure)
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
self
- an Iterableclosure
- a 1 or 2 arg Closure used to determine the correct orderingpublic static <T> T max(Iterator<T> self, Closure closure)
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.
self
- an Iteratorclosure
- a Closure used to determine the correct orderingmax(java.util.Collection, groovy.lang.Closure)
public static <T> T max(T[] self, Closure closure)
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.
self
- an Object arrayclosure
- a Closure used to determine the correct orderingmax(java.util.Collection, groovy.lang.Closure)
@Deprecated public static <T> T max(Collection<T> self, Comparator<T> comparator)
max(Iterable, Comparator)
public static <T> T max(Iterable<T> self, Comparator<T> comparator)
assert "hello" == ["hello","hi","hey"].max( { a, b -> a.length() <=> b.length() } as Comparator )
self
- an Iterablecomparator
- a Comparatorpublic static <T> T max(Iterator<T> self, Comparator<T> comparator)
self
- an Iteratorcomparator
- a Comparatorpublic static <T> T max(T[] self, Comparator<T> comparator)
self
- an Object arraycomparator
- a Comparatorpublic static int size(Iterator self)
size()
method for Iterator
.
The iterator will become exhausted of elements after determining the size value.self
- an Iteratorpublic static int size(Iterable self)
size()
method for Iterable
.
def items = [1, 2, 3] def iterable = { [ hasNext:{ !items.isEmpty() }, next:{ items.pop() } ] as Iterator } as Iterable assert iterable.size() == 3
self
- an Iterablepublic static int size(Object[] self)
size()
method for an array.self
- an Array of objectspublic static <T> List<T> getAt(List<T> self, Range range)
def list = [1, "a", 4.5, true] assert list[1..2] == ["a", 4.5]
self
- a Listrange
- a Range indicating the items to getpublic static <T> List<T> getAt(ListWithDefault<T> self, Collection indices)
def list = [].withDefault { 42 } assert list[1,0,2] == [42, 42, 42]
self
- a ListWithDefaultindices
- a Collection of indicespublic static <T> List<T> getAt(ListWithDefault<T> self, Range range)
def list = [].withDefault { 42 } assert list[1..2] == [null, 42]
self
- a ListWithDefaultrange
- a Range indicating the items to getpublic static <T> List<T> getAt(ListWithDefault<T> self, EmptyRange range)
def list = [true, 1, 3.4].withDefault{ 42 } assert list[0..<0] == []
self
- a ListWithDefaultrange
- a Range indicating the items to getpublic static <T> List<T> getAt(List<T> self, EmptyRange range)
def list = [true, 1, 3.4] assert list[0..<0] == []
self
- a Listrange
- a Range indicating the items to getpublic static <T> List<T> getAt(List<T> self, Collection indices)
def list = [true, 1, 3.4, false] assert list[1,0,2] == [1, true, 3.4]
self
- a Listindices
- a Collection of indicespublic static <T> List<T> getAt(T[] self, Collection indices)
self
- an Array of Objectsindices
- a Collection of indicespublic static <K,V> Map<K,V> subMap(Map<K,V> map, Collection<K> keys)
assert [1:10, 2:20, 4:40].subMap( [2, 4] ) == [2:20, 4:40]
map
- a Mapkeys
- a Collection of keyspublic static <K,V> Map<K,V> subMap(Map<K,V> map, K[] keys)
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
map
- a Mapkeys
- an array of keyspublic static <K,V> V get(Map<K,V> map, K key, V defaultValue)
def map=[:] map.get("a", []) << 5 assert map == [a:[5]]
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 keypublic static <T> List<T> getAt(T[] array, Range range)
array
- an Array of Objectsrange
- a Rangepublic static <T> List<T> getAt(T[] array, IntRange range)
array
- an Array of Objectsrange
- an IntRangepublic static <T> List<T> getAt(T[] array, EmptyRange range)
array
- an Array of Objectsrange
- an EmptyRangepublic static <T> List<T> getAt(T[] array, ObjectRange range)
array
- an Array of Objectsrange
- an ObjectRangepublic static <T> List<T> toList(T[] array)
array
- an Array of Objectspublic static <T> T getAt(List<T> self, int idx)
def list = [2, "a", 5.3] assert list[1] == "a"
self
- a Listidx
- an indexpublic static <T> T getAt(Iterator<T> self, int idx)
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
self
- an Iteratoridx
- an index value (-self.size() <= idx < self.size())public static <T> T getAt(Iterable<T> self, int idx)
// 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
self
- an Iterableidx
- an index value (-self.size() <= idx < self.size()) but using -ve index values will be inefficientpublic static <T> void putAt(List<T> self, int idx, T value)
def list = [2, 3] list[0] = 1 assert list == [1, 3]
self
- a Listidx
- an indexvalue
- the value to put at the given indexpublic static void putAt(List self, EmptyRange range, Object value)
def list = ["a", true] list[1..<1] = 5 assert list == ["a", 5, true]
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 valuespublic static void putAt(List self, EmptyRange range, Collection value)
def list = ["a", true] list[1..<1] = [4, 3, 2] assert list == ["a", 4, 3, 2, true]
self
- a Listrange
- the (in this case empty) subset of the list to setvalue
- the Collection of valuesputAt(java.util.List, groovy.lang.EmptyRange, java.lang.Object)
public static void putAt(List self, IntRange range, Collection col)
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.
self
- a Listrange
- the subset of the list to setcol
- the collection of values to put at the given sublistpublic static void putAt(List self, IntRange range, Object value)
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. The
value
operand is
always treated as a single value.self
- a Listrange
- the subset of the list to setvalue
- the value to put at the given sublistpublic static void putAt(List self, List splice, List values)
def list = ["a", true, 42, 9.4] list[1, 4] = ["x", false] assert list == ["a", "x", 42, 9.4, false]
self
- a Listsplice
- the subset of the list to setvalues
- the value to put at the given sublistpublic static void putAt(List self, List splice, Object value)
def list = ["a", true, 42, 9.4] list[1, 3] = 5 assert list == ["a", 5, 42, 5]
self
- a Listsplice
- the subset of the list to setvalue
- the value to put at the given sublistpublic static <K,V> V getAt(Map<K,V> self, K key)
def map = [a:10] assert map["a"] == 10
self
- a Mapkey
- an Object as a key for the mappublic static <K,V> Map<K,V> plus(Map<K,V> left, Map<K,V> right)
Map
containing all entries from left
and right
,
giving precedence to right
. Any keys appearing in both Maps
will appear in the resultant map with values from the right
operand. If the left
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 the left
Map type for common cases as
described above.
assert [a:10, b:20] + [a:5, c:7] == [a:5, b:20, c:7]
left
- a Mapright
- a Mappublic static <K,V> V putAt(Map<K,V> self, K key, V value)
self
- a Mapkey
- an Object as a key for the mapvalue
- the value to put into the mappublic static List getAt(Collection coll, String property)
assert [String, Long, Integer] == ["a",5L,2]["class"]
coll
- a Collectionproperty
- a Stringpublic static <K,V> Map<K,V> asImmutable(Map<? extends K,? extends V> self)
self
- a MapCollections.unmodifiableMap(java.util.Map)
public static <K,V> SortedMap<K,V> asImmutable(SortedMap<K,? extends V> self)
self
- a SortedMapCollections.unmodifiableSortedMap(java.util.SortedMap)
public static <T> List<T> asImmutable(List<? extends T> self)
self
- a ListCollections.unmodifiableList(java.util.List)
public static <T> Set<T> asImmutable(Set<? extends T> self)
self
- a SetCollections.unmodifiableSet(java.util.Set)
public static <T> SortedSet<T> asImmutable(SortedSet<T> self)
self
- a SortedSetCollections.unmodifiableSortedSet(java.util.SortedSet)
public static <T> Collection<T> asImmutable(Collection<? extends T> self)
def mutable = [1,2,3] def immutable = mutable.asImmutable() mutable << 4 try { immutable << 4 assert false } catch (UnsupportedOperationException) { assert true }
self
- a CollectionCollections.unmodifiableCollection(java.util.Collection)
public static <K,V> Map<K,V> asSynchronized(Map<K,V> self)
self
- a MapCollections.synchronizedMap(java.util.Map)
public static <K,V> SortedMap<K,V> asSynchronized(SortedMap<K,V> self)
self
- a SortedMapCollections.synchronizedSortedMap(java.util.SortedMap)
public static <T> Collection<T> asSynchronized(Collection<T> self)
self
- a CollectionCollections.synchronizedCollection(java.util.Collection)
public static <T> List<T> asSynchronized(List<T> self)
self
- a ListCollections.synchronizedList(java.util.List)
public static <T> Set<T> asSynchronized(Set<T> self)
self
- a SetCollections.synchronizedSet(java.util.Set)
public static <T> SortedSet<T> asSynchronized(SortedSet<T> self)
self
- a SortedSetCollections.synchronizedSortedSet(java.util.SortedSet)
public static SpreadMap spread(Map self)
toSpreadMap(java.util.Map)
.self
- a mappublic static SpreadMap toSpreadMap(Map self)
SpreadMap
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()) == 10Note that toSpreadMap() is not normally used explicitly but under the covers by Groovy.
self
- a map to be converted into a SpreadMapSpreadMap.SpreadMap(java.util.Map)
public static SpreadMap toSpreadMap(Object[] self)
self
- an object arraySpreadMap.SpreadMap(java.lang.Object[])
,
toSpreadMap(java.util.Map)
public static SpreadMap toSpreadMap(List self)
self
- a listSpreadMap.SpreadMap(java.util.List)
,
toSpreadMap(java.util.Map)
public static <K,V> Map<K,V> withDefault(Map<K,V> self, Closure init)
get(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
self
- a Mapinit
- a Closure which is passed the unknown keypublic static <T> List<T> withDefault(List<T> self, Closure init)
withLazyDefault
which decorates a list allowing
it to grow when called with index values outside the normal list bounds.self
- a Listinit
- a Closure with the target index as parameter which generates the default valuewithLazyDefault(java.util.List, groovy.lang.Closure)
,
withEagerDefault(java.util.List, groovy.lang.Closure)
public static <T> List<T> withLazyDefault(List<T> self, Closure init)
init
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 the init
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)
and get(index)
. If an index greater than
or equal to the current size()
is used, the list will grow automatically
up to the specified index. Gaps will be filled by null
. If a default value
should also be used to fill gaps instead of null
, use withEagerDefault
.
If getAt(index)
or get(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 the init
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
self
- a Listinit
- a Closure with the target index as parameter which generates the default valuepublic static <T> List<T> withEagerDefault(List<T> self, Closure init)
init
Closure. Null values
can be stored in the list.
How it works: The decorated list intercepts all calls
to getAt(index)
and get(index)
. If an index greater than
or equal to the current size()
is used, the list will grow automatically
up to the specified index. Gaps will be filled by calling the init
Closure.
If generating a default value is a costly operation consider using withLazyDefault
.
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]
self
- a Listinit
- a Closure with the target index as parameter which generates the default value@Deprecated public static <T> List<T> sort(Collection<T> self)
sort(Iterable,boolean)
public static <T> List<T> sort(Iterable<T> self)
assert [1,2,3] == [3,1,2].sort()
self
- the Iterable to be sortedsort(Collection, boolean)
@Deprecated public static <T> List<T> sort(Collection<T> self, boolean mutate)
sort(Iterable, boolean)
public static <T> List<T> sort(Iterable<T> self, boolean mutate)
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]
self
- the collection to be sortedmutate
- false will always cause a new list to be created, true will mutate lists in placepublic static <K,V> Map<K,V> sort(Map<K,V> self, Closure closure)
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]
self
- the original unsorted mapclosure
- a Closure used as a comparatorpublic static <K,V> Map<K,V> sort(Map<K,V> self, Comparator<K> comparator)
def map = [ba:3, cz:6, ab:5].sort({ a, b -> a[-1] <=> b[-1] } as Comparator) assert map*.value == [3, 5, 6]
self
- the original unsorted mapcomparator
- a Comparatorpublic static <K,V> Map<K,V> sort(Map<K,V> self)
map = [ba:3, cz:6, ab:5].sort() assert map*.value == [5, 3, 6]
self
- the original unsorted mappublic static <T> T[] sort(T[] self)
self
- the array to be sortedpublic static <T> T[] sort(T[] self, boolean mutate)
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[]
self
- the array to be sortedmutate
- false will always cause a new array to be created, true will mutate the array in placepublic static <T> Iterator<T> sort(Iterator<T> self)
self
- the Iterator to be sortedpublic static <T> Iterator<T> sort(Iterator<T> self, Comparator<T> comparator)
self
- the Iterator to be sortedcomparator
- a Comparator used for comparing items@Deprecated public static <T> List<T> sort(Collection<T> self, Comparator<T> comparator)
sort(Iterable, boolean, Comparator)
@Deprecated public static <T> List<T> sort(Collection<T> self, boolean mutate, Comparator<T> comparator)
sort(Iterable, boolean, Comparator)
public static <T> List<T> sort(Iterable<T> self, boolean mutate, Comparator<T> comparator)
assert ["hi","hey","hello"] == ["hello","hi","hey"].sort( { 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"]
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 comparisonpublic static <T> T[] sort(T[] self, Comparator<T> comparator)
self
- the array to be sortedcomparator
- a Comparator used for the comparisonpublic static <T> T[] sort(T[] self, boolean mutate, Comparator<T> comparator)
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[]
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 comparisonpublic static <T> Iterator<T> sort(Iterator<T> self, Closure closure)
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.
self
- the Iterator to be sortedclosure
- a Closure used to determine the correct orderingpublic static <T> T[] sort(T[] self, Closure closure)
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.
self
- the array containing the elements to be sortedclosure
- a Closure used to determine the correct orderingpublic static <T> T[] sort(T[] self, boolean mutate, Closure closure)
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[]
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 orderingpublic static <T> List<T> sort(Collection<T> self, Closure closure)
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() }
self
- a Collection to be sortedclosure
- a 1 or 2 arg Closure used to determine the correct orderingsort(Collection, boolean, Closure)
public static <T> List<T> sort(Iterable<T> self, Closure closure)
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() }
self
- the Iterable to be sortedclosure
- a 1 or 2 arg Closure used to determine the correct orderingsort(Collection, boolean, Closure)
@Deprecated public static <T> List<T> sort(Collection<T> self, boolean mutate, Closure closure)
sort(Iterable, boolean, Closure)
public static <T> List<T> sort(Iterable<T> self, boolean mutate, Closure closure)
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"]
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 orderingpublic static <T> SortedSet<T> sort(SortedSet<T> self)
self
- an already sorted setpublic static <K,V> SortedMap<K,V> sort(SortedMap<K,V> self)
self
- an already sorted mappublic static <T> T pop(List<T> self)
def list = ["a", false, 2] assert list.pop() == 2 assert list == ["a", false]
self
- a ListNoSuchElementException
- if the list is empty and you try to pop() it.public static <K,V> Map<K,V> putAll(Map<K,V> self, Collection<Map.Entry<K,V>> entries)
self
- a Mapentries
- a Collection of Map.Entry items to be added to the Map.public static <K,V> Map<K,V> plus(Map<K,V> self, Collection<Map.Entry<K,V>> entries)
Map
containing all entries from self
and entries
,
giving precedence to entries
. Any keys appearing in both Maps
will appear in the resultant map with values from the entries
operand. If self
map is one of TreeMap, LinkedHashMap, Hashtable
or Properties, the returned Map will preserve that type, otherwise a HashMap will
be returned.self
- a Mapentries
- a Collection of Map.Entry items to be added to the Map.public static <T> boolean push(List<T> self, T value)
def list = [3, 4, 2] list.push("x") assert list == [3, 4, 2, "x"]
self
- a Listvalue
- element to be appended to this list.NoSuchElementException
- if the list is empty and you try to pop() it.public static <T> T last(List<T> self)
def list = [3, 4, 2] assert list.last() == 2 // check original is unaltered assert list == [3, 4, 2]
self
- a ListNoSuchElementException
- if the list is empty and you try to access the last() item.public static <T> T last(Iterable<T> self)
def set = [3, 4, 2] as LinkedHashSet assert set.last() == 2 // check original unaltered assert set == [3, 4, 2] as SetThe first element returned by the Iterable's iterator is returned. If the Iterable doesn't guarantee a defined order it may appear like a random element is returned.
self
- an IterableNoSuchElementException
- if the Iterable is empty and you try to access the last() item.public static <T> T last(T[] self)
def array = [3, 4, 2].toArray() assert array.last() == 2
self
- an arrayNoSuchElementException
- if the array is empty and you try to access the last() item.public static <T> T first(List<T> self)
def list = [3, 4, 2] assert list.first() == 3 // check original is unaltered assert list == [3, 4, 2]
self
- a ListNoSuchElementException
- if the list is empty and you try to access the first() item.public static <T> T first(Iterable<T> self)
def set = [3, 4, 2] as LinkedHashSet assert set.first() == 3 // check original is unaltered assert set == [3, 4, 2] as SetThe first element returned by the Iterable's iterator is returned. If the Iterable doesn't guarantee a defined order it may appear like a random element is returned.
self
- an IterableNoSuchElementException
- if the Iterable is empty and you try to access the first() item.public static <T> T first(T[] self)
def array = [3, 4, 2].toArray() assert array.first() == 3
self
- an arrayNoSuchElementException
- if the array is empty and you try to access the first() item.public static <T> T head(List<T> self)
def list = [3, 4, 2] assert list.head() == 3 assert list == [3, 4, 2]
self
- a ListNoSuchElementException
- if the list is empty and you try to access the head() item.public static <T> T head(T[] self)
def array = [3, 4, 2].toArray() assert array.head() == 3
self
- an Object arrayNoSuchElementException
- if the array is empty and you try to access the head() item.public static <T> List<T> tail(List<T> self)
def list = [3, 4, 2] assert list.tail() == [4, 2] assert list == [3, 4, 2]
self
- a ListNoSuchElementException
- if the list is empty and you try to access the tail() item.public static <T> T[] tail(T[] self)
String[] strings = ["a", "b", "c"] def result = strings.tail() assert strings.class.componentType == String
self
- an Object arrayNoSuchElementException
- if the list is empty and you try to access the tail() item.public static <T> List<T> take(List<T> self, int num)
num
elements from the head of this list.
def strings = [ 'a', 'b', 'c' ] assert strings.take( 0 ) == [] assert strings.take( 2 ) == [ 'a', 'b' ] assert strings.take( 5 ) == [ 'a', 'b', 'c' ]Similar to
take(Iterable, int)
except that it attempts to preserve the type of the original list.self
- the original listnum
- the number of elements to take from this listnum
elements of this list,
or else the whole list if it has less then num
elements.public static <T> T[] take(T[] self, int num)
num
elements from the head of this array.
String[] strings = [ 'a', 'b', 'c' ] assert strings.take( 0 ) == [] as String[] assert strings.take( 2 ) == [ 'a', 'b' ] as String[] assert strings.take( 5 ) == [ 'a', 'b', 'c' ] as String[]
self
- the original arraynum
- the number of elements to take from this arraynum
elements of this array,
or else the whole array if it has less then num
elements.public static <T> List<T> take(Iterable<T> self, int num)
num
elements from the head of this Iterable.
class AbcIterable implements Iterable{ Iterator iterator() { "abc".iterator() } } def abc = new AbcIterable() assert abc.take(0) == [] assert abc.take(1) == ['a'] assert abc.take(3) == ['a', 'b', 'c'] assert abc.take(5) == ['a', 'b', 'c']
self
- the original Iterablenum
- the number of elements to take from this Iterablenum
elements from this Iterable,
or else all the elements from the Iterable if it has less then num
elements.public static <K,V> Map<K,V> take(Map<K,V> self, int num)
num
elements from the head of this map.
If the map instance does not have ordered keys, then this function could return a random num
entries. Groovy by default uses LinkedHashMap, so this shouldn't be an issue in the main.
def strings = [ 'a':10, 'b':20, 'c':30 ] assert strings.take( 0 ) == [:] assert strings.take( 2 ) == [ 'a':10, 'b':20 ] assert strings.take( 5 ) == [ 'a':10, 'b':20, 'c':30 ]
self
- the original mapnum
- the number of elements to take from this mapnum
elements of this map,
or else the whole map if it has less then num
elements.public static <T> Iterator<T> take(Iterator<T> self, int num)
num
elements from this iterator.
The original iterator is stepped along by num
elements.
def a = 0 def iter = [ hasNext:{ true }, next:{ a++ } ] as Iterator def iteratorCompare( Iterator a, List b ) { a.collect { it } == b } assert iteratorCompare( iter.take( 0 ), [] ) assert iteratorCompare( iter.take( 2 ), [ 0, 1 ] ) assert iteratorCompare( iter.take( 5 ), [ 2, 3, 4, 5, 6 ] )
self
- the Iteratornum
- the number of elements to take from this iteratornum
elements of this iterator.@Deprecated public static CharSequence take(CharSequence self, int num)
public static <T> List<T> drop(List<T> self, int num)
def strings = [ 'a', 'b', 'c' ] assert strings.drop( 0 ) == [ 'a', 'b', 'c' ] assert strings.drop( 2 ) == [ 'c' ] assert strings.drop( 5 ) == []Similar to
drop(Iterable, int)
except that it attempts to preserve the type of the original list.self
- the original listnum
- the number of elements to drop from this listnum
ones, or else the empty list, if this list has
less than num
elements.public static <T> List<T> drop(Iterable<T> self, int num)
class AbcIterable implements Iterable{ Iterator iterator() { "abc".iterator() } } def abc = new AbcIterable() assert abc.drop(0) == ['a', 'b', 'c'] assert abc.drop(1) == ['b', 'c'] assert abc.drop(3) == [] assert abc.drop(5) == []
self
- the original Iterablenum
- the number of elements to drop from this Iterablenum
elements,
or an empty list if it has less then num
elements.public static <T> T[] drop(T[] self, int num)
String[] strings = [ 'a', 'b', 'c' ] assert strings.drop( 0 ) == [ 'a', 'b', 'c' ] as String[] assert strings.drop( 2 ) == [ 'c' ] as String[] assert strings.drop( 5 ) == [] as String[]
self
- the original arraynum
- the number of elements to drop from this arraynum
ones, or else the empty array, if this
array has less than num
elements.public static <K,V> Map<K,V> drop(Map<K,V> self, int num)
def strings = [ 'a':10, 'b':20, 'c':30 ] assert strings.drop( 0 ) == [ 'a':10, 'b':20, 'c':30 ] assert strings.drop( 2 ) == [ 'c':30 ] assert strings.drop( 5 ) == [:]If the map instance does not have ordered keys, then this function could drop a random
num
entries. Groovy by default uses LinkedHashMap, so this shouldn't be an issue in the main.self
- the original mapnum
- the number of elements to drop from this mapnum
ones, or else the empty map, if this map has
less than num
elements.public static <T> Iterator<T> drop(Iterator<T> self, int num)
num
elements.
def iteratorCompare( Iterator a, List b ) { a.collect { it } == b } def iter = [ 1, 2, 3, 4, 5 ].listIterator() assert iteratorCompare( iter.drop( 0 ), [ 1, 2, 3, 4, 5 ] ) iter = [ 1, 2, 3, 4, 5 ].listIterator() assert iteratorCompare( iter.drop( 2 ), [ 3, 4, 5 ] ) iter = [ 1, 2, 3, 4, 5 ].listIterator() assert iteratorCompare( iter.drop( 5 ), [] )
self
- the original iteratornum
- the number of elements to drop from this iteratornum
elements if they exist.public static <T> List<T> takeWhile(List<T> self, Closure condition)
takeWhile(Iterable, groovy.lang.Closure)
except that it attempts to preserve the type of the original list.
def nums = [ 1, 3, 2 ] assert nums.takeWhile{ it < 1 } == [] assert nums.takeWhile{ it < 3 } == [ 1 ] assert nums.takeWhile{ it < 4 } == [ 1, 3, 2 ]
self
- the original listcondition
- the closure that must evaluate to true to
continue taking elementspublic static <T> List<T> takeWhile(Iterable<T> self, Closure condition)
class AbcIterable implements Iterable{ Iterator iterator() { "abc".iterator() } } def abc = new AbcIterable() assert abc.takeWhile{ it < 'b' } == ['a'] assert abc.takeWhile{ it <= 'b' } == ['a', 'b']
self
- an Iterablecondition
- the closure that must evaluate to true to
continue taking elementspublic static <K,V> Map<K,V> takeWhile(Map<K,V> self, Closure<?> condition)
def shopping = [milk:1, bread:2, chocolate:3] assert shopping.takeWhile{ it.key.size() < 6 } == [milk:1, bread:2] assert shopping.takeWhile{ it.value % 2 } == [milk:1] assert shopping.takeWhile{ k, v -> k.size() + v <= 7 } == [milk:1, bread:2]If the map instance does not have ordered keys, then this function could appear to take random entries. Groovy by default uses LinkedHashMap, so this shouldn't be an issue in the main.
self
- a Mapcondition
- a 1 (or 2) arg Closure that must evaluate to true for the
entry (or key and value) to continue taking elementspublic static <T> T[] takeWhile(T[] self, Closure condition)
def nums = [ 1, 3, 2 ] as Integer[] assert nums.takeWhile{ it < 1 } == [] as Integer[] assert nums.takeWhile{ it < 3 } == [ 1 ] as Integer[] assert nums.takeWhile{ it < 4 } == [ 1, 3, 2 ] as Integer[]
self
- the original arraycondition
- the closure that must evaluate to true to
continue taking elementspublic static <T> Iterator<T> takeWhile(Iterator<T> self, Closure condition)
def a = 0 def iter = [ hasNext:{ true }, next:{ a++ } ] as Iterator assert [].iterator().takeWhile{ it < 3 }.toList() == [] assert [1, 2, 3, 4, 5].iterator().takeWhile{ it < 3 }.toList() == [ 1, 2 ] assert iter.takeWhile{ it < 5 }.toList() == [ 0, 1, 2, 3, 4 ]
self
- the Iteratorcondition
- the closure that must evaluate to true to
continue taking elementspublic static <T> List<T> dropWhile(List<T> self, Closure<?> condition)
dropWhile(Iterable, groovy.lang.Closure)
except that it attempts to preserve the type of the original list.
def nums = [ 1, 3, 2 ] assert nums.dropWhile{ it < 4 } == [] assert nums.dropWhile{ it < 3 } == [ 3, 2 ] assert nums.dropWhile{ it != 2 } == [ 2 ] assert nums.dropWhile{ it == 0 } == [ 1, 3, 2 ]
self
- the original listcondition
- the closure that must evaluate to true to continue dropping elementspublic static <T> List<T> dropWhile(Iterable<T> self, Closure<?> condition)
class AbcIterable implements Iterable{ Iterator iterator() { "abc".iterator() } } def abc = new AbcIterable() assert abc.dropWhile{ it < 'b' } == ['b', 'c'] assert abc.dropWhile{ it <= 'b' } == ['c']
self
- an Iterablecondition
- the closure that must evaluate to true to continue dropping elementspublic static <K,V> Map<K,V> dropWhile(Map<K,V> self, Closure<?> condition)
def shopping = [milk:1, bread:2, chocolate:3] assert shopping.dropWhile{ it.key.size() < 6 } == [chocolate:3] assert shopping.dropWhile{ it.value % 2 } == [bread:2, chocolate:3] assert shopping.dropWhile{ k, v -> k.size() + v <= 7 } == [chocolate:3]If the map instance does not have ordered keys, then this function could appear to drop random entries. Groovy by default uses LinkedHashMap, so this shouldn't be an issue in the main.
self
- a Mapcondition
- a 1 (or 2) arg Closure that must evaluate to true for the
entry (or key and value) to continue dropping elementspublic static <T> T[] dropWhile(T[] self, Closure<?> condition)
def nums = [ 1, 3, 2 ] as Integer[] assert nums.dropWhile{ it <= 3 } == [ ] as Integer[] assert nums.dropWhile{ it < 3 } == [ 3, 2 ] as Integer[] assert nums.dropWhile{ it != 2 } == [ 2 ] as Integer[] assert nums.dropWhile{ it == 0 } == [ 1, 3, 2 ] as Integer[]
self
- the original arraycondition
- the closure that must evaluate to true to
continue dropping elementspublic static <T> Iterator<T> dropWhile(Iterator<T> self, Closure<?> condition)
def a = 0 def iter = [ hasNext:{ a < 10 }, next:{ a++ } ] as Iterator assert [].iterator().dropWhile{ it < 3 }.toList() == [] assert [1, 2, 3, 4, 5].iterator().dropWhile{ it < 3 }.toList() == [ 3, 4, 5 ] assert iter.dropWhile{ it < 5 }.toList() == [ 5, 6, 7, 8, 9 ]
self
- the Iteratorcondition
- the closure that must evaluate to true to continue dropping elements@Deprecated public static <T> List<T> asList(Collection<T> self)
asList(Iterable)
public static <T> List<T> asList(Iterable<T> self)
Example usage:
assert new HashSet().asList() instanceof List
self
- an Iterable to be converted into a Listpublic static boolean asBoolean(Object object)
object
- the object to coercepublic static boolean asBoolean(Boolean bool)
bool
- the Booleanpublic static boolean asBoolean(Collection collection)
assert [1,2].asBoolean() == true
assert [].asBoolean() == false
collection
- the collectionpublic static boolean asBoolean(Map map)
assert [:] as Boolean == false assert [a:2] as Boolean == true
map
- the mappublic static boolean asBoolean(Iterator iterator)
iterator
- the iteratorpublic static boolean asBoolean(Enumeration enumeration)
enumeration
- the enumerationpublic static boolean asBoolean(Object[] array)
array
- the arraypublic static boolean asBoolean(byte[] array)
array
- an arraypublic static boolean asBoolean(short[] array)
array
- an arraypublic static boolean asBoolean(int[] array)
array
- an arraypublic static boolean asBoolean(long[] array)
array
- an arraypublic static boolean asBoolean(float[] array)
array
- an arraypublic static boolean asBoolean(double[] array)
array
- an arraypublic static boolean asBoolean(boolean[] array)
array
- an arraypublic static boolean asBoolean(char[] array)
array
- an arraypublic static boolean asBoolean(Character character)
character
- the characterpublic static boolean asBoolean(Number number)
number
- the numberpublic static <T> T asType(Collection col, Class<T> clazz)
col
- a collectionclazz
- the desired classasType(java.lang.Object, java.lang.Class)
public static <T> T asType(Object[] ary, Class<T> clazz)
ary
- an arrayclazz
- the desired classasType(java.lang.Object, java.lang.Class)
public static <T> T asType(Closure cl, Class<T> clazz)
cl
- the implementation of the single methodclazz
- the target typepublic static <T> T asType(Map map, Class<T> clazz)
map
- this mapclazz
- the target typepublic static <T> List<T> reverse(List<T> self)
def list = ["a", 4, false] assert list.reverse() == [false, 4, "a"] assert list == ["a", 4, false]
self
- a Listreverse(List, boolean)
public static <T> List<T> reverse(List<T> self, boolean mutate)
def list = ["a", 4, false] assert list.reverse(false) == [false, 4, "a"] assert list == ["a", 4, false] assert list.reverse(true) == [false, 4, "a"] assert list == [false, 4, "a"]
self
- a Listmutate
- true if the list itself should be reversed in place and returned, false if a new list should be createdpublic static <T> T[] reverse(T[] self)
self
- an arrayreverse(Object[], boolean)
public static <T> T[] reverse(T[] self, boolean mutate)
self
- an arraymutate
- true if the array itself should be reversed in place and returned, false if a new array should be createdpublic static <T> Iterator<T> reverse(Iterator<T> self)
self
- an Iteratorpublic static <T> T[] plus(T[] left, T[] right)
Integer[] a = [1, 2, 3] Integer[] b = [4, 5, 6] assert a + b == [1, 2, 3, 4, 5, 6] as Integer[]
left
- the left Arrayright
- the right Arraypublic static <T> T[] plus(T[] left, T right)
Integer[] a = [1, 2, 3] Integer[] result = a + 4 assert result == [1, 2, 3, 4] as Integer[]
left
- the arrayright
- the value to appendpublic static <T> T[] plus(T[] left, Collection<T> right)
Integer[] a = [1, 2, 3] def additions = [7, 8] assert a + additions == [1, 2, 3, 7, 8] as Integer[]
left
- the arrayright
- a Collection to be appendedpublic static <T> T[] plus(T[] left, Iterable<T> right)
class AbcIterable implements Iterable{ Iterator iterator() { "abc".iterator() } } String[] letters = ['x', 'y', 'z'] def result = letters + new AbcIterable() assert result == ['x', 'y', 'z', 'a', 'b', 'c'] as String[] assert result.class.array
left
- the arrayright
- an Iterable to be appendedpublic static <T> Collection<T> plus(Collection<T> left, Collection<T> right)
assert [1,2,3,4] == [1,2] + [3,4]
left
- the left Collectionright
- the right Collectionpublic static <T> Collection<T> plus(Collection<T> left, Iterable<T> right)
left
- the left Collectionright
- the right Iterableplus(Collection, Collection)
public static <T> List<T> plus(List<T> self, int index, T[] items)
def items = [1, 2, 3] def newItems = items.plus(2, 'a'..'c' as String[]) assert newItems == [1, 2, 'a', 'b', 'c', 3] assert items == [1, 2, 3]See also
addAll
for similar functionality with modify semantics, i.e. which performs
the changes on the original list itself.self
- an original listitems
- array containing elements to be merged with elements from the original listindex
- index at which to insert the first element from the specified arrayplus(List, int, List)
public static <T> List<T> plus(List<T> self, int index, List<T> additions)
def items = [1, 2, 3] def newItems = items.plus(2, 'a'..'c') assert newItems == [1, 2, 'a', 'b', 'c', 3] assert items == [1, 2, 3]See also
addAll
for similar functionality with modify semantics, i.e. which performs
the changes on the original list itself.self
- an original Listadditions
- a List containing elements to be merged with elements from the original Listindex
- index at which to insert the first element from the given additions Listpublic static <T> List<T> plus(List<T> self, int index, Iterable<T> additions)
self
- an original listadditions
- an Iterable containing elements to be merged with the elements from the original Listindex
- index at which to insert the first element from the given additions Iterableplus(List, int, List)
public static <T> Collection<T> plus(Collection<T> left, T right)
assert [1,2,3] == [1,2] + 3
left
- a Collectionright
- an object to add/appendpublic static <T> List<T> multiply(Collection<T> self, Number factor)
assert [1,2,3,1,2,3] == [1,2,3] * 2
self
- a Collectionfactor
- the number of times to appendpublic static <T> Collection<T> intersect(Collection<T> left, Collection<T> right)
assert [4,5] == [1,2,3,4,5].intersect([4,5,6,7,8])
left
- a Collectionright
- a Collectionpublic static <K,V> Map<K,V> intersect(Map<K,V> left, Map<K,V> right)
assert [4:4,5:5] == [1:1,2:2,3:3,4:4,5:5].intersect([4:4,5:5,6:6,7:7,8:8])
assert [1: 1, 2: 2, 3: 3, 4: 4].intersect( [1: 1.0, 2: 2, 5: 5] ) == [1:1, 2:2]
left
- a mapright
- a mappublic static boolean disjoint(Collection left, Collection right)
true
if the intersection of two collections is empty.
assert [1,2,3].disjoint([3,4,5]) == false
assert [1,2].disjoint([3,4]) == true
left
- a Collectionright
- a Collectiontrue
if the intersection of two collections
is empty, false
otherwise.public static boolean equals(int[] left, int[] right)
left
- an int arrayright
- the array being comparedpublic static boolean equals(Object[] left, List right)
false
if either collection is null
.left
- an arrayright
- the List being comparedpublic static boolean equals(List left, Object[] right)
false
if either collection is null
.
assert [1, "a"].equals( [ 1, "a" ] as Object[] )
left
- a Listright
- the Object[] being compared topublic static boolean equals(List left, List right)
null
, the result
is true; otherwise if either list is null
, the result
is false
.
assert ["a", 2].equals(["a", 2]) assert ![2, "a"].equals("a", 2) assert [2.0, "a"].equals(2L, "a") // number comparison at work
left
- a Listright
- the List being compared totrue
if the contents of both lists are identical,
false
otherwise.public static <T> boolean equals(Set<T> self, Set<T> other)
Returns true if the two sets have the same size, and every member
of the specified set is contained in this set (or equivalently, every member
of this set is contained in the specified set).
If numbers exist in the sets, then they are compared as numbers,
for example 2 == 2L. If both sets are null
, the result
is true; otherwise if either set is null
, the result
is false
. Example usage:
Set s1 = ["a", 2] def s2 = [2, 'a'] as Set Set s3 = [3, 'a'] def s4 = [2.0, 'a'] as Set def s5 = [2L, 'a'] as Set assert s1.equals(s2) assert !s1.equals(s3) assert s1.equals(s4) assert s1.equals(s5)
self
- a Setother
- the Set being compared topublic static boolean equals(Map self, Map other)
Example usage:
assert [a:2, b:3] == [a:2L, b:3.0]
self
- this Mapother
- the Map being compared topublic static <T> Set<T> minus(Set<T> self, Collection<?> removeMe)
self
- a Set objectremoveMe
- the items to remove from the Setpublic static <T> Set<T> minus(Set<T> self, Iterable<?> removeMe)
self
- a Set objectremoveMe
- the items to remove from the Setpublic static <T> Set<T> minus(Set<T> self, Object removeMe)
self
- a Set objectremoveMe
- the element to remove from the Setpublic static <T> T[] minus(T[] self, Iterable removeMe)
self
- an object arrayremoveMe
- a Collection of elements to removepublic static <T> T[] minus(T[] self, Object[] removeMe)
self
- an object arrayremoveMe
- an array of elements to removepublic static <T> List<T> minus(List<T> self, Collection<?> removeMe)
assert [1, "a", true, true, false, 5.3] - [true, 5.3] == [1, "a", false]
self
- a ListremoveMe
- a Collection of elements to removepublic static <T> List<T> minus(List<T> self, Iterable<?> removeMe)
class AbcIterable implements Iterable{ Iterator iterator() { "abc".iterator() } } assert "backtrack".toList() - new AbcIterable() == ["k", "t", "r", "k"]
self
- a ListremoveMe
- an Iterable of elements to removepublic static <T> List<T> minus(List<T> self, Object removeMe)
assert ["a", 5, 5, true] - 5 == ["a", true]
self
- a List objectremoveMe
- an element to remove from the listpublic static <T> T[] minus(T[] self, Object removeMe)
self
- an object arrayremoveMe
- an element to remove from the arraypublic static <K,V> Map<K,V> minus(Map<K,V> self, Map removeMe)
self
- a map objectremoveMe
- the entries to remove from the mappublic static Collection<?> flatten(Collection<?> self)
assert [1,2,3,4,5] == [1,[2,3],[[4]],[],5].flatten()
self
- a Collection to flattenpublic static Collection<?> flatten(Iterable<?> self)
assert [1,2,3,4,5] == [1,[2,3],[[4]],[],5].flatten()
self
- a Iterable to flattenpublic static Collection flatten(Object[] self)
self
- an Array to flattenpublic static Collection flatten(boolean[] self)
self
- a boolean Array to flattenpublic static Collection flatten(byte[] self)
self
- a byte Array to flattenpublic static Collection flatten(char[] self)
self
- a char Array to flattenpublic static Collection flatten(short[] self)
self
- a short Array to flattenpublic static Collection flatten(int[] self)
self
- an int Array to flattenpublic static Collection flatten(long[] self)
self
- a long Array to flattenpublic static Collection flatten(float[] self)
self
- a float Array to flattenpublic static Collection flatten(double[] self)
self
- a double Array to flattenpublic static <T> Collection<T> flatten(Collection<T> self, Closure<? extends T> flattenUsing)
self
- a CollectionflattenUsing
- a closure to determine how to flatten non-Array, non-Collection elementspublic static <T> Collection<T> flatten(Iterable<T> self, Closure<? extends T> flattenUsing)
self
- an IterableflattenUsing
- a closure to determine how to flatten non-Array, non-Collection elementspublic static <T> Collection<T> leftShift(Collection<T> self, T value)
def list = [1,2] list << 3 assert list == [1,2,3]
self
- a Collectionvalue
- an Object to be added to the collection.public static <T> BlockingQueue<T> leftShift(BlockingQueue<T> self, T value) throws InterruptedException
def list = new java.util.concurrent.LinkedBlockingQueue () list << 3 << 2 << 1 assert list.iterator().collect{it} == [3,2,1]
self
- a Collectionvalue
- an Object to be added to the collection.InterruptedException
public static <K,V> Map<K,V> leftShift(Map<K,V> self, Map.Entry<K,V> entry)
self
- a Mapentry
- a Map.Entry to be added to the Map.public static <K,V> Map<K,V> leftShift(Map<K,V> self, Map<K,V> other)
map1 << map2
; otherwise it's just a synonym for
putAll
though it returns the original map rather than
being a void
method. Example usage:
def map = [a:1, b:2] map << [c:3, d:4] assert map == [a:1, b:2, c:3, d:4]
self
- a Mapother
- another Map whose entries should be added to the original Map.public static Number leftShift(Number self, Number operand)
self
- a Number objectoperand
- the shift distance by which to left shift the numberpublic static Number rightShift(Number self, Number operand)
self
- a Number objectoperand
- the shift distance by which to right shift the numberpublic static Number rightShiftUnsigned(Number self, Number operand)
self
- a Number objectoperand
- the shift distance by which to right shift (unsigned) the numberpublic static List<Byte> getAt(byte[] array, Range range)
array
- a byte arrayrange
- a range indicating the indices for the items to retrievepublic static List<Character> getAt(char[] array, Range range)
array
- a char arrayrange
- a range indicating the indices for the items to retrievepublic static List<Short> getAt(short[] array, Range range)
array
- a short arrayrange
- a range indicating the indices for the items to retrievepublic static List<Integer> getAt(int[] array, Range range)
array
- an int arrayrange
- a range indicating the indices for the items to retrievepublic static List<Long> getAt(long[] array, Range range)
array
- a long arrayrange
- a range indicating the indices for the items to retrievepublic static List<Float> getAt(float[] array, Range range)
array
- a float arrayrange
- a range indicating the indices for the items to retrievepublic static List<Double> getAt(double[] array, Range range)
array
- a double arrayrange
- a range indicating the indices for the items to retrievepublic static List<Boolean> getAt(boolean[] array, Range range)
array
- a boolean arrayrange
- a range indicating the indices for the items to retrievepublic static List<Byte> getAt(byte[] array, IntRange range)
array
- a byte arrayrange
- an IntRange indicating the indices for the items to retrievepublic static List<Character> getAt(char[] array, IntRange range)
array
- a char arrayrange
- an IntRange indicating the indices for the items to retrievepublic static List<Short> getAt(short[] array, IntRange range)
array
- a short arrayrange
- an IntRange indicating the indices for the items to retrievepublic static List<Integer> getAt(int[] array, IntRange range)
array
- an int arrayrange
- an IntRange indicating the indices for the items to retrievepublic static List<Long> getAt(long[] array, IntRange range)
array
- a long arrayrange
- an IntRange indicating the indices for the items to retrievepublic static List<Float> getAt(float[] array, IntRange range)
array
- a float arrayrange
- an IntRange indicating the indices for the items to retrievepublic static List<Double> getAt(double[] array, IntRange range)
array
- a double arrayrange
- an IntRange indicating the indices for the items to retrievepublic static List<Boolean> getAt(boolean[] array, IntRange range)
array
- a boolean arrayrange
- an IntRange indicating the indices for the items to retrievepublic static List<Byte> getAt(byte[] array, ObjectRange range)
array
- a byte arrayrange
- an ObjectRange indicating the indices for the items to retrievepublic static List<Character> getAt(char[] array, ObjectRange range)
array
- a char arrayrange
- an ObjectRange indicating the indices for the items to retrievepublic static List<Short> getAt(short[] array, ObjectRange range)
array
- a short arrayrange
- an ObjectRange indicating the indices for the items to retrievepublic static List<Integer> getAt(int[] array, ObjectRange range)
array
- an int arrayrange
- an ObjectRange indicating the indices for the items to retrievepublic static List<Long> getAt(long[] array, ObjectRange range)
array
- a long arrayrange
- an ObjectRange indicating the indices for the items to retrievepublic static List<Float> getAt(float[] array, ObjectRange range)
array
- a float arrayrange
- an ObjectRange indicating the indices for the items to retrievepublic static List<Double> getAt(double[] array, ObjectRange range)
array
- a double arrayrange
- an ObjectRange indicating the indices for the items to retrievepublic static List<Boolean> getAt(boolean[] array, ObjectRange range)
array
- a byte arrayrange
- an ObjectRange indicating the indices for the items to retrievepublic static List<Byte> getAt(byte[] array, Collection indices)
array
- a byte arrayindices
- a collection of indices for the items to retrievepublic static List<Character> getAt(char[] array, Collection indices)
array
- a char arrayindices
- a collection of indices for the items to retrievepublic static List<Short> getAt(short[] array, Collection indices)
array
- a short arrayindices
- a collection of indices for the items to retrievepublic static List<Integer> getAt(int[] array, Collection indices)
array
- an int arrayindices
- a collection of indices for the items to retrievepublic static List<Long> getAt(long[] array, Collection indices)
array
- a long arrayindices
- a collection of indices for the items to retrievepublic static List<Float> getAt(float[] array, Collection indices)
array
- a float arrayindices
- a collection of indices for the items to retrievepublic static List<Double> getAt(double[] array, Collection indices)
array
- a double arrayindices
- a collection of indices for the items to retrievepublic static List<Boolean> getAt(boolean[] array, Collection indices)
array
- a boolean arrayindices
- a collection of indices for the items to retrievepublic static boolean getAt(BitSet self, int index)
self
- a BitSetindex
- index to retrieveBitSet
public static BitSet getAt(BitSet self, IntRange range)
public static void putAt(BitSet self, IntRange range, boolean value)
public static void putAt(BitSet self, int index, boolean value)
self
- a BitSetindex
- index of the entry to setvalue
- valueBitSet
public static int size(boolean[] array)
array
- a boolean arrayArray.getLength(java.lang.Object)
public static int size(byte[] array)
array
- a byte arrayArray.getLength(java.lang.Object)
public static int size(char[] array)
array
- a char arrayArray.getLength(java.lang.Object)
public static int size(short[] array)
array
- a short arrayArray.getLength(java.lang.Object)
public static int size(int[] array)
array
- an int arrayArray.getLength(java.lang.Object)
public static int size(long[] array)
array
- a long arrayArray.getLength(java.lang.Object)
public static int size(float[] array)
array
- a float arrayArray.getLength(java.lang.Object)
public static int size(double[] array)
array
- a double arrayArray.getLength(java.lang.Object)
public static List<Byte> toList(byte[] array)
array
- a byte arraypublic static List<Boolean> toList(boolean[] array)
array
- a boolean arraypublic static List<Character> toList(char[] array)
array
- a char arraypublic static List<Short> toList(short[] array)
array
- a short arraypublic static List<Integer> toList(int[] array)
array
- an int arraypublic static List<Long> toList(long[] array)
array
- a long arraypublic static List<Float> toList(float[] array)
array
- a float arraypublic static List<Double> toList(double[] array)
array
- a double arraypublic static Set<Byte> toSet(byte[] array)
array
- a byte arraypublic static Set<Boolean> toSet(boolean[] array)
array
- a boolean arraypublic static Set<Character> toSet(char[] array)
array
- a char arraypublic static Set<Short> toSet(short[] array)
array
- a short arraypublic static Set<Integer> toSet(int[] array)
array
- an int arraypublic static Set<Long> toSet(long[] array)
array
- a long arraypublic static Set<Float> toSet(float[] array)
array
- a float arraypublic static Set<Double> toSet(double[] array)
array
- a double arraypublic static <T> Set<T> toSet(Collection<T> self)
Example usage:
def result = [1, 2, 2, 2, 3].toSet() assert result instanceof Set assert result == [1, 2, 3] as Set
self
- a collectionpublic static <T> Set<T> toSet(Iterator<T> self)
self
- an iteratorpublic static <T> Set<T> toSet(Enumeration<T> self)
self
- an enumerationprotected static Object primitiveArrayGet(Object self, int idx)
self
- an array objectidx
- the index of interestprotected static List primitiveArrayGet(Object self, Range range)
self
- an array objectrange
- the range of indices of interestprotected static List primitiveArrayGet(Object self, Collection indices)
self
- an array objectindices
- the indices of interestprotected static Object primitiveArrayPut(Object self, int idx, Object newValue)
self
- an objectidx
- the index of interestnewValue
- the new value to be put into the index of interestpublic static Boolean toBoolean(Boolean self)
self
- a Booleanpublic static boolean contains(int[] self, Object value)
self
- the array we are searchingvalue
- the value being searched forpublic static boolean contains(long[] self, Object value)
self
- the array we are searchingvalue
- the value being searched forpublic static boolean contains(short[] self, Object value)
self
- the array we are searchingvalue
- the value being searched forpublic static boolean contains(char[] self, Object value)
self
- the array we are searchingvalue
- the value being searched forpublic static boolean contains(boolean[] self, Object value)
self
- the array within which we count the number of occurrencesvalue
- the value being searched forpublic static boolean contains(double[] self, Object value)
self
- the array we are searchingvalue
- the value being searched forpublic static boolean contains(float[] self, Object value)
self
- the array we are searchingvalue
- the value being searched forpublic static boolean contains(byte[] self, Object value)
self
- the array we are searchingvalue
- the value being searched forpublic static boolean contains(Object[] self, Object value)
self
- the array we are searchingvalue
- the value being searched forpublic static String toString(boolean[] self)
self
- an arraypublic static String toString(byte[] self)
self
- an arraypublic static String toString(char[] self)
self
- an arraypublic static String toString(short[] self)
self
- an arraypublic static String toString(int[] self)
self
- an arraypublic static String toString(long[] self)
self
- an arraypublic static String toString(float[] self)
self
- an arraypublic static String toString(double[] self)
self
- an arraypublic static String toString(AbstractMap self)
self
- a MaptoMapString(java.util.Map)
public static String toMapString(Map self)
[one:1, two:2, three:3]
.self
- a Mappublic static String toMapString(Map self, int maxSize)
[one:1, two:2, three:3]
.self
- a MapmaxSize
- stop after approximately this many characters and append '...'public static String toString(AbstractCollection self)
[1, 2, a]
.self
- a CollectiontoListString(java.util.Collection)
public static String toListString(Collection self)
[1, 2, a]
.self
- a Collectionpublic static String toListString(Collection self, int maxSize)
[1, 2, a]
.self
- a CollectionmaxSize
- stop after approximately this many characters and append '...'public static String toString(Object[] self)
self
- an Object[]toArrayString(java.lang.Object[])
public static String toArrayString(Object[] self)
{1, 2, "a"}
.self
- an Object[]public static String toString(Object value)
value
- an objectpublic static Character next(Character self)
self
- a Characterpublic static Number next(Number self)
self
- a Numberpublic static Character previous(Character self)
self
- a Characterpublic static Number previous(Number self)
self
- a Numberpublic static Number plus(Character left, Number right)
left
- a Characterright
- a NumberInteger.valueOf(int)
public static Number plus(Number left, Character right)
left
- a Numberright
- a CharacterInteger.valueOf(int)
public static Number plus(Character left, Character right)
left
- a Characterright
- a Characterplus(java.lang.Number, java.lang.Character)
public static int compareTo(Character left, Number right)
left
- a Characterright
- a Numberpublic static int compareTo(Number left, Character right)
left
- a Numberright
- a Characterpublic static int compareTo(Character left, Character right)
left
- a Characterright
- a Characterpublic static int compareTo(Number left, Number right)
left
- a Numberright
- another Number to compare topublic static Number minus(Character left, Number right)
left
- a Characterright
- a Numberpublic static Number minus(Number left, Character right)
left
- a Numberright
- a Characterpublic static Number minus(Character left, Character right)
left
- a Characterright
- a Characterpublic static Number multiply(Character left, Number right)
left
- a Characterright
- a Numberpublic static Number multiply(Number left, Character right)
left
- a Numberright
- a Characterpublic static Number multiply(Character left, Character right)
left
- a Characterright
- another Characterpublic static Number multiply(BigDecimal left, Double right)
left
- a BigDecimalright
- a Doublepublic static Number multiply(BigDecimal left, BigInteger right)
left
- a BigDecimalright
- a BigIntegerpublic static Number power(Number self, Number exponent)
self
- a Numberexponent
- a Number exponentpublic static Number power(BigDecimal self, Integer exponent)
self
- a BigDecimalexponent
- an Integer exponentpublic static Number power(BigInteger self, Integer exponent)
self
- a BigIntegerexponent
- an Integer exponentpublic static Number power(Integer self, Integer exponent)
self
- an Integerexponent
- an Integer exponentpublic static Number power(Long self, Integer exponent)
self
- a Longexponent
- an Integer exponentpublic static BigInteger power(BigInteger self, BigInteger exponent)
self
- a BigIntegerexponent
- an BigInteger exponentpublic static Number div(Character left, Number right)
left
- a Characterright
- a Numberpublic static Number div(Number left, Character right)
left
- a Numberright
- a Characterpublic static Number div(Character left, Character right)
left
- a Characterright
- another Characterpublic static Number intdiv(Character left, Number right)
left
- a Characterright
- a Numberpublic static Number intdiv(Number left, Character right)
left
- a Numberright
- a Characterpublic static Number intdiv(Character left, Character right)
left
- a Characterright
- another Characterpublic static Number intdiv(Number left, Number right)
left
- a Numberright
- another Numberpublic static Number or(Number left, Number right)
left
- a Numberright
- another Number to bitwise ORpublic static Number and(Number left, Number right)
left
- a Numberright
- another Number to bitwise ANDpublic static BitSet and(BitSet left, BitSet right)
left
- a BitSetright
- another BitSet to bitwise ANDpublic static BitSet xor(BitSet left, BitSet right)
left
- a BitSetright
- another BitSet to bitwise ANDpublic static BitSet bitwiseNegate(BitSet self)
self
- a BitSetpublic static Number bitwiseNegate(Number left)
left
- a Numberpublic static BitSet or(BitSet left, BitSet right)
left
- a BitSetright
- another BitSet to bitwise ANDpublic static Number xor(Number left, Number right)
left
- a Numberright
- another Number to bitwse XORpublic static Number mod(Number left, Number right)
left
- a Numberright
- another Number to modpublic static Number unaryMinus(Number left)
-10
left
- a Numberpublic static Number unaryPlus(Number left)
+10
left
- a Numberpublic static void times(Number self, Closure closure)
10.times { println it }Prints the numbers 0 through 9.
self
- a Numberclosure
- the closure to call a number of timespublic static void upto(Number self, Number to, Closure closure)
self
- a Numberto
- another Number to go up toclosure
- the closure to callpublic static void upto(long self, Number to, Closure closure)
self
- a longto
- the end numberclosure
- the code to execute for each numberpublic static void upto(Long self, Number to, Closure closure)
self
- a Longto
- the end numberclosure
- the code to execute for each numberpublic static void upto(float self, Number to, Closure closure)
self
- a floatto
- the end numberclosure
- the code to execute for each numberpublic static void upto(Float self, Number to, Closure closure)
self
- a Floatto
- the end numberclosure
- the code to execute for each numberpublic static void upto(double self, Number to, Closure closure)
self
- a doubleto
- the end numberclosure
- the code to execute for each numberpublic static void upto(Double self, Number to, Closure closure)
self
- a Doubleto
- the end numberclosure
- the code to execute for each numberpublic static void upto(BigInteger self, Number to, Closure closure)
0.upto( 10 ) { println it }Prints numbers 0 to 10
self
- a BigIntegerto
- the end numberclosure
- the code to execute for each numberpublic static void upto(BigDecimal self, Number to, Closure closure)
0.1.upto( 10 ) { println it }Prints numbers 0.1, 1.1, 2.1... to 9.1
self
- a BigDecimalto
- the end numberclosure
- the code to execute for each numberpublic static void downto(Number self, Number to, Closure closure)
self
- a Numberto
- another Number to go down toclosure
- the closure to callpublic static void downto(long self, Number to, Closure closure)
self
- a longto
- the end numberclosure
- the code to execute for each numberpublic static void downto(Long self, Number to, Closure closure)
self
- a Longto
- the end numberclosure
- the code to execute for each numberpublic static void downto(float self, Number to, Closure closure)
self
- a floatto
- the end numberclosure
- the code to execute for each numberpublic static void downto(Float self, Number to, Closure closure)
self
- a Floatto
- the end numberclosure
- the code to execute for each numberpublic static void downto(double self, Number to, Closure closure)
self
- a doubleto
- the end numberclosure
- the code to execute for each numberpublic static void downto(Double self, Number to, Closure closure)
self
- a Doubleto
- the end numberclosure
- the code to execute for each numberpublic static void downto(BigInteger self, Number to, Closure closure)
self
- a BigIntegerto
- the end numberclosure
- the code to execute for each numberpublic static void downto(BigDecimal self, Number to, Closure closure)
10.5.downto(0) { println it }Prints numbers 10.5, 9.5 ... to 0.5.
self
- a BigDecimalto
- the end numberclosure
- the code to execute for each numberpublic static void step(Number self, Number to, Number stepNumber, Closure closure)
0.step( 10, 2 ) { println it }Prints even numbers 0 through 8.
self
- a Number to start withto
- a Number to go up to, exclusivestepNumber
- a Number representing the step incrementclosure
- the closure to callpublic static int abs(Number number)
number
- a Numberpublic static long abs(Long number)
number
- a Longpublic static float abs(Float number)
number
- a Floatpublic static double abs(Double number)
number
- a Doublepublic static int round(Float number)
number
- a Floatpublic static float round(Float number, int precision)
number
- a Floatprecision
- the number of decimal places to keeppublic static float trunc(Float number, int precision)
number
- a Floatprecision
- the number of decimal places to keeppublic static float trunc(Float number)
number
- a Doublepublic static long round(Double number)
number
- a Doublepublic static double round(Double number, int precision)
number
- a Doubleprecision
- the number of decimal places to keeppublic static double trunc(Double number)
number
- a Doublepublic static double trunc(Double number, int precision)
number
- a Doubleprecision
- the number of decimal places to keeppublic static boolean isUpperCase(Character self)
self
- a CharacterCharacter.isUpperCase(char)
public static boolean isLowerCase(Character self)
self
- a CharacterCharacter.isLowerCase(char)
public static boolean isLetter(Character self)
self
- a CharacterCharacter.isLetter(char)
public static boolean isDigit(Character self)
self
- a CharacterCharacter.isDigit(char)
public static boolean isLetterOrDigit(Character self)
self
- a CharacterCharacter.isLetterOrDigit(char)
public static boolean isWhitespace(Character self)
self
- a CharacterCharacter.isWhitespace(char)
public static char toUpperCase(Character self)
self
- a Character to convertCharacter.isUpperCase(char)
,
String.toUpperCase()
public static char toLowerCase(Character self)
self
- a Character to convertCharacter.isLowerCase(char)
,
String.toLowerCase()
public static Integer toInteger(Number self)
self
- a Numberpublic static Long toLong(Number self)
self
- a Numberpublic static Float toFloat(Number self)
self
- a Numberpublic static Double toDouble(Number self)
self
- a Numberpublic static BigDecimal toBigDecimal(Number self)
self
- a Numberpublic static <T> T asType(Number self, Class<T> c)
asType(java.lang.Object, java.lang.Class)
:
self
- this numberc
- the desired type of the transformed resultpublic static BigInteger toBigInteger(Number self)
self
- a Numberpublic static Boolean and(Boolean left, Boolean right)
left
- left operatorright
- right operatorpublic static Boolean or(Boolean left, Boolean right)
left
- left operatorright
- right operatorpublic static Boolean implies(Boolean left, Boolean right)
left
- left operatorright
- right operatorpublic static Boolean xor(Boolean left, Boolean right)
left
- left operatorright
- right operatorpublic static TimerTask runAfter(Timer timer, int delay, Closure closure)
timer
- a timer objectdelay
- the delay in milliseconds before running the closure codeclosure
- the closure to invokepublic static void eachByte(Byte[] self, Closure closure)
self
- a Byte arrayclosure
- a closureeach(java.lang.Object, groovy.lang.Closure)
public static void eachByte(byte[] self, Closure closure)
self
- a byte arrayclosure
- a closureeach(java.lang.Object, groovy.lang.Closure)
public static int findIndexOf(Object self, Closure closure)
self
- the iteration object over which to iterateclosure
- the filter to perform a match on the collectionpublic static int findIndexOf(Object self, int startIndex, Closure closure)
self
- the iteration object over which to iteratestartIndex
- start matching from this indexclosure
- the filter to perform a match on the collectionpublic static int findLastIndexOf(Object self, Closure closure)
self
- the iteration object over which to iterateclosure
- the filter to perform a match on the collectionpublic static int findLastIndexOf(Object self, int startIndex, Closure closure)
self
- the iteration object over which to iteratestartIndex
- start matching from this indexclosure
- the filter to perform a match on the collectionpublic static List<Number> findIndexValues(Object self, Closure closure)
self
- the iteration object over which to iterateclosure
- the filter to perform a match on the collectionpublic static List<Number> findIndexValues(Object self, Number startIndex, Closure closure)
self
- the iteration object over which to iteratestartIndex
- start matching from this indexclosure
- the filter to perform a match on the collectionpublic static ClassLoader getRootLoader(ClassLoader self)
null
will be returned. The name is used for comparison because
a direct comparison using == may fail as the class may be loaded through
different classloaders.self
- a ClassLoaderRootLoader
public static <T> T asType(Object obj, Class<T> type)
obj
- the object to converttype
- the goal typepublic static <T> T newInstance(Class<T> c)
c
- a classpublic static <T> T newInstance(Class<T> c, Object[] args)
newInstance(null)
or simply
newInstance()
for the default (no-arg) constructor.c
- a classargs
- the constructor argumentspublic static MetaClass getMetaClass(Class c)
String.metaClass.myMethod = { println "foo" }
c
- The java.lang.Class instancepublic static MetaClass getMetaClass(Object obj)
obj
- The object in questionpublic static MetaClass getMetaClass(GroovyObject obj)
obj
- The object in questionpublic static void setMetaClass(Class self, MetaClass metaClass)
self
- the class whose metaclass we wish to setmetaClass
- the new MetaClasspublic static void setMetaClass(Object self, MetaClass metaClass)
self
- the object whose metaclass we want to setmetaClass
- the new metaclass valuepublic static void setMetaClass(GroovyObject self, MetaClass metaClass)
self
- the object whose metaclass we want to setmetaClass
- the new metaclass valuepublic static MetaClass metaClass(Class self, Closure closure)
self
- the class whose metaclass we wish to updateclosure
- the closure representing the new metaclassGroovyRuntimeException
- if the metaclass can't be set for this classpublic static MetaClass metaClass(Object self, Closure closure)
self
- the object whose metaclass we wish to updateclosure
- the closure representing the new metaclassGroovyRuntimeException
- if the metaclass can't be set for this objectpublic static <T> Iterator<T> iterator(T[] a)
a
- an arrayDefaultTypeTransformation.asCollection(java.lang.Object[])
public static Iterator iterator(Object o)
o
- an objectDefaultTypeTransformation.asCollection(java.lang.Object)
public static <T> Iterator<T> iterator(Enumeration<T> enumeration)
remove()
method is unsupported since the
underlying Enumeration does not provide a mechanism for removing items.enumeration
- an Enumeration objectpublic static <T> Iterator<T> iterator(Iterator<T> self)
self
- an iterator objectpublic static List<MetaMethod> respondsTo(Object self, String name, Object[] argTypes)
Returns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name and arguments types.
Note that this method's return value is based on realised methods and does not take into account objects or classes that implement invokeMethod or methodMissing
This method is "safe" in that it will always return a value and never throw an exception
self
- The object to inspectname
- The name of the method of interestargTypes
- The argument types to match againstMetaObjectProtocol.respondsTo(java.lang.Object, java.lang.String, java.lang.Object[])
public static List<MetaMethod> respondsTo(Object self, String name)
Returns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name regardless of the arguments.
Note that this method's return value is based on realised methods and does not take into account objects or classes that implement invokeMethod or methodMissing
This method is "safe" in that it will always return a value and never throw an exception
self
- The object to inspectname
- The name of the method of interestMetaObjectProtocol.respondsTo(java.lang.Object, java.lang.String)
public static MetaProperty hasProperty(Object self, String name)
Returns true of the implementing MetaClass has a property of the given name
Note that this method will only return true for realised properties and does not take into account implementation of getProperty or propertyMissing
self
- The object to inspectname
- The name of the property of interestMetaObjectProtocol.hasProperty(java.lang.Object, java.lang.String)
@Deprecated public static boolean asBoolean(CharSequence string)
@Deprecated public static boolean asBoolean(Matcher matcher)
@Deprecated public static <T> T asType(CharSequence self, Class<T> c)
@Deprecated public static <T> T asType(GString self, Class<T> c)
@Deprecated public static <T> T asType(String self, Class<T> c)
@Deprecated public static Pattern bitwiseNegate(CharSequence self)
@Deprecated public static Pattern bitwiseNegate(String self)
@Deprecated public static CharSequence capitalize(CharSequence self)
@Deprecated public static String capitalize(String self)
@Deprecated public static CharSequence center(CharSequence self, Number numberOfChars)
@Deprecated public static CharSequence center(CharSequence self, Number numberOfChars, CharSequence padding)
@Deprecated public static String center(String self, Number numberOfChars)
@Deprecated public static String center(String self, Number numberOfChars, String padding)
@Deprecated public static boolean contains(CharSequence self, CharSequence text)
@Deprecated public static boolean contains(String self, String text)
@Deprecated public static int count(CharSequence self, CharSequence text)
@Deprecated public static int count(String self, String text)
@Deprecated protected static StringBufferWriter createStringBufferWriter(StringBuffer self)
@Deprecated protected static StringWriter createStringWriter(String self)
@Deprecated public static CharSequence denormalize(CharSequence self)
@Deprecated public static String denormalize(String self)
@Deprecated public static CharSequence drop(CharSequence self, int num)
@Deprecated public static <T> T eachLine(CharSequence self, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T eachLine(CharSequence self, int firstLine, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T eachLine(String self, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T eachLine(String self, int firstLine, Closure<T> closure) throws IOException
IOException
@Deprecated public static String eachMatch(CharSequence self, CharSequence regex, Closure closure)
@Deprecated public static String eachMatch(CharSequence self, Pattern pattern, Closure closure)
@Deprecated public static String eachMatch(String self, Pattern pattern, Closure closure)
@Deprecated public static String eachMatch(String self, String regex, Closure closure)
@Deprecated public static CharSequence expand(CharSequence self)
@Deprecated public static CharSequence expand(CharSequence self, int tabStop)
@Deprecated public static String expand(String self)
@Deprecated public static String expand(String self, int tabStop)
@Deprecated public static CharSequence expandLine(CharSequence self, int tabStop)
@Deprecated public static String expandLine(String self, int tabStop)
@Deprecated public static CharSequence find(CharSequence self, CharSequence regex)
@Deprecated public static CharSequence find(CharSequence self, CharSequence regex, Closure closure)
@Deprecated public static CharSequence find(CharSequence self, Pattern pattern)
@Deprecated public static CharSequence find(CharSequence self, Pattern pattern, Closure closure)
@Deprecated public static String find(String self, Pattern pattern)
@Deprecated public static String find(String self, Pattern pattern, Closure closure)
@Deprecated public static String find(String self, String regex)
@Deprecated public static String find(String self, String regex, Closure closure)
@Deprecated public static List<CharSequence> findAll(CharSequence self, CharSequence regex)
@Deprecated public static <T> List<T> findAll(CharSequence self, CharSequence regex, Closure<T> closure)
@Deprecated public static List<CharSequence> findAll(CharSequence self, Pattern pattern)
@Deprecated public static <T> List<T> findAll(CharSequence self, Pattern pattern, Closure<T> closure)
@Deprecated public static List<String> findAll(String self, Pattern pattern)
@Deprecated public static <T> List<T> findAll(String self, Pattern pattern, Closure<T> closure)
@Deprecated public static List<String> findAll(String self, String regex)
@Deprecated public static <T> List<T> findAll(String self, String regex, Closure<T> closure)
@Deprecated public static CharSequence getAt(CharSequence self, Collection indices)
@Deprecated public static CharSequence getAt(CharSequence text, EmptyRange range)
@Deprecated public static CharSequence getAt(CharSequence text, int index)
@Deprecated public static CharSequence getAt(CharSequence text, IntRange range)
@Deprecated public static CharSequence getAt(CharSequence text, Range range)
@Deprecated public static List getAt(Matcher self, Collection indices)
@Deprecated public static Object getAt(Matcher matcher, int idx)
@Deprecated public static String getAt(String self, Collection indices)
@Deprecated public static String getAt(String text, EmptyRange range)
@Deprecated public static String getAt(String text, int index)
@Deprecated public static String getAt(String text, IntRange range)
@Deprecated public static String getAt(String text, Range range)
@Deprecated public static char[] getChars(CharSequence self)
@Deprecated public static char[] getChars(String self)
@Deprecated public static int getCount(Matcher matcher)
@Deprecated public static boolean hasGroup(Matcher matcher)
@Deprecated public static boolean isAllWhitespace(CharSequence self)
@Deprecated public static boolean isAllWhitespace(String self)
@Deprecated public static boolean isBigDecimal(CharSequence self)
@Deprecated public static boolean isBigDecimal(String self)
@Deprecated public static boolean isBigInteger(CharSequence self)
@Deprecated public static boolean isBigInteger(String self)
@Deprecated public static boolean isCase(CharSequence caseValue, Object switchValue)
@Deprecated public static boolean isCase(GString caseValue, Object switchValue)
@Deprecated public static boolean isCase(Pattern caseValue, Object switchValue)
@Deprecated public static boolean isCase(String caseValue, Object switchValue)
@Deprecated public static boolean isDouble(CharSequence self)
@Deprecated public static boolean isDouble(String self)
@Deprecated public static boolean isFloat(CharSequence self)
@Deprecated public static boolean isFloat(String self)
@Deprecated public static boolean isInteger(CharSequence self)
@Deprecated public static boolean isInteger(String self)
@Deprecated public static boolean isLong(CharSequence self)
@Deprecated public static boolean isLong(String self)
@Deprecated public static boolean isNumber(CharSequence self)
@Deprecated public static boolean isNumber(String self)
@Deprecated public static Iterator iterator(Matcher matcher)
@Deprecated public static StringBuilder leftShift(CharSequence self, Object value)
@Deprecated public static StringBuffer leftShift(String self, Object value)
@Deprecated public static StringBuffer leftShift(StringBuffer self, Object value)
@Deprecated public static StringBuilder leftShift(StringBuilder self, Object value)
@Deprecated public static boolean matches(CharSequence self, Pattern pattern)
@Deprecated public static boolean matches(String self, Pattern pattern)
@Deprecated public static CharSequence minus(CharSequence self, Object target)
@Deprecated public static String minus(String self, Object target)
@Deprecated public static CharSequence multiply(CharSequence self, Number factor)
@Deprecated public static String multiply(String self, Number factor)
@Deprecated public static CharSequence next(CharSequence self)
@Deprecated public static String next(String self)
@Deprecated public static CharSequence normalize(CharSequence self)
@Deprecated public static String normalize(String self)
@Deprecated public static CharSequence padLeft(CharSequence self, Number numberOfChars)
@Deprecated public static CharSequence padLeft(CharSequence self, Number numberOfChars, CharSequence padding)
@Deprecated public static String padLeft(String self, Number numberOfChars)
@Deprecated public static String padLeft(String self, Number numberOfChars, String padding)
@Deprecated public static CharSequence padRight(CharSequence self, Number numberOfChars)
@Deprecated public static CharSequence padRight(CharSequence self, Number numberOfChars, CharSequence padding)
@Deprecated public static String padRight(String self, Number numberOfChars)
@Deprecated public static String padRight(String self, Number numberOfChars, String padding)
@Deprecated public static CharSequence plus(CharSequence left, Object value)
@Deprecated public static String plus(Number value, String right)
@Deprecated public static String plus(String left, Object value)
@Deprecated public static String plus(StringBuffer left, String value)
@Deprecated public static CharSequence previous(CharSequence self)
@Deprecated public static String previous(String self)
@Deprecated public static void putAt(StringBuffer self, EmptyRange range, Object value)
@Deprecated public static void putAt(StringBuffer self, IntRange range, Object value)
@Deprecated public static List<CharSequence> readLines(CharSequence self) throws IOException
IOException
@Deprecated public static List<String> readLines(String self) throws IOException
IOException
@Deprecated public static CharSequence replaceAll(CharSequence self, CharSequence regex, CharSequence replacement)
@Deprecated public static CharSequence replaceAll(CharSequence self, CharSequence regex, Closure closure)
@Deprecated public static CharSequence replaceAll(CharSequence self, Pattern pattern, CharSequence replacement)
@Deprecated public static String replaceAll(CharSequence self, Pattern pattern, Closure closure)
@Deprecated public static String replaceAll(String self, Pattern pattern, Closure closure)
@Deprecated public static String replaceAll(String self, Pattern pattern, String replacement)
@Deprecated public static String replaceAll(String self, String regex, Closure closure)
@Deprecated public static String replaceFirst(CharSequence self, CharSequence regex, CharSequence replacement)
@Deprecated public static String replaceFirst(CharSequence self, CharSequence regex, Closure closure)
@Deprecated public static CharSequence replaceFirst(CharSequence self, Pattern pattern, CharSequence replacement)
@Deprecated public static String replaceFirst(CharSequence self, Pattern pattern, Closure closure)
@Deprecated public static String replaceFirst(String self, Pattern pattern, Closure closure)
@Deprecated public static String replaceFirst(String self, Pattern pattern, String replacement)
@Deprecated public static String replaceFirst(String self, String regex, Closure closure)
@Deprecated public static CharSequence reverse(CharSequence self)
@Deprecated public static String reverse(String self)
@Deprecated public static void setIndex(Matcher matcher, int idx)
@Deprecated public static int size(CharSequence text)
@Deprecated public static long size(Matcher self)
@Deprecated public static int size(String text)
@Deprecated public static int size(StringBuffer buffer)
@Deprecated public static CharSequence[] split(CharSequence self)
@Deprecated public static String[] split(GString self)
@Deprecated public static String[] split(String self)
@Deprecated public static <T> T splitEachLine(CharSequence self, CharSequence regex, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T splitEachLine(CharSequence self, Pattern pattern, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T splitEachLine(String self, Pattern pattern, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T splitEachLine(String self, String regex, Closure<T> closure) throws IOException
IOException
@Deprecated public static CharSequence stripIndent(CharSequence self)
@Deprecated public static CharSequence stripIndent(CharSequence self, int numChars)
@Deprecated public static String stripIndent(String self)
@Deprecated public static String stripIndent(String self, int numChars)
@Deprecated public static CharSequence stripMargin(CharSequence self)
@Deprecated public static CharSequence stripMargin(CharSequence self, char marginChar)
@Deprecated public static String stripMargin(CharSequence self, CharSequence marginChar)
@Deprecated public static String stripMargin(String self)
@Deprecated public static String stripMargin(String self, char marginChar)
@Deprecated public static String stripMargin(String self, String marginChar)
@Deprecated public static BigDecimal toBigDecimal(CharSequence self)
@Deprecated public static BigDecimal toBigDecimal(String self)
@Deprecated public static BigInteger toBigInteger(CharSequence self)
@Deprecated public static BigInteger toBigInteger(String self)
@Deprecated public static Boolean toBoolean(String self)
@Deprecated public static Character toCharacter(String self)
@Deprecated public static Double toDouble(CharSequence self)
@Deprecated public static Double toDouble(String self)
@Deprecated public static Float toFloat(CharSequence self)
@Deprecated public static Float toFloat(String self)
@Deprecated public static Integer toInteger(CharSequence self)
@Deprecated public static Integer toInteger(String self)
@Deprecated public static List<CharSequence> tokenize(CharSequence self)
@Deprecated public static List<CharSequence> tokenize(CharSequence self, Character token)
@Deprecated public static List<CharSequence> tokenize(CharSequence self, CharSequence token)
@Deprecated public static List<String> tokenize(String self)
@Deprecated public static List<String> tokenize(String self, Character token)
@Deprecated public static List<String> tokenize(String self, String token)
@Deprecated public static List<CharSequence> toList(CharSequence self)
@Deprecated public static List<String> toList(String self)
@Deprecated public static Long toLong(CharSequence self)
@Deprecated public static Long toLong(String self)
@Deprecated public static Set<CharSequence> toSet(CharSequence self)
@Deprecated public static Set<String> toSet(String self)
@Deprecated public static Short toShort(CharSequence self)
@Deprecated public static Short toShort(String self)
@Deprecated public static URI toURI(CharSequence self) throws URISyntaxException
URISyntaxException
@Deprecated public static URI toURI(String self) throws URISyntaxException
URISyntaxException
@Deprecated public static URL toURL(CharSequence self) throws MalformedURLException
MalformedURLException
@Deprecated public static URL toURL(String self) throws MalformedURLException
MalformedURLException
@Deprecated public static CharSequence tr(CharSequence self, CharSequence sourceSet, CharSequence replacementSet) throws ClassNotFoundException
ClassNotFoundException
@Deprecated public static String tr(String self, String sourceSet, String replacementSet) throws ClassNotFoundException
ClassNotFoundException
@Deprecated public static CharSequence unexpand(CharSequence self)
@Deprecated public static CharSequence unexpand(CharSequence self, int tabStop)
@Deprecated public static String unexpand(String self)
@Deprecated public static String unexpand(String self, int tabStop)
@Deprecated public static CharSequence unexpandLine(CharSequence self, int tabStop)
@Deprecated public static String unexpandLine(String self, int tabStop)
@Deprecated public static Process execute(String self) throws IOException
IOException
@Deprecated public static Process execute(String self, String[] envp, File dir) throws IOException
IOException
@Deprecated public static Process execute(String self, List envp, File dir) throws IOException
IOException
@Deprecated public static Process execute(String[] commandArray) throws IOException
IOException
@Deprecated public static Process execute(String[] commandArray, String[] envp, File dir) throws IOException
IOException
@Deprecated public static Process execute(String[] commandArray, List envp, File dir) throws IOException
IOException
@Deprecated public static Process execute(List commands) throws IOException
IOException
@Deprecated public static Process execute(List commands, String[] envp, File dir) throws IOException
IOException
@Deprecated public static Process execute(List commands, List envp, File dir) throws IOException
IOException
@Deprecated public static <T> T withStreams(Socket socket, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T withObjectStreams(Socket socket, Closure<T> closure) throws IOException
IOException
@Deprecated public static Writer leftShift(Socket self, Object value) throws IOException
IOException
@Deprecated public static OutputStream leftShift(Socket self, byte[] value) throws IOException
IOException
@Deprecated public static Socket accept(ServerSocket serverSocket, Closure closure) throws IOException
IOException
@Deprecated public static Socket accept(ServerSocket serverSocket, boolean runInANewThread, Closure closure) throws IOException
IOException
@Deprecated public static long size(File self)
@Deprecated public static Writer leftShift(Writer self, Object value) throws IOException
IOException
@Deprecated public static void write(Writer self, Writable writable) throws IOException
IOException
@Deprecated public static Writer leftShift(OutputStream self, Object value) throws IOException
IOException
@Deprecated public static void leftShift(ObjectOutputStream self, Object value) throws IOException
IOException
@Deprecated public static OutputStream leftShift(OutputStream self, InputStream in) throws IOException
IOException
@Deprecated public static OutputStream leftShift(OutputStream self, byte[] value) throws IOException
IOException
@Deprecated public static ObjectOutputStream newObjectOutputStream(File file) throws IOException
IOException
@Deprecated public static ObjectOutputStream newObjectOutputStream(OutputStream outputStream) throws IOException
IOException
@Deprecated public static <T> T withObjectOutputStream(File file, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T withObjectOutputStream(OutputStream outputStream, Closure<T> closure) throws IOException
IOException
@Deprecated public static ObjectInputStream newObjectInputStream(File file) throws IOException
IOException
@Deprecated public static ObjectInputStream newObjectInputStream(InputStream inputStream) throws IOException
IOException
@Deprecated public static ObjectInputStream newObjectInputStream(InputStream inputStream, ClassLoader classLoader) throws IOException
IOException
@Deprecated public static ObjectInputStream newObjectInputStream(File file, ClassLoader classLoader) throws IOException
IOException
@Deprecated public static void eachObject(File self, Closure closure) throws IOException, ClassNotFoundException
IOException
ClassNotFoundException
@Deprecated public static void eachObject(ObjectInputStream ois, Closure closure) throws IOException, ClassNotFoundException
IOException
ClassNotFoundException
@Deprecated public static <T> T withObjectInputStream(File file, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T withObjectInputStream(File file, ClassLoader classLoader, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T withObjectInputStream(InputStream inputStream, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T withObjectInputStream(InputStream inputStream, ClassLoader classLoader, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T eachLine(File self, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T eachLine(File self, String charset, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T eachLine(File self, int firstLine, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T eachLine(File self, String charset, int firstLine, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T eachLine(InputStream stream, String charset, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T eachLine(InputStream stream, String charset, int firstLine, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T eachLine(InputStream stream, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T eachLine(InputStream stream, int firstLine, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T eachLine(URL url, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T eachLine(URL url, int firstLine, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T eachLine(URL url, String charset, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T eachLine(URL url, String charset, int firstLine, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T eachLine(Reader self, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T eachLine(Reader self, int firstLine, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T splitEachLine(File self, String regex, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T splitEachLine(File self, Pattern pattern, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T splitEachLine(File self, String regex, String charset, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T splitEachLine(File self, Pattern pattern, String charset, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T splitEachLine(URL self, String regex, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T splitEachLine(URL self, Pattern pattern, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T splitEachLine(URL self, String regex, String charset, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T splitEachLine(URL self, Pattern pattern, String charset, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T splitEachLine(Reader self, String regex, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T splitEachLine(Reader self, Pattern pattern, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T splitEachLine(InputStream stream, String regex, String charset, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T splitEachLine(InputStream stream, Pattern pattern, String charset, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T splitEachLine(InputStream stream, String regex, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T splitEachLine(InputStream stream, Pattern pattern, Closure<T> closure) throws IOException
IOException
@Deprecated public static String readLine(Reader self) throws IOException
IOException
@Deprecated public static List<String> readLines(File file) throws IOException
IOException
@Deprecated public static List<String> readLines(File file, String charset) throws IOException
IOException
@Deprecated public static List<String> readLines(InputStream stream) throws IOException
IOException
@Deprecated public static List<String> readLines(InputStream stream, String charset) throws IOException
IOException
@Deprecated public static List<String> readLines(URL self) throws IOException
IOException
@Deprecated public static List<String> readLines(URL self, String charset) throws IOException
IOException
@Deprecated public static List<String> readLines(Reader reader) throws IOException
IOException
@Deprecated public static String getText(File file, String charset) throws IOException
IOException
@Deprecated public static String getText(File file) throws IOException
IOException
@Deprecated public static String getText(URL url) throws IOException
IOException
@Deprecated public static String getText(URL url, Map parameters) throws IOException
IOException
@Deprecated public static String getText(URL url, String charset) throws IOException
IOException
@Deprecated public static String getText(URL url, Map parameters, String charset) throws IOException
IOException
@Deprecated public static String getText(InputStream is) throws IOException
IOException
@Deprecated public static String getText(InputStream is, String charset) throws IOException
IOException
@Deprecated public static String getText(Reader reader) throws IOException
IOException
@Deprecated public static String getText(BufferedReader reader) throws IOException
IOException
@Deprecated public static byte[] getBytes(File file) throws IOException
IOException
@Deprecated public static byte[] getBytes(URL url) throws IOException
IOException
@Deprecated public static byte[] getBytes(InputStream is) throws IOException
IOException
@Deprecated public static void setBytes(File file, byte[] bytes) throws IOException
IOException
@Deprecated public static void setBytes(OutputStream os, byte[] bytes) throws IOException
IOException
@Deprecated public static void writeLine(BufferedWriter writer, String line) throws IOException
IOException
@Deprecated public static void write(File file, String text) throws IOException
IOException
@Deprecated public static void setText(File file, String text) throws IOException
IOException
@Deprecated public static void setText(File file, String text, String charset) throws IOException
IOException
@Deprecated public static File leftShift(File file, Object text) throws IOException
IOException
@Deprecated public static File leftShift(File file, byte[] bytes) throws IOException
IOException
@Deprecated public static File leftShift(File file, InputStream data) throws IOException
IOException
@Deprecated public static void write(File file, String text, String charset) throws IOException
IOException
@Deprecated public static void append(File file, Object text) throws IOException
IOException
@Deprecated public static void append(File file, byte[] bytes) throws IOException
IOException
@Deprecated public static void append(File self, InputStream stream) throws IOException
IOException
@Deprecated public static void append(File file, Object text, String charset) throws IOException
IOException
@Deprecated public static void eachFile(File self, FileType fileType, Closure closure) throws FileNotFoundException, IllegalArgumentException
@Deprecated public static void eachFile(File self, Closure closure) throws FileNotFoundException, IllegalArgumentException
@Deprecated public static void eachDir(File self, Closure closure) throws FileNotFoundException, IllegalArgumentException
@Deprecated public static void eachFileRecurse(File self, FileType fileType, Closure closure) throws FileNotFoundException, IllegalArgumentException
@Deprecated public static void traverse(File self, Map<String,Object> options, Closure closure) throws FileNotFoundException, IllegalArgumentException
@Deprecated public static void traverse(File self, Closure closure) throws FileNotFoundException, IllegalArgumentException
@Deprecated public static void traverse(File self, Map<String,Object> options) throws FileNotFoundException, IllegalArgumentException
@Deprecated public static void eachFileRecurse(File self, Closure closure) throws FileNotFoundException, IllegalArgumentException
@Deprecated public static void eachDirRecurse(File self, Closure closure) throws FileNotFoundException, IllegalArgumentException
@Deprecated public static void eachFileMatch(File self, FileType fileType, Object nameFilter, Closure closure) throws FileNotFoundException, IllegalArgumentException
@Deprecated public static void eachFileMatch(File self, Object nameFilter, Closure closure) throws FileNotFoundException, IllegalArgumentException
@Deprecated public static void eachDirMatch(File self, Object nameFilter, Closure closure) throws FileNotFoundException, IllegalArgumentException
@Deprecated public static boolean deleteDir(File self)
@Deprecated public static boolean renameTo(File self, String newPathName)
@Deprecated public static Iterator<String> iterator(Reader self)
@Deprecated public static Iterator<Byte> iterator(InputStream self)
@Deprecated public static Iterator<Byte> iterator(DataInputStream self)
@Deprecated public static File asWritable(File file)
@Deprecated public static <T> T asType(File f, Class<T> c)
@Deprecated public static File asWritable(File file, String encoding)
@Deprecated public static BufferedReader newReader(File file) throws IOException
IOException
@Deprecated public static BufferedReader newReader(File file, String charset) throws FileNotFoundException, UnsupportedEncodingException
@Deprecated public static BufferedReader newReader(InputStream self)
@Deprecated public static BufferedReader newReader(InputStream self, String charset) throws UnsupportedEncodingException
UnsupportedEncodingException
@Deprecated public static <T> T withReader(File file, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T withReader(File file, String charset, Closure<T> closure) throws IOException
IOException
@Deprecated public static BufferedOutputStream newOutputStream(File file) throws IOException
IOException
@Deprecated public static DataOutputStream newDataOutputStream(File file) throws IOException
IOException
@Deprecated public static Object withOutputStream(File file, Closure closure) throws IOException
IOException
@Deprecated public static Object withInputStream(File file, Closure closure) throws IOException
IOException
@Deprecated public static <T> T withInputStream(URL url, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T withDataOutputStream(File file, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T withDataInputStream(File file, Closure<T> closure) throws IOException
IOException
@Deprecated public static BufferedWriter newWriter(File file) throws IOException
IOException
@Deprecated public static BufferedWriter newWriter(File file, boolean append) throws IOException
IOException
@Deprecated public static BufferedWriter newWriter(File file, String charset, boolean append) throws IOException
IOException
@Deprecated public static BufferedWriter newWriter(File file, String charset) throws IOException
IOException
@Deprecated public static <T> T withWriter(File file, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T withWriter(File file, String charset, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T withWriterAppend(File file, String charset, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T withWriterAppend(File file, Closure<T> closure) throws IOException
IOException
@Deprecated public static PrintWriter newPrintWriter(File file) throws IOException
IOException
@Deprecated public static PrintWriter newPrintWriter(File file, String charset) throws IOException
IOException
@Deprecated public static PrintWriter newPrintWriter(Writer writer)
@Deprecated public static <T> T withPrintWriter(File file, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T withPrintWriter(File file, String charset, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T withPrintWriter(Writer writer, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T withWriter(Writer writer, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T withReader(Reader reader, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T withStream(InputStream stream, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T withReader(URL url, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T withReader(URL url, String charset, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T withReader(InputStream in, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T withReader(InputStream in, String charset, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T withWriter(OutputStream stream, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T withWriter(OutputStream stream, String charset, Closure<T> closure) throws IOException
IOException
@Deprecated public static <T> T withStream(OutputStream os, Closure<T> closure) throws IOException
IOException
@Deprecated public static BufferedInputStream newInputStream(File file) throws FileNotFoundException
FileNotFoundException
@Deprecated public static BufferedInputStream newInputStream(URL url) throws MalformedURLException, IOException
MalformedURLException
IOException
@Deprecated public static BufferedInputStream newInputStream(URL url, Map parameters) throws MalformedURLException, IOException
MalformedURLException
IOException
@Deprecated public static BufferedReader newReader(URL url) throws MalformedURLException, IOException
MalformedURLException
IOException
@Deprecated public static BufferedReader newReader(URL url, Map parameters) throws MalformedURLException, IOException
MalformedURLException
IOException
@Deprecated public static BufferedReader newReader(URL url, String charset) throws MalformedURLException, IOException
MalformedURLException
IOException
@Deprecated public static BufferedReader newReader(URL url, Map parameters, String charset) throws MalformedURLException, IOException
MalformedURLException
IOException
@Deprecated public static DataInputStream newDataInputStream(File file) throws FileNotFoundException
FileNotFoundException
@Deprecated public static void eachByte(File self, Closure closure) throws IOException
IOException
@Deprecated public static void eachByte(File self, int bufferLen, Closure closure) throws IOException
IOException
@Deprecated public static void eachByte(InputStream is, Closure closure) throws IOException
IOException
@Deprecated public static void eachByte(InputStream is, int bufferLen, Closure closure) throws IOException
IOException
@Deprecated public static void eachByte(URL url, Closure closure) throws IOException
IOException
@Deprecated public static void eachByte(URL url, int bufferLen, Closure closure) throws IOException
IOException
@Deprecated public static void transformChar(Reader self, Writer writer, Closure closure) throws IOException
IOException
@Deprecated public static void transformLine(Reader reader, Writer writer, Closure closure) throws IOException
IOException
@Deprecated public static void filterLine(Reader reader, Writer writer, Closure closure) throws IOException
IOException
@Deprecated public static Writable filterLine(File self, Closure closure) throws IOException
IOException
@Deprecated public static Writable filterLine(File self, String charset, Closure closure) throws IOException
IOException
@Deprecated public static void filterLine(File self, Writer writer, Closure closure) throws IOException
IOException
@Deprecated public static void filterLine(File self, Writer writer, String charset, Closure closure) throws IOException
IOException
@Deprecated public static Writable filterLine(Reader reader, Closure closure)
@Deprecated public static Writable filterLine(InputStream self, Closure predicate)
@Deprecated public static Writable filterLine(InputStream self, String charset, Closure predicate) throws UnsupportedEncodingException
UnsupportedEncodingException
@Deprecated public static void filterLine(InputStream self, Writer writer, Closure predicate) throws IOException
IOException
@Deprecated public static void filterLine(InputStream self, Writer writer, String charset, Closure predicate) throws IOException
IOException
@Deprecated public static Writable filterLine(URL self, Closure predicate) throws IOException
IOException
@Deprecated public static Writable filterLine(URL self, String charset, Closure predicate) throws IOException
IOException
@Deprecated public static void filterLine(URL self, Writer writer, Closure predicate) throws IOException
IOException
@Deprecated public static void filterLine(URL self, Writer writer, String charset, Closure predicate) throws IOException
IOException
@Deprecated public static byte[] readBytes(File file) throws IOException
IOException
public static Object withTraits(Object self, Class<?>... traits)
self
- object to be wrappedtraits
- a list of trait classes