This class defines new groovy methods which appear on normal JDK
classes inside the Groovy environment. Static methods are used with the
first parameter being the destination class,
i.e. 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.
| Modifiers | Name | Description |
|---|---|---|
static Class[] |
DGM_LIKE_CLASSES |
|
static Class[] |
additionals |
| Type | Name and description |
|---|---|
static int |
abs(Number number)Truncate the value |
static long |
abs(Long number) |
static float |
abs(Float number)Determine if a Character is uppercase. |
static double |
abs(Double number)Determine if a Character is lowercase. |
static Socket |
accept(ServerSocket serverSocket, Closure closure) |
static Socket |
accept(ServerSocket serverSocket, boolean runInANewThread, Closure closure) |
static boolean |
addAll(Collection self, Object[] items) |
static boolean |
addAll(List self, int index, Object[] items)Splits all items into two lists based on the closure condition. |
static void |
addShutdownHook(Object self, Closure closure) |
static Number |
and(Number left, Number right) |
static BitSet |
and(BitSet left, BitSet right) |
static Boolean |
and(Boolean left, Boolean right)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 boolean |
any(Object self, Closure closure) |
static boolean |
any(Iterator self, Closure closure) |
static boolean |
any(Iterable self, Closure closure) |
static boolean |
any(Map self, Closure closure) |
static boolean |
any(Object self) |
static void |
append(File file, Object text) |
static void |
append(File file, byte[] bytes) |
static void |
append(File self, InputStream stream) |
static void |
append(File file, Object text, String charset) |
static boolean |
asBoolean(Object object) |
static boolean |
asBoolean(Boolean bool) |
static boolean |
asBoolean(Collection collection) |
static boolean |
asBoolean(Map map) |
static boolean |
asBoolean(Iterator iterator) |
static boolean |
asBoolean(Enumeration enumeration) |
static boolean |
asBoolean(Object[] array) |
static boolean |
asBoolean(byte[] array) |
static boolean |
asBoolean(short[] array) |
static boolean |
asBoolean(int[] array) |
static boolean |
asBoolean(long[] array) |
static boolean |
asBoolean(float[] array) |
static boolean |
asBoolean(double[] array) |
static boolean |
asBoolean(boolean[] array) |
static boolean |
asBoolean(char[] array) |
static boolean |
asBoolean(Character character) |
static boolean |
asBoolean(Number number) |
static boolean |
asBoolean(CharSequence string) |
static boolean |
asBoolean(Matcher matcher) |
static Map |
asImmutable(Map self)A convenience method for creating an immutable list |
static SortedMap |
asImmutable(SortedMap self) |
static List |
asImmutable(List self) |
static Set |
asImmutable(Set self) |
static SortedSet |
asImmutable(SortedSet self) |
static Collection |
asImmutable(Collection self)A convenience method for creating a synchronized SortedMap. |
static List |
asList(Collection self) |
static List |
asList(Iterable self)Coerce an Boolean instance to a boolean value. |
static Map |
asSynchronized(Map self) |
static SortedMap |
asSynchronized(SortedMap self) |
static Collection |
asSynchronized(Collection self) |
static List |
asSynchronized(List self) |
static Set |
asSynchronized(Set self) |
static SortedSet |
asSynchronized(SortedSet self) |
static Object |
asType(Collection col, Class clazz) |
static Object |
asType(Object[] ary, Class clazz)Converts the given array to either a List, Set, or SortedSet. |
static Object |
asType(Closure cl, Class clazz) |
static Object |
asType(Map map, Class clazz)Creates a new List with the identical contents to this list but in reverse order. |
static Object |
asType(Number self, Class c)Traverse through each byte of this Byte array. |
static Object |
asType(Object obj, Class type)Adds a "metaClass" property to all class objects so you can use the syntax String.metaClass.myMethod = { println "foo" } |
static Object |
asType(CharSequence self, Class c) |
static Object |
asType(GString self, Class c) |
static Object |
asType(String self, Class c) |
static Object |
asType(File f, Class c) |
static File |
asWritable(File file) |
static File |
asWritable(File file, String encoding) |
static BitSet |
bitwiseNegate(BitSet self)Iterates from this number up to the given number, inclusive, incrementing by one each time. |
static Number |
bitwiseNegate(Number left) |
static Pattern |
bitwiseNegate(CharSequence self) |
static Pattern |
bitwiseNegate(String self) |
protected static Object |
callClosureForLine(Closure closure, String line, int counter) |
protected static Object |
callClosureForMapEntry(Closure closure, Map.Entry entry) |
protected static Object |
callClosureForMapEntryAndCounter(Closure closure, Map.Entry entry, int counter) |
static CharSequence |
capitalize(CharSequence self) |
static String |
capitalize(String self) |
static CharSequence |
center(CharSequence self, Number numberOfChars) |
static CharSequence |
center(CharSequence self, Number numberOfChars, CharSequence padding) |
static String |
center(String self, Number numberOfChars) |
static String |
center(String self, Number numberOfChars, String padding) |
static List |
collate(List self, int size) |
static List |
collate(List self, int size, int step) |
static List |
collate(List self, int size, boolean keepRemainder) |
static List |
collate(List self, int size, int step, boolean keepRemainder) |
static List |
collect(Object self, Closure transform)Iterates through this aggregate Object transforming each item into a new value using the transform closure, returning a list of transformed values.
|
static Collection |
collect(Object self)Iterates through this aggregate Object transforming each item into a new value using the transform closure
and adding it to the supplied collector. |
static Collection |
collect(Object self, Collection collector, Closure transform) |
static List |
collect(Collection self, Closure transform)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 List |
collect(Collection self)Iterates through this collection transforming each value into a new value using the transform closure
and adding it to the supplied collector.
|
static Collection |
collect(Collection self, Collection collector, Closure transform) |
static Collection |
collect(Map self, Collection collector, Closure transform) |
static List |
collect(Map self, Closure transform) |
static List |
collectAll(Collection self, Closure transform) |
static Collection |
collectAll(Collection self, Collection collector, Closure transform) |
static Map |
collectEntries(Map self, Map collector, Closure transform) |
static Map |
collectEntries(Map self, Closure transform)@deprecated Use the Iterable version of collectEntries instead |
static Map |
collectEntries(Collection self, Closure transform) |
static Map |
collectEntries(Iterator self, Closure transform) |
static Map |
collectEntries(Iterable self, Closure transform)@deprecated Use the Iterable version of collectEntries instead |
static Map |
collectEntries(Collection self) |
static Map |
collectEntries(Iterator self) |
static Map |
collectEntries(Iterable self)@deprecated Use the Iterable version of collectEntries instead |
static Map |
collectEntries(Collection self, Map collector, Closure transform) |
static Map |
collectEntries(Iterator self, Map collector, Closure transform) |
static Map |
collectEntries(Iterable self, Map collector, Closure transform)@deprecated Use the Iterable version of collectEntries instead |
static Map |
collectEntries(Collection self, Map collector) |
static Map |
collectEntries(Iterator self, Map 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 Map |
collectEntries(Iterable self, Map collector) |
static Map |
collectEntries(E[] self, Map collector, Closure transform)A variant of collectEntries using the identity closure as the transform. |
static Map |
collectEntries(Object[] self, Map collector) |
static Map |
collectEntries(E[] self, Closure transform)A variant of collectEntries using the identity closure as the transform. |
static Map |
collectEntries(Object[] self) |
static List |
collectMany(Collection self, Closure projection)@deprecated Use the Iterable version of collectMany instead |
static Collection |
collectMany(Collection self, Collection collector, Closure projection) |
static List |
collectMany(Iterable self, Closure projection) |
static Collection |
collectMany(Iterable self, Collection collector, Closure projection) |
static Collection |
collectMany(Map self, Collection collector, Closure projection) |
static Collection |
collectMany(Map self, Closure projection) |
static List |
collectMany(E[] self, Closure projection) |
static List |
collectMany(Iterator self, Closure projection) |
static List |
collectNested(Collection self, Closure transform) |
static List |
collectNested(Iterable self, Closure transform)Deprecated alias for collectNested |
static Collection |
collectNested(Collection self, Collection collector, Closure transform) |
static Collection |
collectNested(Iterable self, Collection collector, Closure transform) |
static List |
combinations(Collection self)Adds GroovyCollections#combinations(Iterable) as a method on Iterables. |
static List |
combinations(Iterable self)Adds GroovyCollections#combinations(Iterable, Closure) as a method on collections. |
static List |
combinations(Iterable self, Closure function)Applies a function on each combination of the input lists. |
static int |
compareTo(Character left, Number right)Multiply a Number by a Character. |
static int |
compareTo(Number left, Character right)Multiply two Characters. |
static int |
compareTo(Character left, Character right) |
static int |
compareTo(Number left, Number right) |
static boolean |
contains(int[] self, Object value) |
static boolean |
contains(long[] self, Object value)Checks whether the array contains the given value. |
static boolean |
contains(short[] self, Object value)Returns the string representation of the given array. |
static boolean |
contains(char[] self, Object value) |
static boolean |
contains(boolean[] self, Object value)Returns the string representation of the given array. |
static boolean |
contains(double[] self, Object value)Returns the string representation of the given array. |
static boolean |
contains(float[] self, Object value)Returns the string representation of the given array. |
static boolean |
contains(byte[] self, Object value)Returns the string representation of the given array. |
static boolean |
contains(Object[] self, Object value)Returns the string representation of the given map. |
static boolean |
contains(CharSequence self, CharSequence text) |
static boolean |
contains(String self, String text) |
static boolean |
containsAll(Collection self, Object[] items)Modifies this collection by removing its elements that are contained within the specified object array. |
static Number |
count(Iterator self, Object value) |
static Number |
count(Iterator self, Closure closure)Counts the number of occurrences which satisfy the given closure from the items within this Iterator. |
static Number |
count(Collection self, Object value)@deprecated use count(Iterable, Closure) |
static Number |
count(Iterable self, Object value)@deprecated use count(Iterable, Closure) |
static Number |
count(Collection self, Closure closure) |
static Number |
count(Iterable self, Closure closure) |
static Number |
count(Map self, Closure closure) |
static Number |
count(Object[] self, Object value)Counts the number of occurrences of the given value inside this array. |
static Number |
count(Object[] self, Closure closure)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 Number |
count(long[] 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 Number |
count(char[] self, Object value)Counts the number of occurrences of the given value inside this array. |
static Number |
count(boolean[] self, Object value)Counts the number of occurrences of the given value inside this array. |
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(byte[] self, Object value) |
static int |
count(CharSequence self, CharSequence text) |
static int |
count(String self, String text) |
static Map |
countBy(Collection self, Closure closure) |
static Map |
countBy(Iterable self, Closure closure)Sorts all array members into groups determined by the supplied mapping closure and counts the group size. |
static Map |
countBy(E[] self, Closure closure)Sorts all iterator items into groups determined by the supplied mapping closure and counts the group size. |
static Map |
countBy(Iterator self, Closure closure) |
static Map |
countBy(Map self, Closure closure)Groups the current element according to the value |
protected static StringBufferWriter |
createStringBufferWriter(StringBuffer self) |
protected static StringWriter |
createStringWriter(String self) |
static boolean |
deleteDir(File self) |
static CharSequence |
denormalize(CharSequence self) |
static String |
denormalize(String self) |
static boolean |
disjoint(Collection left, Collection right)Compare the contents of this array to the contents of the given array. |
static Number |
div(Character left, Number right)Bitwise AND together two Numbers. |
static Number |
div(Number left, Character right) |
static Number |
div(Character left, Character right) |
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 void |
downto(long self, Number to, Closure closure) |
static void |
downto(Long self, Number to, Closure closure) |
static void |
downto(float self, Number to, Closure closure) |
static void |
downto(Float self, Number to, Closure closure) |
static void |
downto(double self, Number to, Closure closure) |
static void |
downto(Double self, Number to, Closure closure)Iterates from this number up to the given number using a step increment. |
static void |
downto(BigInteger self, Number to, Closure closure) |
static void |
downto(BigDecimal self, Number to, Closure closure)Get the absolute value |
static List |
drop(List self, int num)Drops the given number of elements from the head of this Iterable. |
static List |
drop(Iterable self, int num)Drops the given number of elements from the head of this array if they are available. |
static Object[] |
drop(Object[] self, int num)Drops the given number of key/value pairs from the head of this map if they are available. |
static Map |
drop(Map self, int num) |
static Iterator |
drop(Iterator self, int num)Returns the longest prefix of this list where each element passed to the given closure condition evaluates to true. |
static CharSequence |
drop(CharSequence self, int num) |
static List |
dropWhile(List self, Closure condition)Returns a suffix of this Iterable where elements are dropped from the front while the given closure evaluates to true. |
static List |
dropWhile(Iterable 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 Map |
dropWhile(Map 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 Object[] |
dropWhile(Object[] self, Closure condition)Creates an Iterator that returns a suffix of the elements from an original Iterator. |
static Iterator |
dropWhile(Iterator self, Closure condition) |
static String |
dump(Object self) |
static Object |
each(Object self, Closure closure)Iterates through an aggregate type or data structure, passing each item to the given closure. |
static Iterable |
each(Iterable self, Closure closure) |
static Map |
each(Map self, Closure closure) |
static void |
eachByte(Byte[] self, Closure closure) |
static void |
eachByte(byte[] self, Closure closure) |
static void |
eachByte(File self, Closure closure) |
static void |
eachByte(File self, int bufferLen, Closure closure) |
static void |
eachByte(InputStream is, Closure closure) |
static void |
eachByte(InputStream is, int bufferLen, Closure closure) |
static void |
eachByte(URL url, Closure closure) |
static void |
eachByte(URL url, int bufferLen, Closure closure) |
static void |
eachCombination(Iterable self, Closure function)Finds all non-null subsequences of a list. |
static void |
eachDir(File self, Closure closure) |
static void |
eachDirMatch(File self, Object nameFilter, Closure closure) |
static void |
eachDirRecurse(File self, Closure closure) |
static void |
eachFile(File self, FileType fileType, Closure closure) |
static void |
eachFile(File self, Closure closure) |
static void |
eachFileMatch(File self, FileType fileType, Object nameFilter, Closure closure) |
static void |
eachFileMatch(File self, Object nameFilter, Closure closure) |
static void |
eachFileRecurse(File self, FileType fileType, Closure closure) |
static void |
eachFileRecurse(File self, Closure closure) |
static Object |
eachLine(CharSequence self, Closure closure) |
static Object |
eachLine(CharSequence self, int firstLine, Closure closure) |
static Object |
eachLine(String self, Closure closure) |
static Object |
eachLine(String self, int firstLine, Closure closure) |
static Object |
eachLine(File self, Closure closure) |
static Object |
eachLine(File self, String charset, Closure closure) |
static Object |
eachLine(File self, int firstLine, Closure closure) |
static Object |
eachLine(File self, String charset, int firstLine, Closure closure) |
static Object |
eachLine(InputStream stream, String charset, Closure closure) |
static Object |
eachLine(InputStream stream, String charset, int firstLine, Closure closure) |
static Object |
eachLine(InputStream stream, Closure closure) |
static Object |
eachLine(InputStream stream, int firstLine, Closure closure) |
static Object |
eachLine(URL url, Closure closure) |
static Object |
eachLine(URL url, int firstLine, Closure closure) |
static Object |
eachLine(URL url, String charset, Closure closure) |
static Object |
eachLine(URL url, String charset, int firstLine, Closure closure) |
static Object |
eachLine(Reader self, Closure closure) |
static Object |
eachLine(Reader self, int firstLine, Closure closure) |
static String |
eachMatch(CharSequence self, CharSequence regex, Closure closure) |
static String |
eachMatch(CharSequence self, Pattern pattern, Closure closure) |
static String |
eachMatch(String self, Pattern pattern, Closure closure) |
static String |
eachMatch(String self, String regex, Closure closure) |
static void |
eachObject(File self, Closure closure) |
static void |
eachObject(ObjectInputStream ois, Closure closure) |
static Iterator |
eachPermutation(Collection self, Closure closure) |
static Object |
eachWithIndex(Object self, Closure closure) |
static Iterable |
eachWithIndex(Iterable self, Closure closure) |
static Iterator |
eachWithIndex(Iterator self, Closure closure) |
static Map |
eachWithIndex(Map self, Closure closure) |
static boolean |
equals(int[] left, int[] right)Determines if the contents of this array are equal to the contents of the given list, in the same order. |
static boolean |
equals(Object[] left, List right) |
static boolean |
equals(List left, Object[] right) |
static boolean |
equals(List left, List right) |
static boolean |
equals(Set self, Set other) |
static boolean |
equals(Map self, Map other)Create a Set composed of the elements of the first Set minus the elements of the given Collection. |
static boolean |
every(Object self, Closure closure) |
static boolean |
every(Iterator self, Closure closure) |
static boolean |
every(Iterable self, Closure closure) |
static boolean |
every(Map self, Closure closure) |
static boolean |
every(Object self) |
static Process |
execute(String self) |
static Process |
execute(String self, String[] envp, File dir) |
static Process |
execute(String self, List envp, File dir) |
static Process |
execute(String[] commandArray) |
static Process |
execute(String[] commandArray, String[] envp, File dir) |
static Process |
execute(String[] commandArray, List envp, File dir) |
static Process |
execute(List commands) |
static Process |
execute(List commands, String[] envp, File dir) |
static Process |
execute(List commands, List envp, File dir) |
static CharSequence |
expand(CharSequence self) |
static CharSequence |
expand(CharSequence self, int tabStop) |
static String |
expand(String self) |
static String |
expand(String self, int tabStop) |
static CharSequence |
expandLine(CharSequence self, int tabStop) |
static String |
expandLine(String self, int tabStop) |
static void |
filterLine(Reader reader, Writer writer, Closure closure) |
static Writable |
filterLine(File self, Closure closure) |
static Writable |
filterLine(File self, String charset, Closure closure) |
static void |
filterLine(File self, Writer writer, Closure closure) |
static void |
filterLine(File self, Writer writer, String charset, Closure closure) |
static Writable |
filterLine(Reader reader, Closure closure) |
static Writable |
filterLine(InputStream self, Closure predicate) |
static Writable |
filterLine(InputStream self, String charset, Closure predicate) |
static void |
filterLine(InputStream self, Writer writer, Closure predicate) |
static void |
filterLine(InputStream self, Writer writer, String charset, Closure predicate) |
static Writable |
filterLine(URL self, Closure predicate) |
static Writable |
filterLine(URL self, String charset, Closure predicate) |
static void |
filterLine(URL self, Writer writer, Closure predicate) |
static void |
filterLine(URL self, Writer writer, String charset, Closure predicate) |
static Object |
find(Object self, Closure closure) |
static Object |
find(Object self)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 Object |
find(Collection self, Closure closure) |
static Object |
find(Object[] self, Closure condition) |
static Object |
find(Collection self) |
static Map.Entry |
find(Map self, Closure closure) |
static CharSequence |
find(CharSequence self, CharSequence regex) |
static CharSequence |
find(CharSequence self, CharSequence regex, Closure closure) |
static CharSequence |
find(CharSequence self, Pattern pattern) |
static CharSequence |
find(CharSequence self, Pattern pattern, Closure closure) |
static String |
find(String self, Pattern pattern) |
static String |
find(String self, Pattern pattern, Closure closure) |
static String |
find(String self, String regex) |
static String |
find(String self, String regex, Closure closure) |
static Collection |
findAll(Collection self, Closure closure)Finds all elements of the array matching the given Closure condition. |
static Collection |
findAll(Object[] self, Closure condition) |
static Collection |
findAll(Collection self)Finds the elements of the array matching the IDENTITY Closure (i.e. matching Groovy truth). |
static Collection |
findAll(Object[] self)Finds all items matching the closure condition. |
static Collection |
findAll(Object self, Closure closure) |
static Collection |
findAll(Object self) |
static Map |
findAll(Map self, Closure closure)@deprecated Use the Iterable version of groupBy instead |
static List |
findAll(CharSequence self, CharSequence regex) |
static List |
findAll(CharSequence self, CharSequence regex, Closure closure) |
static List |
findAll(CharSequence self, Pattern pattern) |
static List |
findAll(CharSequence self, Pattern pattern, Closure closure) |
static List |
findAll(String self, Pattern pattern) |
static List |
findAll(String self, Pattern pattern, Closure closure) |
static List |
findAll(String self, String regex) |
static List |
findAll(String self, String regex, Closure closure) |
static int |
findIndexOf(Object self, Closure closure) |
static int |
findIndexOf(Object self, int startIndex, Closure closure) |
static List |
findIndexValues(Object self, Closure closure) |
static List |
findIndexValues(Object self, Number startIndex, Closure closure) |
static int |
findLastIndexOf(Object self, Closure closure) |
static int |
findLastIndexOf(Object self, int startIndex, Closure closure) |
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 null. |
static Object |
findResult(Object self, Closure closure) |
static Object |
findResult(Collection self, Object defaultResult, Closure closure) |
static Object |
findResult(Collection self, Closure closure)@deprecated Use the Iterable version of findResults instead |
static Object |
findResult(Map self, Object defaultResult, Closure closure) |
static Object |
findResult(Map self, Closure closure) |
static Collection |
findResults(Collection self, Closure filteringTransform) |
static Collection |
findResults(Iterable self, Closure filteringTransform) |
static Collection |
findResults(Map self, Closure filteringTransform) |
static Object |
first(List self) |
static Object |
first(Iterable self) |
static Object |
first(Object[] self)Returns the first item from the Object array. |
static Collection |
flatten(Collection self)Flatten an array. |
static Collection |
flatten(Iterable self) |
static Collection |
flatten(Object[] self) |
static Collection |
flatten(boolean[] self) |
static Collection |
flatten(byte[] self) |
static Collection |
flatten(char[] self) |
static Collection |
flatten(short[] self) |
static Collection |
flatten(int[] self) |
static Collection |
flatten(long[] self) |
static Collection |
flatten(float[] self) |
static Collection |
flatten(double[] self) |
static Collection |
flatten(Collection self, Closure flattenUsing) |
static Collection |
flatten(Iterable self, Closure flattenUsing) |
static Object |
get(Map map, Object key, Object defaultValue)Support the range subscript operator for an Array |
static Object |
getAt(Object self, String property)Allows the subscript operator to be used to lookup dynamic property values. |
static List |
getAt(List self, Range range) |
static List |
getAt(ListWithDefault self, Collection indices)Support the range subscript operator for an eager or lazy List. |
static List |
getAt(ListWithDefault self, Range range) |
static List |
getAt(ListWithDefault self, EmptyRange range)Support the range subscript operator for a List. |
static List |
getAt(List self, EmptyRange range) |
static List |
getAt(List self, Collection indices)Select a List of items from an Object array using a Collection to identify the indices to be selected. |
static List |
getAt(Object[] self, Collection indices)Creates a sub-Map containing the given keys. |
static List |
getAt(Object[] array, Range range)@param array an Array of Objects |
static List |
getAt(Object[] array, IntRange range)@param array an Array of Objects |
static List |
getAt(Object[] array, EmptyRange range)Allows conversion of arrays into a mutable List. |
static List |
getAt(Object[] array, ObjectRange range) |
static Object |
getAt(List self, int idx) |
static Object |
getAt(Iterator self, int idx) |
static Object |
getAt(Iterable self, int idx)A helper method to allow lists to work with subscript operators. |
static Object |
getAt(Map self, Object key)Returns a new Map containing all entries from left and right,
giving precedence to right. |
static List |
getAt(Collection coll, String property)A convenience method for creating an immutable map. |
static List |
getAt(byte[] array, Range range)Support the subscript operator with a range for an int array |
static List |
getAt(char[] array, Range range) |
static List |
getAt(short[] array, Range range) |
static List |
getAt(int[] array, Range range) |
static List |
getAt(long[] array, Range range) |
static List |
getAt(float[] array, Range range) |
static List |
getAt(double[] array, Range range) |
static List |
getAt(boolean[] array, Range range)Support the subscript operator with an IntRange for a short array |
static List |
getAt(byte[] array, IntRange range)Support the subscript operator with an IntRange for an int array |
static List |
getAt(char[] array, IntRange range)Support the subscript operator with an IntRange for a long array |
static List |
getAt(short[] array, IntRange range)Support the subscript operator with an IntRange for a float array |
static List |
getAt(int[] array, IntRange range)Support the subscript operator with an IntRange for a double array |
static List |
getAt(long[] array, IntRange range)Support the subscript operator with an IntRange for a boolean array |
static List |
getAt(float[] array, IntRange range)Support the subscript operator with an ObjectRange for a byte array |
static List |
getAt(double[] array, IntRange range)Support the subscript operator with an ObjectRange for a char array |
static List |
getAt(boolean[] array, IntRange range)Support the subscript operator with an ObjectRange for a short array |
static List |
getAt(byte[] array, ObjectRange range) |
static List |
getAt(char[] array, ObjectRange range) |
static List |
getAt(short[] array, ObjectRange range) |
static List |
getAt(int[] array, ObjectRange range) |
static List |
getAt(long[] array, ObjectRange range) |
static List |
getAt(float[] array, ObjectRange range) |
static List |
getAt(double[] array, ObjectRange range) |
static List |
getAt(boolean[] array, ObjectRange range) |
static List |
getAt(byte[] array, Collection indices) |
static List |
getAt(char[] array, Collection indices) |
static List |
getAt(short[] array, Collection indices) |
static List |
getAt(int[] array, Collection indices) |
static List |
getAt(long[] array, Collection indices) |
static List |
getAt(float[] array, Collection indices) |
static List |
getAt(double[] array, Collection indices) |
static List |
getAt(boolean[] array, Collection indices) |
static boolean |
getAt(BitSet self, int index) |
static BitSet |
getAt(BitSet self, IntRange range) |
static CharSequence |
getAt(CharSequence self, Collection indices) |
static CharSequence |
getAt(CharSequence text, EmptyRange range) |
static CharSequence |
getAt(CharSequence text, int index) |
static CharSequence |
getAt(CharSequence text, IntRange range) |
static CharSequence |
getAt(CharSequence text, Range range) |
static List |
getAt(Matcher self, Collection indices) |
static Object |
getAt(Matcher matcher, int idx) |
static String |
getAt(String self, Collection indices) |
static String |
getAt(String text, EmptyRange range) |
static String |
getAt(String text, int index) |
static String |
getAt(String text, IntRange range) |
static String |
getAt(String text, Range range) |
static byte[] |
getBytes(File file) |
static byte[] |
getBytes(URL url) |
static byte[] |
getBytes(InputStream is) |
static char[] |
getChars(CharSequence self) |
static char[] |
getChars(String self) |
static int |
getCount(Matcher matcher) |
static MetaClass |
getMetaClass(Class c) |
static MetaClass |
getMetaClass(Object obj) |
static MetaClass |
getMetaClass(GroovyObject obj) |
static List |
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. |
static ClassLoader |
getRootLoader(ClassLoader self)Convenience method to dynamically create a new instance of this class. |
protected static List |
getSubList(List self, List splice) |
static String |
getText(File file, String charset) |
static String |
getText(File file) |
static String |
getText(URL url) |
static String |
getText(URL url, Map parameters) |
static String |
getText(URL url, String charset) |
static String |
getText(URL url, Map parameters, String charset) |
static String |
getText(InputStream is) |
static String |
getText(InputStream is, String charset) |
static String |
getText(Reader reader) |
static String |
getText(BufferedReader reader) |
static Collection |
grep(Object self, Object filter) |
static Collection |
grep(Collection self, Object filter)Iterates over the collection of items and returns each item that matches the given filter - calling the isCase(java.lang.Object, java.lang.Object)
method used by switch statements. |
static Collection |
grep(Object[] self, Object filter) |
static Collection |
grep(Object self) |
static Collection |
grep(Collection self) |
static Collection |
grep(Object[] self) |
protected static void |
groupAnswer(Map answer, Object element, Object value) |
static Map |
groupBy(Collection self, Closure closure) |
static Map |
groupBy(Iterable self, Closure closure) |
static Map |
groupBy(Object[] self, Closure closure)@deprecated Use the Iterable version of groupBy instead |
static Map |
groupBy(Collection self, Object... closures) |
static Map |
groupBy(Iterable self, Object... closures) |
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 Map |
groupBy(Collection self, List closures) |
static Map |
groupBy(Iterable self, List 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, List closures) |
static Map |
groupBy(Map self, Closure closure) |
static Map |
groupBy(Map self, Object... closures) |
static Map |
groupBy(Map self, List closures)Groups the members of a map into sub maps determined by the supplied mapping closures. |
static Map |
groupEntriesBy(Map self, Closure closure) |
static boolean |
hasGroup(Matcher matcher) |
static MetaProperty |
hasProperty(Object self, String name) |
static Object |
head(List self)Returns the items from the List excluding the first item. |
static Object |
head(Object[] self) |
static Object |
identity(Object self, Closure closure) |
static Boolean |
implies(Boolean left, Boolean right) |
static Object |
inject(Collection self, Closure closure) |
static Object |
inject(Collection self, Object initialValue, Closure closure) |
static Object |
inject(Map self, Object initialValue, Closure closure) |
static Object |
inject(Iterator self, Object initialValue, Closure closure) |
static Object |
inject(Object self, Closure closure)Iterates through the given Object, passing in the initial value to the closure along with the first item. |
static Object |
inject(Object self, Object initialValue, Closure 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 Object |
inject(E[] self, Closure closure) |
static Object |
inject(E[] self, Object initialValue, Closure closure)@deprecated Use the Iterable version of sum instead |
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, Number right) |
static Number |
intdiv(Number left, Character right) |
static Number |
intdiv(Character left, Character right) |
static Number |
intdiv(Number left, Number right) |
static Collection |
intersect(Collection left, Collection right) |
static Map |
intersect(Map left, Map right)Returns true if the intersection of two collections is empty.
|
static Object |
invokeMethod(Object object, String method, Object arguments) |
static boolean |
is(Object self, Object other)Identity check. |
static boolean |
isAllWhitespace(CharSequence self) |
static boolean |
isAllWhitespace(String self) |
static boolean |
isBigDecimal(CharSequence self) |
static boolean |
isBigDecimal(String self) |
static boolean |
isBigInteger(CharSequence self) |
static boolean |
isBigInteger(String self) |
static boolean |
isCase(Object caseValue, Object switchValue) |
static boolean |
isCase(Class caseValue, Object switchValue) |
static boolean |
isCase(Collection caseValue, Object switchValue) |
static boolean |
isCase(Map caseValue, Object switchValue) |
static boolean |
isCase(Number caseValue, Number switchValue) |
static boolean |
isCase(CharSequence caseValue, Object switchValue) |
static boolean |
isCase(GString caseValue, Object switchValue) |
static boolean |
isCase(Pattern caseValue, Object switchValue) |
static boolean |
isCase(String caseValue, Object switchValue) |
static boolean |
isDigit(Character self) |
static boolean |
isDouble(CharSequence self) |
static boolean |
isDouble(String self) |
static boolean |
isFloat(CharSequence self) |
static boolean |
isFloat(String self) |
static boolean |
isInteger(CharSequence self) |
static boolean |
isInteger(String self) |
static boolean |
isLetter(Character self)Transform a Number into a Double |
static boolean |
isLetterOrDigit(Character self)Transform a Number into a BigDecimal |
static boolean |
isLong(CharSequence self) |
static boolean |
isLong(String self) |
static boolean |
isLowerCase(Character self)Transform a Number into a Float |
static boolean |
isNumber(CharSequence self) |
static boolean |
isNumber(String self) |
static boolean |
isUpperCase(Character self)Transform a Number into a Long |
static boolean |
isWhitespace(Character self) |
static Iterator |
iterator(Object[] a) |
static Iterator |
iterator(Object o) |
static Iterator |
iterator(Enumeration enumeration) |
static Iterator |
iterator(Iterator self) |
static Iterator |
iterator(Matcher matcher) |
static Iterator |
iterator(Reader self) |
static Iterator |
iterator(InputStream self) |
static Iterator |
iterator(DataInputStream self) |
static String |
join(Iterator self, String separator)@deprecated Use the Iterable version of join instead |
static String |
join(Collection self, String separator) |
static String |
join(Iterable self, String separator) |
static String |
join(Object[] self, String separator) |
static Object |
last(List self) |
static Object |
last(Iterable self)Returns the last item from the array. |
static Object |
last(Object[] self) |
static Collection |
leftShift(Collection self, Object value)Overloads the left shift operator to provide an easy way to append Map.Entry values to a Map. |
static BlockingQueue |
leftShift(BlockingQueue self, Object value) |
static Map |
leftShift(Map self, Map.Entry entry) |
static Map |
leftShift(Map self, Map other)Implementation of the right shift (unsigned) operator for integral types. |
static Number |
leftShift(Number self, Number operand)Support the subscript operator with a range for a byte array |
static StringBuilder |
leftShift(CharSequence self, Object value) |
static StringBuffer |
leftShift(String self, Object value) |
static StringBuffer |
leftShift(StringBuffer self, Object value) |
static StringBuilder |
leftShift(StringBuilder self, Object value) |
static Writer |
leftShift(Socket self, Object value) |
static OutputStream |
leftShift(Socket self, byte[] value) |
static Writer |
leftShift(Writer self, Object value) |
static Writer |
leftShift(OutputStream self, Object value) |
static void |
leftShift(ObjectOutputStream self, Object value) |
static OutputStream |
leftShift(OutputStream self, InputStream in) |
static OutputStream |
leftShift(OutputStream self, byte[] value) |
static File |
leftShift(File file, Object text) |
static File |
leftShift(File file, byte[] bytes) |
static File |
leftShift(File file, InputStream data) |
static boolean |
matches(CharSequence self, Pattern pattern) |
static boolean |
matches(String self, Pattern pattern) |
static Map.Entry |
max(Map self, Closure closure) |
static Object |
max(Collection self) |
static Object |
max(Iterable self) |
static Object |
max(Iterator self)@deprecated Use the Iterable version of max instead |
static Object |
max(Object[] self) |
static Object |
max(Collection self, Closure closure) |
static Object |
max(Iterable self, Closure closure) |
static Object |
max(Iterator self, Closure closure)Selects the maximum value found from the Object array using the closure to determine the correct ordering. |
static Object |
max(Object[] self, Closure closure)@deprecated Use the Iterable version of max instead |
static Object |
max(Collection self, Comparator comparator) |
static Object |
max(Iterable self, Comparator comparator)Selects the maximum value found from the Iterator using the given comparator. |
static Object |
max(Iterator self, Comparator comparator)Provide the standard Groovy size() method for Iterator.
|
static Object |
max(Object[] self, Comparator comparator) |
static MetaClass |
metaClass(Class self, Closure closure)Allows an Enumeration to behave like an Iterator. |
static MetaClass |
metaClass(Object self, Closure closure)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 Object |
min(Collection self)Adds min() method to Collection objects. |
static Object |
min(Iterable self) |
static Object |
min(Iterator self)@deprecated Use the Iterable version of min instead |
static Object |
min(Object[] self)Selects the minimum value found in the Iterable using the given comparator. |
static Object |
min(Collection self, Comparator comparator) |
static Object |
min(Iterable self, Comparator comparator)Selects the minimum value found from the Iterator using the given comparator. |
static Object |
min(Iterator self, Comparator comparator)@deprecated Use the Iterable version of min instead |
static Object |
min(Object[] self, Comparator comparator) |
static Object |
min(Collection self, Closure closure) |
static Object |
min(Iterable self, Closure closure) |
static Map.Entry |
min(Map self, Closure closure) |
static Object |
min(Iterator self, Closure closure)Selects the minimum value found from the Object array using the closure to determine the correct ordering. |
static Object |
min(Object[] self, Closure closure)@deprecated Use the Iterable version of max instead |
static Set |
minus(Set self, Collection removeMe)Create a Set composed of the elements of the first Set minus the elements from the given Iterable. |
static Set |
minus(Set self, Iterable removeMe)Create an array composed of the elements of the first array minus the elements of the given Iterable. |
static Set |
minus(Set self, Object removeMe) |
static Object[] |
minus(Object[] self, Iterable removeMe)Create a List composed of the elements of the first list minus every occurrence of elements of the given Collection. |
static Object[] |
minus(Object[] self, Object[] removeMe) |
static List |
minus(List self, Collection removeMe) |
static List |
minus(List self, Iterable removeMe)Create a List composed of the elements of the first list minus every occurrence of elements of the given Iterable. |
static List |
minus(List self, Object removeMe) |
static Object[] |
minus(Object[] self, Object removeMe)Flatten a collection. |
static Map |
minus(Map self, Map removeMe) |
static Number |
minus(Character left, Number right) |
static Number |
minus(Number left, Character right) |
static Number |
minus(Character left, Character right) |
static CharSequence |
minus(CharSequence self, Object target) |
static String |
minus(String self, Object target) |
static void |
mixin(MetaClass self, List categoryClasses) |
static void |
mixin(Class self, List categoryClasses) |
static void |
mixin(Class self, Class categoryClass) |
static void |
mixin(Class self, Class[] categoryClass) |
static void |
mixin(MetaClass self, Class categoryClass) |
static void |
mixin(MetaClass self, Class[] categoryClass) |
static Number |
mod(Number left, Number right) |
static List |
multiply(Collection self, Number factor) |
static Number |
multiply(Character left, Number right) |
static Number |
multiply(Number left, Character right) |
static Number |
multiply(Character left, Character right)Power of an integer to an integer certain exponent. |
static Number |
multiply(BigDecimal left, Double right) |
static Number |
multiply(BigDecimal left, BigInteger right) |
static CharSequence |
multiply(CharSequence self, Number factor) |
static String |
multiply(String self, Number factor) |
static DataInputStream |
newDataInputStream(File file) |
static DataOutputStream |
newDataOutputStream(File file) |
static BufferedInputStream |
newInputStream(File file) |
static BufferedInputStream |
newInputStream(URL url) |
static BufferedInputStream |
newInputStream(URL url, Map parameters) |
static Object |
newInstance(Class c)Set the metaclass for an object. |
static Object |
newInstance(Class c, Object[] args)Sets/updates the metaclass for a given class to a closure. |
static ObjectInputStream |
newObjectInputStream(File file) |
static ObjectInputStream |
newObjectInputStream(InputStream inputStream) |
static ObjectInputStream |
newObjectInputStream(InputStream inputStream, ClassLoader classLoader) |
static ObjectInputStream |
newObjectInputStream(File file, ClassLoader classLoader) |
static ObjectOutputStream |
newObjectOutputStream(File file) |
static ObjectOutputStream |
newObjectOutputStream(OutputStream outputStream) |
static BufferedOutputStream |
newOutputStream(File file) |
static PrintWriter |
newPrintWriter(File file) |
static PrintWriter |
newPrintWriter(File file, String charset) |
static PrintWriter |
newPrintWriter(Writer writer) |
static BufferedReader |
newReader(File file) |
static BufferedReader |
newReader(File file, String charset) |
static BufferedReader |
newReader(InputStream self) |
static BufferedReader |
newReader(InputStream self, String charset) |
static BufferedReader |
newReader(URL url) |
static BufferedReader |
newReader(URL url, Map parameters) |
static BufferedReader |
newReader(URL url, String charset) |
static BufferedReader |
newReader(URL url, Map parameters, String charset) |
static BufferedWriter |
newWriter(File file) |
static BufferedWriter |
newWriter(File file, boolean append) |
static BufferedWriter |
newWriter(File file, String charset, boolean append) |
static BufferedWriter |
newWriter(File file, String charset) |
static Character |
next(Character self)Compare a Number and a Character. |
static Number |
next(Number self) |
static CharSequence |
next(CharSequence self) |
static String |
next(String self) |
static CharSequence |
normalize(CharSequence self) |
static String |
normalize(String self) |
static int |
numberAwareCompareTo(Comparable self, Comparable other)Provides a method that compares two comparables using Groovy's default number aware comparator. |
static Number |
or(Number left, Number right) |
static BitSet |
or(BitSet left, BitSet right) |
static Boolean |
or(Boolean left, Boolean right)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 CharSequence |
padLeft(CharSequence self, Number numberOfChars) |
static CharSequence |
padLeft(CharSequence self, Number numberOfChars, CharSequence padding) |
static String |
padLeft(String self, Number numberOfChars) |
static String |
padLeft(String self, Number numberOfChars, String padding) |
static CharSequence |
padRight(CharSequence self, Number numberOfChars) |
static CharSequence |
padRight(CharSequence self, Number numberOfChars, CharSequence padding) |
static String |
padRight(String self, Number numberOfChars) |
static String |
padRight(String self, Number numberOfChars, String padding) |
static Set |
permutations(List self) |
static List |
permutations(List self, Closure function)Iterates over all permutations of a collection, running a closure for each iteration. |
static Map |
plus(Map left, Map right)Support the subscript operator for Collection. |
static Map |
plus(Map self, Collection entries) |
static Object[] |
plus(Object[] left, Object[] right) |
static Object[] |
plus(Object[] left, Object right) |
static Object[] |
plus(Object[] left, Collection right) |
static Object[] |
plus(Object[] left, Iterable right)Create a Collection as a union of a Collection and an Iterable. |
static Collection |
plus(Collection left, Collection right) |
static Collection |
plus(Collection left, Iterable right) |
static List |
plus(List self, int index, Object[] items)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 List |
plus(List self, int index, List 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 List |
plus(List self, int index, Iterable additions)Create a List composed of the elements of this list, repeated a certain number of times. |
static Collection |
plus(Collection left, Object right) |
static Number |
plus(Character left, Number right) |
static Number |
plus(Number left, Character right) |
static Number |
plus(Character left, Character right)Multiply a Character by a Number. |
static CharSequence |
plus(CharSequence left, Object value) |
static String |
plus(Number value, String right) |
static String |
plus(String left, Object value) |
static String |
plus(StringBuffer left, String value) |
static Object |
pop(List self) |
static Number |
power(Number self, Number exponent) |
static Number |
power(BigDecimal self, Integer exponent)Divide one Character by another. |
static Number |
power(BigInteger self, Integer exponent)Integer Divide a Character by a Number. |
static Number |
power(Integer self, Integer exponent) |
static Number |
power(Long self, Integer exponent)Integer Divide two Numbers. |
static Character |
previous(Character self) |
static Number |
previous(Number self)@todo maybe a double dispatch thing to handle new large numbers? |
static CharSequence |
previous(CharSequence self) |
static String |
previous(String self) |
protected static Object |
primitiveArrayGet(Object self, int idx)Checks whether the array contains the given value. |
protected static List |
primitiveArrayGet(Object self, Range range) |
protected static List |
primitiveArrayGet(Object self, Collection indices)Checks whether the array contains the given value. |
protected static Object |
primitiveArrayPut(Object self, int idx, Object newValue)Checks whether the array contains the given value. |
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(PrintWriter self, Object value)Print a value formatted Groovy style to the print writer. |
static void |
print(PrintStream self, Object value) |
static void |
print(Closure self, Object value) |
static void |
print(Object self, PrintWriter out) |
static void |
printf(Object self, String format, Object[] values) |
static void |
printf(Object self, String format, Object arg) |
static void |
println(Object self) |
static void |
println(Closure 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(PrintWriter self, Object value)Print a value formatted Groovy style (followed by a newline) to the print writer. |
static void |
println(PrintStream self, Object value) |
static void |
println(Closure self, Object value) |
static void |
println(Object self, PrintWriter out) |
static boolean |
push(List self, Object value) |
static Map |
putAll(Map self, Collection entries) |
static void |
putAt(Object self, String property, Object newValue) |
static void |
putAt(List self, int idx, Object value) |
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, EmptyRange range, Collection value) |
static void |
putAt(List self, IntRange range, Collection col)List subscript assignment operator when given a range as the index. |
static void |
putAt(List self, IntRange range, Object value) |
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) |
static Object |
putAt(Map self, Object key, Object value) |
static void |
putAt(BitSet self, IntRange range, boolean value)Support assigning a range of values with a single assignment statement. |
static void |
putAt(BitSet self, int index, boolean value) |
static void |
putAt(StringBuffer self, EmptyRange range, Object value) |
static void |
putAt(StringBuffer self, IntRange range, Object value) |
static byte[] |
readBytes(File file) |
static String |
readLine(Reader self) |
static List |
readLines(CharSequence self) |
static List |
readLines(String self) |
static List |
readLines(File file) |
static List |
readLines(File file, String charset) |
static List |
readLines(InputStream stream) |
static List |
readLines(InputStream stream, String charset) |
static List |
readLines(URL self) |
static List |
readLines(URL self, String charset) |
static List |
readLines(Reader reader) |
static boolean |
removeAll(Collection self, Object[] items) |
static boolean |
removeAll(Collection self, Closure condition) |
static boolean |
renameTo(File self, String newPathName) |
static CharSequence |
replaceAll(CharSequence self, CharSequence regex, CharSequence replacement) |
static CharSequence |
replaceAll(CharSequence self, CharSequence regex, Closure closure) |
static CharSequence |
replaceAll(CharSequence self, Pattern pattern, CharSequence replacement) |
static String |
replaceAll(CharSequence self, Pattern pattern, Closure closure) |
static String |
replaceAll(String self, Pattern pattern, Closure closure) |
static String |
replaceAll(String self, Pattern pattern, String replacement) |
static String |
replaceAll(String self, String regex, Closure closure) |
static String |
replaceFirst(CharSequence self, CharSequence regex, CharSequence replacement) |
static String |
replaceFirst(CharSequence self, CharSequence regex, Closure closure) |
static CharSequence |
replaceFirst(CharSequence self, Pattern pattern, CharSequence replacement) |
static String |
replaceFirst(CharSequence self, Pattern pattern, Closure closure) |
static String |
replaceFirst(String self, Pattern pattern, Closure closure) |
static String |
replaceFirst(String self, Pattern pattern, String replacement) |
static String |
replaceFirst(String self, String regex, Closure closure) |
static List |
respondsTo(Object self, String name, Object[] argTypes) |
static List |
respondsTo(Object self, String name) |
static boolean |
retainAll(Collection self, Object[] items) |
static boolean |
retainAll(Collection self, Closure condition) |
static List |
reverse(List self)Reverses the elements in a list. |
static List |
reverse(List self, boolean mutate) |
static Object[] |
reverse(Object[] self)Reverses the iterator. |
static Object[] |
reverse(Object[] self, boolean mutate) |
static Iterator |
reverse(Iterator self)Create an array containing elements from an original array plus an additional appended element. |
static CharSequence |
reverse(CharSequence self) |
static String |
reverse(String self) |
static Map |
reverseEach(Map self, Closure closure) |
static List |
reverseEach(List self, Closure closure) |
static Object[] |
reverseEach(Object[] self, Closure closure) |
static Number |
rightShift(Number self, Number operand)Support the subscript operator with a range for a char array |
static Number |
rightShiftUnsigned(Number self, Number operand)Support the subscript operator with a range for a short array |
static int |
round(Float number) |
static float |
round(Float number, int precision) |
static long |
round(Double number) |
static double |
round(Double number, int precision) |
static TimerTask |
runAfter(Timer timer, int delay, 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 void |
setBytes(File file, byte[] bytes) |
static void |
setBytes(OutputStream os, byte[] bytes) |
static void |
setIndex(Matcher matcher, int idx) |
static void |
setMetaClass(Class self, MetaClass metaClass) |
static void |
setMetaClass(Object self, MetaClass metaClass) |
static void |
setMetaClass(GroovyObject self, MetaClass metaClass) |
static void |
setText(File file, String text) |
static void |
setText(File file, String text, String charset) |
static int |
size(Iterator self) |
static int |
size(Object[] self) |
static int |
size(boolean[] array) |
static int |
size(byte[] array) |
static int |
size(char[] array) |
static int |
size(short[] array)Converts this array to a List of the same size, with each element added to the list. |
static int |
size(int[] array)Converts this array to a List of the same size, with each element added to the list. |
static int |
size(long[] array) |
static int |
size(float[] array) |
static int |
size(double[] array) |
static int |
size(CharSequence text) |
static long |
size(Matcher self) |
static int |
size(String text) |
static int |
size(StringBuffer buffer) |
static long |
size(File self) |
static List |
sort(Collection self) |
static List |
sort(Iterable self) |
static List |
sort(Collection self, boolean mutate) |
static List |
sort(Iterable self, boolean mutate) |
static Map |
sort(Map self, Closure closure) |
static Map |
sort(Map self, Comparator comparator)Modifies this array so that its elements are in sorted order. |
static Map |
sort(Map self) |
static Object[] |
sort(Object[] self) |
static Object[] |
sort(Object[] self, boolean mutate)Sorts the given iterator items into a sorted iterator using the comparator. |
static Iterator |
sort(Iterator self)@deprecated Use the Iterable version of sort instead |
static Iterator |
sort(Iterator self, Comparator comparator) |
static List |
sort(Collection self, Comparator comparator) |
static List |
sort(Collection self, boolean mutate, Comparator comparator) |
static List |
sort(Iterable self, boolean mutate, Comparator comparator) |
static Object[] |
sort(Object[] self, Comparator comparator) |
static Object[] |
sort(Object[] self, boolean mutate, Comparator comparator) |
static Iterator |
sort(Iterator self, Closure closure) |
static Object[] |
sort(Object[] self, Closure closure) |
static Object[] |
sort(Object[] self, boolean mutate, Closure closure)Sorts this Collection using the given Closure to determine the correct ordering. |
static List |
sort(Collection self, Closure closure)Sorts this Iterable using the given Closure to determine the correct ordering. |
static List |
sort(Iterable self, Closure closure) |
static List |
sort(Collection self, boolean mutate, Closure closure) |
static List |
sort(Iterable self, boolean mutate, Closure closure)Avoids doing unnecessary work when sorting an already sorted set (i.e. an identity function for an already sorted set). |
static SortedSet |
sort(SortedSet self)Removes the last item from the List. |
static SortedMap |
sort(SortedMap self)Provides an easy way to append multiple Map.Entry values to a Map. |
static Collection |
split(Object self, Closure closure) |
static Collection |
split(Collection self, Closure closure) |
static CharSequence[] |
split(CharSequence self) |
static String[] |
split(GString self) |
static String[] |
split(String self) |
static Object |
splitEachLine(CharSequence self, CharSequence regex, Closure closure) |
static Object |
splitEachLine(CharSequence self, Pattern pattern, Closure closure) |
static Object |
splitEachLine(String self, Pattern pattern, Closure closure) |
static Object |
splitEachLine(String self, String regex, Closure closure) |
static Object |
splitEachLine(File self, String regex, Closure closure) |
static Object |
splitEachLine(File self, Pattern pattern, Closure closure) |
static Object |
splitEachLine(File self, String regex, String charset, Closure closure) |
static Object |
splitEachLine(File self, Pattern pattern, String charset, Closure closure) |
static Object |
splitEachLine(URL self, String regex, Closure closure) |
static Object |
splitEachLine(URL self, Pattern pattern, Closure closure) |
static Object |
splitEachLine(URL self, String regex, String charset, Closure closure) |
static Object |
splitEachLine(URL self, Pattern pattern, String charset, Closure closure) |
static Object |
splitEachLine(Reader self, String regex, Closure closure) |
static Object |
splitEachLine(Reader self, Pattern pattern, Closure closure) |
static Object |
splitEachLine(InputStream stream, String regex, String charset, Closure closure) |
static Object |
splitEachLine(InputStream stream, Pattern pattern, String charset, Closure closure) |
static Object |
splitEachLine(InputStream stream, String regex, Closure closure) |
static Object |
splitEachLine(InputStream stream, Pattern pattern, Closure closure) |
static SpreadMap |
spread(Map self) |
static String |
sprintf(Object self, String format, Object[] values) |
static String |
sprintf(Object self, String format, Object arg) |
static void |
step(Number self, Number to, Number stepNumber, Closure closure)Get the absolute value |
static CharSequence |
stripIndent(CharSequence self) |
static CharSequence |
stripIndent(CharSequence self, int numChars) |
static String |
stripIndent(String self) |
static String |
stripIndent(String self, int numChars) |
static CharSequence |
stripMargin(CharSequence self) |
static CharSequence |
stripMargin(CharSequence self, char marginChar) |
static String |
stripMargin(CharSequence self, CharSequence marginChar) |
static String |
stripMargin(String self) |
static String |
stripMargin(String self, char marginChar) |
static String |
stripMargin(String self, String marginChar) |
static Map |
subMap(Map map, Collection keys)Creates a sub-Map containing the given keys. |
static Map |
subMap(Map map, Object[] keys)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 Set |
subsequences(List self)Finds all permutations of a collection. |
static Object |
sum(Collection self) |
static Object |
sum(Iterable self) |
static Object |
sum(Object[] self)@deprecated Use the Iterable version of sum instead |
static Object |
sum(Iterator self) |
static Object |
sum(Collection self, Object initialValue) |
static Object |
sum(Iterable self, Object initialValue) |
static Object |
sum(Object[] self, Object initialValue) |
static Object |
sum(Iterator self, Object initialValue) |
static Object |
sum(Collection self, Closure closure)Sums the result of apply a closure to each item of an Iterable. |
static Object |
sum(Iterable self, Closure closure) |
static Object |
sum(Object[] self, Closure closure) |
static Object |
sum(Iterator self, Closure closure) |
static Object |
sum(Collection self, Object initialValue, Closure closure) |
static Object |
sum(Iterable self, Object initialValue, Closure closure) |
static Object |
sum(Object[] self, Object initialValue, Closure closure) |
static Object |
sum(Iterator self, Object initialValue, Closure closure) |
static List |
tail(List self) |
static Object[] |
tail(Object[] self) |
static List |
take(List self, int num)Returns the first num elements from the head of this array.
|
static Object[] |
take(Object[] self, int num) |
static List |
take(Iterable self, int num)Returns a new map containing the first num elements from the head of this map.
|
static Map |
take(Map self, int num)Returns an iterator of up to the first num elements from this iterator.
|
static Iterator |
take(Iterator self, int num) |
static CharSequence |
take(CharSequence self, int num) |
static List |
takeWhile(List 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 List |
takeWhile(Iterable 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 Map |
takeWhile(Map self, Closure condition)Returns the longest prefix of this array where each element passed to the given closure evaluates to true. |
static Object[] |
takeWhile(Object[] self, Closure condition) |
static Iterator |
takeWhile(Iterator self, Closure condition) |
static void |
times(Number self, Closure closure) |
static String |
toArrayString(Object[] self) |
static BigDecimal |
toBigDecimal(Number self)Logical implication of two boolean operators |
static BigDecimal |
toBigDecimal(CharSequence self) |
static BigDecimal |
toBigDecimal(String self) |
static BigInteger |
toBigInteger(Number self)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 BigInteger |
toBigInteger(CharSequence self) |
static BigInteger |
toBigInteger(String self) |
static Boolean |
toBoolean(Boolean self) |
static Boolean |
toBoolean(String self) |
static Character |
toCharacter(String self) |
static Double |
toDouble(Number self)Logical disjunction of two boolean operators |
static Double |
toDouble(CharSequence self) |
static Double |
toDouble(String self) |
static Float |
toFloat(Number self) |
static Float |
toFloat(CharSequence self) |
static Float |
toFloat(String self) |
static Integer |
toInteger(Number self) |
static Integer |
toInteger(CharSequence self) |
static Integer |
toInteger(String self) |
static List |
toList(Collection self)Convert an iterator to a List. |
static List |
toList(Iterator self) |
static List |
toList(Iterable self)Convert an enumeration to a List. |
static List |
toList(Enumeration self) |
static List |
toList(Object[] array) |
static List |
toList(byte[] array) |
static List |
toList(boolean[] array) |
static List |
toList(char[] array) |
static List |
toList(short[] array) |
static List |
toList(int[] array) |
static List |
toList(long[] array) |
static List |
toList(float[] array) |
static List |
toList(double[] array) |
static List |
toList(CharSequence self) |
static List |
toList(String self) |
static String |
toListString(Collection self) |
static String |
toListString(Collection self, int maxSize) |
static Long |
toLong(Number self) |
static Long |
toLong(CharSequence self) |
static Long |
toLong(String self) |
static char |
toLowerCase(Character self) |
static String |
toMapString(Map self) |
static String |
toMapString(Map self, int maxSize) |
static Set |
toSet(byte[] array) |
static Set |
toSet(boolean[] array) |
static Set |
toSet(char[] array) |
static Set |
toSet(short[] array) |
static Set |
toSet(int[] array) |
static Set |
toSet(long[] array) |
static Set |
toSet(float[] array)Implements the getAt(Collection) method for primitive type arrays. |
static Set |
toSet(double[] array) |
static Set |
toSet(Collection self)Implements the setAt(int idx) method for primitive type arrays. |
static Set |
toSet(Iterator self)Checks whether the array contains the given value. |
static Set |
toSet(Enumeration self)Checks whether the array contains the given value. |
static Set |
toSet(CharSequence self) |
static Set |
toSet(String self) |
static Short |
toShort(CharSequence self) |
static Short |
toShort(String self) |
static SpreadMap |
toSpreadMap(Map self)Creates a spreadable map from this array. |
static SpreadMap |
toSpreadMap(Object[] self) |
static SpreadMap |
toSpreadMap(List self) |
static String |
toString(boolean[] self) |
static String |
toString(byte[] self) |
static String |
toString(char[] self) |
static String |
toString(short[] self)Returns the string representation of the given list. |
static String |
toString(int[] self) |
static String |
toString(long[] self) |
static String |
toString(float[] self) |
static String |
toString(double[] self) |
static String |
toString(AbstractMap self) |
static String |
toString(AbstractCollection self)Decrement a Number by one. |
static String |
toString(Object[] self) |
static String |
toString(Object value)Compare a Character and a Number. |
static URI |
toURI(CharSequence self) |
static URI |
toURI(String self) |
static URL |
toURL(CharSequence self) |
static URL |
toURL(String self) |
static char |
toUpperCase(Character self) |
static List |
tokenize(CharSequence self) |
static List |
tokenize(CharSequence self, Character token) |
static List |
tokenize(CharSequence self, CharSequence token) |
static List |
tokenize(String self) |
static List |
tokenize(String self, Character token) |
static List |
tokenize(String self, String token) |
static CharSequence |
tr(CharSequence self, CharSequence sourceSet, CharSequence replacementSet) |
static String |
tr(String self, String sourceSet, String replacementSet) |
static void |
transformChar(Reader self, Writer writer, Closure closure) |
static void |
transformLine(Reader reader, Writer writer, Closure closure) |
static List |
transpose(List self) |
static void |
traverse(File self, Map options, Closure closure) |
static void |
traverse(File self, Closure closure) |
static void |
traverse(File self, Map options) |
static float |
trunc(Float number, int precision) |
static float |
trunc(Float number) |
static double |
trunc(Double number) |
static double |
trunc(Double number, int precision) |
static Number |
unaryMinus(Number left)Iterates from this number up to the given number, inclusive, incrementing by one each time. |
static Number |
unaryPlus(Number left) |
static CharSequence |
unexpand(CharSequence self) |
static CharSequence |
unexpand(CharSequence self, int tabStop) |
static String |
unexpand(String self) |
static String |
unexpand(String self, int tabStop) |
static CharSequence |
unexpandLine(CharSequence self, int tabStop) |
static String |
unexpandLine(String self, int tabStop) |
static Iterator |
unique(Iterator self) |
static Collection |
unique(Collection self) |
static Collection |
unique(Collection self, boolean mutate) |
static Iterator |
unique(Iterator self, Closure closure) |
static Collection |
unique(Collection self, Closure closure) |
static Collection |
unique(Collection self, boolean mutate, Closure closure) |
static Iterator |
unique(Iterator self, Comparator comparator)Returns an iterator equivalent to this iterator with all duplicated items removed by using the supplied comparator. |
static Collection |
unique(Collection self, Comparator comparator) |
static Collection |
unique(Collection self, boolean mutate, Comparator comparator) |
static void |
upto(Number self, Number to, Closure closure) |
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) |
static void |
upto(float self, Number to, Closure closure) |
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(double self, Number to, Closure closure) |
static void |
upto(Double self, Number to, Closure closure) |
static void |
upto(BigInteger self, Number to, Closure closure)Iterates from this number down to the given number, inclusive, decrementing by one each time. |
static void |
upto(BigDecimal self, Number to, Closure closure)Iterates from this number down to the given number, inclusive, decrementing by one each time. |
static Object |
use(Object self, Class categoryClass, Closure closure)Scoped use method |
static Object |
use(Object self, List categoryClassList, Closure closure) |
static Object |
use(Object self, Object[] array) |
static Object |
with(Object self, Closure closure) |
static Object |
withDataInputStream(File file, Closure closure) |
static Object |
withDataOutputStream(File file, Closure closure) |
static Map |
withDefault(Map 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 List |
withDefault(List self, Closure init) |
static List |
withEagerDefault(List self, Closure init)@deprecated Use the Iterable version of sort instead |
static Object |
withInputStream(File file, Closure closure) |
static Object |
withInputStream(URL url, Closure closure) |
static List |
withLazyDefault(List self, Closure init) |
static Object |
withObjectInputStream(File file, Closure closure) |
static Object |
withObjectInputStream(File file, ClassLoader classLoader, Closure closure) |
static Object |
withObjectInputStream(InputStream inputStream, Closure closure) |
static Object |
withObjectInputStream(InputStream inputStream, ClassLoader classLoader, Closure closure) |
static Object |
withObjectOutputStream(File file, Closure closure) |
static Object |
withObjectOutputStream(OutputStream outputStream, Closure closure) |
static Object |
withObjectStreams(Socket socket, Closure closure) |
static Object |
withOutputStream(File file, Closure closure) |
static Object |
withPrintWriter(File file, Closure closure) |
static Object |
withPrintWriter(File file, String charset, Closure closure) |
static Object |
withPrintWriter(Writer writer, Closure closure) |
static Object |
withReader(File file, Closure closure) |
static Object |
withReader(File file, String charset, Closure closure) |
static Object |
withReader(Reader reader, Closure closure) |
static Object |
withReader(URL url, Closure closure) |
static Object |
withReader(URL url, String charset, Closure closure) |
static Object |
withReader(InputStream in, Closure closure) |
static Object |
withReader(InputStream in, String charset, Closure closure) |
static Object |
withStream(InputStream stream, Closure closure) |
static Object |
withStream(OutputStream os, Closure closure) |
static Object |
withStreams(Socket socket, Closure closure) |
static Object |
withTraits(Object self, Class... traits) |
static Object |
withWriter(File file, Closure closure) |
static Object |
withWriter(File file, String charset, Closure closure) |
static Object |
withWriter(Writer writer, Closure closure) |
static Object |
withWriter(OutputStream stream, Closure closure) |
static Object |
withWriter(OutputStream stream, String charset, Closure closure) |
static Object |
withWriterAppend(File file, String charset, Closure closure) |
static Object |
withWriterAppend(File file, Closure closure) |
static void |
write(Writer self, Writable writable) |
static void |
write(File file, String text) |
static void |
write(File file, String text, String charset) |
static void |
writeLine(BufferedWriter writer, String line) |
static BitSet |
xor(BitSet left, BitSet right) |
static Number |
xor(Number left, Number right) |
static Boolean |
xor(Boolean left, Boolean right) |
| Methods inherited from class | Name |
|---|---|
class DefaultGroovyMethodsSupport |
cloneSimilarCollection, cloneSimilarMap, closeQuietly, closeWithWarning, createSimilarArray, createSimilarCollection, createSimilarCollection, createSimilarList, createSimilarMap, createSimilarOrDefaultCollection, createSimilarSet, normaliseIndex, sameType, subListBorders, subListBorders |
class Object |
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll |
Truncate the value
number - a Floatprecision - the number of decimal places to keepDetermine if a Character is uppercase. Synonym for 'Character.isUpperCase(this)'.
self - a CharacterDetermine if a Character is lowercase. Synonym for 'Character.isLowerCase(this)'.
self - a CharacterSplits all items into two lists based on the closure condition. The first list contains all items matching the closure expression. The second list all those that don't.
self - an Object with an Iterator returning its valuesclosure - a closure conditionIterates 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.
self - the iteration object over which to iteratestartIndex - start matching from this indexclosure - the filter to perform a match on the collectionA convenience method for creating an immutable list
self - a ListA convenience method for creating a synchronized SortedMap.
self - a SortedMapCoerce an Boolean instance to a boolean value.
bool - the BooleanConverts the given array to either a List, Set, or SortedSet. If the given class is something else, the call is deferred to {link #asType(Object,Class)}.
ary - an arrayclazz - the desired classCreates a new List with the identical contents to this list but in reverse order.
def list = ["a", 4, false] assert list.reverse() == [false, 4, "a"] assert list == ["a", 4, false]
self - a ListTraverse through each byte of this Byte array. Alias for each.
self - a Byte arrayclosure - a closure Adds a "metaClass" property to all class objects so you can use the syntax
String.metaClass.myMethod = { println "foo" }
c - The java.lang.Class instanceIterates from this number up to the given number, inclusive, incrementing by one each time.
self - a Numberto - another Number to go up toclosure - the closure to call Iterates through this aggregate Object transforming each item into a new value using the
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 object Iterates through this aggregate Object transforming each item into a new value using the 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 objectIterates through this collection transforming each entry into a new value using Closure.IDENTITY as a transformer, basically returning a list of items copied from the original collection.
assert [1,2,3] == [1,2,3].collect()
self - a collection Iterates through this collection transforming each value into a new value using the 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 collectionA variant of collectEntries for Iterables using the identity closure as the transform and a supplied map as the destination of transformed entries.
self - an Iterablecollector - the Map into which the transformed entries are putA variant of collectEntries using the identity closure as the transform.
self - an Object arraycollector - the Map into which the transformed entries are putA variant of collectEntries using the identity closure as the transform.
self - an Object arrayDeprecated alias for collectNested
Adds GroovyCollections#combinations(Iterable) as a method on Iterables.
Example usage:
assert [['a', 'b'],[1, 2, 3]].combinations() == [['a', 1], ['b', 1], ['a', 2], ['b', 2], ['a', 3], ['b', 3]]
self - an Iterable of collectionsAdds GroovyCollections#combinations(Iterable, Closure) as a method on collections.
Example usage:
assert [[2, 3],[4, 5, 6]].combinations {x,y -> x*y } == [8, 12, 10, 15, 12, 18]
self - a Collection of listsfunction - a closure to be called on each combinationApplies a function on each combination of the input lists.
Example usage:
[[2, 3],[4, 5, 6]].eachCombination { println "Found $it" }
self - a Collection of listsfunction - a closure to be called on each combinationMultiply a Number by a Character. The ordinal value of the Character is used in the multiplication (the ordinal value is the unicode value which for simple character sets is the ASCII value).
left - a Numberright - a CharacterMultiply two Characters. The ordinal values of the Characters are used in the multiplication (the ordinal value is the unicode value which for simple character sets is the ASCII value).
left - a Characterright - another CharacterChecks whether the array contains the given value.
self - the array we are searchingvalue - the value being searched forReturns the string representation of the given array.
self - an arrayReturns the string representation of the given array.
self - an arrayReturns the string representation of the given array.
self - an arrayReturns the string representation of the given array.
self - an arrayReturns the string representation of the given array.
self - an arrayReturns the string representation of the given map.
self - a Map Modifies this collection by removing its elements that are contained
within the specified object array.
See also 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 collectionCounts the number of occurrences which satisfy the given closure from the items within this Iterator. The iterator will become exhausted of elements after determining the count value.
Example usage:
assert [2,4,2,1,3,5,2,4,3].toSet().iterator().count{ it % 2 == 0 } == 2
self - the Iterator from which we count the number of matching occurrencesclosure - a closure condition Counts the number of occurrences of the given value inside this array.
Comparison is done using Groovy's == operator (using
compareTo(value) == 0 or equals(value) ).
self - the array within which we count the number of occurrencesvalue - the value being searched for Counts the number of occurrences of the given value inside this array.
Comparison is done using Groovy's == operator (using
compareTo(value) == 0 or equals(value) ).
self - the array within which we count the number of occurrencesvalue - the value being searched for Counts the number of occurrences of the given value inside this array.
Comparison is done using Groovy's == operator (using
compareTo(value) == 0 or equals(value) ).
self - the array within which we count the number of occurrencesvalue - the value being searched for Counts the number of occurrences of the given value inside this array.
Comparison is done using Groovy's == operator (using
compareTo(value) == 0 or equals(value) ).
self - the array within which we count the number of occurrencesvalue - the value being searched for Counts the number of occurrences of the given value inside this array.
Comparison is done using Groovy's == operator (using
compareTo(value) == 0 or equals(value) ).
self - the array within which we count the number of occurrencesvalue - the value being searched for Counts the number of occurrences of the given value inside this array.
Comparison is done using Groovy's == operator (using
compareTo(value) == 0 or equals(value) ).
self - the array within which we count the number of occurrencesvalue - the value being searched for Counts the number of occurrences of the given value inside this array.
Comparison is done using Groovy's == operator (using
compareTo(value) == 0 or equals(value) ).
self - the array within which we count the number of occurrencesvalue - the value being searched for Counts the number of occurrences of the given value inside this array.
Comparison is done using Groovy's == operator (using
compareTo(value) == 0 or equals(value) ).
self - the array within which we count the number of occurrencesvalue - the value being searched for Counts the number of occurrences of the given value inside this array.
Comparison is done using Groovy's == operator (using
compareTo(value) == 0 or equals(value) ).
self - the array within which we count the number of occurrencesvalue - the value being searched forSorts all array members into groups determined by the supplied mapping closure and counts the group size. The closure should return the key that each item should be grouped by. The returned Map will have an entry for each distinct key returned from the closure, with each value being the frequency of items occurring for that group.
Example usage:
assert ([1,2,2,2,3] as Object[]).countBy{ it % 2 } == [1:2, 0:3]
self - an object array to group and countclosure - a closure mapping items to the frequency keysSorts all iterator items into groups determined by the supplied mapping closure and counts the group size. The closure should return the key that each item should be grouped by. The returned Map will have an entry for each distinct key returned from the closure, with each value being the frequency of items occurring for that group.
Example usage:
assert [1,2,2,2,3].toSet().iterator().countBy{ it % 2 } == [1:2, 0:1]
self - an iterator to group and countclosure - a closure mapping items to the frequency keysGroups the current element according to the value
answer - the map containing the resultselement - the element to be placedvalue - the value according to which the element will be placedCompare the contents of this array to the contents of the given array.
left - an int arrayright - the array being comparedBitwise AND together two Numbers.
left - a Numberright - another Number to bitwise ANDIterates from this number down to the given number, inclusive, decrementing by one each time.
self - a Floatto - the end numberclosure - the code to execute for each numberIterates from this number up to the given number using a step increment. Each intermediate number is passed to the given closure. Example:
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 callGet the absolute value
number - a NumberDrops the given number of elements from the head of this Iterable.
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.Drops the given number of elements from the head of this array if they are available.
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.Drops the given number of key/value pairs from the head of this map if they are available.
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.Returns the longest prefix of this list where each element passed to the given closure condition evaluates to true. Similar to 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 elementsReturns a suffix of this Iterable where elements are dropped from the front while the given closure evaluates to true.
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 elementsCreate 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).
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 elementsCreate 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.
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 elementsCreates an Iterator that returns a suffix of the elements from an original Iterator. As many elements as possible are dropped from the front of the original Iterator such that calling the given closure condition evaluates to true when passed each of the dropped elements.
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 elementsIterates through an aggregate type or data structure, passing each item to the given closure. Custom types may utilize this method by simply providing an "iterator()" method. The items returned from the resulting iterator will be passed to the closure.
self - the object over which we iterateclosure - the closure applied on each element foundFinds all non-null subsequences of a list.
Example usage:
def result = [1, 2, 3].subsequences() assert result == [[1, 2, 3], [1, 3], [2, 3], [1, 2], [1], [2], [3]] as Set
self - the List of items Determines if the contents of this array are equal to the
contents of the given list, in the same order. This returns
false if either collection is null.
left - an arrayright - the List being comparedCreate a Set composed of the elements of the first Set minus the elements of the given Collection.
self - a Set objectremoveMe - the items to remove from the SetTreats 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.
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 stopFinds all elements of the array matching the given Closure condition.
def items = [1,2,3,4] as Integer[]
assert [2,4] == items.findAll { it % 2 == 0 }
self - an arraycondition - a closure conditionFinds the elements of the array matching the IDENTITY Closure (i.e. matching Groovy truth).
Example:
def items = [1, 2, 0, false, true, '', 'foo', [], [4, 5], null] as Object[] assert items.findAll() == [1, 2, true, 'foo', [4, 5]]
self - an arrayFinds all items matching the closure condition.
self - an Object with an Iterator returning its valuesclosure - a closure conditionTreats 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.
self - an Object with an iterator returning its valuesclosure - a closure that returns a non-null value when processing should stopReturns the first item from the Object array.
def array = [3, 4, 2].toArray() assert array.head() == 3
self - an Object arrayFlatten an array. This array and any nested arrays or collections have their contents (recursively) added to the new collection.
self - a boolean Array to flattenSupport the range subscript operator for an Array
array - an Array of Objectsrange - a Range Allows the subscript operator to be used to lookup dynamic property values.
bean[somePropertyNameExpression]. The normal property notation
of groovy is neater and more concise but only works with compile-time known
property names.
self - the object to act uponproperty - the property name of interestSupport the range subscript operator for an eager or lazy List.
def list = [].withDefault { 42 }
assert list[1..2] == [null, 42]
self - a ListWithDefaultrange - a Range indicating the items to getSupport the range subscript operator for a List.
def list = [true, 1, 3.4] assert list[0..<0] == []
self - a Listrange - a Range indicating the items to getSelect a List of items from an Object array using a Collection to identify the indices to be selected.
self - an Array of Objectsindices - a Collection of indicesCreates a sub-Map containing the given keys. This method is similar to List.subList() but uses keys rather than index ranges.
assert [1:10, 2:20, 4:40].subMap( [2, 4] ) == [2:20, 4:40]
map - a Mapkeys - a Collection of keys
array - an Array of Objectsrange - an EmptyRange
array - an Array of Objectsrange - an ObjectRangeAllows conversion of arrays into a mutable List.
array - an Array of ObjectsA helper method to allow lists to work with subscript operators.
def list = [2, 3] list[0] = 1 assert list == [1, 3]
self - a Listidx - an indexvalue - the value to put at the given index Returns a new 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 MapA convenience method for creating an immutable map.
self - a MapSupport the subscript operator with a range for an int array
array - an int arrayrange - a range indicating the indices for the items to retrieveSupport the subscript operator with an IntRange for a short array
array - a short arrayrange - an IntRange indicating the indices for the items to retrieveSupport the subscript operator with an IntRange for an int array
array - an int arrayrange - an IntRange indicating the indices for the items to retrieveSupport the subscript operator with an IntRange for a long array
array - a long arrayrange - an IntRange indicating the indices for the items to retrieveSupport the subscript operator with an IntRange for a float array
array - a float arrayrange - an IntRange indicating the indices for the items to retrieveSupport the subscript operator with an IntRange for a double array
array - a double arrayrange - an IntRange indicating the indices for the items to retrieveSupport the subscript operator with an IntRange for a boolean array
array - a boolean arrayrange - an IntRange indicating the indices for the items to retrieveSupport the subscript operator with an ObjectRange for a byte array
array - a byte arrayrange - an ObjectRange indicating the indices for the items to retrieveSupport the subscript operator with an ObjectRange for a char array
array - a char arrayrange - an ObjectRange indicating the indices for the items to retrieveSupport the subscript operator with an ObjectRange for a short array
array - a short arrayrange - an ObjectRange indicating the indices for the items to retrieveRetrieves 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'.
self - the receiver objectConvenience 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.
self - the receiver objectConvenience method to dynamically create a new instance of this class. Calls the default constructor.
c - a class Iterates over the collection of items and returns each item that matches
the given filter - calling the 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)Sorts all array members into (sub)groups determined by the supplied mapping closures as per the Iterable variant of this method.
self - an array to groupclosures - an array of closures, each mapping entries on keysSorts all array members into (sub)groups determined by the supplied mapping closures as per the list variant of this method.
self - an array to groupclosures - a list of closures, each mapping entries on keys Groups the members of a map into sub maps determined by the supplied
mapping closures. Each closure will be passed a Map.Entry or key and
value (depending on the number of parameters the closure accepts) and
should return the key that each item should be grouped under. The
resulting map will have an entry for each 'group path' returned by all
closures, with values being the map members from the original map that
belong to each such 'group path'.
If 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 }, { 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 keysReturns the items from the List excluding the first item.
def list = [3, 4, 2] assert list.tail() == [4, 2] assert list == [3, 4, 2]
self - a ListIterates through the given Object, passing in the initial value to the closure along with the first item. The result is passed back (injected) into the closure along with the second item. The new result is injected back into the closure along with the third item and so on until further iteration of the object is not possible. Also known as foldLeft in functional parlance.
self - an ObjectinitialValue - some initial valueclosure - a closureIterates 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.
self - an Object[]closure - a closureInspects returns the String that matches what would be typed into a terminal to create this object.
self - any Object Returns 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. Identity check. Since == is overridden in Groovy with the meaning of equality
we need some fallback to check for object identity. Invoke using the
'is' method, like so: def same = this.is(that)
self - an objectother - an object to compare identity withTransform a Number into a Double
self - a NumberTransform a Number into a BigDecimal
self - a NumberTransform a Number into a Float
self - a NumberTransform a Number into a Long
self - a NumberReturns the last item from the array.
def array = [3, 4, 2].toArray() assert array.last() == 2
self - an arrayOverloads the left shift operator to provide an easy way to append Map.Entry values to a Map.
self - a Mapentry - a Map.Entry to be added to the Map.Implementation of the right shift (unsigned) operator for integral types. Non integral Number types throw UnsupportedOperationException.
self - a Number objectoperand - the shift distance by which to right shift (unsigned) the numberSupport the subscript operator with a range for a byte array
array - a byte arrayrange - a range indicating the indices for the items to retrieveSelects the maximum value found from the Object array using the closure to determine the correct ordering.
If the closure has two parameters it is used like a traditional Comparator. I.e. it should compare its two parameters for order, returning a negative integer, zero, or a positive integer when the first parameter is less than, equal to, or greater than the second respectively. Otherwise, the Closure is assumed to take a single parameter and return a Comparable (typically an Integer) which is then used for further comparison.
self - an Object arrayclosure - a Closure used to determine the correct orderingSelects the maximum value found from the Iterator using the given comparator.
self - an Iteratorcomparator - a Comparator Provide the standard Groovy size() method for Iterator.
The iterator will become exhausted of elements after determining the size value.
self - an IteratorAllows an Enumeration to behave like an Iterator. Note that the Iterator.remove method is unsupported since the underlying Enumeration does not provide a mechanism for removing items.
enumeration - an Enumeration objectAn 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.
self - an iterator objectAdds min() method to Collection objects.
assert 2 == [4,2,5].min()
self - a CollectionSelects the minimum value found in the Iterable using the given comparator.
assert "hi" == ["hello","hi","hey"].min( { a, b -> a.length() <=> b.length() } as Comparator )
self - an Iterablecomparator - a ComparatorSelects the minimum value found from the Iterator using the given comparator.
self - an Iteratorcomparator - a ComparatorSelects the minimum value found from the Object array using the closure to determine the correct ordering.
If the closure has two parameters it is used like a traditional Comparator. I.e. it should compare its two parameters for order, returning a negative integer, zero, or a positive integer when the first parameter is less than, equal to, or greater than the second respectively. Otherwise, the Closure is assumed to take a single parameter and return a Comparable (typically an Integer) which is then used for further comparison.
self - an Object arrayclosure - a Closure used to determine the correct orderingCreate a Set composed of the elements of the first Set minus the elements from the given Iterable.
self - a Set objectremoveMe - the items to remove from the SetCreate an array composed of the elements of the first array minus the elements of the given Iterable.
self - an object arrayremoveMe - a Collection of elements to removeCreate a List composed of the elements of the first list minus every occurrence of elements of the given Collection.
assert [1, "a", true, true, false, 5.3] - [true, 5.3] == [1, "a", false]
self - a ListremoveMe - a Collection of elements to removeCreate a List composed of the elements of the first list minus every occurrence of elements of the given Iterable.
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 removeassert [1,2,3,4,5] == [1,[2,3],[[4]],[],5].flatten()public static Object[] minus(Object[] self, Object removeMe)
Flatten a collection. This collection and any nested arrays or collections have their contents (recursively) added to the new collection.
assert [1,2,3,4,5] == [1,[2,3],[[4]],[],5].flatten()
self - a Collection to flattenPower of an integer to an integer certain exponent. If the exponent is positive, convert to a BigInteger and call BigInteger.pow(int) method to maintain precision. Called by the '**' operator.
self - an Integerexponent - an Integer exponentSet the metaclass for an object.
self - the object whose metaclass we want to setmetaClass - the new metaclass valueSets/updates the metaclass for a given class to a closure.
self - the class whose metaclass we wish to updateclosure - the closure representing the new metaclassCompare a Number and a Character. The ordinal value of the Character is used in the comparison (the ordinal value is the unicode value which for simple character sets is the ASCII value).
left - a Numberright - a CharacterProvides a method that compares two comparables using Groovy's default number aware comparator.
self - a Comparableother - another ComparableIterates 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.
self - the iteration object over which to iterateclosure - the filter to perform a match on the collectionIterates over all permutations of a collection, running a closure for each iteration.
Example usage:
def permutations = []
[1, 2, 3].eachPermutation{ permutations << it }
assert permutations == [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
self - the Collection of itemsclosure - the closure to call for each permutationSupport the subscript operator for Collection.
assert [String, Long, Integer] == ["a",5L,2]["class"]
coll - a Collectionproperty - a StringCreate a Collection as a union of a Collection and an Iterable. If the left collection is a Set, then the returned collection will be a Set otherwise a List. This operation will always create a new object for the result, while the operands remain unchanged.
left - the left Collectionright - the right IterableCreates 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. Shifts the element currently at that index (if any) and any subsequent elements to the right (increasing their indices). The new elements will appear in the resulting List in the order that they occur in the original lists. The behavior of this operation is undefined if the original lists are modified while the operation is in progress. The original lists remain unchanged.
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 ListCreates a new List by inserting all of the elements in the given Iterable to the elements from this List at the specified index.
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 IterableCreate a List composed of the elements of this list, repeated a certain number of times. Note that for non-primitive elements, multiple references to the same instance will be added.
assert [1,2,3,1,2,3] == [1,2,3] * 2
self - a Collectionfactor - the number of times to appendMultiply a Character by a Number. The ordinal value of the Character is used in the multiplication (the ordinal value is the unicode value which for simple character sets is the ASCII value).
left - a Characterright - a NumberDivide one Character by another. The ordinal values of the Characters are used in the division (the ordinal value is the unicode value which for simple character sets is the ASCII value).
left - a Characterright - another CharacterInteger Divide a Character by a Number. The ordinal value of the Character is used in the division (the ordinal value is the unicode value which for simple character sets is the ASCII value).
left - a Characterright - a NumberInteger Divide two Numbers.
left - a Numberright - another NumberChecks whether the array contains the given value.
self - the array we are searchingvalue - the value being searched forChecks whether the array contains the given value.
self - the array within which we count the number of occurrencesvalue - the value being searched forChecks whether the array contains the given value.
self - the array we are searchingvalue - the value being searched forPrint a value formatted Groovy style to self if it is a Writer, otherwise to the standard output stream.
self - any Objectvalue - the value to printPrint a value formatted Groovy style to the print writer.
self - a PrintWritervalue - the value to printPrint a linebreak to the standard output stream. This method delegates to the owner to execute the method.
self - a closurePrint a value formatted Groovy style (followed by a newline) to self if it is a Writer, otherwise to the standard output stream.
self - any Objectvalue - the value to printPrint a value formatted Groovy style (followed by a newline) to the print writer.
self - a PrintWritervalue - the value to printA helper method to allow lists to work with subscript operators.
def list = ["a", true] list[1..<1] = [4, 3, 2] assert list == ["a", 4, 3, 2, true]
self - a Listrange - the (in this case empty) subset of the list to setvalue - the Collection of valuesList subscript assignment operator when given a range as the index. Example:
def myList = [4, 3, 5, 1, 2, 8, 10] myList[3..5] = "b" assert myList == [4, 3, 5, "b", 10]Items in the given range are replaced with the operand. 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 sublistA helper method to allow lists to work with subscript operators.
def list = ["a", true, 42, 9.4] list[1, 3] = 5 assert list == ["a", 5, 42, 5]
self - a Listsplice - the subset of the list to setvalue - the value to put at the given sublistSupport assigning a range of values with a single assignment statement.
self - a BitSetrange - the range of values to setvalue - valueReverses the elements in a list. If mutate is true, the original list is modified in place and returned. Otherwise, a new list containing the reversed items is produced.
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 createdReverses the iterator. The original iterator will become exhausted of elements after determining the reversed values. A new iterator for iterating through the reversed values is returned.
self - an IteratorCreate an array containing elements from an original array plus an additional appended element.
Integer[] a = [1, 2, 3] Integer[] result = a + 4 assert result == [1, 2, 3, 4] as Integer[]
left - the arrayright - the value to appendSupport the subscript operator with a range for a char array
array - a char arrayrange - a range indicating the indices for the items to retrieveSupport the subscript operator with a range for a short array
array - a short arrayrange - a range indicating the indices for the items to retrieveIterates 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.
self - the iteration object over which to iterateclosure - the filter to perform a match on the collectionConverts this array to a List of the same size, with each element added to the list.
array - an int arrayConverts this array to a List of the same size, with each element added to the list.
array - a long arrayModifies this array so that its elements are in sorted order. The array items are assumed to be comparable.
self - the array to be sortedSorts the given iterator items into a sorted iterator using the comparator. The original iterator will become exhausted of elements after completing this method call. A new iterator is produced that traverses the items in sorted order.
self - the Iterator to be sortedcomparator - a Comparator used for comparing itemsSorts this Collection using the given Closure to determine the correct ordering. If the Collection is a List, it is sorted in place and returned. Otherwise, the elements are first placed into a new list which is then sorted and returned - leaving the original Collection unchanged.
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 orderingSorts this Iterable using the given Closure to determine the correct ordering. If the Iterable is a List, it is sorted in place and returned. Otherwise, the elements are first placed into a new list which is then sorted and returned - leaving the original Iterable unchanged.
If the Closure has two parameters it is used like a traditional Comparator. I.e. it should compare its two parameters for order, returning a negative integer, zero, or a positive integer when the first parameter is less than, equal to, or greater than the second respectively. Otherwise, the Closure is assumed to take a single parameter and return a Comparable (typically an Integer) which is then used for further comparison.
assert ["hi","hey","hello"] == ["hello","hi","hey"].sort { it.length() }
assert ["hi","hey","hello"] == ["hello","hi","hey"].sort { a, b -> a.length() <=> b.length() }
self - the Iterable to be sortedclosure - a 1 or 2 arg Closure used to determine the correct orderingAvoids doing unnecessary work when sorting an already sorted set (i.e. an identity function for an already sorted set).
self - an already sorted setRemoves the last item from the List. Using add() and pop() is similar to push and pop on a Stack.
def list = ["a", false, 2] assert list.pop() == 2 assert list == ["a", false]
self - a ListProvides an easy way to append multiple Map.Entry values to a Map.
self - a Mapentries - a Collection of Map.Entry items to be added to the Map.Get the absolute value
number - a FloatCreates a sub-Map containing the given keys. This method is similar to List.subList() but uses keys rather than index ranges. The original map is unaltered.
def orig = [1:10, 2:20, 3:30, 4:40] assert orig.subMap([1, 3] as int[]) == [1:10, 3:30] assert orig.subMap([2, 4] as Integer[]) == [2:20, 4:40] assert orig.size() == 4
map - a Mapkeys - an array of keysLooks up an item in a Map for the given key and returns the value - unless there is no entry for the given key in which case add the default value to the map and return that.
def map=[:]
map.get("a", []) << 5
assert map == [a:[5]]
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 keyFinds all permutations of a collection.
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 itemsarray.collect(closure).sum().
public static Object sum(Collection self, Closure closure) Sums the result of apply a closure to each item of an Iterable.
coll.sum(closure) is equivalent to:
coll.collect(closure).sum().
assert 4+6+10+12 == [2,3,5,6].sum() { it * 2 }
self - an Iterableclosure - a single parameter closure that returns a numeric value.array.sum(initVal, closure) is equivalent to:
public static Object sum(Collection self, Object initialValue, Closure closure) Returns the first 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. Returns a new map containing the first 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. Returns an iterator of up to the first 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.Returns a List containing the longest prefix of the elements from this Iterable where each element passed to the given closure evaluates to true.
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 elementsReturns the longest prefix of this Map where each entry (or key/value pair) when passed to the given closure evaluates to true.
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 elementsReturns the longest prefix of this array where each element passed to the given closure evaluates to true.
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 elementsLogical implication of two boolean operators
left - left operatorright - right operatorIterates 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.
self - the iteration object over which to iterateclosure - the filter to perform a match on the collectionLogical disjunction of two boolean operators
left - left operatorright - right operatorConvert an iterator to a List. The iterator will become exhausted of elements after making this conversion.
self - an iteratorConvert an enumeration to a List.
self - an enumerationImplements the getAt(Collection) method for primitive type arrays. Each value in the collection argument is assumed to be a valid array index. The value at each index is then added to a list which is returned.
self - an array objectindices - the indices of interestImplements the setAt(int idx) method for primitive type arrays.
self - an objectidx - the index of interestnewValue - the new value to be put into the index of interestChecks whether the array contains the given value.
self - the array we are searchingvalue - the value being searched forChecks whether the array contains the given value.
self - the array we are searchingvalue - the value being searched forCreates a spreadable map from this array.
self - an object array Returns the string representation of the given list. The string
displays the contents of the list, similar to a list literal, i.e.
[1, 2, a].
self - a CollectionDecrement a Number by one.
self - a NumberCompare a Character and a Number. The ordinal value of the Character is used in the comparison (the ordinal value is the unicode value which for simple character sets is the ASCII value).
left - a Characterright - a NumberIterates from this number up to the given number, inclusive, incrementing by one each time.
self - a floatto - the end numberclosure - the code to execute for each numberReturns an iterator equivalent to this iterator with all duplicated items removed by using the supplied comparator.
self - an Iteratorcomparator - a ComparatorIterates from this number up to the given number, inclusive, incrementing by one each time.
self - a Doubleto - the end numberclosure - the code to execute for each numberIterates from this number up to the given number, inclusive, incrementing by one each time.
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 numberIterates from this number down to the given number, inclusive, decrementing by one each time.
self - a longto - the end numberclosure - the code to execute for each numberIterates from this number down to the given number, inclusive, decrementing by one each time.
self - a Longto - the end numberclosure - the code to execute for each numberScoped use method
self - any ObjectcategoryClass - a category class to useclosure - the closure to invoke with the category in place An alias for 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 value