|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.codehaus.groovy.runtime.DefaultGroovyMethodsSupport
org.codehaus.groovy.runtime.DefaultGroovyMethods
public class DefaultGroovyMethods
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.
Nested Class Summary | |
---|---|
protected static class |
DefaultGroovyMethods.ProcessRunner
A Runnable which waits for a process to complete together with a notification scheme allowing another thread to wait a maximum number of seconds for the process to complete before killing it. |
Nested classes/interfaces inherited from class org.codehaus.groovy.runtime.DefaultGroovyMethodsSupport |
---|
DefaultGroovyMethodsSupport.RangeInfo |
Field Summary | |
---|---|
static java.lang.Class[] |
additionals
|
Constructor Summary | |
---|---|
DefaultGroovyMethods()
|
Method Summary | ||
---|---|---|
static double |
abs(java.lang.Double number)
Get the absolute value |
|
static float |
abs(java.lang.Float number)
Get the absolute value |
|
static long |
abs(java.lang.Long number)
Get the absolute value |
|
static int |
abs(java.lang.Number number)
Get the absolute value |
|
static java.net.Socket |
accept(java.net.ServerSocket serverSocket,
Closure closure)
Accepts a connection and passes the resulting Socket to the closure which runs in a new Thread. |
|
static
|
addAll(java.util.Collection<T> self,
T[] items)
Adds all of the elements in the specified array to this collection. |
|
static
|
addAll(java.util.List<T> self,
int index,
T[] items)
Inserts all of the elements in the specified array into this list at the specified position. |
|
static void |
addShutdownHook(java.lang.Object self,
Closure closure)
Allows the usage of addShutdownHook without getting the runtime first. |
|
static java.util.BitSet |
and(java.util.BitSet left,
java.util.BitSet right)
Bitwise AND together two BitSets. |
|
static java.lang.Boolean |
and(java.lang.Boolean left,
java.lang.Boolean right)
Logical conjunction of two boolean operators. |
|
static java.lang.Number |
and(java.lang.Number left,
java.lang.Number right)
Bitwise AND together two Numbers. |
|
static
|
any(java.util.Map<K,V> self,
Closure closure)
Iterates over the entries of a map, and checks whether a predicate is valid for at least one entry. |
|
static boolean |
any(java.lang.Object self)
Iterates over the elements of a collection, and checks whether at least one element is true according to the Groovy Truth. |
|
static boolean |
any(java.lang.Object self,
Closure closure)
Iterates over the contents of an object or collection, and checks whether a predicate is valid for at least one element. |
|
static void |
append(java.io.File file,
byte[] bytes)
Append bytes to the end of a File. |
|
static void |
append(java.io.File self,
java.io.InputStream stream)
Append binary data to the file. |
|
static void |
append(java.io.File file,
java.lang.Object text)
Append the text at the end of the File. |
|
static void |
append(java.io.File file,
java.lang.Object text,
java.lang.String charset)
Append the text at the end of the File, using a specified encoding. |
|
static boolean |
asBoolean(java.lang.Boolean bool)
Coerce an Boolean instance to a boolean value. |
|
static boolean |
asBoolean(boolean[] array)
Coerces a boolean array to a boolean value. |
|
static boolean |
asBoolean(byte[] array)
Coerces a byte array to a boolean value. |
|
static boolean |
asBoolean(char[] array)
Coerces a char array to a boolean value. |
|
static boolean |
asBoolean(java.lang.Character character)
Coerce a character to a boolean value. |
|
static boolean |
asBoolean(java.lang.CharSequence string)
Coerce a string (an instance of CharSequence) to a boolean value. |
|
static boolean |
asBoolean(java.util.Collection collection)
Coerce a collection instance to a boolean value. |
|
static boolean |
asBoolean(double[] array)
Coerces a double array to a boolean value. |
|
static boolean |
asBoolean(java.util.Enumeration enumeration)
Coerce an enumeration instance to a boolean value. |
|
static boolean |
asBoolean(float[] array)
Coerces a float array to a boolean value. |
|
static boolean |
asBoolean(GroovyResultSet grs)
Coerce a GroovyResultSet to a boolean value. |
|
static boolean |
asBoolean(int[] array)
Coerces an int array to a boolean value. |
|
static boolean |
asBoolean(java.util.Iterator iterator)
Coerce an iterator instance to a boolean value. |
|
static boolean |
asBoolean(long[] array)
Coerces a long array to a boolean value. |
|
static boolean |
asBoolean(java.util.Map map)
Coerce a map instance to a boolean value. |
|
static boolean |
asBoolean(java.util.regex.Matcher matcher)
Coerce a Matcher instance to a boolean value. |
|
static boolean |
asBoolean(java.lang.Number number)
Coerce a number to a boolean value. |
|
static boolean |
asBoolean(java.lang.Object object)
Coerce an object instance to a boolean value. |
|
static boolean |
asBoolean(java.lang.Object[] array)
Coerce an Object array to a boolean value. |
|
static boolean |
asBoolean(short[] array)
Coerces a short array to a boolean value. |
|
static
|
asImmutable(java.util.Collection<? extends T> self)
A convenience method for creating an immutable Collection. |
|
static
|
asImmutable(java.util.List<? extends T> self)
A convenience method for creating an immutable list |
|
static
|
asImmutable(java.util.Map<? extends K,? extends V> self)
A convenience method for creating an immutable map. |
|
static
|
asImmutable(java.util.Set<? extends T> self)
A convenience method for creating an immutable list. |
|
static
|
asImmutable(java.util.SortedMap<K,? extends V> self)
A convenience method for creating an immutable sorted map. |
|
static
|
asImmutable(java.util.SortedSet<T> self)
A convenience method for creating an immutable sorted set. |
|
static
|
asList(java.util.Collection<T> self)
Converts this Collection to a List. |
|
static
|
asSynchronized(java.util.Collection<T> self)
A convenience method for creating a synchronized Collection. |
|
static
|
asSynchronized(java.util.List<T> self)
A convenience method for creating a synchronized List. |
|
static
|
asSynchronized(java.util.Map<K,V> self)
A convenience method for creating a synchronized Map. |
|
static
|
asSynchronized(java.util.Set<T> self)
A convenience method for creating a synchronized Set. |
|
static
|
asSynchronized(java.util.SortedMap<K,V> self)
A convenience method for creating a synchronized SortedMap. |
|
static
|
asSynchronized(java.util.SortedSet<T> self)
A convenience method for creating a synchronized SortedSet. |
|
static java.lang.Object |
asType(Closure cl,
java.lang.Class clazz)
Coerces the closure to an implementation of the given class. |
|
static java.lang.Object |
asType(java.util.Collection col,
java.lang.Class clazz)
Converts the given collection to another type. |
|
static java.lang.Object |
asType(java.io.File f,
java.lang.Class c)
Converts this File to a Writable or delegates to default
asType(java.lang.Object, java.lang.Class) . |
|
static java.lang.Object |
asType(GString self,
java.lang.Class c)
Converts the GString to a File, or delegates to the default asType(java.lang.Object, java.lang.Class) |
|
static java.lang.Object |
asType(java.util.Map map,
java.lang.Class clazz)
Coerces this map to the given type, using the map's keys as the public method names, and values as the implementation. |
|
static java.lang.Object |
asType(java.lang.Number self,
java.lang.Class c)
Transform this number to a the given type, using the 'as' operator. |
|
static java.lang.Object |
asType(java.lang.Object[] ary,
java.lang.Class clazz)
Converts the given array to either a List, Set, or SortedSet. |
|
static java.lang.Object |
asType(java.lang.Object obj,
java.lang.Class type)
Converts a given object to a type. |
|
static java.lang.Object |
asType(java.lang.String self,
java.lang.Class c)
Provides a method to perform custom 'dynamic' type conversion to the given class using the as operator. |
|
static java.io.File |
asWritable(java.io.File file)
Converts this File to a Writable . |
|
static java.io.File |
asWritable(java.io.File file,
java.lang.String encoding)
Allows a file to return a Writable implementation that can output itself to a Writer stream. |
|
static java.util.BitSet |
bitwiseNegate(java.util.BitSet self)
Bitwise NEGATE a BitSet. |
|
static java.util.regex.Pattern |
bitwiseNegate(java.lang.String self)
Turns a String into a regular expression Pattern |
|
protected static java.lang.Object |
callClosureForLine(Closure closure,
java.lang.String line,
int counter)
|
|
protected static java.lang.Object |
callClosureForMapEntry(Closure closure,
java.util.Map.Entry entry)
|
|
protected static java.lang.Object |
callClosureForMapEntryAndCounter(Closure closure,
java.util.Map.Entry entry,
int counter)
|
|
static java.lang.String |
capitalize(java.lang.String self)
Convenience method to capitalize the first letter of a string (typically the first letter of a word). |
|
static java.lang.String |
center(java.lang.String self,
java.lang.Number numberOfChars)
Center a String and pad it with spaces appended around it |
|
static java.lang.String |
center(java.lang.String self,
java.lang.Number numberOfChars,
java.lang.String padding)
Center a String and pad it with the characters appended around it |
|
static void |
clearTime(java.util.Calendar self)
Deprecated. moved to DateGroovyMethods.clearTime(java.util.Calendar) |
|
static void |
clearTime(java.util.Date self)
Deprecated. moved to DateGroovyMethods.clearTime(java.util.Date) |
|
static void |
clearTime(java.sql.Date self)
Deprecated. moved to DateGroovyMethods.clearTime(java.sql.Date) |
|
static java.util.List |
collect(java.util.Collection self,
Closure closure)
Iterates through this collection transforming each entry into a new value using the closure as a transformer, returning a list of transformed values. |
|
static java.util.Collection |
collect(java.util.Collection self,
java.util.Collection collection,
Closure closure)
Iterates through this collection transforming each value into a new value using the closure as a transformer, returning an initial collection plus the transformed values. |
|
static java.util.List |
collect(java.util.Map self,
Closure closure)
Iterates through this Map transforming each entry into a new value using the closure as a transformer, returning a list of transformed values. |
|
static java.util.Collection |
collect(java.util.Map self,
java.util.Collection collection,
Closure closure)
Iterates through this Map transforming each entry into a new value using the closure as a transformer, returning a list of transformed values. |
|
static java.util.List |
collect(java.lang.Object self,
Closure closure)
Iterates through this object transforming each value into a new value using the closure as a transformer, returning a list of transformed values. |
|
static java.util.Collection |
collect(java.lang.Object self,
java.util.Collection collection,
Closure closure)
Iterates through this object transforming each object into a new value using the closure as a transformer and adding it to the collection, returning the resulting collection. |
|
static java.util.List |
collectAll(java.util.Collection self,
Closure closure)
Recursively iterates through this collection transforming each non-Collection value into a new value using the closure as a transformer. |
|
static java.util.Collection |
collectAll(java.util.Collection self,
java.util.Collection collection,
Closure closure)
Recursively iterates through this collection transforming each non-Collection value into a new value using the closure as a transformer. |
|
static java.util.List |
combinations(java.util.Collection self)
Adds GroovyCollections#combinations(Collection) as a method on collections. |
|
static int |
compareTo(java.lang.Character left,
java.lang.Character right)
Compare two Characters. |
|
static int |
compareTo(java.lang.Character left,
java.lang.Number right)
Compare a Character and a Number. |
|
static int |
compareTo(java.lang.Number left,
java.lang.Character right)
Compare a Number and a Character. |
|
static int |
compareTo(java.lang.Number left,
java.lang.Number right)
Compare two Numbers. |
|
static java.lang.Thread |
consumeProcessErrorStream(java.lang.Process self,
java.io.OutputStream err)
Gets the error stream from a process and reads it to keep the process from blocking due to a full buffer. |
|
static java.lang.Thread |
consumeProcessErrorStream(java.lang.Process self,
java.lang.StringBuffer error)
Gets the error stream from a process and reads it to keep the process from blocking due to a full buffer. |
|
static java.lang.Thread |
consumeProcessErrorStream(java.lang.Process self,
java.io.Writer err)
Gets the error stream from a process and reads it to keep the process from blocking due to a full buffer. |
|
static void |
consumeProcessOutput(java.lang.Process self)
Gets the output and error streams from a process and reads them to keep the process from blocking due to a full output buffer. |
|
static void |
consumeProcessOutput(java.lang.Process self,
java.io.OutputStream output,
java.io.OutputStream error)
Gets the output and error streams from a process and reads them to keep the process from blocking due to a full output buffer. |
|
static void |
consumeProcessOutput(java.lang.Process self,
java.lang.StringBuffer output,
java.lang.StringBuffer error)
Gets the output and error streams from a process and reads them to keep the process from blocking due to a full output buffer. |
|
static java.lang.Thread |
consumeProcessOutputStream(java.lang.Process self,
java.io.OutputStream output)
Gets the output stream from a process and reads it to keep the process from blocking due to a full output buffer. |
|
static java.lang.Thread |
consumeProcessOutputStream(java.lang.Process self,
java.lang.StringBuffer output)
Gets the output stream from a process and reads it to keep the process from blocking due to a full output buffer. |
|
static java.lang.Thread |
consumeProcessOutputStream(java.lang.Process self,
java.io.Writer output)
Gets the output stream from a process and reads it to keep the process from blocking due to a full output buffer. |
|
static boolean |
contains(java.lang.String self,
java.lang.String text)
Provide an implementation of contains() like Collection.contains(java.lang.Object) to make Strings more polymorphic. |
|
static boolean |
containsAll(java.util.Collection self,
java.lang.Object[] items)
Returns true if this collection contains all of the elements in the specified array. |
|
static java.lang.Number |
count(boolean[] self,
java.lang.Object value)
Counts the number of occurrences of the given value inside this array. |
|
static java.lang.Number |
count(byte[] self,
java.lang.Object value)
Counts the number of occurrences of the given value inside this array. |
|
static java.lang.Number |
count(char[] self,
java.lang.Object value)
Counts the number of occurrences of the given value inside this array. |
|
static java.lang.Number |
count(java.util.Collection self,
java.lang.Object value)
Counts the number of occurrences of the given value inside this collection. |
|
static java.lang.Number |
count(double[] self,
java.lang.Object value)
Counts the number of occurrences of the given value inside this array. |
|
static java.lang.Number |
count(float[] self,
java.lang.Object value)
Counts the number of occurrences of the given value inside this array. |
|
static java.lang.Number |
count(int[] self,
java.lang.Object value)
Counts the number of occurrences of the given value inside this array. |
|
static java.lang.Number |
count(java.util.Iterator self,
java.lang.Object value)
Counts the number of occurrences of the given value from the items within this Iterator. |
|
static java.lang.Number |
count(long[] self,
java.lang.Object value)
Counts the number of occurrences of the given value inside this array. |
|
static java.lang.Number |
count(java.lang.Object[] self,
java.lang.Object value)
Counts the number of occurrences of the given value inside this array. |
|
static java.lang.Number |
count(short[] self,
java.lang.Object value)
Counts the number of occurrences of the given value inside this array. |
|
static int |
count(java.lang.String self,
java.lang.String text)
Count the number of occurencies of a substring. |
|
protected static StringBufferWriter |
createStringBufferWriter(java.lang.StringBuffer self)
|
|
protected static java.io.StringWriter |
createStringWriter(java.lang.String self)
|
|
static byte[] |
decodeBase64(java.lang.String value)
Deprecated. moved to EncodingGroovyMethods.decodeBase64(java.lang.String) |
|
static boolean |
deleteDir(java.io.File self)
Deletes a directory with all contained files and subdirectories. |
|
static java.lang.String |
denormalize(java.lang.String self)
Return a String with lines (separated by LF, CR/LF, or CR) terminated by the platform specific line separator. |
|
static boolean |
disjoint(java.util.Collection left,
java.util.Collection right)
Returns true if the intersection of two collections is empty. |
|
static java.lang.Number |
div(java.lang.Character left,
java.lang.Character right)
Divide one Character by another. |
|
static java.lang.Number |
div(java.lang.Character left,
java.lang.Number right)
Divide a Character by a Number. |
|
static java.lang.Number |
div(java.lang.Number left,
java.lang.Character right)
Divide a Number by a Character. |
|
static void |
downto(java.math.BigDecimal self,
java.lang.Number to,
Closure closure)
Iterates from this number down to the given number, inclusive, decrementing by one each time. |
|
static void |
downto(java.math.BigInteger self,
java.lang.Number to,
Closure closure)
Iterates from this number down to the given number, inclusive, decrementing by one each time. |
|
static void |
downto(double self,
java.lang.Number to,
Closure closure)
Iterates from this number down to the given number, inclusive, decrementing by one each time. |
|
static void |
downto(java.lang.Double self,
java.lang.Number to,
Closure closure)
Iterates from this number down to the given number, inclusive, decrementing by one each time. |
|
static void |
downto(float self,
java.lang.Number to,
Closure closure)
Iterates from this number down to the given number, inclusive, decrementing by one each time. |
|
static void |
downto(java.lang.Float self,
java.lang.Number to,
Closure closure)
Iterates from this number down to the given number, inclusive, decrementing by one each time. |
|
static void |
downto(long self,
java.lang.Number to,
Closure closure)
Iterates from this number down to the given number, inclusive, decrementing by one each time. |
|
static void |
downto(java.lang.Long self,
java.lang.Number to,
Closure closure)
Iterates from this number down to the given number, inclusive, decrementing by one each time. |
|
static void |
downto(java.lang.Number self,
java.lang.Number to,
Closure closure)
Iterates from this number down to the given number, inclusive, decrementing by one each time. |
|
static java.lang.String |
dump(java.lang.Object self)
Generates a detailed dump string of an object showing its class, hashCode and fields. |
|
static
|
each(java.util.Map<K,V> self,
Closure closure)
Allows a Map to be iterated through using a closure. |
|
static
|
each(T self,
Closure closure)
Iterates through an aggregate type or data structure, passing each item to the given closure. |
|
static void |
eachByte(byte[] self,
Closure closure)
Traverse through each byte of this byte array. |
|
static void |
eachByte(java.lang.Byte[] self,
Closure closure)
Traverse through each byte of this Byte array. |
|
static void |
eachByte(java.io.File self,
Closure closure)
Traverse through each byte of this File |
|
static void |
eachByte(java.io.File self,
int bufferLen,
Closure closure)
Traverse through the bytes of this File, bufferLen bytes at a time. |
|
static void |
eachByte(java.io.InputStream is,
Closure closure)
Traverse through each byte of the specified stream. |
|
static void |
eachByte(java.io.InputStream is,
int bufferLen,
Closure closure)
Traverse through each the specified stream reading bytes into a buffer and calling the 2 parameter closure with this buffer and the number of bytes. |
|
static void |
eachByte(java.net.URL url,
Closure closure)
Reads the InputStream from this URL, passing each byte to the given closure. |
|
static void |
eachByte(java.net.URL url,
int bufferLen,
Closure closure)
Reads the InputStream from this URL, passing a byte[] and a number of bytes to the given closure. |
|
static void |
eachDir(java.io.File self,
Closure closure)
Invokes the closure for each subdirectory in this directory, ignoring regular files. |
|
static void |
eachDirMatch(java.io.File self,
java.lang.Object nameFilter,
Closure closure)
Invokes the closure for each subdirectory whose name (dir.name) matches the given nameFilter in the given directory - calling the isCase(java.lang.Object, java.lang.Object) method to determine if a match occurs. |
|
static void |
eachDirRecurse(java.io.File self,
Closure closure)
Invokes the closure for each descendant directory of this directory. |
|
static void |
eachFile(java.io.File self,
Closure closure)
Invokes the closure for each 'child' file in this 'parent' folder/directory. |
|
static void |
eachFile(java.io.File self,
FileType fileType,
Closure closure)
Invokes the closure for each 'child' file in this 'parent' folder/directory. |
|
static void |
eachFileMatch(java.io.File self,
FileType fileType,
java.lang.Object nameFilter,
Closure closure)
Invokes the closure for each file whose name (file.name) matches the given nameFilter in the given directory - calling the isCase(java.lang.Object, java.lang.Object) method to determine if a match occurs. |
|
static void |
eachFileMatch(java.io.File self,
java.lang.Object nameFilter,
Closure closure)
Invokes the closure for each file whose name (file.name) matches the given nameFilter in the given directory - calling the isCase(java.lang.Object, java.lang.Object) method to determine if a match occurs. |
|
static void |
eachFileRecurse(java.io.File self,
Closure closure)
Invokes the closure for each descendant file in this directory. |
|
static void |
eachFileRecurse(java.io.File self,
FileType fileType,
Closure closure)
Invokes the closure for each descendant file in this directory. |
|
static java.lang.Object |
eachLine(java.io.File self,
Closure closure)
Iterates through this file line by line. |
|
static java.lang.Object |
eachLine(java.io.File self,
int firstLine,
Closure closure)
Iterates through this file line by line. |
|
static java.lang.Object |
eachLine(java.io.File self,
java.lang.String charset,
Closure closure)
Iterates through this file line by line. |
|
static java.lang.Object |
eachLine(java.io.File self,
java.lang.String charset,
int firstLine,
Closure closure)
Iterates through this file line by line. |
|
static java.lang.Object |
eachLine(java.io.InputStream stream,
Closure closure)
Iterates through this stream, passing each line to the given 1 or 2 arg closure. |
|
static java.lang.Object |
eachLine(java.io.InputStream stream,
int firstLine,
Closure closure)
Iterates through this stream, passing each line to the given 1 or 2 arg closure. |
|
static java.lang.Object |
eachLine(java.io.InputStream stream,
java.lang.String charset,
Closure closure)
Iterates through this stream reading with the provided charset, passing each line to the given 1 or 2 arg closure. |
|
static java.lang.Object |
eachLine(java.io.InputStream stream,
java.lang.String charset,
int firstLine,
Closure closure)
Iterates through this stream reading with the provided charset, passing each line to the given 1 or 2 arg closure. |
|
static java.lang.Object |
eachLine(java.io.Reader self,
Closure closure)
Iterates through the given reader line by line. |
|
static java.lang.Object |
eachLine(java.io.Reader self,
int firstLine,
Closure closure)
Iterates through the given reader line by line. |
|
static java.lang.Object |
eachLine(java.lang.String self,
Closure closure)
Iterates through this String line by line. |
|
static java.lang.Object |
eachLine(java.lang.String self,
int firstLine,
Closure closure)
Iterates through this String line by line. |
|
static java.lang.Object |
eachLine(java.net.URL url,
Closure closure)
Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure. |
|
static java.lang.Object |
eachLine(java.net.URL url,
int firstLine,
Closure closure)
Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure. |
|
static java.lang.Object |
eachLine(java.net.URL url,
java.lang.String charset,
Closure closure)
Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure. |
|
static java.lang.Object |
eachLine(java.net.URL url,
java.lang.String charset,
int firstLine,
Closure closure)
Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure. |
|
static java.lang.String |
eachMatch(java.lang.String self,
java.util.regex.Pattern pattern,
Closure closure)
Process each regex group matched substring of the given pattern. |
|
static java.lang.String |
eachMatch(java.lang.String self,
java.lang.String regex,
Closure closure)
Process each regex group matched substring of the given string. |
|
static void |
eachObject(java.io.File self,
Closure closure)
Iterates through the given file object by object. |
|
static void |
eachObject(java.io.ObjectInputStream ois,
Closure closure)
Iterates through the given object stream object by object. |
|
static
|
eachPermutation(java.util.Collection<T> self,
Closure closure)
Iterates over all permutations of a collection, running a closure for each iteration. |
|
static
|
eachWithIndex(java.util.Map<K,V> self,
Closure closure)
Allows a Map to be iterated through using a closure. |
|
static java.lang.Object |
eachWithIndex(java.lang.Object self,
Closure closure)
Iterates through an aggregate type or data structure, passing each item and the item's index (a counter starting at zero) to the given closure. |
|
static Writable |
encodeBase64(byte[] data)
Deprecated. moved to EncodingGroovyMethods.encodeBase64(byte[]) |
|
static Writable |
encodeBase64(java.lang.Byte[] data)
Deprecated. moved to EncodingGroovyMethods.encodeBase64(java.lang.Byte[]) |
|
static Writable |
encodeBase64(byte[] data,
boolean chunked)
Deprecated. moved to EncodingGroovyMethods.encodeBase64(byte[], boolean) |
|
static Writable |
encodeBase64(java.lang.Byte[] data,
boolean chunked)
Deprecated. moved to EncodingGroovyMethods.encodeBase64(java.lang.Byte[], boolean) |
|
static boolean |
equals(int[] left,
int[] right)
Compare the contents of this array to the contents of the given array. |
|
static boolean |
equals(java.util.List left,
java.util.List right)
Compare the contents of two Lists. |
|
static boolean |
equals(java.util.List left,
java.lang.Object[] right)
Determines if the contents of this list are equal to the contents of the given array in the same order. |
|
static boolean |
equals(java.lang.Object[] left,
java.util.List right)
Determines if the contents of this array are equal to the contents of the given list, in the same order. |
|
static
|
every(java.util.Map<K,V> self,
Closure closure)
Iterates over the entries of a map, and checks whether a predicate is valid for all entries. |
|
static boolean |
every(java.lang.Object self)
Iterates over every element of a collection, and checks whether all elements are true according to the Groovy Truth. |
|
static boolean |
every(java.lang.Object self,
Closure closure)
Used to determine if the given predicate closure is valid (i.e.&nsbp;returns true for all items in this data structure). |
|
static java.lang.Process |
execute(java.util.List commands)
Executes the command specified by the given list. |
|
static java.lang.Process |
execute(java.util.List commands,
java.util.List envp,
java.io.File dir)
Executes the command specified by the given list, with the environment defined by envp and under the working directory dir . |
|
static java.lang.Process |
execute(java.util.List commands,
java.lang.String[] envp,
java.io.File dir)
Executes the command specified by the given list, with the environment defined by envp and under the working directory dir . |
|
static java.lang.Process |
execute(java.lang.String self)
Executes the command specified by self as a command-line process. |
|
static java.lang.Process |
execute(java.lang.String[] commandArray)
Executes the command specified by the given String array. |
|
static java.lang.Process |
execute(java.lang.String[] commandArray,
java.util.List envp,
java.io.File dir)
Executes the command specified by the String array given in the first parameter,
with the environment defined by envp and under the working directory dir . |
|
static java.lang.Process |
execute(java.lang.String[] commandArray,
java.lang.String[] envp,
java.io.File dir)
Executes the command specified by the String array given in the first parameter,
with the environment defined by envp and under the working directory dir . |
|
static java.lang.Process |
execute(java.lang.String self,
java.util.List envp,
java.io.File dir)
Executes the command specified by self with environment defined
by envp and under the working directory dir . |
|
static java.lang.Process |
execute(java.lang.String self,
java.lang.String[] envp,
java.io.File dir)
Executes the command specified by self with environment defined by envp
and under the working directory dir . |
|
static java.lang.String |
expand(java.lang.String self)
Expands all tabs into spaces with tabStops of size 8. |
|
static java.lang.String |
expand(java.lang.String self,
int tabStop)
Expands all tabs into spaces. |
|
static java.lang.String |
expandLine(java.lang.String self,
int tabStop)
Expands all tabs into spaces. |
|
static Writable |
filterLine(java.io.File self,
Closure closure)
Filters the lines of a File and creates a Writeable in return to stream the filtered lines. |
|
static Writable |
filterLine(java.io.File self,
java.lang.String charset,
Closure closure)
Filters the lines of a File and creates a Writeable in return to stream the filtered lines. |
|
static void |
filterLine(java.io.File self,
java.io.Writer writer,
Closure closure)
Filter the lines from this File, and write them to the given writer based on the given closure predicate. |
|
static void |
filterLine(java.io.File self,
java.io.Writer writer,
java.lang.String charset,
Closure closure)
Filter the lines from this File, and write them to the given writer based on the given closure predicate. |
|
static Writable |
filterLine(java.io.InputStream self,
Closure predicate)
Filter lines from an input stream using a closure predicate. |
|
static Writable |
filterLine(java.io.InputStream self,
java.lang.String charset,
Closure predicate)
Filter lines from an input stream using a closure predicate. |
|
static void |
filterLine(java.io.InputStream self,
java.io.Writer writer,
Closure predicate)
Uses a closure to filter lines from this InputStream and pass them to the given writer. |
|
static void |
filterLine(java.io.InputStream self,
java.io.Writer writer,
java.lang.String charset,
Closure predicate)
Uses a closure to filter lines from this InputStream and pass them to the given writer. |
|
static Writable |
filterLine(java.io.Reader reader,
Closure closure)
Filter the lines from this Reader, and return a Writable which can be used to stream the filtered lines to a destination. |
|
static void |
filterLine(java.io.Reader reader,
java.io.Writer writer,
Closure closure)
Filter the lines from a reader and write them on the writer, according to a closure which returns true if the line should be included. |
|
static Writable |
filterLine(java.net.URL self,
Closure predicate)
Filter lines from a URL using a closure predicate. |
|
static Writable |
filterLine(java.net.URL self,
java.lang.String charset,
Closure predicate)
Filter lines from a URL using a closure predicate. |
|
static void |
filterLine(java.net.URL self,
java.io.Writer writer,
Closure predicate)
Uses a closure to filter lines from this URL and pass them to the given writer. |
|
static void |
filterLine(java.net.URL self,
java.io.Writer writer,
java.lang.String charset,
Closure predicate)
Uses a closure to filter lines from this URL and pass them to the given writer. |
|
static
|
find(java.util.Collection<T> self,
Closure closure)
Finds the first value matching the closure condition. |
|
static
|
find(java.util.Map<K,V> self,
Closure closure)
Finds the first entry matching the closure condition. |
|
static java.lang.Object |
find(java.lang.Object self,
Closure closure)
Finds the first value matching the closure condition |
|
static java.lang.String |
find(java.lang.String self,
java.util.regex.Pattern pattern)
Finds the first occurrence of a compiled regular expression Pattern within a String. |
|
static java.lang.String |
find(java.lang.String self,
java.util.regex.Pattern pattern,
Closure closure)
Finds the first occurrence of a compiled regular expression Pattern within a String. |
|
static java.lang.String |
find(java.lang.String self,
java.lang.String regex)
Finds the first occurrence of a regular expression String within a String. |
|
static java.lang.String |
find(java.lang.String self,
java.lang.String regex,
Closure closure)
Finds the first occurrence of a regular expression String within a String. |
|
static
|
findAll(java.util.Collection<T> self,
Closure closure)
Finds all values matching the closure condition. |
|
static
|
findAll(java.util.Map<K,V> self,
Closure closure)
Finds all entries matching the closure condition. |
|
static java.util.Collection |
findAll(java.lang.Object self,
Closure closure)
Finds all items matching the closure condition. |
|
static java.util.List |
findAll(java.lang.String self,
java.util.regex.Pattern pattern)
Finds all occurrences of a regular expression Pattern within a String. |
|
static java.util.List |
findAll(java.lang.String self,
java.util.regex.Pattern pattern,
Closure closure)
Finds all occurrences of a compiled regular expression Pattern within a String. |
|
static java.util.List |
findAll(java.lang.String self,
java.lang.String regex)
Finds all occurrences of a regular expression string within a String. |
|
static java.util.List |
findAll(java.lang.String self,
java.lang.String regex,
Closure closure)
Finds all occurrences of a regular expression string within a String. |
|
static int |
findIndexOf(java.lang.Object self,
Closure closure)
Iterates over the elements of an iterable collection of items and returns the index of the first item that matches the condition specified in the closure. |
|
static int |
findIndexOf(java.lang.Object self,
int startIndex,
Closure closure)
Iterates over the elements of an iterable collection of items, starting from a specified startIndex, and returns the index of the first item that matches the condition specified in the closure. |
|
static java.util.List<java.lang.Number> |
findIndexValues(java.lang.Object self,
Closure closure)
Iterates over the elements of an iterable collection of items and returns the index values of the items that match the condition specified in the closure. |
|
static java.util.List<java.lang.Number> |
findIndexValues(java.lang.Object self,
java.lang.Number startIndex,
Closure closure)
Iterates over the elements of an iterable collection of items, starting from a specified startIndex, and returns the index values of the items that match the condition specified in the closure. |
|
static int |
findLastIndexOf(java.lang.Object self,
Closure closure)
Iterates over the elements of an iterable collection of items and returns the index of the last item that matches the condition specified in the closure. |
|
static int |
findLastIndexOf(java.lang.Object self,
int startIndex,
Closure closure)
Iterates over the elements of an iterable collection of items, starting from a specified startIndex, and returns the index of the last item that matches the condition specified in the closure. |
|
static
|
first(java.util.List<T> self)
Returns the first item from the List. |
|
static
|
first(T[] self)
Returns the first item from the Object array. |
|
static java.util.Collection |
flatten(boolean[] self)
Flatten an array. |
|
static java.util.Collection |
flatten(byte[] self)
Flatten an array. |
|
static java.util.Collection |
flatten(char[] self)
Flatten an array. |
|
static java.util.Collection |
flatten(java.util.Collection self)
Flatten a collection. |
|
static java.util.Collection |
flatten(java.util.Collection self,
Closure flattenUsing)
Flatten a collection. |
|
static java.util.Collection |
flatten(double[] self)
Flatten an array. |
|
static java.util.Collection |
flatten(float[] self)
Flatten an array. |
|
static java.util.Collection |
flatten(int[] self)
Flatten an array. |
|
static java.util.Collection |
flatten(long[] self)
Flatten an array. |
|
static java.util.Collection |
flatten(java.lang.Object[] self)
Flatten an array. |
|
static java.util.Collection |
flatten(short[] self)
Flatten an array. |
|
static java.lang.String |
format(java.util.Calendar self,
java.lang.String pattern)
Deprecated. moved to DateGroovyMethods.format(java.util.Calendar, java.lang.String) |
|
static java.lang.String |
format(java.util.Date self,
java.lang.String format)
Deprecated. moved to DateGroovyMethods.format(java.util.Date, java.lang.String) |
|
static
|
get(java.util.Map<K,V> map,
K key,
V defaultValue)
Looks up an item in a Map for the given key and returns the value - unless there is no entry for the given key in which case add the default value to the map and return that. |
|
static boolean |
getAt(java.util.BitSet self,
int index)
Support the subscript operator for a Bitset |
|
static java.util.BitSet |
getAt(java.util.BitSet self,
IntRange range)
Support retrieving a subset of a BitSet using a Range |
|
static java.util.List<java.lang.Boolean> |
getAt(boolean[] array,
java.util.Collection indices)
Support the subscript operator with a collection for a boolean array |
|
static java.util.List<java.lang.Boolean> |
getAt(boolean[] array,
IntRange range)
Support the subscript operator with an IntRange for a boolean array |
|
static java.util.List<java.lang.Boolean> |
getAt(boolean[] array,
ObjectRange range)
Support the subscript operator with an ObjectRange for a byte array |
|
static java.util.List<java.lang.Boolean> |
getAt(boolean[] array,
Range range)
Support the subscript operator with a range for a boolean array |
|
static java.util.List<java.lang.Byte> |
getAt(byte[] array,
java.util.Collection indices)
Support the subscript operator with a collection for a byte array |
|
static java.util.List<java.lang.Byte> |
getAt(byte[] array,
IntRange range)
Support the subscript operator with an IntRange for a byte array |
|
static java.util.List<java.lang.Byte> |
getAt(byte[] array,
ObjectRange range)
Support the subscript operator with an ObjectRange for a byte array |
|
static java.util.List<java.lang.Byte> |
getAt(byte[] array,
Range range)
Support the subscript operator with a range for a byte array |
|
static java.util.List<java.lang.Character> |
getAt(char[] array,
java.util.Collection indices)
Support the subscript operator with a collection for a char array |
|
static java.util.List<java.lang.Character> |
getAt(char[] array,
IntRange range)
Support the subscript operator with an IntRange for a char array |
|
static java.util.List<java.lang.Character> |
getAt(char[] array,
ObjectRange range)
Support the subscript operator with an ObjectRange for a char array |
|
static java.util.List<java.lang.Character> |
getAt(char[] array,
Range range)
Support the subscript operator with a range for a char array |
|
static java.lang.CharSequence |
getAt(java.lang.CharSequence self,
java.util.Collection indices)
Select a List of characters from a CharSequence using a Collection to identify the indices to be selected. |
|
static java.lang.CharSequence |
getAt(java.lang.CharSequence text,
EmptyRange range)
Support the range subscript operator for CharSequence or StringBuffer with EmptyRange |
|
static java.lang.CharSequence |
getAt(java.lang.CharSequence text,
int index)
Support the subscript operator for CharSequence. |
|
static java.lang.CharSequence |
getAt(java.lang.CharSequence text,
IntRange range)
Support the range subscript operator for CharSequence or StringBuffer with IntRange |
|
static java.lang.CharSequence |
getAt(java.lang.CharSequence text,
Range range)
Support the range subscript operator for CharSequence |
|
static java.util.List |
getAt(java.util.Collection coll,
java.lang.String property)
Support the subscript operator for List assert [String, Long, Integer] == ["a",5L,2]["class"] |
|
static int |
getAt(java.util.Date self,
int field)
Deprecated. moved to DateGroovyMethods.getAt(java.util.Date, int) |
|
static java.util.List<java.lang.Double> |
getAt(double[] array,
java.util.Collection indices)
Support the subscript operator with a collection for a double array |
|
static java.util.List<java.lang.Double> |
getAt(double[] array,
IntRange range)
Support the subscript operator with an IntRange for a double array |
|
static java.util.List<java.lang.Double> |
getAt(double[] array,
ObjectRange range)
Support the subscript operator with an ObjectRange for a double array |
|
static java.util.List<java.lang.Double> |
getAt(double[] array,
Range range)
Support the subscript operator with a range for a double array |
|
static java.util.List<java.lang.Float> |
getAt(float[] array,
java.util.Collection indices)
Support the subscript operator with a collection for a float array |
|
static java.util.List<java.lang.Float> |
getAt(float[] array,
IntRange range)
Support the subscript operator with an IntRange for a float array |
|
static java.util.List<java.lang.Float> |
getAt(float[] array,
ObjectRange range)
Support the subscript operator with an ObjectRange for a float array |
|
static java.util.List<java.lang.Float> |
getAt(float[] array,
Range range)
Support the subscript operator with a range for a float array |
|
static java.util.List<java.lang.Integer> |
getAt(int[] array,
java.util.Collection indices)
Support the subscript operator with a collection for an int array |
|
static java.util.List<java.lang.Integer> |
getAt(int[] array,
IntRange range)
Support the subscript operator with an IntRange for an int array |
|
static java.util.List<java.lang.Integer> |
getAt(int[] array,
ObjectRange range)
Support the subscript operator with an ObjectRange for an int array |
|
static java.util.List<java.lang.Integer> |
getAt(int[] array,
Range range)
Support the subscript operator with a range for an int array |
|
static
|
getAt(java.util.Iterator<T> self,
int idx)
Support the subscript operator for an Iterator. |
|
static
|
getAt(java.util.List<T> self,
java.util.Collection indices)
Select a List of items from a List using a Collection to identify the indices to be selected. |
|
static
|
getAt(java.util.List<T> self,
EmptyRange range)
Support the range subscript operator for a List def list = [true, 1, 3.4] assert list[0..<0] == [] |
|
static
|
getAt(java.util.List<T> self,
int idx)
Support the subscript operator for a List. |
|
static
|
getAt(java.util.List<T> self,
Range range)
Support the range subscript operator for a List def list = [1, "a", 4.5, true] assert list[1..2] == ["a", 4.5] |
|
static java.util.List<java.lang.Long> |
getAt(long[] array,
java.util.Collection indices)
Support the subscript operator with a collection for a long array |
|
static java.util.List<java.lang.Long> |
getAt(long[] array,
IntRange range)
Support the subscript operator with an IntRange for a long array |
|
static java.util.List<java.lang.Long> |
getAt(long[] array,
ObjectRange range)
Support the subscript operator with an ObjectRange for a long array |
|
static java.util.List<java.lang.Long> |
getAt(long[] array,
Range range)
Support the subscript operator with a range for a long array |
|
static
|
getAt(java.util.Map<K,V> self,
K key)
Support the subscript operator for a Map. |
|
static java.util.List |
getAt(java.util.regex.Matcher self,
java.util.Collection indices)
Select a List of values from a Matcher using a Collection to identify the indices to be selected. |
|
static java.lang.Object |
getAt(java.util.regex.Matcher matcher,
int idx)
Support the subscript operator, e.g. matcher[index], for a regex Matcher. |
|
static java.lang.Object |
getAt(java.lang.Object self,
java.lang.String property)
Allows the subscript operator to be used to lookup dynamic property values. |
|
static java.util.List<java.lang.Short> |
getAt(short[] array,
java.util.Collection indices)
Support the subscript operator with a collection for a short array |
|
static java.util.List<java.lang.Short> |
getAt(short[] array,
IntRange range)
Support the subscript operator with an IntRange for a short array |
|
static java.util.List<java.lang.Short> |
getAt(short[] array,
ObjectRange range)
Support the subscript operator with an ObjectRange for a short array |
|
static java.util.List<java.lang.Short> |
getAt(short[] array,
Range range)
Support the subscript operator with a range for a short array |
|
static java.lang.String |
getAt(java.lang.String self,
java.util.Collection indices)
Select a List of characters from a String using a Collection to identify the indices to be selected. |
|
static java.lang.String |
getAt(java.lang.String text,
EmptyRange range)
Support the range subscript operator for String with EmptyRange |
|
static java.lang.String |
getAt(java.lang.String text,
int index)
Support the subscript operator for String. |
|
static java.lang.String |
getAt(java.lang.String text,
IntRange range)
Support the range subscript operator for String with IntRange |
|
static java.lang.String |
getAt(java.lang.String text,
Range range)
Support the range subscript operator for String |
|
static
|
getAt(T[] self,
java.util.Collection indices)
Select a List of items from an Object array using a Collection to identify the indices to be selected. |
|
static
|
getAt(T[] array,
EmptyRange range)
|
|
static
|
getAt(T[] array,
IntRange range)
|
|
static
|
getAt(T[] array,
ObjectRange range)
|
|
static
|
getAt(T[] array,
Range range)
Support the range subscript operator for an Array |
|
static byte[] |
getBytes(java.io.File file)
Read the content of the File and returns it as a byte[]. |
|
static byte[] |
getBytes(java.io.InputStream is)
Read the content of this InputStream and return it as a byte[]. |
|
static byte[] |
getBytes(java.net.URL url)
Read the content of this URL and returns it as a byte[]. |
|
static char[] |
getChars(java.lang.String self)
Converts the given String into an array of characters. |
|
static int |
getCount(java.util.regex.Matcher matcher)
Find the number of Strings matched to the given Matcher. |
|
static java.lang.String |
getDateString(java.util.Date self)
Deprecated. moved to DateGroovyMethods.getDateString(java.util.Date) |
|
static java.lang.String |
getDateTimeString(java.util.Date self)
Deprecated. moved to DateGroovyMethods.getDateTimeString(java.util.Date) |
|
static java.io.InputStream |
getErr(java.lang.Process self)
An alias method so that a process appears similar to System.out, System.in, System.err; you can use process.in, process.out, process.err in a similar fashion. |
|
static java.io.InputStream |
getIn(java.lang.Process self)
An alias method so that a process appears similar to System.out, System.in, System.err; you can use process.in, process.out, process.err in a similar fashion. |
|
static MetaClass |
getMetaClass(java.lang.Class c)
Adds a "metaClass" property to all class objects so you can use the syntax String.metaClass.myMethod = { println "foo" } |
|
static MetaClass |
getMetaClass(GroovyObject obj)
Obtains a MetaClass for an object either from the registry or in the case of a GroovyObject from the object itself. |
|
static MetaClass |
getMetaClass(java.lang.Object obj)
Obtains a MetaClass for an object either from the registry or in the case of a GroovyObject from the object itself. |
|
static java.util.List<PropertyValue> |
getMetaPropertyValues(java.lang.Object self)
Retrieves the list 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 java.io.OutputStream |
getOut(java.lang.Process self)
An alias method so that a process appears similar to System.out, System.in, System.err; you can use process.in, process.out, process.err in a similar fashion. |
|
static java.util.Map |
getProperties(java.lang.Object self)
Convenience method that calls getMetaPropertyValues(java.lang.Object) (self)
and provides the data in form of simple key/value pairs, i.e.&nsbp;without
type() information. |
|
static java.lang.ClassLoader |
getRootLoader(java.lang.ClassLoader self)
Iterates through the classloader parents until it finds a loader with a class named "org.codehaus.groovy.tools.RootLoader". |
|
protected static java.util.List |
getSubList(java.util.List self,
java.util.List splice)
|
|
static java.lang.String |
getText(java.io.BufferedReader reader)
Read the content of the BufferedReader and return it as a String. |
|
static java.lang.String |
getText(java.io.File file)
Read the content of the File and returns it as a String. |
|
static java.lang.String |
getText(java.io.File file,
java.lang.String charset)
Read the content of the File using the specified encoding and return it as a String. |
|
static java.lang.String |
getText(java.io.InputStream is)
Read the content of this InputStream and return it as a String. |
|
static java.lang.String |
getText(java.io.InputStream is,
java.lang.String charset)
Read the content of this InputStream using specified charset and return it as a String. |
|
static java.lang.String |
getText(java.lang.Process self)
Read the text of the output stream of the Process. |
|
static java.lang.String |
getText(java.io.Reader reader)
Read the content of the Reader and return it as a String. |
|
static java.lang.String |
getText(java.net.URL url)
Read the content of this URL and returns it as a String. |
|
static java.lang.String |
getText(java.net.URL url,
java.lang.String charset)
Read the data from this URL and return it as a String. |
|
static java.lang.String |
getTimeString(java.util.Date self)
Deprecated. moved to DateGroovyMethods.getTimeString(java.util.Date) |
|
static java.util.Collection |
grep(java.lang.Object self,
java.lang.Object filter)
Iterates over every element of the collection and returns each item that matches the given filter - calling the
method used by switch statements. |
|
protected static
|
groupAnswer(java.util.Map<java.lang.Object,java.util.List<T>> answer,
T element,
java.lang.Object value)
Groups the current element according to the value |
|
static
|
groupBy(java.util.Collection<T> self,
Closure closure)
Sorts all collection members into groups determined by the supplied mapping closure. |
|
static
|
groupBy(java.util.Map<K,V> self,
Closure closure)
Groups the members of a map into sub maps determined by the supplied mapping closure. |
|
static
|
groupEntriesBy(java.util.Map<K,V> self,
Closure closure)
Groups all map entries into groups determined by the supplied mapping closure. |
|
static boolean |
hasGroup(java.util.regex.Matcher matcher)
Check whether a Matcher contains a group or not. |
|
static MetaProperty |
hasProperty(java.lang.Object self,
java.lang.String name)
Returns true of the implementing MetaClass has a property of the given name |
|
static
|
head(java.util.List<T> self)
Returns the first item from the List. |
|
static
|
head(T[] self)
Returns the first item from the Object array. |
|
static java.lang.Object |
identity(java.lang.Object self,
Closure closure)
Allows the closure to be called for the object reference self synonym for 'with()'. |
|
static java.lang.Object |
inject(java.util.Collection self,
java.lang.Object value,
Closure closure)
Iterates through the given collection, passing in the initial value to the closure along with the current iterated item then passing into the next iteration the value of the previous closure. |
|
static java.lang.Object |
inject(java.util.Iterator self,
java.lang.Object value,
Closure closure)
Iterates through the given iterator, passing in the initial value to the closure along with the current iterated item then passing into the next iteration the value of the previous closure. |
|
static java.lang.Object |
inject(java.lang.Object[] self,
java.lang.Object initialValue,
Closure closure)
Iterates through the given array of objects, passing in the initial value to the closure along with the current iterated item then passing into the next iteration the value of the previous closure. |
|
static java.lang.Object |
inject(java.lang.Object self,
java.lang.Object value,
Closure closure)
Iterates through the given object, passing in the initial value to the closure along with the current iterated item then passing into the next iteration the value of the previous closure. |
|
static java.lang.String |
inspect(java.lang.Object self)
Inspects returns the String that matches what would be typed into a terminal to create this object. |
|
static java.lang.Number |
intdiv(java.lang.Character left,
java.lang.Character right)
Integer Divide two Characters. |
|
static java.lang.Number |
intdiv(java.lang.Character left,
java.lang.Number right)
Integer Divide a Character by a Number. |
|
static java.lang.Number |
intdiv(java.lang.Number left,
java.lang.Character right)
Integer Divide a Number by a Character. |
|
static java.lang.Number |
intdiv(java.lang.Number left,
java.lang.Number right)
Integer Divide two Numbers. |
|
static
|
intersect(java.util.Collection<T> left,
java.util.Collection<T> right)
Create a Collection composed of the intersection of both collections. |
|
static
|
intersect(java.util.Map<K,V> left,
java.util.Map<K,V> right)
Create a Map composed of the intersection of both maps. |
|
static java.lang.Object |
invokeMethod(java.lang.Object object,
java.lang.String method,
java.lang.Object arguments)
Provide a dynamic method invocation method which can be overloaded in classes to implement dynamic proxies easily. |
|
static boolean |
is(java.lang.Object self,
java.lang.Object other)
Identity check. |
|
static boolean |
isAllWhitespace(java.lang.String self)
True if a String only contains whitespace characters. |
|
static boolean |
isBigDecimal(java.lang.String self)
Determine if a String can be parsed into a BigDecimal. |
|
static boolean |
isBigInteger(java.lang.String self)
Determine if a String can be parsed into a BigInteger. |
|
static boolean |
isCase(java.lang.Class caseValue,
java.lang.Object switchValue)
Special 'Case' implementation for Class, which allows testing for a certain class in a switch statement. |
|
static boolean |
isCase(java.util.Collection caseValue,
java.lang.Object switchValue)
'Case' implementation for collections which tests if the 'switch' operand is contained in any of the 'case' values. |
|
static boolean |
isCase(GString caseValue,
java.lang.Object switchValue)
'Case' implementation for a GString, which simply calls the equivalet method for String. |
|
static boolean |
isCase(java.lang.Number caseValue,
java.lang.Number switchValue)
Special 'case' implementation for all numbers, which delegates to the compareTo() method for comparing numbers of different
types. |
|
static boolean |
isCase(java.lang.Object caseValue,
java.lang.Object switchValue)
Method for overloading the behavior of the 'case' method in switch statements. |
|
static boolean |
isCase(java.util.regex.Pattern caseValue,
java.lang.Object switchValue)
'Case' implementation for the Pattern class, which allows
testing a String against a number of regular expressions. |
|
static boolean |
isCase(java.lang.String caseValue,
java.lang.Object switchValue)
'Case' implementation for a String, which uses String#equals(Object) in order to allow Strings to be used in switch statements. |
|
static boolean |
isDigit(java.lang.Character self)
Determines if a character is a digit. |
|
static boolean |
isDouble(java.lang.String self)
Determine if a String can be parsed into a Double. |
|
static boolean |
isFloat(java.lang.String self)
Determine if a String can be parsed into a Float. |
|
static boolean |
isInteger(java.lang.String self)
Determine if a String can be parsed into an Integer. |
|
static boolean |
isLetter(java.lang.Character self)
Determines if a character is a letter. |
|
static boolean |
isLetterOrDigit(java.lang.Character self)
Determines if a character is a letter or digit. |
|
static boolean |
isLong(java.lang.String self)
Determine if a String can be parsed into a Long. |
|
static boolean |
isLowerCase(java.lang.Character self)
Determine if a Character is lowercase. |
|
static boolean |
isNumber(java.lang.String self)
Determine if a String can be parsed into a Number. |
|
static boolean |
isUpperCase(java.lang.Character self)
Determine if a Character is uppercase. |
|
static boolean |
isWhitespace(java.lang.Character self)
Determines if a character is a whitespace character. |
|
static java.util.Iterator<java.lang.Byte> |
iterator(java.io.DataInputStream self)
Standard iterator for a data input stream which iterates through the stream content a Byte at a time. |
|
static
|
iterator(java.util.Enumeration<T> enumeration)
Allows an Enumeration to behave like an Iterator. |
|
static java.util.Iterator |
iterator(java.io.File self)
Deprecated. use File#eachLine instead please |
|
static java.util.Iterator<java.lang.Byte> |
iterator(java.io.InputStream self)
Standard iterator for a input stream which iterates through the stream content in a byte-based fashion. |
|
static
|
iterator(java.util.Iterator<T> self)
An identity function for iterators, supporting 'duck-typing' when trying to get an iterator for each object within a collection, some of which may already be iterators. |
|
static java.util.Iterator |
iterator(java.util.regex.Matcher matcher)
Returns an Iterator which traverses each match. |
|
static java.util.Iterator<org.w3c.dom.Node> |
iterator(org.w3c.dom.NodeList nodeList)
Deprecated. moved to XmlGroovyMethods.iterator(org.w3c.dom.NodeList) |
|
static java.util.Iterator |
iterator(java.lang.Object o)
Attempts to create an Iterator for the given object by first converting it to a Collection. |
|
static java.util.Iterator<java.lang.String> |
iterator(java.io.Reader self)
Creates an iterator which will traverse through the reader a line at a time. |
|
static
|
iterator(T[] a)
Attempts to create an Iterator for the given object by first converting it to a Collection. |
|
static java.lang.String |
join(java.util.Collection self,
java.lang.String separator)
Concatenates the toString() representation of each
item in this collection, with the given String as a separator between
each item. |
|
static java.lang.String |
join(java.util.Iterator<java.lang.Object> self,
java.lang.String separator)
Concatenates the toString() representation of each
item from the iterator, with the given String as a separator between
each item. |
|
static java.lang.String |
join(java.lang.Object[] self,
java.lang.String separator)
Concatenates the toString() representation of each
items in this array, with the given String as a separator between each
item. |
|
static
|
last(java.util.List<T> self)
Returns the last item from the List. |
|
static
|
last(T[] self)
Returns the last item from the Object array. |
|
static
|
leftShift(java.util.concurrent.BlockingQueue<T> self,
T value)
Overloads the left shift operator to provide an easy way to append objects to a BlockingQueue. |
|
static
|
leftShift(java.util.Collection<T> self,
T value)
Overloads the left shift operator to provide an easy way to append objects to a Collection. |
|
static java.io.File |
leftShift(java.io.File file,
byte[] bytes)
Write bytes to a File. |
|
static java.io.File |
leftShift(java.io.File file,
java.io.InputStream data)
Append binary data to the file. |
|
static java.io.File |
leftShift(java.io.File file,
java.lang.Object text)
Write the text to the File. |
|
static
|
leftShift(java.util.Map<K,V> self,
java.util.Map.Entry<K,V> entry)
Overloads the left shift operator to provide an easy way to append Map.Entry values to a Map. |
|
static
|
leftShift(java.util.Map<K,V> self,
java.util.Map<K,V> other)
Overloads the left shift operator to provide an easy way to put one maps entries into another map. |
|
static java.lang.Number |
leftShift(java.lang.Number self,
java.lang.Number operand)
Implementation of the left shift operator for integral types. |
|
static void |
leftShift(java.io.ObjectOutputStream self,
java.lang.Object value)
Overloads the leftShift operator to add objects to an ObjectOutputStream. |
|
static java.io.OutputStream |
leftShift(java.io.OutputStream self,
byte[] value)
Overloads the leftShift operator to provide an append mechanism to add bytes to a stream. |
|
static java.io.OutputStream |
leftShift(java.io.OutputStream self,
java.io.InputStream in)
Pipe an InputStream into an OutputStream for efficient stream copying. |
|
static java.io.Writer |
leftShift(java.io.OutputStream self,
java.lang.Object value)
Overloads the leftShift operator to provide an append mechanism to add values to a stream. |
|
static java.io.OutputStream |
leftShift(java.lang.Process self,
byte[] value)
Overloads the left shift operator to provide an append mechanism to pipe into a Process |
|
static java.io.Writer |
leftShift(java.lang.Process self,
java.lang.Object value)
Overloads the left shift operator (<<) to provide an append mechanism to pipe data to a Process. |
|
static java.io.OutputStream |
leftShift(java.net.Socket self,
byte[] value)
Overloads the left shift operator to provide an append mechanism to add bytes to the output stream of a socket |
|
static java.io.Writer |
leftShift(java.net.Socket self,
java.lang.Object value)
Overloads the left shift operator to provide an append mechanism to add things to the output stream of a socket |
|
static java.lang.StringBuffer |
leftShift(java.lang.StringBuffer self,
java.lang.Object value)
Overloads the left shift operator to provide an easy way to append multiple objects as string representations to a StringBuffer. |
|
static java.lang.StringBuffer |
leftShift(java.lang.String self,
java.lang.Object value)
Overloads the left shift operator to provide an easy way to append multiple objects as string representations to a String. |
|
static java.io.Writer |
leftShift(java.io.Writer self,
java.lang.Object value)
Overloads the left shift operator to provide a mechanism to append values to a writer. |
|
static boolean |
matches(java.lang.String self,
java.util.regex.Pattern pattern)
Tells whether or not self matches the given compiled regular expression Pattern. |
|
static
|
max(java.util.Collection<T> self)
Adds max() method to Collection objects. |
|
static
|
max(java.util.Collection<T> self,
Closure closure)
Selects the maximum value found in the collection using the closure to determine the correct ordering. |
|
static
|
max(java.util.Collection<T> self,
java.util.Comparator<T> comparator)
Selects the maximum value found in the collection using the given comparator. |
|
static
|
max(java.util.Iterator<T> self)
Adds max() method to Iterator objects. |
|
static
|
max(java.util.Iterator<T> self,
Closure closure)
Selects the maximum value found from the Iterator using the closure to determine the correct ordering. |
|
static
|
max(java.util.Iterator<T> self,
java.util.Comparator<T> comparator)
Selects the maximum value found from the Iterator using the given comparator. |
|
static
|
max(T[] self)
Adds max() method to Object arrays. |
|
static
|
max(T[] self,
Closure closure)
Selects the maximum value found from the Object array using the closure to determine the correct ordering. |
|
static
|
max(T[] self,
java.util.Comparator<T> comparator)
Selects the maximum value found from the Object array using the given comparator. |
|
static MetaClass |
metaClass(java.lang.Class self,
Closure closure)
Sets/updates the metaclass for a given class to a closure. |
|
static MetaClass |
metaClass(java.lang.Object self,
Closure closure)
Sets/updates the metaclass for a given object to a closure. |
|
static
|
min(java.util.Collection<T> self)
Adds min() method to Collection objects. |
|
static
|
min(java.util.Collection<T> self,
Closure closure)
Selects the minimum value found in the collection using the closure to determine the correct ordering. |
|
static
|
min(java.util.Collection<T> self,
java.util.Comparator<T> comparator)
Selects the minimum value found in the collection using the given comparator. |
|
static
|
min(java.util.Iterator<T> self)
Adds min() method to Iterator objects. |
|
static
|
min(java.util.Iterator<T> self,
Closure closure)
Selects the minimum value found from the Iterator using the closure to determine the correct ordering. |
|
static
|
min(java.util.Iterator<T> self,
java.util.Comparator<T> comparator)
Selects the minimum value found from the Iterator using the given comparator. |
|
static
|
min(T[] self)
Adds min() method to Object arrays. |
|
static
|
min(T[] self,
Closure closure)
Selects the minimum value found from the Object array using the closure to determine the correct ordering. |
|
static
|
min(T[] self,
java.util.Comparator<T> comparator)
Selects the minimum value found from the Object array using the given comparator. |
|
static int |
minus(java.util.Calendar self,
java.util.Calendar then)
Deprecated. moved to DateGroovyMethods.minus(java.util.Calendar, java.util.Calendar) |
|
static java.lang.Number |
minus(java.lang.Character left,
java.lang.Character right)
Subtract one Character from another. |
|
static java.lang.Number |
minus(java.lang.Character left,
java.lang.Number right)
Subtract a Number from a Character. |
|
static int |
minus(java.util.Date self,
java.util.Date then)
Deprecated. moved to DateGroovyMethods.minus(java.util.Date, java.util.Date) |
|
static java.util.Date |
minus(java.util.Date self,
int days)
Deprecated. moved to DateGroovyMethods.minus(java.util.Date, int) |
|
static java.sql.Date |
minus(java.sql.Date self,
int days)
Deprecated. moved to DateGroovyMethods.minus(java.sql.Date, int) |
|
static
|
minus(java.util.List<T> self,
java.util.Collection<T> removeMe)
Create a List composed of the elements of the first list minus every occurrence of elements of the given collection. |
|
static
|
minus(java.util.List<T> self,
java.lang.Object operand)
Create a new List composed of the elements of the first list minus every occurrence of the operand. |
|
static
|
minus(java.util.Map<K,V> self,
java.util.Map<K,V> operands)
Create a Map composed of the entries of the first map minus the entries of the given map. |
|
static java.lang.Number |
minus(java.lang.Number left,
java.lang.Character right)
Subtract a Character from a Number. |
|
static
|
minus(java.util.Set<T> self,
java.util.Collection operands)
Create a Set composed of the elements of the first set minus the elements of the given collection. |
|
static
|
minus(java.util.Set<T> self,
java.lang.Object operand)
Create a Set composed of the elements of the first set minus the operand. |
|
static java.lang.String |
minus(java.lang.String self,
java.lang.Object target)
Remove a part of a String. |
|
static
|
minus(T[] self,
java.util.Collection<T> removeMe)
Create an array composed of the elements of the first array minus the elements of the given collection. |
|
static
|
minus(T[] self,
java.lang.Object operand)
Create a new object array composed of the elements of the first array minus the operand. |
|
static
|
minus(T[] self,
T[] removeMe)
Create an array composed of the elements of the first array minus the elements of the given array. |
|
static void |
mixin(java.lang.Class self,
java.lang.Class categoryClass)
Extend class globally with category methods. |
|
static void |
mixin(java.lang.Class self,
java.lang.Class[] categoryClass)
Extend class globally with category methods. |
|
static void |
mixin(java.lang.Class self,
java.util.List<java.lang.Class> categoryClasses)
Extend class globally with category methods. |
|
static void |
mixin(MetaClass self,
java.lang.Class categoryClass)
Extend class globally with category methods. |
|
static void |
mixin(MetaClass self,
java.lang.Class[] categoryClass)
Extend class globally with category methods. |
|
static void |
mixin(MetaClass self,
java.util.List<java.lang.Class> categoryClasses)
Extend object with category methods. |
|
static java.lang.Number |
mod(java.lang.Number left,
java.lang.Number right)
Performs a division modulus operation. |
|
static java.lang.Number |
multiply(java.math.BigDecimal left,
java.math.BigInteger right)
Multiply a BigDecimal and a BigInteger. |
|
static java.lang.Number |
multiply(java.math.BigDecimal left,
java.lang.Double right)
Multiply a BigDecimal and a Double. |
|
static java.lang.Number |
multiply(java.lang.Character left,
java.lang.Character right)
Multiply two Characters. |
|
static java.lang.Number |
multiply(java.lang.Character left,
java.lang.Number right)
Multiply a Character by a Number. |
|
static
|
multiply(java.util.Collection<T> self,
java.lang.Number factor)
Create a List composed of the elements of this list, repeated a certain number of times. |
|
static java.lang.Number |
multiply(java.lang.Number left,
java.lang.Character right)
Multiply a Number by a Character. |
|
static java.lang.String |
multiply(java.lang.String self,
java.lang.Number factor)
Repeat a String a certain number of times. |
|
static java.io.DataInputStream |
newDataInputStream(java.io.File file)
Create a data input stream for this file |
|
static java.io.DataOutputStream |
newDataOutputStream(java.io.File file)
Creates a new data output stream for this file. |
|
static java.io.BufferedInputStream |
newInputStream(java.io.File file)
Creates a buffered input stream for this file. |
|
static java.io.BufferedInputStream |
newInputStream(java.net.URL url)
Creates a buffered input stream for this URL. |
|
static
|
newInstance(java.lang.Class<T> c)
Convenience method to dynamically create a new instance of this class. |
|
static
|
newInstance(java.lang.Class<T> c,
java.lang.Object[] args)
Helper to construct a new instance from the given arguments. |
|
static java.io.ObjectInputStream |
newObjectInputStream(java.io.File file)
Create an object input stream for this file. |
|
static java.io.ObjectInputStream |
newObjectInputStream(java.io.File file,
java.lang.ClassLoader classLoader)
Create an object input stream for this file using the given class loader. |
|
static java.io.ObjectInputStream |
newObjectInputStream(java.io.InputStream inputStream)
Create an object input stream for this input stream. |
|
static java.io.ObjectInputStream |
newObjectInputStream(java.io.InputStream inputStream,
java.lang.ClassLoader classLoader)
Create an object input stream for this input stream using the given class loader. |
|
static java.io.ObjectOutputStream |
newObjectOutputStream(java.io.File file)
Create an object output stream for this file. |
|
static java.io.ObjectOutputStream |
newObjectOutputStream(java.io.OutputStream outputStream)
Create an object output stream for this output stream. |
|
static java.io.BufferedOutputStream |
newOutputStream(java.io.File file)
Create a buffered output stream for this file. |
|
static java.io.PrintWriter |
newPrintWriter(java.io.File file)
Create a new PrintWriter for this file. |
|
static java.io.PrintWriter |
newPrintWriter(java.io.File file,
java.lang.String charset)
Create a new PrintWriter for this file, using specified charset. |
|
static java.io.PrintWriter |
newPrintWriter(java.io.Writer writer)
Create a new PrintWriter for this file, using specified charset. |
|
static java.io.BufferedReader |
newReader(java.io.File file)
Create a buffered reader for this file. |
|
static java.io.BufferedReader |
newReader(java.io.File file,
java.lang.String charset)
Create a buffered reader for this file, using the specified charset as the encoding. |
|
static java.io.BufferedReader |
newReader(java.io.InputStream self)
Creates a reader for this input stream. |
|
static java.io.BufferedReader |
newReader(java.io.InputStream self,
java.lang.String charset)
Creates a reader for this input stream, using the specified charset as the encoding. |
|
static java.io.BufferedReader |
newReader(java.net.URL url)
Creates a buffered reader for this URL. |
|
static java.io.BufferedReader |
newReader(java.net.URL url,
java.lang.String charset)
Creates a buffered reader for this URL using the given encoding. |
|
static java.io.BufferedWriter |
newWriter(java.io.File file)
Create a buffered writer for this file. |
|
static java.io.BufferedWriter |
newWriter(java.io.File file,
boolean append)
Creates a buffered writer for this file, optionally appending to the existing file content. |
|
static java.io.BufferedWriter |
newWriter(java.io.File file,
java.lang.String charset)
Creates a buffered writer for this file, writing data using the given encoding. |
|
static java.io.BufferedWriter |
newWriter(java.io.File file,
java.lang.String charset,
boolean append)
Helper method to create a buffered writer for a file. |
|
static java.lang.Character |
next(java.lang.Character self)
Increment a Character by one. |
|
static java.util.Date |
next(java.util.Date self)
Deprecated. moved to DateGroovyMethods.next(java.util.Date) |
|
static java.sql.Date |
next(java.sql.Date self)
Deprecated. moved to DateGroovyMethods.next(java.sql.Date) |
|
static java.lang.Number |
next(java.lang.Number self)
Increment a Number by one. |
|
static java.lang.String |
next(java.lang.String self)
This method is called by the ++ operator for the class String. |
|
static java.lang.String |
normalize(java.lang.String self)
Return a String with linefeeds and carriage returns normalized to linefeeds. |
|
static int |
numberAwareCompareTo(java.lang.Comparable self,
java.lang.Comparable other)
Provides a method that compares two comparables using Groovy's default number aware comparator. |
|
static java.util.BitSet |
or(java.util.BitSet left,
java.util.BitSet right)
Bitwise OR together two BitSets. |
|
static java.lang.Boolean |
or(java.lang.Boolean left,
java.lang.Boolean right)
Logical disjunction of two boolean operators |
|
static java.lang.Number |
or(java.lang.Number left,
java.lang.Number right)
Bitwise OR together two numbers. |
|
static java.lang.Process |
or(java.lang.Process left,
java.lang.Process right)
Overrides the or operator to allow one Process to asynchronously pipe data to another Process. |
|
static java.lang.String |
padLeft(java.lang.String self,
java.lang.Number numberOfChars)
Pad a String with the spaces appended to the left |
|
static java.lang.String |
padLeft(java.lang.String self,
java.lang.Number numberOfChars,
java.lang.String padding)
Pad a String with the characters appended to the left |
|
static java.lang.String |
padRight(java.lang.String self,
java.lang.Number numberOfChars)
Pad a String with the spaces appended to the right |
|
static java.lang.String |
padRight(java.lang.String self,
java.lang.Number numberOfChars,
java.lang.String padding)
Pad a String with the characters appended to the right |
|
static
|
permutations(java.util.List<T> self)
Finds all permutations of a collection. |
|
static java.lang.Process |
pipeTo(java.lang.Process left,
java.lang.Process right)
Allows one Process to asynchronously pipe data to another Process. |
|
static java.lang.Number |
plus(java.lang.Character left,
java.lang.Character right)
Add one Character to another. |
|
static java.lang.Number |
plus(java.lang.Character left,
java.lang.Number right)
Add a Character and a Number. |
|
static
|
plus(java.util.Collection<T> left,
java.util.Collection<T> right)
Create a Collection as a union of two collections. |
|
static
|
plus(java.util.Collection<T> left,
T right)
Create a collection as a union of a Collection and an Object. |
|
static java.util.Date |
plus(java.util.Date self,
int days)
Deprecated. moved to DateGroovyMethods.plus(java.util.Date, int) |
|
static java.sql.Date |
plus(java.sql.Date self,
int days)
Deprecated. moved to DateGroovyMethods.plus(java.sql.Date, int) |
|
static
|
plus(java.util.Map<K,V> self,
java.util.Collection<java.util.Map.Entry<K,V>> entries)
Returns a new Map containing all entries from self and entries ,
giving precedence to entries . |
|
static
|
plus(java.util.Map<K,V> left,
java.util.Map<K,V> right)
Returns a new Map containing all entries from left and right ,
giving precedence to right . |
|
static java.lang.Number |
plus(java.lang.Number left,
java.lang.Character right)
Add a Number and a Character. |
|
static java.lang.String |
plus(java.lang.Number value,
java.lang.String right)
Appends a String to the string representation of this number. |
|
static java.lang.String |
plus(java.lang.StringBuffer left,
java.lang.String value)
Appends a String to this StringBuffer. |
|
static java.lang.String |
plus(java.lang.String left,
java.lang.Object value)
Appends the String representation of the given operand to this string. |
|
static
|
pop(java.util.List<T> self)
Removes the last item from the List. |
|
static java.lang.Number |
power(java.lang.Number self,
java.lang.Number exponent)
Power of a Number to a certain exponent. |
|
static java.lang.Character |
previous(java.lang.Character self)
Decrement a Character by one. |
|
static java.util.Date |
previous(java.util.Date self)
Deprecated. moved to DateGroovyMethods.previous(java.util.Date) |
|
static java.sql.Date |
previous(java.sql.Date self)
Deprecated. moved to DateGroovyMethods.previous(java.sql.Date) |
|
static java.lang.Number |
previous(java.lang.Number self)
Decrement a Number by one. |
|
static java.lang.String |
previous(java.lang.String self)
This method is called by the -- operator for the class String. |
|
protected static java.util.List |
primitiveArrayGet(java.lang.Object self,
java.util.Collection indices)
Implements the getAt(Collection) method for primitve type arrays. |
|
protected static java.lang.Object |
primitiveArrayGet(java.lang.Object self,
int idx)
Implements the getAt(int) method for primitve type arrays. |
|
protected static java.util.List |
primitiveArrayGet(java.lang.Object self,
Range range)
Implements the getAt(Range) method for primitve type arrays. |
|
protected static java.lang.Object |
primitiveArrayPut(java.lang.Object self,
int idx,
java.lang.Object newValue)
Implements the setAt(int idx) method for primitve type arrays. |
|
static void |
print(Closure self,
java.lang.Object value)
Print a value to the standard output stream. |
|
static void |
print(java.lang.Object self,
java.lang.Object value)
Print a value formatted Groovy style to self if it is a Writer, otherwise to the standard output stream. |
|
static void |
print(java.lang.Object self,
java.io.PrintWriter out)
Print to a console in interactive format. |
|
static void |
print(java.io.PrintStream self,
java.lang.Object value)
Print a value formatted Groovy style to the print stream. |
|
static void |
print(java.io.PrintWriter self,
java.lang.Object value)
Print a value formatted Groovy style to the print writer. |
|
static void |
printf(java.lang.Object self,
java.lang.String format,
java.lang.Object arg)
Prints a formatted string using the specified format string and arguments. |
|
static void |
printf(java.lang.Object self,
java.lang.String format,
java.lang.Object[] values)
Printf to a console (Only works with JDK1.5 or later). |
|
static void |
println(Closure self)
Print a linebreak to the standard output stream. |
|
static void |
println(Closure self,
java.lang.Object value)
Print a value (followed by a newline) to the standard output stream. |
|
static void |
println(java.lang.Object self)
Print a linebreak to the standard output stream. |
|
static void |
println(java.lang.Object self,
java.lang.Object value)
Print a value formatted Groovy style (followed by a newline) to self if it is a Writer, otherwise to the standard output stream. |
|
static void |
println(java.lang.Object self,
java.io.PrintWriter out)
Print to a console in interactive format. |
|
static void |
println(java.io.PrintStream self,
java.lang.Object value)
Print a value formatted Groovy style (followed by a newline) to the print stream. |
|
static void |
println(java.io.PrintWriter self,
java.lang.Object value)
Print a value formatted Groovy style (followed by a newline) to the print writer. |
|
static
|
push(java.util.List<T> self,
T value)
Appends an item to the List. |
|
static
|
putAll(java.util.Map<K,V> self,
java.util.Collection<java.util.Map.Entry<K,V>> entries)
Provides an easy way to append multiple Map.Entry values to a Map. |
|
static void |
putAt(java.util.BitSet self,
int index,
boolean value)
Support subscript-style assignment for a BitSet. |
|
static void |
putAt(java.util.BitSet self,
IntRange range,
boolean value)
Support assigning a range of values with a single assignment statement. |
|
static
|
putAt(java.util.List<T> self,
int idx,
T value)
A helper method to allow lists to work with subscript operators. |
|
static void |
putAt(java.util.List self,
EmptyRange range,
java.util.Collection value)
A helper method to allow lists to work with subscript operators. |
|
static void |
putAt(java.util.List self,
EmptyRange range,
java.lang.Object value)
A helper method to allow lists to work with subscript operators. |
|
static void |
putAt(java.util.List self,
IntRange range,
java.util.Collection col)
List subscript assignment operator when given a range as the index and the assignment operand is a collection. |
|
static void |
putAt(java.util.List self,
IntRange range,
java.lang.Object value)
List subscript assignment operator when given a range as the index. |
|
static void |
putAt(java.util.List self,
java.util.List splice,
java.util.List values)
A helper method to allow lists to work with subscript operators. |
|
static void |
putAt(java.util.List self,
java.util.List splice,
java.lang.Object value)
A helper method to allow lists to work with subscript operators. |
|
static
|
putAt(java.util.Map<K,V> self,
K key,
V value)
A helper method to allow lists to work with subscript operators |
|
static void |
putAt(java.lang.Object self,
java.lang.String property,
java.lang.Object newValue)
Allows the subscript operator to be used to set dynamically named property values. |
|
static void |
putAt(java.lang.StringBuffer self,
EmptyRange range,
java.lang.Object value)
Support the range subscript operator for StringBuffer. |
|
static void |
putAt(java.lang.StringBuffer self,
IntRange range,
java.lang.Object value)
Support the range subscript operator for StringBuffer. |
|
static byte[] |
readBytes(java.io.File file)
Reads the content of the file into a byte array. |
|
static java.lang.String |
readLine(java.io.InputStream stream)
Deprecated. use Reader#readLine instead please |
|
static java.lang.String |
readLine(java.io.Reader self)
Read a single, whole line from the given Reader. |
|
static java.util.List<java.lang.String> |
readLines(java.io.File file)
Reads the file into a list of Strings, with one item for each line. |
|
static java.util.List<java.lang.String> |
readLines(java.io.File file,
java.lang.String charset)
Reads the file into a list of Strings, with one item for each line. |
|
static java.util.List<java.lang.String> |
readLines(java.io.InputStream stream)
Reads the stream into a list, with one element for each line. |
|
static java.util.List<java.lang.String> |
readLines(java.io.InputStream stream,
java.lang.String charset)
Reads the stream into a list, with one element for each line. |
|
static java.util.List<java.lang.String> |
readLines(java.io.Reader reader)
Reads the reader into a list of Strings, with one entry for each line. |
|
static java.util.List<java.lang.String> |
readLines(java.lang.String self)
Return the lines of a String as a List of Strings. |
|
static java.util.List<java.lang.String> |
readLines(java.net.URL self)
Reads the URL contents into a list, with one element for each line. |
|
static java.util.List<java.lang.String> |
readLines(java.net.URL self,
java.lang.String charset)
Reads the URL contents into a list, with one element for each line. |
|
static
|
removeAll(java.util.Collection<T> self,
T[] items)
Removes all of this collection's elements that are also contained in the specified array. |
|
static boolean |
removeAll(java.util.Collection self,
Closure closure)
Removes the elements in this collection that are matched according to the specified closure condition. |
|
static boolean |
renameTo(java.io.File self,
java.lang.String newPathName)
Renames the file. |
|
static java.lang.String |
replaceAll(java.lang.String self,
java.util.regex.Pattern pattern,
Closure closure)
Replaces all occurrences of a captured group by the result of a closure on that text. |
|
static java.lang.String |
replaceAll(java.lang.String self,
java.util.regex.Pattern pattern,
java.lang.String replacement)
Replaces all substrings of a String that match the given compiled regular expression with the given replacement. |
|
static java.lang.String |
replaceAll(java.lang.String self,
java.lang.String regex,
Closure closure)
Replaces all occurrences of a captured group by the result of a closure on that text. |
|
static java.lang.String |
replaceFirst(java.lang.String self,
java.util.regex.Pattern pattern,
java.lang.String replacement)
Replaces the first substring of a String that matches the given compiled regular expression with the given replacement. |
|
static java.util.List |
respondsTo(java.lang.Object self,
java.lang.String name)
Returns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name regardless of the arguments. |
|
static java.util.List |
respondsTo(java.lang.Object self,
java.lang.String name,
java.lang.Object[] argTypes)
Returns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name and arguments types. |
|
static
|
retainAll(java.util.Collection<T> self,
T[] items)
Retains only the elements in this collection that are contained in the specified array. |
|
static boolean |
retainAll(java.util.Collection self,
Closure closure)
Retains only the elements in this collection that are matched according to the specified closure condition. |
|
static
|
reverse(java.util.Iterator<T> self)
Reverses the iterator. |
|
static
|
reverse(java.util.List<T> self)
Reverses the list. |
|
static java.lang.String |
reverse(java.lang.String self)
Creates a new string which is the reverse (backwards) of this string |
|
static
|
reverse(T[] self)
Reverse the items in an Object array. |
|
static
|
reverseEach(java.util.List<T> self,
Closure closure)
Iterate over each element of the list in the reverse order. |
|
static
|
reverseEach(java.util.Map<K,V> self,
Closure closure)
Allows a Map to be iterated through in reverse order using a closure. |
|
static
|
reverseEach(T[] self,
Closure closure)
Iterate over each element of the array in the reverse order. |
|
static java.lang.Number |
rightShift(java.lang.Number self,
java.lang.Number operand)
Implementation of the right shift operator for integral types. |
|
static java.lang.Number |
rightShiftUnsigned(java.lang.Number self,
java.lang.Number operand)
Implementation of the right shift (unsigned) operator for integral types. |
|
static long |
round(java.lang.Double number)
Round the value |
|
static double |
round(java.lang.Double number,
int precision)
Round the value |
|
static int |
round(java.lang.Float number)
Round the value |
|
static float |
round(java.lang.Float number,
int precision)
Round the value |
|
static java.util.TimerTask |
runAfter(java.util.Timer timer,
int delay,
Closure closure)
Allows a simple syntax for using timers. |
|
static void |
setBytes(java.io.File file,
byte[] bytes)
Write the bytes from the byte array to the File. |
|
static void |
setBytes(java.io.OutputStream os,
byte[] bytes)
Write the byte[] to the output stream. |
|
static void |
setIndex(java.util.regex.Matcher matcher,
int idx)
Set the position of the given Matcher to the given index. |
|
static void |
setMetaClass(java.lang.Class self,
MetaClass metaClass)
Sets the metaclass for a given class. |
|
static void |
setMetaClass(java.lang.Object self,
MetaClass metaClass)
Set the metaclass for an object |
|
static void |
setText(java.io.File file,
java.lang.String text)
Synonym for write(text) allowing file.text = 'foo'. |
|
static void |
setText(java.io.File file,
java.lang.String text,
java.lang.String charset)
Synonym for write(text, charset) allowing: |
|
static int |
size(boolean[] array)
Allows arrays to behave similar to collections. |
|
static int |
size(byte[] array)
Allows arrays to behave similar to collections. |
|
static int |
size(char[] array)
Allows arrays to behave similar to collections. |
|
static int |
size(double[] array)
Allows arrays to behave similar to collections. |
|
static long |
size(java.io.File self)
Provide the standard Groovy size() method for File . |
|
static int |
size(float[] array)
Allows arrays to behave similar to collections. |
|
static int |
size(int[] array)
Allows arrays to behave similar to collections. |
|
static int |
size(java.util.Iterator self)
Provide the standard Groovy size() method for Iterator . |
|
static int |
size(long[] array)
Allows arrays to behave similar to collections. |
|
static long |
size(java.util.regex.Matcher self)
Provide the standard Groovy size() method for Matcher . |
|
static int |
size(java.lang.Object[] self)
Provide the standard Groovy size() method for an array. |
|
static int |
size(short[] array)
Allows arrays to behave similar to collections. |
|
static int |
size(java.lang.String text)
Provide the standard Groovy size() method for String . |
|
static int |
size(java.lang.StringBuffer buffer)
Provide the standard Groovy size() method for StringBuffer . |
|
static
|
sort(java.util.Collection<T> self)
Sorts the given collection into a sorted list. |
|
static
|
sort(java.util.Collection<T> self,
Closure closure)
Sorts this Collection using the closure to determine the correct ordering. |
|
static
|
sort(java.util.Collection<T> self,
java.util.Comparator<T> comparator)
Sorts the Collection using the given comparator. |
|
static
|
sort(java.util.Iterator<T> self)
Sorts the given iterator items into a sorted iterator. |
|
static
|
sort(java.util.Iterator<T> self,
Closure closure)
Sorts the given iterator items into a sorted iterator using the Closure to determine the correct ordering. |
|
static
|
sort(java.util.Iterator<T> self,
java.util.Comparator<T> comparator)
Sorts the given iterator items into a sorted iterator using the comparator. |
|
static
|
sort(java.util.Map<K,V> self)
Sorts the elements from the given map into a new ordered Map using the natural ordering of the keys to determine the ordering. |
|
static
|
sort(java.util.Map<K,V> self,
Closure closure)
Sorts the elements from the given map into a new ordered map using the closure as a comparator to determine the ordering. |
|
static
|
sort(java.util.Map<K,V> self,
java.util.Comparator<K> comparator)
Sorts the elements from the given map into a new ordered Map using the specified key comparator to determine the ordering. |
|
static
|
sort(java.util.SortedSet<T> self)
Avoids doing unnecessary work when sorting an already sorted set. |
|
static
|
sort(T[] self)
Sorts the given Object array into sorted order. |
|
static
|
sort(T[] self,
Closure closure)
Sorts the given Object array into a newly created array using the Closure to determine the correct ordering. |
|
static
|
sort(T[] self,
java.util.Comparator<T> comparator)
Sorts the given Object array into sorted order using the given comparator. |
|
static
|
split(java.util.Collection<T> self,
Closure closure)
Splits all items into two collections based on the closure condition. |
|
static java.lang.String[] |
split(GString self)
Convenience method to split a GString (with whitespace as delimiter). |
|
static java.util.Collection |
split(java.lang.Object self,
Closure closure)
Splits all items into two lists based on the closure condition. |
|
static java.lang.String[] |
split(java.lang.String self)
Convenience method to split a string (with whitespace as delimiter) Like tokenize, but returns an Array of Strings instead of a List |
|
static java.lang.Object |
splitEachLine(java.io.File self,
java.util.regex.Pattern pattern,
Closure closure)
Iterates through this file line by line, splitting each line using the given separator Pattern. |
|
static java.lang.Object |
splitEachLine(java.io.File self,
java.util.regex.Pattern pattern,
java.lang.String charset,
Closure closure)
Iterates through this file line by line, splitting each line using the given regex separator Pattern. |
|
static java.lang.Object |
splitEachLine(java.io.File self,
java.lang.String regex,
Closure closure)
Iterates through this file line by line, splitting each line using the given regex separator. |
|
static java.lang.Object |
splitEachLine(java.io.File self,
java.lang.String regex,
java.lang.String charset,
Closure closure)
Iterates through this file line by line, splitting each line using the given regex separator. |
|
static java.lang.Object |
splitEachLine(java.io.InputStream stream,
java.util.regex.Pattern pattern,
Closure closure)
Iterates through the given InputStream line by line, splitting each line using the given separator Pattern. |
|
static java.lang.Object |
splitEachLine(java.io.InputStream stream,
java.util.regex.Pattern pattern,
java.lang.String charset,
Closure closure)
Iterates through the given InputStream line by line using the specified encoding, splitting each line using the given separator Pattern. |
|
static java.lang.Object |
splitEachLine(java.io.InputStream stream,
java.lang.String regex,
Closure closure)
Iterates through the given InputStream line by line, splitting each line using the given separator. |
|
static java.lang.Object |
splitEachLine(java.io.InputStream stream,
java.lang.String regex,
java.lang.String charset,
Closure closure)
Iterates through the given InputStream line by line using the specified encoding, splitting each line using the given separator. |
|
static java.lang.Object |
splitEachLine(java.io.Reader self,
java.util.regex.Pattern pattern,
Closure closure)
Iterates through the given reader line by line, splitting each line using the given regex separator Pattern. |
|
static java.lang.Object |
splitEachLine(java.io.Reader self,
java.lang.String regex,
Closure closure)
Iterates through the given reader line by line, splitting each line using the given regex separator. |
|
static java.lang.Object |
splitEachLine(java.lang.String self,
java.util.regex.Pattern pattern,
Closure closure)
Iterates through the given String line by line, splitting each line using the given separator Pattern. |
|
static java.lang.Object |
splitEachLine(java.lang.String self,
java.lang.String regex,
Closure closure)
Iterates through the given String line by line, splitting each line using the given separator. |
|
static java.lang.Object |
splitEachLine(java.net.URL self,
java.util.regex.Pattern pattern,
Closure closure)
Iterates through the input stream associated with this URL line by line, splitting each line using the given regex separator Pattern. |
|
static java.lang.Object |
splitEachLine(java.net.URL self,
java.util.regex.Pattern pattern,
java.lang.String charset,
Closure closure)
Iterates through the input stream associated with this URL line by line, splitting each line using the given regex separator Pattern. |
|
static java.lang.Object |
splitEachLine(java.net.URL self,
java.lang.String regex,
Closure closure)
Iterates through the input stream associated with this URL line by line, splitting each line using the given regex separator. |
|
static java.lang.Object |
splitEachLine(java.net.URL self,
java.lang.String regex,
java.lang.String charset,
Closure closure)
Iterates through the input stream associated with this URL line by line, splitting each line using the given regex separator. |
|
static SpreadMap |
spread(java.util.Map self)
Synonym for toSpreadMap(java.util.Map) . |
|
static java.lang.String |
sprintf(java.lang.Object self,
java.lang.String format,
java.lang.Object arg)
Returns a formatted string using the specified format string and arguments. |
|
static java.lang.String |
sprintf(java.lang.Object self,
java.lang.String format,
java.lang.Object[] values)
Sprintf to a string (Only works with JDK1.5 or later). |
|
static void |
step(java.lang.Number self,
java.lang.Number to,
java.lang.Number stepNumber,
Closure closure)
Iterates from this number up to the given number using a step increment. |
|
static java.lang.String |
stripIndent(java.lang.String self)
Strip leading spaces from every line in a String. |
|
static java.lang.String |
stripIndent(java.lang.String self,
int numChars)
Strip numChar leading characters from every line in a String. |
|
static java.lang.String |
stripMargin(java.lang.String self)
Strip leading whitespace/control characters followed by '|' from every line in a String. |
|
static java.lang.String |
stripMargin(java.lang.String self,
char marginChar)
Strip leading whitespace/control characters followed by marginChar from every line in a String. |
|
static java.lang.String |
stripMargin(java.lang.String self,
java.lang.String marginChar)
Strip leading whitespace/control characters followed by marginChar from every line in a String. |
|
static
|
subMap(java.util.Map<K,V> map,
java.util.Collection<K> keys)
Creates a sub-Map containing the given keys. |
|
static
|
subsequences(java.util.List<T> self)
Finds all non-null subsequences of a list. |
|
static java.lang.Object |
sum(java.util.Collection self)
Sums the items in a collection. |
|
static java.lang.Object |
sum(java.util.Collection self,
Closure closure)
Sums the result of apply a closure to each item of a collection. |
|
static java.lang.Object |
sum(java.util.Collection self,
java.lang.Object initialValue)
Sums the items in a collection, adding the result to some initial value. |
|
static java.lang.Object |
sum(java.util.Collection self,
java.lang.Object initialValue,
Closure closure)
Sums the result of applying a closure to each item of a collection to some initial value. |
|
static java.lang.Object |
sum(java.util.Iterator<java.lang.Object> self)
Sums the items from an Iterator. |
|
static java.lang.Object |
sum(java.util.Iterator<java.lang.Object> self,
Closure closure)
Sums the result of apply a closure to each item returned from an iterator. |
|
static java.lang.Object |
sum(java.util.Iterator<java.lang.Object> self,
java.lang.Object initialValue)
Sums the items from an Iterator, adding the result to some initial value. |
|
static java.lang.Object |
sum(java.util.Iterator<java.lang.Object> self,
java.lang.Object initialValue,
Closure closure)
Sums the result of applying a closure to each item of an Iterator to some initial value. |
|
static java.lang.Object |
sum(java.lang.Object[] self)
Sums the items in an array. |
|
static java.lang.Object |
sum(java.lang.Object[] self,
Closure closure)
Sums the result of apply a closure to each item of an array. |
|
static java.lang.Object |
sum(java.lang.Object[] self,
java.lang.Object initialValue)
Sums the items in an array, adding the result to some initial value. |
|
static java.lang.Object |
sum(java.lang.Object[] self,
java.lang.Object initialValue,
Closure closure)
Sums the result of applying a closure to each item of an array to some initial value. |
|
static
|
tail(java.util.List<T> self)
Returns the items from the List excluding the first item. |
|
static
|
tail(T[] self)
Returns the items from the Object array excluding the first item. |
|
static void |
times(java.lang.Number self,
Closure closure)
Executes the closure this many times, starting from zero. |
|
static java.lang.String |
toArrayString(java.lang.Object[] self)
Returns the string representation of the given array. |
|
static java.math.BigDecimal |
toBigDecimal(java.lang.Number self)
Transform a Number into a BigDecimal |
|
static java.math.BigDecimal |
toBigDecimal(java.lang.String self)
Parse a String into a BigDecimal |
|
static java.math.BigInteger |
toBigInteger(java.lang.Number self)
Transform this Number into a BigInteger. |
|
static java.math.BigInteger |
toBigInteger(java.lang.String self)
Parse a String into a BigInteger |
|
static java.lang.Boolean |
toBoolean(java.lang.String self)
Converts the given string into a Boolean object. |
|
static java.lang.Character |
toCharacter(java.lang.String self)
Converts the given string into a Character object using the first character in the string. |
|
static java.lang.Double |
toDouble(java.lang.Number self)
Transform a Number into a Double |
|
static java.lang.Double |
toDouble(java.lang.String self)
Parse a String into a Double |
|
static java.lang.Float |
toFloat(java.lang.Number self)
Transform a Number into a Float |
|
static java.lang.Float |
toFloat(java.lang.String self)
Parse a String into a Float |
|
static java.lang.Integer |
toInteger(java.lang.Number self)
Transform a Number into an Integer |
|
static java.lang.Integer |
toInteger(java.lang.String self)
Parse a String into an Integer |
|
static java.util.List |
tokenize(java.lang.String self)
Tokenize a String (with a whitespace as the delimiter). |
|
static java.util.List |
tokenize(java.lang.String self,
java.lang.Character token)
Tokenize a String based on the given character delimiter. |
|
static java.util.List |
tokenize(java.lang.String self,
java.lang.String token)
Tokenize a String based on the given string delimiter. |
|
static java.util.List<java.lang.Boolean> |
toList(boolean[] array)
Converts this array to a List of the same size, with each element added to the list. |
|
static java.util.List<java.lang.Byte> |
toList(byte[] array)
Converts this array to a List of the same size, with each element added to the list. |
|
static java.util.List<java.lang.Character> |
toList(char[] array)
Converts this array to a List of the same size, with each element added to the list. |
|
static
|
toList(java.util.Collection<T> self)
Convert a Collection to a List. |
|
static java.util.List<java.lang.Double> |
toList(double[] array)
Converts this array to a List of the same size, with each element added to the list. |
|
static
|
toList(java.util.Enumeration<T> self)
Convert an enumeration to a List. |
|
static java.util.List<java.lang.Float> |
toList(float[] array)
Converts this array to a List of the same size, with each element added to the list. |
|
static java.util.List<java.lang.Integer> |
toList(int[] array)
Converts this array to a List of the same size, with each element added to the list. |
|
static
|
toList(java.util.Iterator<T> self)
Convert an iterator to a List. |
|
static java.util.List<java.lang.Long> |
toList(long[] array)
Converts this array to a List of the same size, with each element added to the list. |
|
static java.util.List<java.lang.Short> |
toList(short[] array)
Converts this array to a List of the same size, with each element added to the list. |
|
static java.util.List<java.lang.String> |
toList(java.lang.String self)
Converts the given String into a List of strings of one character. |
|
static
|
toList(T[] array)
Allows conversion of arrays into a mutable List. |
|
static java.lang.String |
toListString(java.util.Collection self)
Returns the string representation of the given list. |
|
static java.lang.String |
toListString(java.util.Collection self,
int maxSize)
Returns the string representation of the given list. |
|
static java.lang.Long |
toLong(java.lang.Number self)
Transform a Number into a Long |
|
static java.lang.Long |
toLong(java.lang.String self)
Parse a String into a Long |
|
static char |
toLowerCase(java.lang.Character self)
Converts the character to lowercase. |
|
static java.lang.String |
toMapString(java.util.Map self)
Returns the string representation of this map. |
|
static java.lang.String |
toMapString(java.util.Map self,
int maxSize)
Returns the string representation of this map. |
|
static GroovyRowResult |
toRowResult(java.sql.ResultSet rs)
Deprecated. moved to SqlGroovyMethods.toRowResult(java.sql.ResultSet) |
|
static java.lang.Short |
toShort(java.lang.String self)
Parse a String into a Short |
|
static SpreadMap |
toSpreadMap(java.util.Map self)
Returns a new SpreadMap from this map. |
|
static SpreadMap |
toSpreadMap(java.lang.Object[] self)
Creates a spreadable map from this array. |
|
static java.lang.String |
toString(java.util.AbstractCollection self)
Returns the string representation of the given collection. |
|
static java.lang.String |
toString(java.util.AbstractMap self)
Returns the string representation of the given map. |
|
static java.lang.String |
toString(boolean[] self)
Returns the string representation of the given array. |
|
static java.lang.String |
toString(byte[] self)
Returns the string representation of the given array. |
|
static java.lang.String |
toString(char[] self)
Returns the string representation of the given array. |
|
static java.lang.String |
toString(double[] self)
Returns the string representation of the given array. |
|
static java.lang.String |
toString(float[] self)
Returns the string representation of the given array. |
|
static java.lang.String |
toString(int[] self)
Returns the string representation of the given array. |
|
static java.lang.String |
toString(long[] self)
Returns the string representation of the given array. |
|
static java.lang.String |
toString(java.lang.Object value)
Create a String representation of this object. |
|
static java.lang.String |
toString(java.lang.Object[] self)
Returns the string representation of this array's contents. |
|
static java.lang.String |
toString(short[] self)
Returns the string representation of the given array. |
|
static char |
toUpperCase(java.lang.Character self)
Converts the character to uppercase. |
|
static java.net.URI |
toURI(java.lang.String self)
Transforms a String representing a URI into a URI object. |
|
static java.net.URL |
toURL(java.lang.String self)
Transforms a String representing a URL into a URL object. |
|
static java.lang.String |
tr(java.lang.String self,
java.lang.String sourceSet,
java.lang.String replacementSet)
Translates a string by replacing characters from the sourceSet with characters from replacementSet. |
|
static void |
transformChar(java.io.Reader self,
java.io.Writer writer,
Closure closure)
Transforms each character from this reader by passing it to the given closure. |
|
static void |
transformLine(java.io.Reader reader,
java.io.Writer writer,
Closure closure)
Transforms the lines from a reader with a Closure and write them to a writer. |
|
static java.util.List |
transpose(java.util.List self)
Adds GroovyCollections#transpose(List) as a method on lists. |
|
static void |
traverse(java.io.File self,
Closure closure)
Invokes the closure for each descendant file in this directory tree. |
|
static void |
traverse(java.io.File self,
java.util.Map<java.lang.String,java.lang.Object> options)
Invokes the closure specified with key 'visit' in the options Map for each descendant file in this directory tree. |
|
static void |
traverse(java.io.File self,
java.util.Map<java.lang.String,java.lang.Object> options,
Closure closure)
Invokes closure for each descendant file in this directory tree. |
|
static double |
trunc(java.lang.Double number)
Truncate the value |
|
static double |
trunc(java.lang.Double number,
int precision)
Truncate the value |
|
static float |
trunc(java.lang.Float number)
Truncate the value |
|
static float |
trunc(java.lang.Float number,
int precision)
Truncate the value |
|
static java.lang.Number |
unaryMinus(java.lang.Number left)
Negates the number. |
|
static java.lang.String |
unexpand(java.lang.String self)
Replaces sequences of whitespaces with tabs using tabStops of size 8. |
|
static java.lang.String |
unexpand(java.lang.String self,
int tabStop)
Replaces sequences of whitespaces with tabs. |
|
static java.lang.String |
unexpandLine(java.lang.String self,
int tabStop)
Replaces sequences of whitespaces with tabs within a line. |
|
static
|
unique(java.util.Collection<T> self)
Modifies this collection to remove all duplicated items, using the default comparator. |
|
static
|
unique(java.util.Collection<T> self,
Closure closure)
A convenience method for making a collection unique using a Closure to determine duplicate (equal) items. |
|
static
|
unique(java.util.Collection<T> self,
java.util.Comparator<T> comparator)
Remove all duplicates from a given Collection. |
|
static
|
unique(java.util.Iterator<T> self)
Returns an iterator equivalent to this iterator all duplicated items removed by using the default comparator. |
|
static
|
unique(java.util.Iterator<T> self,
Closure closure)
Returns an iterator equivalent to this iterator but with all duplicated items removed by using a Closure to determine duplicate (equal) items. |
|
static
|
unique(java.util.Iterator<T> self,
java.util.Comparator<T> comparator)
Returns an iterator equivalent to this iterator with all duplicated items removed by using the supplied comparator. |
|
static void |
upto(java.math.BigDecimal self,
java.lang.Number to,
Closure closure)
Iterates from this number up to the given number, inclusive, incrementing by one each time. |
|
static void |
upto(java.math.BigInteger self,
java.lang.Number to,
Closure closure)
Iterates from this number up to the given number, inclusive, incrementing by one each time. |
|
static void |
upto(double self,
java.lang.Number to,
Closure closure)
Iterates from this number up to the given number, inclusive, incrementing by one each time. |
|
static void |
upto(java.lang.Double self,
java.lang.Number to,
Closure closure)
Iterates from this number up to the given number, inclusive, incrementing by one each time. |
|
static void |
upto(float self,
java.lang.Number to,
Closure closure)
Iterates from this number up to the given number, inclusive, incrementing by one each time. |
|
static void |
upto(java.lang.Float self,
java.lang.Number to,
Closure closure)
Iterates from this number up to the given number, inclusive, incrementing by one each time. |
|
static void |
upto(long self,
java.lang.Number to,
Closure closure)
Iterates from this number up to the given number, inclusive, incrementing by one each time. |
|
static void |
upto(java.lang.Long self,
java.lang.Number to,
Closure closure)
Iterates from this number up to the given number, inclusive, incrementing by one each time. |
|
static void |
upto(java.lang.Number self,
java.lang.Number to,
Closure closure)
Iterates from this number up to the given number, inclusive, incrementing by one each time. |
|
static java.lang.Object |
use(java.lang.Object self,
java.lang.Class categoryClass,
Closure closure)
Scoped use method |
|
static java.lang.Object |
use(java.lang.Object self,
java.util.List<java.lang.Class> categoryClassList,
Closure closure)
Scoped use method with list of categories. |
|
static java.lang.Object |
use(java.lang.Object self,
java.lang.Object[] array)
Allows you to use a list of categories, specifying the list as varargs. |
|
static void |
waitForOrKill(java.lang.Process self,
long numberOfMillis)
Wait for the process to finish during a certain amount of time, otherwise stops the process. |
|
static void |
waitForProcessOutput(java.lang.Process self)
Gets the output and error streams from a process and reads them to keep the process from blocking due to a full output buffer. |
|
static void |
waitForProcessOutput(java.lang.Process self,
java.io.OutputStream output,
java.io.OutputStream error)
Gets the output and error streams from a process and reads them to keep the process from blocking due to a full output buffer. |
|
static void |
waitForProcessOutput(java.lang.Process self,
java.lang.StringBuffer output,
java.lang.StringBuffer error)
Gets the output and error streams from a process and reads them to keep the process from blocking due to a full output buffer. |
|
static java.lang.Object |
with(java.lang.Object self,
Closure closure)
Allows the closure to be called for the object reference self |
|
static java.lang.Object |
withDataInputStream(java.io.File file,
Closure closure)
Create a new DataInputStream for this file and passes it into the closure. |
|
static java.lang.Object |
withDataOutputStream(java.io.File file,
Closure closure)
Create a new DataOutputStream for this file and passes it into the closure. |
|
static
|
withDefault(java.util.Map<K,V> self,
Closure init)
Wraps a map using the delegate pattern with a wrapper that intercepts all calls to get(key) . |
|
static java.lang.Object |
withInputStream(java.io.File file,
Closure closure)
Create a new InputStream for this file and passes it into the closure. |
|
static java.lang.Object |
withInputStream(java.net.URL url,
Closure closure)
Creates a new InputStream for this URL and passes it into the closure. |
|
static java.lang.Object |
withObjectInputStream(java.io.File file,
java.lang.ClassLoader classLoader,
Closure closure)
Create a new ObjectInputStream for this file associated with the given class loader and pass it to the closure. |
|
static java.lang.Object |
withObjectInputStream(java.io.File file,
Closure closure)
Create a new ObjectInputStream for this file and pass it to the closure. |
|
static java.lang.Object |
withObjectInputStream(java.io.InputStream inputStream,
java.lang.ClassLoader classLoader,
Closure closure)
Create a new ObjectInputStream for this file and pass it to the closure. |
|
static java.lang.Object |
withObjectInputStream(java.io.InputStream inputStream,
Closure closure)
Create a new ObjectInputStream for this file and pass it to the closure. |
|
static java.lang.Object |
withObjectOutputStream(java.io.File file,
Closure closure)
Create a new ObjectOutputStream for this file and then pass it to the closure. |
|
static java.lang.Object |
withObjectOutputStream(java.io.OutputStream outputStream,
Closure closure)
Create a new ObjectOutputStream for this output stream and then pass it to the closure. |
|
static java.lang.Object |
withObjectStreams(java.net.Socket socket,
Closure closure)
Creates an InputObjectStream and an OutputObjectStream from a Socket, and passes them to the closure. |
|
static java.lang.Object |
withOutputStream(java.io.File file,
Closure closure)
Creates a new OutputStream for this file and passes it into the closure. |
|
static void |
withOutputStream(java.lang.Process self,
Closure closure)
Creates a new buffered OutputStream as stdin for this process, passes it to the closure, and ensures the stream is flushed and closed after the closure returns. |
|
static java.lang.Object |
withPrintWriter(java.io.File file,
Closure closure)
Create a new PrintWriter for this file which is then passed it into the given closure. |
|
static java.lang.Object |
withPrintWriter(java.io.File file,
java.lang.String charset,
Closure closure)
Create a new PrintWriter with a specified charset for this file. |
|
static java.lang.Object |
withPrintWriter(java.io.Writer writer,
Closure closure)
Create a new PrintWriter with a specified charset for this file. |
|
static java.lang.Object |
withReader(java.io.File file,
Closure closure)
Create a new BufferedReader for this file and then passes it into the closure, ensuring the reader is closed after the closure returns. |
|
static java.lang.Object |
withReader(java.io.File file,
java.lang.String charset,
Closure closure)
Create a new BufferedReader for this file using the specified charset and then passes it into the closure, ensuring the reader is closed after the closure returns. |
|
static java.lang.Object |
withReader(java.io.InputStream in,
Closure closure)
Helper method to create a new Reader for a stream and then passes it into the closure. |
|
static java.lang.Object |
withReader(java.io.InputStream in,
java.lang.String charset,
Closure closure)
Helper method to create a new Reader for a stream and then passes it into the closure. |
|
static java.lang.Object |
withReader(java.io.Reader reader,
Closure closure)
Allows this reader to be used within the closure, ensuring that it is closed before this method returns. |
|
static java.lang.Object |
withReader(java.net.URL url,
Closure closure)
Helper method to create a new BufferedReader for a URL and then passes it to the closure. |
|
static java.lang.Object |
withReader(java.net.URL url,
java.lang.String charset,
Closure closure)
Helper method to create a new Reader for a URL and then passes it to the closure. |
|
static java.lang.Object |
withStream(java.io.InputStream stream,
Closure closure)
Allows this input stream to be used within the closure, ensuring that it is flushed and closed before this method returns. |
|
static java.lang.Object |
withStream(java.io.OutputStream os,
Closure closure)
Passes this OutputStream to the closure, ensuring that the stream is closed after the closure returns, regardless of errors. |
|
static java.lang.Object |
withStreams(java.net.Socket socket,
Closure closure)
Passes the Socket's InputStream and OutputStream to the closure. |
|
static java.lang.Object |
withWriter(java.io.File file,
Closure closure)
Creates a new BufferedWriter for this file, passes it to the closure, and ensures the stream is flushed and closed after the closure returns. |
|
static java.lang.Object |
withWriter(java.io.File file,
java.lang.String charset,
Closure closure)
Creates a new BufferedWriter for this file, passes it to the closure, and ensures the stream is flushed and closed after the closure returns. |
|
static java.lang.Object |
withWriter(java.io.OutputStream stream,
Closure closure)
Creates a writer from this stream, passing it to the given closure. |
|
static java.lang.Object |
withWriter(java.io.OutputStream stream,
java.lang.String charset,
Closure closure)
Creates a writer from this stream, passing it to the given closure. |
|
static void |
withWriter(java.lang.Process self,
Closure closure)
Creates a new BufferedWriter as stdin for this process, passes it to the closure, and ensures the stream is flushed and closed after the closure returns. |
|
static java.lang.Object |
withWriter(java.io.Writer writer,
Closure closure)
Allows this writer to be used within the closure, ensuring that it is flushed and closed before this method returns. |
|
static java.lang.Object |
withWriterAppend(java.io.File file,
Closure closure)
Create a new BufferedWriter for this file in append mode. |
|
static java.lang.Object |
withWriterAppend(java.io.File file,
java.lang.String charset,
Closure closure)
Create a new BufferedWriter which will append to this file. |
|
static void |
write(java.io.File file,
java.lang.String text)
Write the text to the File. |
|
static void |
write(java.io.File file,
java.lang.String text,
java.lang.String charset)
Write the text to the File, using the specified encoding. |
|
static void |
write(java.io.Writer self,
Writable writable)
A helper method so that dynamic dispatch of the writer.write(object) method will always use the more efficient Writable.writeTo(writer) mechanism if the object implements the Writable interface. |
|
static void |
writeLine(java.io.BufferedWriter writer,
java.lang.String line)
Write the text and append a newline (using the platform's line-ending). |
|
static java.util.BitSet |
xor(java.util.BitSet left,
java.util.BitSet right)
Bitwise XOR together two BitSets. |
|
static java.lang.Boolean |
xor(java.lang.Boolean left,
java.lang.Boolean right)
Exclusive disjunction of two boolean operators |
|
static java.lang.Number |
xor(java.lang.Number left,
java.lang.Number right)
Bitwise XOR together two Numbers. |
Methods inherited from class org.codehaus.groovy.runtime.DefaultGroovyMethodsSupport |
---|
cloneSimilarCollection, cloneSimilarMap, closeQuietly, closeWithWarning, createSimilarCollection, createSimilarCollection, createSimilarList, createSimilarMap, createSimilarOrDefaultCollection, createSimilarSet, normaliseIndex, sameType, subListBorders, subListBorders |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.Class[] additionals
Constructor Detail |
---|
public DefaultGroovyMethods()
Method Detail |
---|
public static boolean is(java.lang.Object self, java.lang.Object other)
def same = this.is(that)
self
- an objectother
- an object to compare identity with
public static java.lang.Object identity(java.lang.Object self, Closure closure)
self
- the object to have a closure act uponclosure
- the closure to call on the object
public static java.lang.Object with(java.lang.Object self, Closure closure)
self
- the object to have a closure act uponclosure
- the closure to call on the object
public static java.lang.Object getAt(java.lang.Object self, java.lang.String property)
bean[somePropertyNameExpression]
. The normal property notation
of groovy is neater and more concise but only works with compile-time known
property names.
self
- the object to act uponproperty
- the property name of interest
public static void putAt(java.lang.Object self, java.lang.String property, java.lang.Object newValue)
bean[somePropertyNameExpression] = foo
. The normal property notation
of groovy is neater and more concise but only works with property names which
are known at compile time.
self
- the object to act uponproperty
- the name of the property to setnewValue
- the value to setpublic static java.lang.String dump(java.lang.Object self)
self
- an object
public static java.util.List<PropertyValue> getMetaPropertyValues(java.lang.Object self)
MetaProperty
objects for 'self' and wraps it
in a list of PropertyValue
objects that additionally provide
the value for each property of 'self'.
self
- the receiver object
PropertyValue
objectsExpando.getMetaPropertyValues()
public static java.util.Map getProperties(java.lang.Object self)
getMetaPropertyValues(java.lang.Object)
(self)
and provides the data in form of simple key/value pairs, i.e.&nsbp;without
type() information.
self
- the receiver object
public static java.lang.Object use(java.lang.Object self, java.lang.Class categoryClass, Closure closure)
self
- any ObjectcategoryClass
- a category class to useclosure
- the closure to invoke with the category in place
public static void mixin(MetaClass self, java.util.List<java.lang.Class> categoryClasses)
self
- any ClasscategoryClasses
- a category classes to usepublic static void mixin(java.lang.Class self, java.util.List<java.lang.Class> categoryClasses)
self
- any ClasscategoryClasses
- a category classes to usepublic static void mixin(java.lang.Class self, java.lang.Class categoryClass)
self
- any ClasscategoryClass
- a category class to usepublic static void mixin(java.lang.Class self, java.lang.Class[] categoryClass)
self
- any ClasscategoryClass
- a category class to usepublic static void mixin(MetaClass self, java.lang.Class categoryClass)
self
- any ClasscategoryClass
- a category class to usepublic static void mixin(MetaClass self, java.lang.Class[] categoryClass)
self
- any ClasscategoryClass
- a category class to usepublic static java.lang.Object use(java.lang.Object self, java.util.List<java.lang.Class> categoryClassList, Closure closure)
self
- any ObjectcategoryClassList
- a list of category classesclosure
- the closure to invoke with the categories in place
public static void addShutdownHook(java.lang.Object self, Closure closure)
self
- the object the method is called on (ignored)closure
- the shutdown hook actionpublic static java.lang.Object use(java.lang.Object self, java.lang.Object[] array)
use(CategoryClass1, CategoryClass2) { ... }
This method saves having to wrap the the category
classes in a list.
self
- any Objectarray
- a list of category classes and a Closure
public static void print(java.lang.Object self, java.lang.Object value)
self
- any Objectvalue
- the value to printpublic static void print(java.io.PrintWriter self, java.lang.Object value)
self
- a PrintWritervalue
- the value to printpublic static void print(java.io.PrintStream self, java.lang.Object value)
self
- a PrintStreamvalue
- the value to printpublic static void print(Closure self, java.lang.Object value)
self
- a generated closurevalue
- the value to printpublic static void println(java.lang.Object self)
self
- any Objectpublic static void println(Closure self)
self
- a closurepublic static void println(java.lang.Object self, java.lang.Object value)
self
- any Objectvalue
- the value to printpublic static void println(java.io.PrintWriter self, java.lang.Object value)
self
- a PrintWritervalue
- the value to printpublic static void println(java.io.PrintStream self, java.lang.Object value)
self
- any Objectvalue
- the value to printpublic static void println(Closure self, java.lang.Object value)
self
- a closurevalue
- the value to printpublic static void printf(java.lang.Object self, java.lang.String format, java.lang.Object[] values)
self
- any Objectformat
- a format stringvalues
- values referenced by the format specifiers in the format string.public static java.lang.String sprintf(java.lang.Object self, java.lang.String format, java.lang.Object[] values)
self
- any Objectformat
- a format stringvalues
- values referenced by the format specifiers in the format string.
public static void printf(java.lang.Object self, java.lang.String format, java.lang.Object arg)
printf ( "Hello, %s!\n" , [ "world" ] as String[] ) printf ( "Hello, %s!\n" , [ "Groovy" ]) printf ( "%d + %d = %d\n" , [ 1 , 2 , 1+2 ] as Integer[] ) printf ( "%d + %d = %d\n" , [ 3 , 3 , 3+3 ]) ( 1..5 ).each { printf ( "-- %d\n" , [ it ] as Integer[] ) } ( 1..5 ).each { printf ( "-- %d\n" , [ it ] as int[] ) } ( 0x41..0x45 ).each { printf ( "-- %c\n" , [ it ] as char[] ) } ( 07..011 ).each { printf ( "-- %d\n" , [ it ] as byte[] ) } ( 7..11 ).each { printf ( "-- %d\n" , [ it ] as short[] ) } ( 7..11 ).each { printf ( "-- %d\n" , [ it ] as long[] ) } ( 7..11 ).each { printf ( "-- %5.2f\n" , [ it ] as float[] ) } ( 7..11 ).each { printf ( "-- %5.2g\n" , [ it ] as double[] ) }
self
- any Objectformat
- A format stringarg
- Argument which is referenced by the format specifiers in the format
string. The type of arg
should be one of Object[], List,
int[], short[], byte[], char[], boolean[], long[], float[], or double[].public static java.lang.String sprintf(java.lang.Object self, java.lang.String format, java.lang.Object arg)
self
- any Objectformat
- A format stringarg
- Argument which is referenced by the format specifiers in the format
string. The type of arg
should be one of Object[], List,
int[], short[], byte[], char[], boolean[], long[], float[], or double[].
public static java.lang.String inspect(java.lang.Object self)
self
- any Object
public static void print(java.lang.Object self, java.io.PrintWriter out)
self
- any Objectout
- the PrintWriter used for printingpublic static void println(java.lang.Object self, java.io.PrintWriter out)
self
- any Objectout
- the PrintWriter used for printingpublic static java.lang.Object invokeMethod(java.lang.Object object, java.lang.String method, java.lang.Object arguments)
object
- any Objectmethod
- the name of the method to callarguments
- the arguments to use
public static boolean isCase(java.lang.Object caseValue, java.lang.Object switchValue)
switch( a ) { case b: //some code }"some code" is called when
b.isCase( a )
returns
true
.
caseValue
- the case valueswitchValue
- the switch value
public static boolean isCase(java.lang.String caseValue, java.lang.Object switchValue)
switch( str ) { case 'one' : // etc... }Note that this returns
true
for the case where both the
'switch' and 'case' operand is null
.
caseValue
- the case valueswitchValue
- the switch value
public static boolean isCase(GString caseValue, java.lang.Object switchValue)
caseValue
- the case valueswitchValue
- the switch value
public static boolean isCase(java.lang.Class caseValue, java.lang.Object switchValue)
switch( obj ) { case List : // obj is a list break; case Set : // etc }
caseValue
- the case valueswitchValue
- the switch value
public static boolean isCase(java.util.Collection caseValue, java.lang.Object switchValue)
switch( 3 ) { case [1,3,5]: assert true break default: assert false }
caseValue
- the case valueswitchValue
- the switch value
Collection.contains(java.lang.Object)
public static boolean isCase(java.util.regex.Pattern caseValue, java.lang.Object switchValue)
Pattern
class, which allows
testing a String against a number of regular expressions.
For example:
switch( str ) { case ~/one/ : // the regex 'one' matches the value of str }Note that this returns true for the case where both the pattern and the 'switch' values are
null
.
caseValue
- the case valueswitchValue
- the switch value
public static boolean isCase(java.lang.Number caseValue, java.lang.Number switchValue)
compareTo()
method for comparing numbers of different
types.
caseValue
- the case valueswitchValue
- the switch value
public static <T> java.util.Iterator<T> unique(java.util.Iterator<T> self)
self
- an Iterator
public static <T> java.util.Collection<T> unique(java.util.Collection<T> self)
assert [1,3] == [1,3,3].unique()
self
- a collection
public static int numberAwareCompareTo(java.lang.Comparable self, java.lang.Comparable other)
self
- a Comparableother
- another Comparable
public static <T> java.util.Iterator<T> unique(java.util.Iterator<T> self, Closure closure)
Comparable.compareTo(java.lang.Object)
or Object.equals(java.lang.Object)
).
If the closure takes two parameters, two items from the Iterator
will be passed as arguments, and the closure should return an
int value (with 0 indicating the items are not unique).
self
- an Iteratorclosure
- a Closure used to determine unique items
public static <T> java.util.Collection<T> unique(java.util.Collection<T> self, Closure closure)
Comparable.compareTo(java.lang.Object)
or Object.equals(java.lang.Object)
).
If the closure takes two parameters, two items from the collection
will be passed as arguments, and the closure should return an
int value (with 0 indicating the items are not unique).
assert [1,4] == [1,3,4,5].unique { it % 2 }
assert [2,3,4] == [2,3,3,4].unique { a, b -> a <=> b }
self
- a Collectionclosure
- a 1 or 2 arg Closure used to determine unique items
public static <T> java.util.Iterator<T> unique(java.util.Iterator<T> self, java.util.Comparator<T> comparator)
self
- an Iteratorcomparator
- a Comparator
public static <T> java.util.Collection<T> unique(java.util.Collection<T> self, java.util.Comparator<T> comparator)
class Person {
def fname, lname
public String toString() {
return fname + " " + lname
}
}
class PersonComparator implements Comparator {
public int compare(Object o1, Object o2) {
Person p1 = (Person) o1
Person p2 = (Person) o2
if (p1.lname != p2.lname)
return p1.lname.compareTo(p2.lname)
else
return p1.fname.compareTo(p2.fname)
}
public boolean equals(Object obj) {
return this.equals(obj)
}
}
Person a = new Person(fname:"John", lname:"Taylor")
Person b = new Person(fname:"Clark", lname:"Taylor")
Person c = new Person(fname:"Tom", lname:"Cruz")
Person d = new Person(fname:"Clark", lname:"Taylor")
def list = [a, b, c, d]
List list2 = list.unique(new PersonComparator())
assert( list2 == list && list == [a, b, c] )
self
- a Collectioncomparator
- a Comparator
public static <T> T each(T self, Closure closure)
self
- the object over which we iterateclosure
- the closure applied on each element found
public static java.lang.Object eachWithIndex(java.lang.Object self, Closure closure)
self
- an Objectclosure
- a Closure to operate on each item
public static <K,V> java.util.Map<K,V> each(java.util.Map<K,V> self, Closure closure)
def result = "" [a:1, b:3].each { key, value -> result += "$key$value" } assert result == "a1b3"
def result = "" [a:1, b:3].each { entry -> result += entry } assert result == "a=1b=3"In general, the order in which the map contents are processed cannot be guaranteed. In practise, specialized forms of Map, e.g. a TreeMap will have its contents processed according to the natural ordering of the map.
self
- the map over which we iterateclosure
- the 1 or 2 arg closure applied on each entry of the map
public static <K,V> java.util.Map<K,V> reverseEach(java.util.Map<K,V> self, Closure closure)
self
- the map over which we iterateclosure
- the 1 or 2 arg closure applied on each entry of the map
each(Map, Closure)
public static <K,V> java.util.Map<K,V> eachWithIndex(java.util.Map<K,V> self, Closure closure)
def result = "" [a:1, b:3].eachWithIndex { key, value, index -> result += "$index($key$value)" } assert result == "0(a1)1(b3)"
def result = "" [a:1, b:3].eachWithIndex { entry, index -> result += "$index($entry)" } assert result == "0(a=1)1(b=3)"
self
- the map over which we iterateclosure
- a 2 or 3 arg Closure to operate on each item
public static <T> java.util.List<T> reverseEach(java.util.List<T> self, Closure closure)
def result = [] [1,2,3].reverseEach { result << it } assert result == [3,2,1]
self
- a Listclosure
- a closure to which each item is passed.
public static <T> T[] reverseEach(T[] self, Closure closure)
self
- an Object arrayclosure
- a closure to which each item is passed
public static <T> T[] reverse(T[] self)
self
- an Object array
public static boolean every(java.lang.Object self, Closure closure)
true
for all items in this data structure).
A simple example for a list:
def list = [3,4,5] def greaterThanTwo = list.every { it > 2 }
self
- the object over which we iterateclosure
- the closure predicate used for matching
public static <K,V> boolean every(java.util.Map<K,V> self, Closure closure)
def map = [a:1, b:2.0, c:2L] assert !map.every { key, value -> value instanceof Integer } assert map.every { entry -> entry.value instanceof Number }
self
- the map over which we iterateclosure
- the 1 or 2 arg Closure predicate used for matching
public static boolean every(java.lang.Object self)
true
according to the Groovy Truth.
Equivalent to self.every({element -> element})
self
- the object over which we iterate
public static boolean any(java.lang.Object self, Closure closure)
self
- the object over which we iterateclosure
- the closure predicate used for matching
public static <K,V> boolean any(java.util.Map<K,V> self, Closure closure)
assert [2:3, 4:5, 5:10].any { key, value -> key * 2 == value } assert ![2:3, 4:5, 5:10].any { entry -> entry.key == entry.value * 2 }
self
- the map over which we iterateclosure
- the 1 or 2 arg closure predicate used for matching
public static boolean any(java.lang.Object self)
self
- the object over which we iterate
public static java.util.Collection grep(java.lang.Object self, java.lang.Object filter)
isCase(java.lang.Object, java.lang.Object)
method used by switch statements. This method can be used with different
kinds of filters like regular expressions, classes, ranges etc.
Example:
def list = ['a', 'b', 'aa', 'bc' ] def filtered = list.grep( ~/a+/ ) //contains 'a' and 'aa'
self
- the object over which we iteratefilter
- the filter to perform on the object (using the isCase(java.lang.Object, java.lang.Object)
method)
public static java.lang.Number count(java.util.Iterator self, java.lang.Object value)
compareTo(value) == 0
or equals(value)
).
The iterator will become exhausted of elements after determining the count value.
self
- the Iterator from which we count the number of matching occurrencesvalue
- the value being searched for
public static java.lang.Number count(java.util.Collection self, java.lang.Object value)
compareTo(value) == 0
or equals(value)
).
assert [2,4,2,1,3,5,2,4,3].count(4) == 2
self
- the collection within which we count the number of occurrencesvalue
- the value being searched for
public static java.lang.Number count(java.lang.Object[] self, java.lang.Object value)
compareTo(value) == 0
or equals(value)
).
self
- the array within which we count the number of occurrencesvalue
- the value being searched for
public static java.lang.Number count(int[] self, java.lang.Object value)
compareTo(value) == 0
or equals(value)
).
self
- the array within which we count the number of occurrencesvalue
- the value being searched for
public static java.lang.Number count(long[] self, java.lang.Object value)
compareTo(value) == 0
or equals(value)
).
self
- the array within which we count the number of occurrencesvalue
- the value being searched for
public static java.lang.Number count(short[] self, java.lang.Object value)
compareTo(value) == 0
or equals(value)
).
self
- the array within which we count the number of occurrencesvalue
- the value being searched for
public static java.lang.Number count(char[] self, java.lang.Object value)
compareTo(value) == 0
or equals(value)
).
self
- the array within which we count the number of occurrencesvalue
- the value being searched for
public static java.lang.Number count(boolean[] self, java.lang.Object value)
compareTo(value) == 0
or equals(value)
).
self
- the array within which we count the number of occurrencesvalue
- the value being searched for
public static java.lang.Number count(double[] self, java.lang.Object value)
compareTo(value) == 0
or equals(value)
).
self
- the array within which we count the number of occurrencesvalue
- the value being searched for
public static java.lang.Number count(float[] self, java.lang.Object value)
compareTo(value) == 0
or equals(value)
).
self
- the array within which we count the number of occurrencesvalue
- the value being searched for
public static java.lang.Number count(byte[] self, java.lang.Object value)
compareTo(value) == 0
or equals(value)
).
self
- the array within which we count the number of occurrencesvalue
- the value being searched for
public static <T> java.util.List<T> toList(java.util.Collection<T> self)
Example usage:
def x = [1,2,3] as HashSet assert x.class == HashSet assert x.toList() instanceof List
self
- a collection
public static <T> java.util.List<T> toList(java.util.Iterator<T> self)
self
- an iterator
public static <T> java.util.List<T> toList(java.util.Enumeration<T> self)
self
- an enumeration
public static java.util.List collect(java.lang.Object self, Closure closure)
def list = [1, 'a', 1.23, true ] def types = list.collect { it.class } assert types == [Integer, String, BigDecimal, Boolean]
self
- the values of the object to transformclosure
- the closure used to transform each element of the collection
public static java.util.Collection collect(java.lang.Object self, java.util.Collection collection, Closure closure)
self
- the values of the object to transformcollection
- the Collection to which the transformed values are addedclosure
- the closure used to map each element of the collection
public static java.util.List collect(java.util.Collection self, Closure closure)
assert [2,4,6] == [1,2,3].collect { it * 2 }
self
- a collectionclosure
- the closure used for mapping
public static java.util.Collection collect(java.util.Collection self, java.util.Collection collection, Closure closure)
assert [1,2,3] as HashSet == [2,4,5,6].collect(new HashSet()) { (int)(it / 2) }
self
- a collectioncollection
- an initial Collection to which the transformed values are addedclosure
- the closure used to transform each element of the collection
public static java.util.List collectAll(java.util.Collection self, Closure closure)
assert [2,[4,6],[8],[]] == [1,[2,3],[4],[]].collectAll { it * 2 }
self
- a collectionclosure
- the closure used to transform each element of the collection
public static java.util.Collection collectAll(java.util.Collection self, java.util.Collection collection, Closure closure)
def x = [1,[2,3],[4],[]].collectAll(new Vector()) { it * 2 } assert x == [2,[4,6],[8],[]] assert x instanceof Vector
self
- a collectioncollection
- an initial Collection to which the transformed values are addedclosure
- the closure used to transform each element of the collection
public static java.util.Collection collect(java.util.Map self, java.util.Collection collection, Closure closure)
assert [a:1, b:2].collect( [] as HashSet ) { key, value -> key*value } == ["a", "bb"] as Set assert [3:20, 2:30].collect( [] as HashSet ) { entry -> entry.key * entry.value } == [60] as Set
self
- a Mapcollection
- the Collection to which the mapped values are addedclosure
- the closure used for mapping, which can take one (Map.Entry) or two (key, value) parameters
public static java.util.List collect(java.util.Map self, Closure closure)
assert [a:1, b:2].collect { key, value -> key*value } == ["a", "bb"] assert [3:20, 2:30].collect { entry -> entry.key * entry.value } == [60, 60]
self
- a Mapclosure
- the closure used to map each element of the collection
public static java.lang.Object find(java.lang.Object self, Closure closure)
self
- an Object with an iterator returning its valuesclosure
- a closure condition
public static <T> T find(java.util.Collection<T> self, Closure closure)
def list = [1,2,3] assert 2 == list.find { it > 1 }
self
- a Collectionclosure
- a closure condition
public static <K,V> java.util.Map.Entry<K,V> find(java.util.Map<K,V> self, Closure closure)
assert [a:1, b:3].find { it.value == 3 }.key == "b"
self
- a Mapclosure
- a 1 or 2 arg Closure condition
public static <T> java.util.Collection<T> findAll(java.util.Collection<T> self, Closure closure)
assert [2,4] == [1,2,3,4].findAll { it % 2 == 0 }
self
- a Collectionclosure
- a closure condition
public static java.util.Collection findAll(java.lang.Object self, Closure closure)
self
- an Object with an Iterator returning its valuesclosure
- a closure condition
public static boolean containsAll(java.util.Collection self, java.lang.Object[] items)
items
- array to be checked for containment in this collection
Collection.containsAll(Collection)
public static <T> boolean removeAll(java.util.Collection<T> self, T[] items)
items
- array containing elements to be removed from this collection
Collection.removeAll(Collection)
public static <T> boolean retainAll(java.util.Collection<T> self, T[] items)
items
- array containing elements to be retained from this collection
Collection.retainAll(Collection)
public static boolean retainAll(java.util.Collection self, Closure closure)
self
- a Collection to be modifiedclosure
- a closure condition
Iterator.remove()
public static boolean removeAll(java.util.Collection self, Closure closure)
self
- a Collection to be modifiedclosure
- a closure condition
Iterator.remove()
public static <T> boolean addAll(java.util.Collection<T> self, T[] items)
items
- array containing elements to be added to this collection
Collection.addAll(Collection)
public static <T> boolean addAll(java.util.List<T> self, int index, T[] items)
items
- array containing elements to be added to this collectionindex
- index at which to insert the first element from the
specified array
List.addAll(int, Collection)
public static java.util.Collection split(java.lang.Object self, Closure closure)
self
- an Object with an Iterator returning its valuesclosure
- a closure condition
public static <T> java.util.Collection<java.util.Collection<T>> split(java.util.Collection<T> self, Closure closure)
assert [[2,4],[1,3]] == [1,2,3,4].split { it % 2 == 0 }
self
- a Collection of valuesclosure
- a closure condition
public static java.util.List combinations(java.util.Collection self)
assert [['a', 'b'],[1, 2, 3]].combinations() == [['a', 1], ['b', 1], ['a', 2], ['b', 2], ['a', 3], ['b', 3]]
self
- a Collection of lists
GroovyCollections.combinations(java.util.Collection)
public static <T> java.util.Set<java.util.List<T>> subsequences(java.util.List<T> self)
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
public static <T> java.util.Set<java.util.List<T>> permutations(java.util.List<T> self)
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 items
public static <T> java.util.Iterator<java.util.List<T>> eachPermutation(java.util.Collection<T> self, Closure closure)
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 permutation
public static java.util.List transpose(java.util.List self)
def result = [['a', 'b'], [1, 2]].transpose() assert result == [['a', 1], ['b', 2]]
self
- a List of lists
GroovyCollections.transpose(java.util.List)
public static <K,V> java.util.Map<K,V> findAll(java.util.Map<K,V> self, Closure closure)
If the self
map is one of TreeMap, LinkedHashMap, Hashtable
or Properties, the returned Map will preserve that type, otherwise a HashMap will
be returned.
def result = [a:1, b:2, c:4, d:5].findAll { it.value % 2 == 0 } assert result.every { it instanceof Map.Entry } assert result*.key == ["b", "c"] assert result*.value == [2, 4]
self
- a Mapclosure
- a 1 or 2 arg Closure condition applying on the entries
public static <T> java.util.Map<java.lang.Object,java.util.List<T>> groupBy(java.util.Collection<T> self, Closure closure)
assert [0:[2,4,6], 1:[1,3,5]] == [1,2,3,4,5,6].groupBy { it % 2 }
self
- a collection to groupclosure
- a closure mapping entries on keys
public static <K,V> java.util.Map<java.lang.Object,java.util.List<java.util.Map.Entry<K,V>>> groupEntriesBy(java.util.Map<K,V> self, Closure closure)
def result = [a:1,b:2,c:3,d:4,e:5,f:6].groupEntriesBy { it.value % 2 } assert result[0]*.key == ["b", "d", "f"] assert result[1]*.value == [1, 3, 5]
self
- a map to groupclosure
- a 1 or 2 arg Closure mapping entries on keys
public static <K,V> java.util.Map<java.lang.Object,java.util.Map<K,V>> groupBy(java.util.Map<K,V> self, Closure closure)
If the self
map is one of TreeMap, Hashtable or Properties,
the returned Map will preserve that type, otherwise a LinkedHashMap will
be returned.
def result = [a:1,b:2,c:3,d:4,e:5,f:6].groupBy { it.value % 2 } assert result == [0:[b:2, d:4, f:6], 1:[a:1, c:3, e:5]]
self
- a map to groupclosure
- a closure mapping entries on keys
protected static <T> void groupAnswer(java.util.Map<java.lang.Object,java.util.List<T>> answer, T element, java.lang.Object value)
answer
- the map containing the resultselement
- the element to be placedvalue
- the value according to which the element will be placedprotected static java.lang.Object callClosureForMapEntry(Closure closure, java.util.Map.Entry entry)
protected static java.lang.Object callClosureForLine(Closure closure, java.lang.String line, int counter)
protected static java.lang.Object callClosureForMapEntryAndCounter(Closure closure, java.util.Map.Entry entry, int counter)
public static java.lang.Object inject(java.util.Collection self, java.lang.Object value, Closure closure)
assert 1*1*2*3*4 == [1,2,3,4].inject(1) { acc, val -> acc * val }
self
- a Collectionvalue
- a valueclosure
- a closure
public static java.lang.Object inject(java.util.Iterator self, java.lang.Object value, Closure closure)
self
- a Collectionvalue
- a valueclosure
- a closure
public static java.lang.Object inject(java.lang.Object self, java.lang.Object value, Closure closure)
self
- a Collectionvalue
- a valueclosure
- a closure
public static java.lang.Object inject(java.lang.Object[] self, java.lang.Object initialValue, Closure closure)
self
- an Object[]initialValue
- an initialValueclosure
- a closure
public static java.lang.Object sum(java.util.Collection self)
assert 1+2+3+4 == [1,2,3,4].sum()
self
- Collection of values to add together
public static java.lang.Object sum(java.lang.Object[] self)
self
- The array of values to add together
sum(java.util.Collection)
public static java.lang.Object sum(java.util.Iterator<java.lang.Object> self)
self
- an Iterator for the values to add together
public static java.lang.Object sum(java.util.Collection self, java.lang.Object initialValue)
assert 5+1+2+3+4 == [1,2,3,4].sum(5)
self
- a collection of values to suminitialValue
- the items in the collection will be summed to this initial value
public static java.lang.Object sum(java.lang.Object[] self, java.lang.Object initialValue)
self
- an array of values to suminitialValue
- the items in the array will be summed to this initial value
public static java.lang.Object sum(java.util.Iterator<java.lang.Object> self, java.lang.Object initialValue)
self
- an Iterator for the values to add togetherinitialValue
- the items in the collection will be summed to this initial value
public static java.lang.Object sum(java.util.Collection self, Closure closure)
coll.sum(closure)
is equivalent to:
coll.collect(closure).sum()
.
assert 4+6+10+12 == [2,3,5,6].sum() { it * 2 }
self
- a Collectionclosure
- a single parameter closure that returns a numeric value.
public static java.lang.Object sum(java.lang.Object[] self, Closure closure)
array.sum(closure)
is equivalent to:
array.collect(closure).sum()
.
self
- An arrayclosure
- a single parameter closure that returns a numeric value.
public static java.lang.Object sum(java.util.Iterator<java.lang.Object> self, Closure closure)
iter.sum(closure)
is equivalent to:
iter.collect(closure).sum()
. The iterator will become
exhausted of elements after determining the sum value.
self
- An Iteratorclosure
- a single parameter closure that returns a numeric value.
public static java.lang.Object sum(java.util.Collection self, java.lang.Object initialValue, Closure closure)
coll.sum(initVal, closure)
is equivalent to:
coll.collect(closure).sum(initVal)
.
assert 50+4+6+10+12 == [2,3,5,6].sum(50) { it * 2 }
self
- a Collectionclosure
- a single parameter closure that returns a numeric value.initialValue
- the closure results will be summed to this initial value
public static java.lang.Object sum(java.lang.Object[] self, java.lang.Object initialValue, Closure closure)
array.sum(initVal, closure)
is equivalent to:
array.collect(closure).sum(initVal)
.
self
- an arrayclosure
- a single parameter closure that returns a numeric value.initialValue
- the closure results will be summed to this initial value
public static java.lang.Object sum(java.util.Iterator<java.lang.Object> self, java.lang.Object initialValue, Closure closure)
iter.sum(initVal, closure)
is equivalent to:
iter.collect(closure).sum(initVal)
. The iterator will become
exhausted of elements after determining the sum value.
self
- an Iteratorclosure
- a single parameter closure that returns a numeric value.initialValue
- the closure results will be summed to this initial value
public static java.lang.String join(java.util.Iterator<java.lang.Object> self, java.lang.String separator)
toString()
representation of each
item from the iterator, with the given String as a separator between
each item. The iterator will become exhausted of elements after
determining the resulting conjoined value.
self
- an Iterator of itemsseparator
- a String separator
public static java.lang.String join(java.util.Collection self, java.lang.String separator)
toString()
representation of each
item in this collection, with the given String as a separator between
each item.
assert "1, 2, 3" == [1,2,3].join(", ")
self
- a Collection of objectsseparator
- a String separator
public static java.lang.String join(java.lang.Object[] self, java.lang.String separator)
toString()
representation of each
items in this array, with the given String as a separator between each
item.
self
- an array of Objectseparator
- a String separator
public static <T> T min(java.util.Collection<T> self)
assert 2 == [4,2,5].min()
self
- a Collection
GroovyCollections.min(java.util.Collection)
public static <T> T min(java.util.Iterator<T> self)
self
- an Iterator
min(java.util.Collection)
public static <T> T min(T[] self)
self
- an Object array
min(java.util.Collection)
public static <T> T min(java.util.Collection<T> self, java.util.Comparator<T> comparator)
assert "hi" == ["hello","hi","hey"].min( { a, b -> a.length() <=> b.length() } as Comparator )
self
- a Collectioncomparator
- a Comparator
public static <T> T min(java.util.Iterator<T> self, java.util.Comparator<T> comparator)
self
- an Iteratorcomparator
- a Comparator
min(java.util.Collection, java.util.Comparator)
public static <T> T min(T[] self, java.util.Comparator<T> comparator)
self
- an Object arraycomparator
- a Comparator
min(java.util.Collection, java.util.Comparator)
public static <T> T min(java.util.Collection<T> self, Closure closure)
assert "hi" == ["hello","hi","hey"].min { it.length() }
self
- a Collectionclosure
- a 1 or 2 arg Closure used to determine the correct ordering
public static <T> T min(java.util.Iterator<T> self, Closure closure)
self
- an Iteratorclosure
- a Closure used to determine the correct ordering
min(java.util.Collection, groovy.lang.Closure)
public static <T> T min(T[] self, Closure closure)
self
- an Object arrayclosure
- a Closure used to determine the correct ordering
min(java.util.Collection, groovy.lang.Closure)
public static <T> T max(java.util.Collection<T> self)
assert 5 == [2,3,1,5,4].max()
self
- a Collection
GroovyCollections.max(java.util.Collection)
public static <T> T max(java.util.Iterator<T> self)
self
- an Iterator
GroovyCollections.max(java.util.Collection)
public static <T> T max(T[] self)
self
- an Object array
max(java.util.Collection)
public static <T> T max(java.util.Collection<T> self, Closure closure)
assert "hello" == ["hello","hi","hey"].max { it.length() }
assert "hello" == ["hello","hi","hey"].max { a, b -> a.length() <=> b.length() }
self
- a Collectionclosure
- a 1 or 2 arg Closure used to determine the correct ordering
public static <T> T max(java.util.Iterator<T> self, Closure closure)
self
- an Iteratorclosure
- a Closure used to determine the correct ordering
max(java.util.Collection, groovy.lang.Closure)
public static <T> T max(T[] self, Closure closure)
self
- an Object arrayclosure
- a Closure used to determine the correct ordering
max(java.util.Collection, groovy.lang.Closure)
public static <T> T max(java.util.Collection<T> self, java.util.Comparator<T> comparator)
assert "hello" == ["hello","hi","hey"].max( { a, b -> a.length() <=> b.length() } as Comparator )
self
- a Collectioncomparator
- a Comparator
public static <T> T max(java.util.Iterator<T> self, java.util.Comparator<T> comparator)
self
- an Iteratorcomparator
- a Comparator
public static <T> T max(T[] self, java.util.Comparator<T> comparator)
self
- an Object arraycomparator
- a Comparator
public static int size(java.util.Iterator self)
size()
method for Iterator
.
The iterator will become exhausted of elements after determining the size value.
self
- an Iterator
public static int size(java.lang.String text)
size()
method for String
.
text
- a String
public static int size(java.lang.StringBuffer buffer)
size()
method for StringBuffer
.
buffer
- a StringBuffer
public static long size(java.io.File self)
size()
method for File
.
self
- a file object
public static long size(java.util.regex.Matcher self)
size()
method for Matcher
.
self
- a matcher object
public static int size(java.lang.Object[] self)
size()
method for an array.
self
- an Array of objects
public static java.lang.CharSequence getAt(java.lang.CharSequence text, int index)
text
- a CharSequenceindex
- the index of the Character to get
public static java.lang.String getAt(java.lang.String text, int index)
text
- a Stringindex
- the index of the Character to get
public static java.lang.CharSequence getAt(java.lang.CharSequence text, Range range)
text
- a CharSequencerange
- a Range
public static java.lang.CharSequence getAt(java.lang.CharSequence text, IntRange range)
text
- a CharSequencerange
- an IntRange
public static java.lang.CharSequence getAt(java.lang.CharSequence text, EmptyRange range)
text
- a CharSequencerange
- an EmptyRange
public static java.lang.String getAt(java.lang.String text, IntRange range)
text
- a Stringrange
- an IntRange
public static java.lang.String getAt(java.lang.String text, EmptyRange range)
text
- a Stringrange
- an EmptyRange
public static java.lang.String getAt(java.lang.String text, Range range)
text
- a Stringrange
- a Range
public static java.lang.String reverse(java.lang.String self)
self
- a String
StringBuilder.reverse()
public static java.lang.String stripMargin(java.lang.String self)
Strip leading whitespace/control characters followed by '|' from every line in a String.
assert 'ABC\n123\n456' == '''ABC |123 |456'''.stripMargin()
self
- The String to strip the margin fromstripMargin(String, char)
public static java.lang.String stripMargin(java.lang.String self, java.lang.String marginChar)
Strip leading whitespace/control characters followed by marginChar from every line in a String.
self
- The String to strip the margin frommarginChar
- Any character that serves as margin delimiterstripMargin(String, char)
public static java.lang.String stripMargin(java.lang.String self, char marginChar)
Strip leading whitespace/control characters followed by marginChar from every line in a String.
assert 'ABC\n123\n456' == '''ABC *123 *456'''.stripMargin('*')
self
- The String to strip the margin frommarginChar
- Any character that serves as margin delimiterpublic static java.lang.String stripIndent(java.lang.String self)
Strip leading spaces from every line in a String. The line with the least number of leading spaces determines the number to remove. Lines only containing whitespace are ignored when calculating the number of leading spaces to strip.
assert ' A\n B\nC' == ' A\n B\n C'.stripIndent()
self
- The String to strip the leading spaces fromstripIndent(String, int)
public static boolean isAllWhitespace(java.lang.String self)
self
- The String to check the characters in
Character.isWhitespace(char)
public static java.lang.String stripIndent(java.lang.String self, int numChars)
Strip numChar leading characters from every line in a String.
assert 'DEF\n456' == '''ABCDEF\n123456'''.stripIndent(3)
self
- The String to strip the characters fromnumChars
- The number of characters to strippublic static java.net.URL toURL(java.lang.String self) throws java.net.MalformedURLException
self
- the String representing a URL
java.net.MalformedURLException
- is thrown if the URL is not well formed.public static java.net.URI toURI(java.lang.String self) throws java.net.URISyntaxException
self
- the String representing a URI
java.net.URISyntaxException
- is thrown if the URI is not well formed.public static java.util.regex.Pattern bitwiseNegate(java.lang.String self)
self
- a String to convert into a regular expression
public static java.lang.String replaceFirst(java.lang.String self, java.util.regex.Pattern pattern, java.lang.String replacement)
Note that backslashes (\) and dollar signs ($) in the
replacement string may cause the results to be different than if it were
being treated as a literal replacement string; see
Matcher.replaceFirst(java.lang.String)
.
Use Matcher.quoteReplacement(java.lang.String)
to suppress the special
meaning of these characters, if desired.
self
- the string that is to be matchedpattern
- the regex Pattern to which the string of interest is to be matchedreplacement
- the string to be substituted for the first match
String.replaceFirst(java.lang.String, java.lang.String)
public static java.lang.String replaceAll(java.lang.String self, java.util.regex.Pattern pattern, java.lang.String replacement)
Note that backslashes (\) and dollar signs ($) in the
replacement string may cause the results to be different than if it were
being treated as a literal replacement string; see
Matcher.replaceAll(java.lang.String)
.
Use Matcher.quoteReplacement(java.lang.String)
to suppress the special
meaning of these characters, if desired.
self
- the string that is to be matchedpattern
- the regex Pattern to which the string of interest is to be matchedreplacement
- the string to be substituted for the first match
String.replaceAll(java.lang.String, java.lang.String)
public static java.lang.String tr(java.lang.String self, java.lang.String sourceSet, java.lang.String replacementSet) throws java.lang.ClassNotFoundException
assert 'hello'.tr('aeiou', 'AEIOU') == 'hEllO'A character range using regex-style syntax can also be used, e.g. here is an example which converts a word from lower to uppercase:
assert 'hello'.tr('a-z', 'A-Z') == 'HELLO'Hyphens at the start or end of sourceSet or replacementSet are treated as normal hyphens and are not considered to be part of a range specification. Similarly, a hyphen immediately after an earlier range is treated as a normal hyphen. So, '-x', 'x-' have no ranges while 'a-c-e' has the range 'a-c' plus the '-' character plus the 'e' character. Unlike the unix tr command, Groovy's tr command supports reverse ranges, e.g.:
assert 'hello'.tr('z-a', 'Z-A') == 'HELLO'If replacementSet is smaller than sourceSet, then the last character from replacementSet is used as the replacement for all remaining source characters as shown here:
assert 'Hello World!'.tr('a-z', 'A') == 'HAAAA WAAAA!'If sourceSet contains repeated characters, the last specified replacement is used as shown here:
assert 'Hello World!'.tr('lloo', '1234') == 'He224 W4r2d!'The functionality provided by tr can be achieved using regular expressions but tr provides a much more compact notation and efficient implementation for certain scenarios.
self
- the string that is to be translatedsourceSet
- the set of characters to translate fromreplacementSet
- the set of replacement characters
java.lang.ClassNotFoundException
StringUtil.tr(String, String, String)
public static boolean matches(java.lang.String self, java.util.regex.Pattern pattern)
self
- the string that is to be matchedpattern
- the regex Pattern to which the string of interest is to be matched
String.matches(java.lang.String)
public static java.lang.String find(java.lang.String self, java.lang.String regex)
For example, if the regex doesn't match the result is null:
assert null == "New York, NY".find(/\d{5}/)
If it does match, we get the matching string back:
assert "10292" == "New York, NY 10292-0098".find(/\d{5}/)
If we have capture groups in our expression, we still get back the full match
assert "10292-0098" == "New York, NY 10292-0098".find(/(\d{5})-?(\d{4})/)
self
- a Stringregex
- the capturing regex
public static java.lang.String find(java.lang.String self, java.util.regex.Pattern pattern)
For example, if the pattern doesn't match the result is null:
assert null == "New York, NY".find(~/\d{5}/)
If it does match, we get the matching string back:
assert "10292" == "New York, NY 10292-0098".find(~/\d{5}/)
If we have capture groups in our expression, the groups are ignored and we get back the full match:
assert "10292-0098" == "New York, NY 10292-0098".find(~/(\d{5})-?(\d{4})/)If you need to work with capture groups, then use the closure version of this method or use Groovy's matcher operators or use eachMatch.
self
- a Stringpattern
- the compiled regex Pattern
public static java.lang.String find(java.lang.String self, java.lang.String regex, Closure closure)
For example, if the regex doesn't match, the result is null:
assert null == "New York, NY".find(~/\d{5}/) { match -> return "-$match-"}
If it does match and we don't have any capture groups in our regex, there is a single parameter on the closure that the match gets passed to:
assert "-10292-" == "New York, NY 10292-0098".find(~/\d{5}/) { match -> return "-$match-"}
If we have capture groups in our expression, our closure has one parameter for the match, followed by one for each of the capture groups:
assert "10292" == "New York, NY 10292-0098".find(~/(\d{5})-?(\d{4})/) { match, zip, plusFour -> assert match == "10292-0098" assert zip == "10292" assert plusFour == "0098" return zip }
If we have capture groups in our expression, and our closure has one parameter, the closure will be passed an array with the first element corresponding to the whole match, followed by an element for each of the capture groups:
assert "10292" == "New York, NY 10292-0098".find(~/(\d{5})-?(\d{4})/) { match, zip, plusFour -> assert array[0] == "10292-0098" assert array[1] == "10292" assert array[2] == "0098" return array[1] }
If a capture group is optional, and doesn't match, then the corresponding value for that capture group passed to the closure will be null as illustrated here:
assert "2339999" == "adsf 233-9999 adsf".find(~/(\d{3})?-?(\d{3})-(\d{4})/) { match, areaCode, exchange, stationNumber -> assert "233-9999" == match assert null == areaCode assert "233" == exchange assert "9999" == stationNumber return "$exchange$stationNumber" }
self
- a Stringregex
- the capturing regex stringclosure
- the closure that will be passed the full match, plus each of the capturing groups
public static java.lang.String find(java.lang.String self, java.util.regex.Pattern pattern, Closure closure)
For example, if the pattern doesn't match, the result is null:
assert null == "New York, NY".find(~/\d{5}/) { match -> return "-$match-"}
If it does match and we don't have any capture groups in our regex, there is a single parameter on the closure that the match gets passed to:
assert "-10292-" == "New York, NY 10292-0098".find(~/\d{5}/) { match -> return "-$match-"}
If we have capture groups in our expression, our closure has one parameter for the match, followed by one for each of the capture groups:
assert "10292" == "New York, NY 10292-0098".find(~/(\d{5})-?(\d{4})/) { match, zip, plusFour -> assert match == "10292-0098" assert zip == "10292" assert plusFour == "0098" return zip }
If we have capture groups in our expression, and our closure has one parameter, the closure will be passed an array with the first element corresponding to the whole match, followed by an element for each of the capture groups:
assert "10292" == "New York, NY 10292-0098".find(~/(\d{5})-?(\d{4})/) { match, zip, plusFour -> assert array[0] == "10292-0098" assert array[1] == "10292" assert array[2] == "0098" return array[1] }
If a capture group is optional, and doesn't match, then the corresponding value for that capture group passed to the closure will be null as illustrated here:
assert "2339999" == "adsf 233-9999 adsf".find(~/(\d{3})?-?(\d{3})-(\d{4})/) { match, areaCode, exchange, stationNumber -> assert "233-9999" == match assert null == areaCode assert "233" == exchange assert "9999" == stationNumber return "$exchange$stationNumber" }
self
- a Stringpattern
- the compiled regex Patternclosure
- the closure that will be passed the full match, plus each of the capturing groups
public static java.util.List findAll(java.lang.String self, java.lang.String regex)
For example, if the regex doesn't match, it returns an empty list:
assert [] == "foo".findAll(/(\w*) Fish/)
Any regular expression matches are returned in a list, and all regex capture groupings are ignored, only the full match is returned:
def expected = ["One Fish", "Two Fish", "Red Fish", "Blue Fish"] assert expected == "One Fish, Two Fish, Red Fish, Blue Fish".findAll(/(\w*) Fish/)If you need to work with capture groups, then use the closure version of this method or use Groovy's matcher operators or use eachMatch.
self
- a Stringregex
- the capturing regex String
public static java.util.List findAll(java.lang.String self, java.util.regex.Pattern pattern)
For example, if the pattern doesn't match, it returns an empty list:
assert [] == "foo".findAll(~/(\w*) Fish/)
Any regular expression matches are returned in a list, and all regex capture groupings are ignored, only the full match is returned:
def expected = ["One Fish", "Two Fish", "Red Fish", "Blue Fish"] assert expected == "One Fish, Two Fish, Red Fish, Blue Fish".findAll(~/(\w*) Fish/)
self
- a Stringpattern
- the compiled regex Pattern
public static java.util.List findAll(java.lang.String self, java.lang.String regex, Closure closure)
For example, if the regex doesn't match, it returns an empty list:
assert [] == "foo".findAll(/(\w*) Fish/) { match, firstWord -> return firstWord }
Any regular expression matches are passed to the closure, if there are no capture groups, there will be one parameter for the match:
assert ["couldn't", "wouldn't"] == "I could not, would not, with a fox.".findAll(/.ould/) { match -> "${match}n't"}
If there are capture groups, the first parameter will be the match followed by one parameter for each capture group:
def orig = "There's a Wocket in my Pocket" assert ["W > Wocket", "P > Pocket"] == orig.findAll(/(.)ocket/) { match, firstLetter -> "$firstLetter > $match" }
self
- a Stringregex
- the capturing regex Stringclosure
- will be passed the full match plus each of the capturing groups
public static java.util.List findAll(java.lang.String self, java.util.regex.Pattern pattern, Closure closure)
For example, if the pattern doesn't match, it returns an empty list:
assert [] == "foo".findAll(~/(\w*) Fish/) { match, firstWord -> return firstWord }
Any regular expression matches are passed to the closure, if there are no capture groups, there will be one parameter for the match:
assert ["couldn't", "wouldn't"] == "I could not, would not, with a fox.".findAll(~/.ould/) { match -> "${match}n't"}
If there are capture groups, the first parameter will be the match followed by one parameter for each capture group:
def orig = "There's a Wocket in my Pocket" assert ["W > Wocket", "P > Pocket"] == orig.findAll(~/(.)ocket/) { match, firstLetter -> "$firstLetter > $match" }
self
- a Stringpattern
- the compiled regex Patternclosure
- will be passed the full match plus each of the capturing groups
public static java.lang.String replaceAll(java.lang.String self, java.lang.String regex, Closure closure)
For examples,
assert "FOOBAR-FOOBAR-" == "foobar-FooBar-".replaceAll("(([fF][oO]{2})[bB]ar)", { Object[] it -> it[0].toUpperCase() }) Here, it[0] is the global string of the matched group it[1] is the first string in the matched group it[2] is the second string in the matched group assert "FOO-FOO-" == "foobar-FooBar-".replaceAll("(([fF][oO]{2})[bB]ar)", { x, y, z -> z.toUpperCase() }) Here, x is the global string of the matched group y is the first string in the matched group z is the second string in the matched group
Note that unlike String.replaceAll(String regex, String replacement), where the replacement string treats '$' and '\' specially (for group substitution), the result of the closure is converted to a string and that value is used literally for the replacement.
self
- a Stringregex
- the capturing regexclosure
- the closure to apply on each captured group
java.util.regex.PatternSyntaxException
- if the regular expression's syntax is invalidMatcher.quoteReplacement(java.lang.String)
public static java.lang.String replaceAll(java.lang.String self, java.util.regex.Pattern pattern, Closure closure)
For examples,
assert "FOOBAR-FOOBAR-" == "foobar-FooBar-".replaceAll(~"(([fF][oO]{2})[bB]ar)", { Object[] it -> it[0].toUpperCase() }) Here, it[0] is the global string of the matched group it[1] is the first string in the matched group it[2] is the second string in the matched group assert "FOO-FOO-" == "foobar-FooBar-".replaceAll("(([fF][oO]{2})[bB]ar)", { x, y, z -> z.toUpperCase() }) Here, x is the global string of the matched group y is the first string in the matched group z is the second string in the matched group
Note that unlike String.replaceAll(String regex, String replacement), where the replacement string treats '$' and '\' specially (for group substitution), the result of the closure is converted to a string and that value is used literally for the replacement.
self
- a Stringpattern
- the capturing regex Patternclosure
- the closure to apply on each captured group
Matcher.quoteReplacement(java.lang.String)
public static java.lang.String padLeft(java.lang.String self, java.lang.Number numberOfChars, java.lang.String padding)
self
- a String objectnumberOfChars
- the total number of characterspadding
- the charaters used for padding
public static java.lang.String padLeft(java.lang.String self, java.lang.Number numberOfChars)
self
- a String objectnumberOfChars
- the total number of characters
public static java.lang.String padRight(java.lang.String self, java.lang.Number numberOfChars, java.lang.String padding)
self
- a String objectnumberOfChars
- the total number of characterspadding
- the charaters used for padding
public static java.lang.String padRight(java.lang.String self, java.lang.Number numberOfChars)
self
- a String objectnumberOfChars
- the total number of characters
public static java.lang.String center(java.lang.String self, java.lang.Number numberOfChars, java.lang.String padding)
self
- a String objectnumberOfChars
- the total number of characterspadding
- the charaters used for padding
public static java.lang.String center(java.lang.String self, java.lang.Number numberOfChars)
self
- a String objectnumberOfChars
- the total number of characters
public static java.lang.Object getAt(java.util.regex.Matcher matcher, int idx)
def p = /ab[d|f]/ def m = "abcabdabeabf" =~ p assert 2 == m.count assert 2 == m.size() // synonym for m.getCount() assert ! m.hasGroup() assert 0 == m.groupCount() def matches = ["abd", "abf"] for (i in 0..<m.count) { assert m[i] == matches[i] }For an example using group matches,
def p = /(?:ab([c|d|e|f]))/ def m = "abcabdabeabf" =~ p assert 4 == m.count assert m.hasGroup() assert 1 == m.groupCount() def matches = [["abc", "c"], ["abd", "d"], ["abe", "e"], ["abf", "f"]] for (i in 0..<m.count) { assert m[i] == matches[i] }For another example using group matches,
def m = "abcabdabeabfabxyzabx" =~ /(?:ab([d|x-z]+))/ assert 3 == m.count assert m.hasGroup() assert 1 == m.groupCount() def matches = [["abd", "d"], ["abxyz", "xyz"], ["abx", "x"]] for (i in 0..<m.count) { assert m[i] == matches[i] }
matcher
- a Matcheridx
- an index
public static void setIndex(java.util.regex.Matcher matcher, int idx)
matcher
- a Matcheridx
- the index numberpublic static int getCount(java.util.regex.Matcher matcher)
matcher
- a Matcher
public static boolean hasGroup(java.util.regex.Matcher matcher)
matcher
- a Matcher
true
if matcher contains at least one group.public static <T> java.util.List<T> getAt(java.util.List<T> self, Range range)
def list = [1, "a", 4.5, true] assert list[1..2] == ["a", 4.5]
self
- a Listrange
- a Range indicating the items to get
List.subList(int,int)
public static <T> java.util.List<T> getAt(java.util.List<T> self, EmptyRange range)
def list = [true, 1, 3.4] assert list[0..<0] == []
self
- a Listrange
- a Range indicating the items to get
List.subList(int,int)
public static <T> java.util.List<T> getAt(java.util.List<T> self, java.util.Collection indices)
def list = [true, 1, 3.4, false] assert list[1,0,2] == [1, true, 3.4]
self
- a Listindices
- a Collection of indices
public static <T> java.util.List<T> getAt(T[] self, java.util.Collection indices)
self
- an Array of Objectsindices
- a Collection of indices
public static java.lang.CharSequence getAt(java.lang.CharSequence self, java.util.Collection indices)
self
- a CharSequenceindices
- a Collection of indices
public static java.lang.String getAt(java.lang.String self, java.util.Collection indices)
self
- a Stringindices
- a Collection of indices
public static java.util.List getAt(java.util.regex.Matcher self, java.util.Collection indices)
self
- a Matcherindices
- a Collection of indices
public static <K,V> java.util.Map<K,V> subMap(java.util.Map<K,V> map, java.util.Collection<K> keys)
assert [1:10, 2:20, 4:40].subMap( [2, 4] ) == [2:20, 4:40]
map
- a Mapkeys
- a Collection of keys
public static <K,V> V get(java.util.Map<K,V> map, K key, V defaultValue)
def map=[:] map.get("a", []) << 5 assert map == [a:[5]]
map
- a Mapkey
- the key to lookup the value ofdefaultValue
- the value to return and add to the map for this key if
there is no entry for the given key
public static <T> java.util.List<T> getAt(T[] array, Range range)
array
- an Array of Objectsrange
- a Range
public static <T> java.util.List<T> getAt(T[] array, IntRange range)
array
- an Array of Objectsrange
- an IntRange
public static <T> java.util.List<T> getAt(T[] array, EmptyRange range)
array
- an Array of Objectsrange
- an EmptyRange
public static <T> java.util.List<T> getAt(T[] array, ObjectRange range)
array
- an Array of Objectsrange
- an ObjectRange
public static <T> java.util.List<T> toList(T[] array)
array
- an Array of Objects
public static <T> T getAt(java.util.List<T> self, int idx)
def list = [2, "a", 5.3] assert list[1] == "a"
self
- a Listidx
- an index
public static <T> T getAt(java.util.Iterator<T> self, int idx)
def iter = [2, "a", 5.3].iterator() assert iter[1] == "a"A more elaborate example:
def items = [2, "a", 5.3] def iter = items.iterator() assert iter[-1] == 5.3 // iter exhausted, so reset iter = items.iterator() assert iter[1] == "a" // iter partially exhausted so now idx starts after "a" assert iter[0] == 5.3
self
- an Iteratoridx
- an index value (-self.size() <= idx < self.size())
public static <T> void putAt(java.util.List<T> self, int idx, T value)
def list = [2, 3] list[0] = 1 assert list == [1, 3]
self
- a Listidx
- an indexvalue
- the value to put at the given indexpublic static void putAt(java.lang.StringBuffer self, IntRange range, java.lang.Object value)
self
- a StringBufferrange
- a Rangevalue
- the object that's toString() will be insertedpublic static void putAt(java.lang.StringBuffer self, EmptyRange range, java.lang.Object value)
self
- a StringBufferrange
- a Rangevalue
- the object that's toString() will be insertedpublic static void putAt(java.util.List self, EmptyRange range, java.lang.Object value)
def list = ["a", true] list[1..<1] = 5 assert list == ["a", 5, true]
self
- a Listrange
- the (in this case empty) subset of the list to setvalue
- the values to put at the given sublist or a Collection of valuespublic static void putAt(java.util.List self, EmptyRange range, java.util.Collection value)
def list = ["a", true] list[1..<1] = [4, 3, 2] assert list == ["a", 4, 3, 2, true]
self
- a Listrange
- the (in this case empty) subset of the list to setvalue
- the Collection of valuesputAt(java.util.List, groovy.lang.EmptyRange, java.lang.Object)
public static void putAt(java.util.List self, IntRange range, java.util.Collection col)
def myList = [4, 3, 5, 1, 2, 8, 10] myList[3..5] = ["a", true] assert myList == [4, 3, 5, "a", true, 10]Items in the given range are relaced with items from the collection.
self
- a Listrange
- the subset of the list to setcol
- the collection of values to put at the given sublistpublic static void putAt(java.util.List self, IntRange range, java.lang.Object value)
def myList = [4, 3, 5, 1, 2, 8, 10] myList[3..5] = "b" assert myList == [4, 3, 5, "b", 10]Items in the given range are relaced with the operand. The
value
operand is
always treated as a single value.
self
- a Listrange
- the subset of the list to setvalue
- the value to put at the given sublistpublic static void putAt(java.util.List self, java.util.List splice, java.util.List values)
def list = ["a", true, 42, 9.4] list[1, 4] = ["x", false] assert list == ["a", "x", 42, 9.4, false]
self
- a Listsplice
- the subset of the list to setvalues
- the value to put at the given sublistpublic static void putAt(java.util.List self, java.util.List splice, java.lang.Object value)
def list = ["a", true, 42, 9.4] list[1, 3] = 5 assert list == ["a", 5, 42, 5]
self
- a Listsplice
- the subset of the list to setvalue
- the value to put at the given sublistprotected static java.util.List getSubList(java.util.List self, java.util.List splice)
public static <K,V> V getAt(java.util.Map<K,V> self, K key)
def map = [a:10] assert map["a"] == 10
self
- a Mapkey
- an Object as a key for the map
public static <K,V> java.util.Map<K,V> plus(java.util.Map<K,V> left, java.util.Map<K,V> right)
Map
containing all entries from left
and right
,
giving precedence to right
. Any keys appearing in both Maps
will appear in the resultant map with values from the right
operand. If the left
map is one of TreeMap, LinkedHashMap, Hashtable
or Properties, the returned Map will preserve that type, otherwise a HashMap will
be returned.
Roughly equivalent to Map m = new HashMap(); m.putAll(left); m.putAll(right); return m;
but with some additional logic to preserve the left
Map type for common cases as
described above.
assert [a:10, b:20] + [a:5, c:7] == [a:5, b:20, c:7]
left
- a Mapright
- a Map
public static <K,V> V putAt(java.util.Map<K,V> self, K key, V value)
self
- a Mapkey
- an Object as a key for the mapvalue
- the value to put into the map
public static java.util.List getAt(java.util.Collection coll, java.lang.String property)
assert [String, Long, Integer] == ["a",5L,2]["class"]
coll
- a Collectionproperty
- a String
public static <K,V> java.util.Map<K,V> asImmutable(java.util.Map<? extends K,? extends V> self)
self
- a Map
Collections.unmodifiableMap(java.util.Map)
public static <K,V> java.util.SortedMap<K,V> asImmutable(java.util.SortedMap<K,? extends V> self)
self
- a SortedMap
Collections.unmodifiableSortedMap(java.util.SortedMap)
public static <T> java.util.List<T> asImmutable(java.util.List<? extends T> self)
self
- a List
Collections.unmodifiableList(java.util.List)
public static <T> java.util.Set<T> asImmutable(java.util.Set<? extends T> self)
self
- a Set
Collections.unmodifiableSet(java.util.Set)
public static <T> java.util.SortedSet<T> asImmutable(java.util.SortedSet<T> self)
self
- a SortedSet
Collections.unmodifiableSortedSet(java.util.SortedSet)
public static <T> java.util.Collection<T> asImmutable(java.util.Collection<? extends T> self)
def mutable = [1,2,3] def immutable = mutable.asImmutable() mutable << 4 try { immutable << 4 assert false } catch (UnsupportedOperationException) { assert true }
self
- a Collection
Collections.unmodifiableCollection(java.util.Collection)
public static <K,V> java.util.Map<K,V> asSynchronized(java.util.Map<K,V> self)
self
- a Map
Collections.synchronizedMap(java.util.Map)
public static <K,V> java.util.SortedMap<K,V> asSynchronized(java.util.SortedMap<K,V> self)
self
- a SortedMap
Collections.synchronizedSortedMap(java.util.SortedMap)
public static <T> java.util.Collection<T> asSynchronized(java.util.Collection<T> self)
self
- a Collection
Collections.synchronizedCollection(java.util.Collection)
public static <T> java.util.List<T> asSynchronized(java.util.List<T> self)
self
- a List
Collections.synchronizedList(java.util.List)
public static <T> java.util.Set<T> asSynchronized(java.util.Set<T> self)
self
- a Set
Collections.synchronizedSet(java.util.Set)
public static <T> java.util.SortedSet<T> asSynchronized(java.util.SortedSet<T> self)
self
- a SortedSet
Collections.synchronizedSortedSet(java.util.SortedSet)
public static SpreadMap spread(java.util.Map self)
toSpreadMap(java.util.Map)
.
self
- a map
public static SpreadMap toSpreadMap(java.util.Map self)
SpreadMap
from this map.
For examples, if there is defined a function like as
, then all of the following three have the same meaning.def fn(a, b, c, d) { return a + b + c + d }
println fn(a:1, [b:2, c:3].toSpreadMap(), d:4) println fn(a:1, *:[b:2, c:3], d:4) println fn(a:1, b:2, c:3, d:4)
self
- a list to be converted into a spreadmap
SpreadMap.SpreadMap(java.util.Map)
public static SpreadMap toSpreadMap(java.lang.Object[] self)
self
- an object array
SpreadMap.SpreadMap(java.lang.Object[])
public static <K,V> java.util.Map<K,V> withDefault(java.util.Map<K,V> self, Closure init)
get(key)
. If an unknown key is found, a default value will be
stored into the Map before being returned. The default value stored will be the
result of calling the supplied Closure with the key as the parameter to the Closure.
Example usage:
def map = [a:1, b:2].withDefault{ k -> k.toCharacter().isLowerCase() ? 10 : -10 } def expected = [a:1, b:2, c:10, D:-10] assert expected.every{ e -> e.value == map[e.key] } def constMap = [:].withDefault{ 42 } assert constMap.foo == 42 assert constMap.size() == 1
self
- a Mapinit
- a Closure which is passed the unknown key
public static <T> java.util.List<T> sort(java.util.Collection<T> self)
assert [1,2,3] == [3,1,2].sort()
self
- the collection to be sorted
public static <K,V> java.util.Map<K,V> sort(java.util.Map<K,V> self, Closure closure)
def map = [a:5, b:3, c:6, d:4].sort { a, b -> a.value <=> b.value } assert map == [b:3, d:4, a:5, c:6]
self
- the map to be sortedclosure
- a Closure used as a comparator
public static <K,V> java.util.Map<K,V> sort(java.util.Map<K,V> self, java.util.Comparator<K> comparator)
def map = [ba:3, cz:6, ab:5].sort({ a, b -> a[-1] <=> b[-1] } as Comparator) assert map*.value == [3, 5, 6]
self
- the map to be sortedcomparator
- a Comparator
public static <K,V> java.util.Map<K,V> sort(java.util.Map<K,V> self)
map = [ba:3, cz:6, ab:5].sort() assert map*.value == [5, 3, 6]
self
- the map to be sorted
public static <T> T[] sort(T[] self)
self
- the array to be sorted
public static <T> java.util.Iterator<T> sort(java.util.Iterator<T> self)
self
- the Iterator to be sorted
public static <T> java.util.Iterator<T> sort(java.util.Iterator<T> self, java.util.Comparator<T> comparator)
self
- the Iterator to be sortedcomparator
- a Comparator used for comparing items
public static <T> java.util.List<T> sort(java.util.Collection<T> self, java.util.Comparator<T> comparator)
assert ["hi","hey","hello"] == ["hello","hi","hey"].sort( { a, b -> a.length() <=> b.length() } as Comparator )
self
- a collection to be sortedcomparator
- a Comparator used for the comparison
public static <T> T[] sort(T[] self, java.util.Comparator<T> comparator)
self
- the array to be sortedcomparator
- a Comparator used for the comparison
public static <T> java.util.Iterator<T> sort(java.util.Iterator<T> self, Closure closure)
self
- the Iterator to be sortedclosure
- a Closure used to determine the correct ordering
public static <T> T[] sort(T[] self, Closure closure)
self
- the array to be sortedclosure
- a Closure used to determine the correct ordering
public static <T> java.util.List<T> sort(java.util.Collection<T> self, Closure closure)
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 ordering
public static <T> java.util.SortedSet<T> sort(java.util.SortedSet<T> self)
self
- an identity function for an already sorted set
public static <T> T pop(java.util.List<T> self)
def list = ["a", false, 2] assert list.pop() == 2 assert list == ["a", false]
self
- a List
java.util.NoSuchElementException
- if the list is empty and you try to pop() it.public static <K,V> java.util.Map<K,V> putAll(java.util.Map<K,V> self, java.util.Collection<java.util.Map.Entry<K,V>> entries)
self
- a Mapentries
- a Collection of Map.Entry items to be added to the Map.
public static <K,V> java.util.Map<K,V> plus(java.util.Map<K,V> self, java.util.Collection<java.util.Map.Entry<K,V>> entries)
Map
containing all entries from self
and entries
,
giving precedence to entries
. Any keys appearing in both Maps
will appear in the resultant map with values from the entries
operand. If self
map is one of TreeMap, LinkedHashMap, Hashtable
or Properties, the returned Map will preserve that type, otherwise a HashMap will
be returned.
self
- a Mapentries
- a Collection of Map.Entry items to be added to the Map.
public static <T> boolean push(java.util.List<T> self, T value)
def list = [3, 4, 2] list.push("x") assert list == [3, 4, 2, "x"]
self
- a Listvalue
- element to be appended to this list.
java.util.NoSuchElementException
- if the list is empty and you try to pop() it.public static <T> T last(java.util.List<T> self)
def list = [3, 4, 2] assert list.last() == 2 assert list == [3, 4, 2]
self
- a List
java.util.NoSuchElementException
- if the list is empty and you try to access the last() item.public static <T> T last(T[] self)
def array = [3, 4, 2].toArray() assert array.last() == 2
self
- an ObjectArray
java.util.NoSuchElementException
- if the array is empty and you try to access the last() item.public static <T> T first(java.util.List<T> self)
def list = [3, 4, 2] assert list.first() == 3 assert list == [3, 4, 2]
self
- a List
java.util.NoSuchElementException
- if the list is empty and you try to access the first() item.public static <T> T first(T[] self)
def array = [3, 4, 2].toArray() assert array.first() == 3
self
- an Object array
java.util.NoSuchElementException
- if the array is empty and you try to access the first() item.public static <T> T head(java.util.List<T> self)
def list = [3, 4, 2] assert list.head() == 3 assert list == [3, 4, 2]
self
- a List
java.util.NoSuchElementException
- if the list is empty and you try to access the head() item.public static <T> T head(T[] self)
def array = [3, 4, 2].toArray() assert array.head() == 3
self
- an Object array
java.util.NoSuchElementException
- if the array is empty and you try to access the head() item.public static <T> java.util.List<T> tail(java.util.List<T> self)
def list = [3, 4, 2] assert list.tail() == [4, 2] assert list == [3, 4, 2]
self
- a List
java.util.NoSuchElementException
- if the list is empty and you try to access the tail() item.public static <T> T[] tail(T[] self)
String[] strings = ["a", "b", "c"] def result = strings.tail() assert strings.class.componentType == String
self
- an Object array
java.util.NoSuchElementException
- if the list is empty and you try to access the tail() item.public static <T> java.util.List<T> asList(java.util.Collection<T> self)
Example usage:
assert new HashSet().asList() instanceof List
self
- a collection to be converted into a List
public static boolean asBoolean(java.lang.Object object)
object
- the object to coerce
public static boolean asBoolean(java.lang.Boolean bool)
bool
- the Boolean
public static boolean asBoolean(java.util.regex.Matcher matcher)
matcher
- the matcher
public static boolean asBoolean(java.util.Collection collection)
assert [1,2].asBoolean() == true
assert [].asBoolean() == false
collection
- the collection
public static boolean asBoolean(java.util.Map map)
assert [:] as Boolean == false assert [a:2] as Boolean == true
map
- the map
public static boolean asBoolean(java.util.Iterator iterator)
iterator
- the iterator
public static boolean asBoolean(java.util.Enumeration enumeration)
enumeration
- the enumeration
public static boolean asBoolean(java.lang.CharSequence string)
string
- the character sequence
public static boolean asBoolean(java.lang.Object[] array)
array
- the array
public static boolean asBoolean(byte[] array)
array
- an array
public static boolean asBoolean(short[] array)
array
- an array
public static boolean asBoolean(int[] array)
array
- an array
public static boolean asBoolean(long[] array)
array
- an array
public static boolean asBoolean(float[] array)
array
- an array
public static boolean asBoolean(double[] array)
array
- an array
public static boolean asBoolean(boolean[] array)
array
- an array
public static boolean asBoolean(char[] array)
array
- an array
public static boolean asBoolean(java.lang.Character character)
character
- the character
public static boolean asBoolean(java.lang.Number number)
number
- the number
public static boolean asBoolean(GroovyResultSet grs)
grs
- the GroovyResultSet
public static java.lang.Object asType(java.util.Collection col, java.lang.Class clazz)
col
- a collectionclazz
- the desired class
asType(java.lang.Object, java.lang.Class)
public static java.lang.Object asType(java.lang.Object[] ary, java.lang.Class clazz)
ary
- an arrayclazz
- the desired class
asType(java.lang.Object, java.lang.Class)
public static java.lang.Object asType(Closure cl, java.lang.Class clazz)
cl
- the implementation of the single methodclazz
- the target type
public static java.lang.Object asType(java.util.Map map, java.lang.Class clazz)
map
- this mapclazz
- the target type
public static <T> java.util.List<T> reverse(java.util.List<T> self)
def list = ["a", 4, false] assert list.reverse() == [false, 4, "a"] assert list == ["a", 4, false]
self
- a List
public static <T> java.util.Iterator<T> reverse(java.util.Iterator<T> self)
self
- an Iterator
public static <T> java.util.Collection<T> plus(java.util.Collection<T> left, java.util.Collection<T> right)
assert [1,2,3,4] == [1,2] + [3,4]
left
- the left Collectionright
- the right Collection
public static <T> java.util.Collection<T> plus(java.util.Collection<T> left, T right)
assert [1,2,3] == [1,2] + 3
left
- a Collectionright
- an object to add/append
public static <T> java.util.List<T> multiply(java.util.Collection<T> self, java.lang.Number factor)
assert [1,2,3,1,2,3] == [1,2,3] * 2
self
- a Collectionfactor
- the number of times to append
public static <T> java.util.Collection<T> intersect(java.util.Collection<T> left, java.util.Collection<T> right)
assert [4,5] == [1,2,3,4,5].intersect([4,5,6,7,8])
left
- a Collectionright
- a Collection
public static <K,V> java.util.Map<K,V> intersect(java.util.Map<K,V> left, java.util.Map<K,V> right)
assert [4:4,5:5] == [1:1,2:2,3:3,4:4,5:5].intersect([4:4,5:5,6:6,7:7,8:8])
assert [1: 1, 2: 2, 3: 3, 4: 4].intersect( [1: 1.0, 2: 2, 5: 5] ) == [1:1, 2:2]
left
- a mapright
- a map
public static boolean disjoint(java.util.Collection left, java.util.Collection right)
true
if the intersection of two collections is empty.
assert [1,2,3].disjoint([3,4,5]) == false
assert [1,2].disjoint([3,4]) == true
left
- a Collectionright
- a Collection
true
if the intersection of two collections
is empty, false
otherwise.public static boolean equals(int[] left, int[] right)
left
- an int arrayright
- the operand array.
public static boolean equals(java.lang.Object[] left, java.util.List right)
false
if either collection is null
.
left
- this arrayright
- the list being compared
public static boolean equals(java.util.List left, java.lang.Object[] right)
false
if either collection is null
.
assert [1, "a"].equals( [ 1, "a" ] as Object[] )
left
- this Listright
- this Object[] being compared to
public static boolean equals(java.util.List left, java.util.List right)
null
, the result
is true; otherwise if either list is null
, the result
is false
.
assert ["a", 2].equals(["a", 2]) assert ![2, "a"].equals("a", 2) assert [2.0, "a"].equals(2L, "a") // number comparison at work
left
- this Listright
- the List being compared to.
true
if the contents of both lists are identical,
false
otherwise.public static <T> java.util.Set<T> minus(java.util.Set<T> self, java.util.Collection operands)
self
- a set objectoperands
- the items to remove from the set
public static <T> java.util.Set<T> minus(java.util.Set<T> self, java.lang.Object operand)
self
- a set objectoperand
- the operand to remove from the set
public static <T> T[] minus(T[] self, java.util.Collection<T> removeMe)
self
- an object arrayremoveMe
- a Collection of elements to remove
public static <T> T[] minus(T[] self, T[] removeMe)
self
- an object arrayremoveMe
- an array of elements to remove
public static <T> java.util.List<T> minus(java.util.List<T> self, java.util.Collection<T> removeMe)
assert [1, "a", true, true, false, 5.3] - [true, 5.3] == [1, "a", false]
self
- a ListremoveMe
- a Collection of elements to remove
public static <T> java.util.List<T> minus(java.util.List<T> self, java.lang.Object operand)
assert ["a", 5, 5, true] - 5 == ["a", true]
self
- a List objectoperand
- an element to remove from the list
public static <T> T[] minus(T[] self, java.lang.Object operand)
self
- an object arrayoperand
- an element to remove from the array
public static <K,V> java.util.Map<K,V> minus(java.util.Map<K,V> self, java.util.Map<K,V> operands)
self
- a map objectoperands
- the entries to remove from the map
public static java.util.Collection flatten(java.util.Collection self)
assert [1,2,3,4,5] == [1,[2,3],[[4]],[],5].flatten()
self
- a Collection to flatten
public static java.util.Collection flatten(java.lang.Object[] self)
self
- an Array to flatten
public static java.util.Collection flatten(boolean[] self)
self
- a boolean Array to flatten
public static java.util.Collection flatten(byte[] self)
self
- a byte Array to flatten
public static java.util.Collection flatten(char[] self)
self
- a char Array to flatten
public static java.util.Collection flatten(short[] self)
self
- a short Array to flatten
public static java.util.Collection flatten(int[] self)
self
- an int Array to flatten
public static java.util.Collection flatten(long[] self)
self
- a long Array to flatten
public static java.util.Collection flatten(float[] self)
self
- a float Array to flatten
public static java.util.Collection flatten(double[] self)
self
- a double Array to flatten
public static java.util.Collection flatten(java.util.Collection self, Closure flattenUsing)
self
- a CollectionflattenUsing
- a closure to determine how to flatten non-Array, non-Collection elements
public static <T> java.util.Collection<T> leftShift(java.util.Collection<T> self, T value)
def list = [1,2] list << 3 assert list == [1,2,3]
self
- a Collectionvalue
- an Object to be added to the collection.
public static <T> java.util.concurrent.BlockingQueue<T> leftShift(java.util.concurrent.BlockingQueue<T> self, T value) throws java.lang.InterruptedException
def list = new java.util.concurrent.LinkedBlockingQueue () list << 3 << 2 << 1 assert list.iterator().collect{it} == [3,2,1]
self
- a Collectionvalue
- an Object to be added to the collection.
java.lang.InterruptedException
public static <K,V> java.util.Map<K,V> leftShift(java.util.Map<K,V> self, java.util.Map.Entry<K,V> entry)
self
- a Mapentry
- a Map.Entry to be added to the Map.
public static <K,V> java.util.Map<K,V> leftShift(java.util.Map<K,V> self, java.util.Map<K,V> other)
map1 << map2
; otherwise it's just a synonym for
putAll
though it returns the original map rather than
being a void
method. Example usage:
def map = [a:1, b:2] map << [c:3, d:4] assert map == [a:1, b:2, c:3, d:4]
self
- a Mapother
- another Map whose entries should be added to the original Map.
public static java.lang.StringBuffer leftShift(java.lang.String self, java.lang.Object value)
self
- a Stringvalue
- an Obect
protected static java.io.StringWriter createStringWriter(java.lang.String self)
protected static StringBufferWriter createStringBufferWriter(java.lang.StringBuffer self)
public static java.lang.StringBuffer leftShift(java.lang.StringBuffer self, java.lang.Object value)
self
- a StringBuffervalue
- a value to append
public static java.io.Writer leftShift(java.io.Writer self, java.lang.Object value) throws java.io.IOException
self
- a Writervalue
- a value to append
java.io.IOException
- if an I/O error occurs.public static java.lang.Number leftShift(java.lang.Number self, java.lang.Number operand)
self
- a Number objectoperand
- the shift distance by which to left shift the number
public static java.lang.Number rightShift(java.lang.Number self, java.lang.Number operand)
self
- a Number objectoperand
- the shift distance by which to right shift the number
public static java.lang.Number rightShiftUnsigned(java.lang.Number self, java.lang.Number operand)
self
- a Number objectoperand
- the shift distance by which to right shift (unsigned) the number
public static void write(java.io.Writer self, Writable writable) throws java.io.IOException
self
- a Writerwritable
- an object implementing the Writable interface
java.io.IOException
- if an I/O error occurs.public static java.io.Writer leftShift(java.io.OutputStream self, java.lang.Object value) throws java.io.IOException
self
- an OutputStreamvalue
- a value to append
java.io.IOException
- if an I/O error occurs.public static void leftShift(java.io.ObjectOutputStream self, java.lang.Object value) throws java.io.IOException
self
- an ObjectOutputStreamvalue
- an object to write to the stream
java.io.IOException
- if an I/O error occurs.public static java.io.OutputStream leftShift(java.io.OutputStream self, java.io.InputStream in) throws java.io.IOException
self
- stream on which to writein
- stream to read from
java.io.IOException
- if an I/O error occurs.public static java.io.OutputStream leftShift(java.io.OutputStream self, byte[] value) throws java.io.IOException
self
- an OutputStreamvalue
- a value to append
java.io.IOException
- if an I/O error occurs.public static java.util.List<java.lang.Byte> getAt(byte[] array, Range range)
array
- a byte arrayrange
- a range indicating the indices for the items to retrieve
public static java.util.List<java.lang.Character> getAt(char[] array, Range range)
array
- a char arrayrange
- a range indicating the indices for the items to retrieve
public static java.util.List<java.lang.Short> getAt(short[] array, Range range)
array
- a short arrayrange
- a range indicating the indices for the items to retrieve
public static java.util.List<java.lang.Integer> getAt(int[] array, Range range)
array
- an int arrayrange
- a range indicating the indices for the items to retrieve
public static java.util.List<java.lang.Long> getAt(long[] array, Range range)
array
- a long arrayrange
- a range indicating the indices for the items to retrieve
public static java.util.List<java.lang.Float> getAt(float[] array, Range range)
array
- a float arrayrange
- a range indicating the indices for the items to retrieve
public static java.util.List<java.lang.Double> getAt(double[] array, Range range)
array
- a double arrayrange
- a range indicating the indices for the items to retrieve
public static java.util.List<java.lang.Boolean> getAt(boolean[] array, Range range)
array
- a boolean arrayrange
- a range indicating the indices for the items to retrieve
public static java.util.List<java.lang.Byte> getAt(byte[] array, IntRange range)
array
- a byte arrayrange
- an IntRange indicating the indices for the items to retrieve
public static java.util.List<java.lang.Character> getAt(char[] array, IntRange range)
array
- a char arrayrange
- an IntRange indicating the indices for the items to retrieve
public static java.util.List<java.lang.Short> getAt(short[] array, IntRange range)
array
- a short arrayrange
- an IntRange indicating the indices for the items to retrieve
public static java.util.List<java.lang.Integer> getAt(int[] array, IntRange range)
array
- an int arrayrange
- an IntRange indicating the indices for the items to retrieve
public static java.util.List<java.lang.Long> getAt(long[] array, IntRange range)
array
- a long arrayrange
- an IntRange indicating the indices for the items to retrieve
public static java.util.List<java.lang.Float> getAt(float[] array, IntRange range)
array
- a float arrayrange
- an IntRange indicating the indices for the items to retrieve
public static java.util.List<java.lang.Double> getAt(double[] array, IntRange range)
array
- a double arrayrange
- an IntRange indicating the indices for the items to retrieve
public static java.util.List<java.lang.Boolean> getAt(boolean[] array, IntRange range)
array
- a boolean arrayrange
- an IntRange indicating the indices for the items to retrieve
public static java.util.List<java.lang.Byte> getAt(byte[] array, ObjectRange range)
array
- a byte arrayrange
- an ObjectRange indicating the indices for the items to retrieve
public static java.util.List<java.lang.Character> getAt(char[] array, ObjectRange range)
array
- a char arrayrange
- an ObjectRange indicating the indices for the items to retrieve
public static java.util.List<java.lang.Short> getAt(short[] array, ObjectRange range)
array
- a short arrayrange
- an ObjectRange indicating the indices for the items to retrieve
public static java.util.List<java.lang.Integer> getAt(int[] array, ObjectRange range)
array
- an int arrayrange
- an ObjectRange indicating the indices for the items to retrieve
public static java.util.List<java.lang.Long> getAt(long[] array, ObjectRange range)
array
- a long arrayrange
- an ObjectRange indicating the indices for the items to retrieve
public static java.util.List<java.lang.Float> getAt(float[] array, ObjectRange range)
array
- a float arrayrange
- an ObjectRange indicating the indices for the items to retrieve
public static java.util.List<java.lang.Double> getAt(double[] array, ObjectRange range)
array
- a double arrayrange
- an ObjectRange indicating the indices for the items to retrieve
public static java.util.List<java.lang.Boolean> getAt(boolean[] array, ObjectRange range)
array
- a byte arrayrange
- an ObjectRange indicating the indices for the items to retrieve
public static java.util.List<java.lang.Byte> getAt(byte[] array, java.util.Collection indices)
array
- a byte arrayindices
- a collection of indices for the items to retrieve
public static java.util.List<java.lang.Character> getAt(char[] array, java.util.Collection indices)
array
- a char arrayindices
- a collection of indices for the items to retrieve
public static java.util.List<java.lang.Short> getAt(short[] array, java.util.Collection indices)
array
- a short arrayindices
- a collection of indices for the items to retrieve
public static java.util.List<java.lang.Integer> getAt(int[] array, java.util.Collection indices)
array
- an int arrayindices
- a collection of indices for the items to retrieve
public static java.util.List<java.lang.Long> getAt(long[] array, java.util.Collection indices)
array
- a long arrayindices
- a collection of indices for the items to retrieve
public static java.util.List<java.lang.Float> getAt(float[] array, java.util.Collection indices)
array
- a float arrayindices
- a collection of indices for the items to retrieve
public static java.util.List<java.lang.Double> getAt(double[] array, java.util.Collection indices)
array
- a double arrayindices
- a collection of indices for the items to retrieve
public static java.util.List<java.lang.Boolean> getAt(boolean[] array, java.util.Collection indices)
array
- a boolean arrayindices
- a collection of indices for the items to retrieve
public static boolean getAt(java.util.BitSet self, int index)
self
- a BitSetindex
- index to retrieve
BitSet
public static java.util.BitSet getAt(java.util.BitSet self, IntRange range)
self
- a BitSetrange
- a Range defining the desired subset
BitSet
,
IntRange
public static void putAt(java.util.BitSet self, IntRange range, boolean value)
self
- a BitSetrange
- the range of values to setvalue
- valueBitSet
,
Range
public static void putAt(java.util.BitSet self, int index, boolean value)
self
- a BitSetindex
- index of the entry to setvalue
- valueBitSet
public static int size(boolean[] array)
array
- a boolean array
Array.getLength(java.lang.Object)
public static int size(byte[] array)
array
- a byte array
Array.getLength(java.lang.Object)
public static int size(char[] array)
array
- a char array
Array.getLength(java.lang.Object)
public static int size(short[] array)
array
- a short array
Array.getLength(java.lang.Object)
public static int size(int[] array)
array
- an int array
Array.getLength(java.lang.Object)
public static int size(long[] array)
array
- a long array
Array.getLength(java.lang.Object)
public static int size(float[] array)
array
- a float array
Array.getLength(java.lang.Object)
public static int size(double[] array)
array
- a double array
Array.getLength(java.lang.Object)
public static java.util.List<java.lang.Byte> toList(byte[] array)
array
- a byte array
public static java.util.List<java.lang.Boolean> toList(boolean[] array)
array
- a boolean array
public static java.util.List<java.lang.Character> toList(char[] array)
array
- a char array
public static java.util.List<java.lang.Short> toList(short[] array)
array
- a short array
public static java.util.List<java.lang.Integer> toList(int[] array)
array
- an int array
public static java.util.List<java.lang.Long> toList(long[] array)
array
- a long array
public static java.util.List<java.lang.Float> toList(float[] array)
array
- a float array
public static java.util.List<java.lang.Double> toList(double[] array)
array
- a double array
protected static java.lang.Object primitiveArrayGet(java.lang.Object self, int idx)
self
- an array objectidx
- the index of interest
protected static java.util.List primitiveArrayGet(java.lang.Object self, Range range)
self
- an array objectrange
- the range of indices of interest
protected static java.util.List primitiveArrayGet(java.lang.Object self, java.util.Collection indices)
self
- an array objectindices
- the indices of interest
protected static java.lang.Object primitiveArrayPut(java.lang.Object self, int idx, java.lang.Object newValue)
self
- an objectidx
- the index of interestnewValue
- the new value to be put into the index of interest
public static java.lang.Character toCharacter(java.lang.String self)
self
- a String
public static java.lang.Boolean toBoolean(java.lang.String self)
self
- a String
public static java.lang.String[] split(java.lang.String self)
self
- the string to split
public static java.lang.String capitalize(java.lang.String self)
assert 'h'.capitalize() == 'H' assert 'hello'.capitalize() == 'Hello' assert 'hello world'.capitalize() == 'Hello world' assert 'Hello World' == 'hello world'.split(' ').collect{ it.capitalize() }.join(' ')
self
- The string to capitalize
public static java.lang.String expand(java.lang.String self)
self
- A String to expand
expand(java.lang.String, int)
public static java.lang.String expand(java.lang.String self, int tabStop)
self
- A String to expandtabStop
- The number of spaces a tab represents
public static java.lang.String expandLine(java.lang.String self, int tabStop)
self
- A line to expandtabStop
- The number of spaces a tab represents
public static java.lang.String unexpand(java.lang.String self)
self
- A String to unexpand
unexpand(java.lang.String, int)
public static java.lang.String unexpand(java.lang.String self, int tabStop)
self
- A String to unexpandtabStop
- The number of spaces a tab represents
public static java.lang.String unexpandLine(java.lang.String self, int tabStop)
self
- A line to unexpandtabStop
- The number of spaces a tab represents
public static java.lang.String[] split(GString self)
self
- the GString to split
split(java.lang.String)
public static java.util.List tokenize(java.lang.String self, java.lang.String token)
self
- a Stringtoken
- the delimiter
StringTokenizer.StringTokenizer(java.lang.String, java.lang.String)
public static java.util.List tokenize(java.lang.String self, java.lang.Character token)
char pathSep = ':' assert "/tmp:/usr".tokenize(pathSep) == ["/tmp", "/usr"]
self
- a Stringtoken
- the delimiter
StringTokenizer.StringTokenizer(java.lang.String, java.lang.String)
public static java.util.List tokenize(java.lang.String self)
self
- a String
StringTokenizer.StringTokenizer(java.lang.String)
public static java.lang.String plus(java.lang.String left, java.lang.Object value)
left
- a Stringvalue
- any Object
public static java.lang.String plus(java.lang.Number value, java.lang.String right)
value
- a Numberright
- a String
public static java.lang.String plus(java.lang.StringBuffer left, java.lang.String value)
left
- a StringBuffervalue
- a String
public static java.lang.String minus(java.lang.String self, java.lang.Object target)
self
- a Stringtarget
- an object representing the part to remove
public static boolean contains(java.lang.String self, java.lang.String text)
Collection.contains(java.lang.Object)
to make Strings more polymorphic.
This method is not required on JDK 1.5 onwards
self
- a Stringtext
- a String to look for
public static int count(java.lang.String self, java.lang.String text)
self
- a Stringtext
- a substring
public static java.lang.String next(java.lang.String self)
self
- a String
public static java.lang.String previous(java.lang.String self)
self
- a String
public static java.lang.Process execute(java.lang.String self) throws java.io.IOException
self
as a command-line process.
For more control over Process construction you can use
java.lang.ProcessBuilder
(JDK 1.5+).
self
- a command line String
java.io.IOException
- if an IOException occurs.public static java.lang.Process execute(java.lang.String self, java.lang.String[] envp, java.io.File dir) throws java.io.IOException
self
with environment defined by envp
and under the working directory dir
.
For more control over Process construction you can use
java.lang.ProcessBuilder
(JDK 1.5+).
self
- a command line String to be executed.envp
- an array of Strings, each element of which
has environment variable settings in the format
name=value, or
null if the subprocess should inherit
the environment of the current process.dir
- the working directory of the subprocess, or
null if the subprocess should inherit
the working directory of the current process.
java.io.IOException
- if an IOException occurs.public static java.lang.Process execute(java.lang.String self, java.util.List envp, java.io.File dir) throws java.io.IOException
self
with environment defined
by envp
and under the working directory dir
.
For more control over Process construction you can use
java.lang.ProcessBuilder
(JDK 1.5+).
self
- a command line String to be executed.envp
- a List of Objects (converted to Strings using toString), each member of which
has environment variable settings in the format
name=value, or
null if the subprocess should inherit
the environment of the current process.dir
- the working directory of the subprocess, or
null if the subprocess should inherit
the working directory of the current process.
java.io.IOException
- if an IOException occurs.public static java.lang.Process execute(java.lang.String[] commandArray) throws java.io.IOException
String
array.
The first item in the array is the command; the others are the parameters.
For more control over Process construction you can use
java.lang.ProcessBuilder
(JDK 1.5+).
commandArray
- an array of String containing the command name and
parameters as separate items in the array.
- Returns:
- the Process which has just started for this command line representation.
- Throws:
java.io.IOException
- if an IOException occurs.- Since:
- 1.0
public static java.lang.Process execute(java.lang.String[] commandArray, java.lang.String[] envp, java.io.File dir) throws java.io.IOException
String
array given in the first parameter,
with the environment defined by envp
and under the working directory dir
.
The first item in the array is the command; the others are the parameters.
For more control over Process construction you can use
java.lang.ProcessBuilder
(JDK 1.5+).
commandArray
- an array of String containing the command name and
parameters as separate items in the array.envp
- an array of Strings, each member of which
has environment variable settings in the format
name=value, or
null if the subprocess should inherit
the environment of the current process.dir
- the working directory of the subprocess, or
null if the subprocess should inherit
the working directory of the current process.
- Returns:
- the Process which has just started for this command line representation.
- Throws:
java.io.IOException
- if an IOException occurs.- Since:
- 1.7.1
public static java.lang.Process execute(java.lang.String[] commandArray, java.util.List envp, java.io.File dir) throws java.io.IOException
String
array given in the first parameter,
with the environment defined by envp
and under the working directory dir
.
The first item in the array is the command; the others are the parameters.
For more control over Process construction you can use
java.lang.ProcessBuilder
(JDK 1.5+).
commandArray
- an array of String containing the command name and
parameters as separate items in the array.envp
- a List of Objects (converted to Strings using toString), each member of which
has environment variable settings in the format
name=value, or
null if the subprocess should inherit
the environment of the current process.dir
- the working directory of the subprocess, or
null if the subprocess should inherit
the working directory of the current process.
- Returns:
- the Process which has just started for this command line representation.
- Throws:
java.io.IOException
- if an IOException occurs.- Since:
- 1.7.1
public static java.lang.Process execute(java.util.List commands) throws java.io.IOException
For more control over Process construction you can use
java.lang.ProcessBuilder
(JDK 1.5+).
commands
- a list containing the command name and
parameters as separate items in the list.
java.io.IOException
- if an IOException occurs.public static java.lang.Process execute(java.util.List commands, java.lang.String[] envp, java.io.File dir) throws java.io.IOException
envp
and under the working directory dir
.
The first item in the list is the command; the others are the parameters. The toString()
method is called on items in the list to convert them to Strings.
For more control over Process construction you can use
java.lang.ProcessBuilder
(JDK 1.5+).
commands
- a List containing the command name and
parameters as separate items in the list.envp
- an array of Strings, each member of which
has environment variable settings in the format
name=value, or
null if the subprocess should inherit
the environment of the current process.dir
- the working directory of the subprocess, or
null if the subprocess should inherit
the working directory of the current process.
java.io.IOException
- if an IOException occurs.public static java.lang.Process execute(java.util.List commands, java.util.List envp, java.io.File dir) throws java.io.IOException
envp
and under the working directory dir
.
The first item in the list is the command; the others are the parameters. The toString()
method is called on items in the list to convert them to Strings.
For more control over Process construction you can use
java.lang.ProcessBuilder
(JDK 1.5+).
commands
- a List containing the command name and
parameters as separate items in the list.envp
- a List of Objects (converted to Strings using toString), each member of which
has environment variable settings in the format
name=value, or
null if the subprocess should inherit
the environment of the current process.dir
- the working directory of the subprocess, or
null if the subprocess should inherit
the working directory of the current process.
java.io.IOException
- if an IOException occurs.public static java.lang.String multiply(java.lang.String self, java.lang.Number factor)
self
- a String to be repeatedfactor
- the number of times the String should be repeated
java.lang.IllegalArgumentException
- if the number of repetitions is < 0public static java.lang.String toString(boolean[] self)
self
- an array
public static java.lang.String toString(byte[] self)
self
- an array
public static java.lang.String toString(char[] self)
self
- an array
public static java.lang.String toString(short[] self)
self
- an array
public static java.lang.String toString(int[] self)
self
- an array
public static java.lang.String toString(long[] self)
self
- an array
public static java.lang.String toString(float[] self)
self
- an array
public static java.lang.String toString(double[] self)
self
- an array
public static java.lang.String toString(java.util.AbstractMap self)
self
- a Map
toMapString(java.util.Map)
public static java.lang.String toMapString(java.util.Map self)
[one:1, two:2, three:3]
.
self
- a Map
public static java.lang.String toMapString(java.util.Map self, int maxSize)
[one:1, two:2, three:3]
.
self
- a MapmaxSize
- stop after approximately this many characters and append '...'
public static java.lang.String toString(java.util.AbstractCollection self)
[1, 2, a]
.
self
- a Collection
toListString(java.util.Collection)
public static java.lang.String toListString(java.util.Collection self)
[1, 2, a]
.
self
- a Collection
public static java.lang.String toListString(java.util.Collection self, int maxSize)
[1, 2, a]
.
self
- a CollectionmaxSize
- stop after approximately this many characters and append '...'
public static java.lang.String toString(java.lang.Object[] self)
self
- an Object[]
toArrayString(java.lang.Object[])
public static java.lang.String toArrayString(java.lang.Object[] self)
{1, 2, "a"}
.
self
- an Object[]
public static java.lang.String toString(java.lang.Object value)
value
- an object
public static java.lang.Character next(java.lang.Character self)
self
- a Character
public static java.lang.Number next(java.lang.Number self)
self
- a Number
public static java.lang.Character previous(java.lang.Character self)
self
- a Character
public static java.lang.Number previous(java.lang.Number self)
self
- a Number
public static java.lang.Number plus(java.lang.Character left, java.lang.Number right)
left
- a Characterright
- a Number
Integer.valueOf(int)
public static java.lang.Number plus(java.lang.Number left, java.lang.Character right)
left
- a Numberright
- a Character
Integer.valueOf(int)
public static java.lang.Number plus(java.lang.Character left, java.lang.Character right)
left
- a Characterright
- a Character
plus(java.lang.Number, java.lang.Character)
public static int compareTo(java.lang.Character left, java.lang.Number right)
left
- a Characterright
- a Number
public static int compareTo(java.lang.Number left, java.lang.Character right)
left
- a Numberright
- a Character
public static int compareTo(java.lang.Character left, java.lang.Character right)
left
- a Characterright
- a Character
public static int compareTo(java.lang.Number left, java.lang.Number right)
left
- a Numberright
- another Number to compare to
public static java.lang.Number minus(java.lang.Character left, java.lang.Number right)
left
- a Characterright
- a Number
public static java.lang.Number minus(java.lang.Number left, java.lang.Character right)
left
- a Numberright
- a Character
public static java.lang.Number minus(java.lang.Character left, java.lang.Character right)
left
- a Characterright
- a Character
public static java.lang.Number multiply(java.lang.Character left, java.lang.Number right)
left
- a Characterright
- a Number
public static java.lang.Number multiply(java.lang.Number left, java.lang.Character right)
left
- a Numberright
- a Character
public static java.lang.Number multiply(java.lang.Character left, java.lang.Character right)
left
- a Characterright
- another Character
public static java.lang.Number multiply(java.math.BigDecimal left, java.lang.Double right)
left
- a BigDecimalright
- a Double
public static java.lang.Number multiply(java.math.BigDecimal left, java.math.BigInteger right)
left
- a BigDecimalright
- a BigInteger
public static java.lang.Number power(java.lang.Number self, java.lang.Number exponent)
self
- a Numberexponent
- a Number exponent
public static java.lang.Number div(java.lang.Character left, java.lang.Number right)
left
- a Characterright
- a Number
public static java.lang.Number div(java.lang.Number left, java.lang.Character right)
left
- a Numberright
- a Character
public static java.lang.Number div(java.lang.Character left, java.lang.Character right)
left
- a Characterright
- another Character
public static java.lang.Number intdiv(java.lang.Character left, java.lang.Number right)
left
- a Characterright
- a Number
public static java.lang.Number intdiv(java.lang.Number left, java.lang.Character right)
left
- a Numberright
- a Character
public static java.lang.Number intdiv(java.lang.Character left, java.lang.Character right)
left
- a Characterright
- another Character
public static java.lang.Number intdiv(java.lang.Number left, java.lang.Number right)
left
- a Numberright
- another Number
public static java.lang.Number or(java.lang.Number left, java.lang.Number right)
left
- a Numberright
- another Number to bitwise OR
public static java.lang.Number and(java.lang.Number left, java.lang.Number right)
left
- a Numberright
- another Number to bitwise AND
public static java.util.BitSet and(java.util.BitSet left, java.util.BitSet right)
left
- a BitSetright
- another BitSet to bitwise AND
public static java.util.BitSet xor(java.util.BitSet left, java.util.BitSet right)
left
- a BitSetright
- another BitSet to bitwise AND
public static java.util.BitSet bitwiseNegate(java.util.BitSet self)
self
- a BitSet
public static java.util.BitSet or(java.util.BitSet left, java.util.BitSet right)
left
- a BitSetright
- another BitSet to bitwise AND
public static java.lang.Number xor(java.lang.Number left, java.lang.Number right)
left
- a Numberright
- another Number to bitwse XOR
public static java.lang.Number mod(java.lang.Number left, java.lang.Number right)
left
- a Numberright
- another Number to mod
public static java.lang.Number unaryMinus(java.lang.Number left)
-10
left
- a Number
public static void times(java.lang.Number self, Closure closure)
10.times { println it }Prints the numbers 0 through 9.
self
- a Numberclosure
- the closure to call a number of timespublic static void upto(java.lang.Number self, java.lang.Number to, Closure closure)
self
- a Numberto
- another Number to go up toclosure
- the closure to callpublic static void upto(long self, java.lang.Number to, Closure closure)
self
- a longto
- the end numberclosure
- the code to execute for each numberpublic static void upto(java.lang.Long self, java.lang.Number to, Closure closure)
self
- a Longto
- the end numberclosure
- the code to execute for each numberpublic static void upto(float self, java.lang.Number to, Closure closure)
self
- a floatto
- the end numberclosure
- the code to execute for each numberpublic static void upto(java.lang.Float self, java.lang.Number to, Closure closure)
self
- a Floatto
- the end numberclosure
- the code to execute for each numberpublic static void upto(double self, java.lang.Number to, Closure closure)
self
- a doubleto
- the end numberclosure
- the code to execute for each numberpublic static void upto(java.lang.Double self, java.lang.Number to, Closure closure)
self
- a Doubleto
- the end numberclosure
- the code to execute for each numberpublic static void upto(java.math.BigInteger self, java.lang.Number to, Closure closure)
0.upto( 10 ) { println it }Prints numbers 0 to 10
self
- a BigIntegerto
- the end numberclosure
- the code to execute for each numberpublic static void upto(java.math.BigDecimal self, java.lang.Number to, Closure closure)
0.1.upto( 10 ) { println it }Prints numbers 0.1, 1.1, 2.1... to 9.1
self
- a BigDecimalto
- the end numberclosure
- the code to execute for each numberpublic static void downto(java.lang.Number self, java.lang.Number to, Closure closure)
self
- a Numberto
- another Number to go down toclosure
- the closure to callpublic static void downto(long self, java.lang.Number to, Closure closure)
self
- a longto
- the end numberclosure
- the code to execute for each numberpublic static void downto(java.lang.Long self, java.lang.Number to, Closure closure)
self
- a Longto
- the end numberclosure
- the code to execute for each numberpublic static void downto(float self, java.lang.Number to, Closure closure)
self
- a floatto
- the end numberclosure
- the code to execute for each numberpublic static void downto(java.lang.Float self, java.lang.Number to, Closure closure)
self
- a Floatto
- the end numberclosure
- the code to execute for each numberpublic static void downto(double self, java.lang.Number to, Closure closure)
self
- a doubleto
- the end numberclosure
- the code to execute for each numberpublic static void downto(java.lang.Double self, java.lang.Number to, Closure closure)
self
- a Doubleto
- the end numberclosure
- the code to execute for each numberpublic static void downto(java.math.BigInteger self, java.lang.Number to, Closure closure)
self
- a BigIntegerto
- the end numberclosure
- the code to execute for each numberpublic static void downto(java.math.BigDecimal self, java.lang.Number to, Closure closure)
10.5.downto(0) { println it }Prints numbers 10.5, 9.5 ... to 0.5.
self
- a BigDecimalto
- the end numberclosure
- the code to execute for each numberpublic static void step(java.lang.Number self, java.lang.Number to, java.lang.Number stepNumber, Closure closure)
0.step( 10, 2 ) { println it }Prints even numbers 0 through 8.
self
- a Number to start withto
- a Number to go up to, exclusivestepNumber
- a Number representing the step incrementclosure
- the closure to callpublic static int abs(java.lang.Number number)
number
- a Number
public static long abs(java.lang.Long number)
number
- a Long
public static float abs(java.lang.Float number)
number
- a Float
public static double abs(java.lang.Double number)
number
- a Double
public static int round(java.lang.Float number)
number
- a Float
public static float round(java.lang.Float number, int precision)
number
- a Floatprecision
- the number of decimal places to keep
public static float trunc(java.lang.Float number, int precision)
number
- a Floatprecision
- the number of decimal places to keep
public static float trunc(java.lang.Float number)
number
- a Double
public static long round(java.lang.Double number)
number
- a Double
public static double round(java.lang.Double number, int precision)
number
- a Doubleprecision
- the number of decimal places to keep
public static double trunc(java.lang.Double number)
number
- a Double
public static double trunc(java.lang.Double number, int precision)
number
- a Doubleprecision
- the number of decimal places to keep
public static java.lang.Integer toInteger(java.lang.String self)
self
- a String
public static java.lang.Long toLong(java.lang.String self)
self
- a String
public static java.lang.Short toShort(java.lang.String self)
self
- a String
public static java.lang.Float toFloat(java.lang.String self)
self
- a String
public static java.lang.Double toDouble(java.lang.String self)
self
- a String
public static java.math.BigInteger toBigInteger(java.lang.String self)
self
- a String
public static java.math.BigDecimal toBigDecimal(java.lang.String self)
self
- a String
public static boolean isInteger(java.lang.String self)
self
- a String
public static boolean isLong(java.lang.String self)
self
- a String
public static boolean isFloat(java.lang.String self)
self
- a String
public static boolean isDouble(java.lang.String self)
self
- a String
public static boolean isBigInteger(java.lang.String self)
self
- a String
public static boolean isBigDecimal(java.lang.String self)
self
- a String
public static boolean isNumber(java.lang.String self)
self
- a String
isBigDecimal(java.lang.String)
public static boolean isUpperCase(java.lang.Character self)
self
- a Character
Character.isUpperCase(char)
public static boolean isLowerCase(java.lang.Character self)
self
- a Character
Character.isLowerCase(char)
public static boolean isLetter(java.lang.Character self)
self
- a Character
Character.isLetter(char)
public static boolean isDigit(java.lang.Character self)
self
- a Character
Character.isDigit(char)
public static boolean isLetterOrDigit(java.lang.Character self)
self
- a Character
Character.isLetterOrDigit(char)
public static boolean isWhitespace(java.lang.Character self)
self
- a Character
Character.isWhitespace(char)
public static char toUpperCase(java.lang.Character self)
self
- a Character to convert
Character.isUpperCase(char)
,
String.toUpperCase()
public static char toLowerCase(java.lang.Character self)
self
- a Character to convert
Character.isLowerCase(char)
,
String.toLowerCase()
public static java.lang.Integer toInteger(java.lang.Number self)
self
- a Number
public static java.lang.Long toLong(java.lang.Number self)
self
- a Number
public static java.lang.Float toFloat(java.lang.Number self)
self
- a Number
public static java.lang.Double toDouble(java.lang.Number self)
self
- a Number
public static java.math.BigDecimal toBigDecimal(java.lang.Number self)
self
- a Number
public static java.lang.Object asType(java.lang.Number self, java.lang.Class c)
asType(java.lang.Object, java.lang.Class)
:
self
- this numberc
- the desired type of the transformed result
public static java.math.BigInteger toBigInteger(java.lang.Number self)
self
- a Number
public static java.lang.Boolean and(java.lang.Boolean left, java.lang.Boolean right)
left
- left operatorright
- right operator
public static java.lang.Boolean or(java.lang.Boolean left, java.lang.Boolean right)
left
- left operatorright
- right operator
public static java.lang.Boolean xor(java.lang.Boolean left, java.lang.Boolean right)
left
- left operatorright
- right operator
public static java.io.ObjectOutputStream newObjectOutputStream(java.io.File file) throws java.io.IOException
file
- a file
java.io.IOException
- if an IOException occurs.public static java.io.ObjectOutputStream newObjectOutputStream(java.io.OutputStream outputStream) throws java.io.IOException
outputStream
- an output stream
java.io.IOException
- if an IOException occurs.public static java.lang.Object withObjectOutputStream(java.io.File file, Closure closure) throws java.io.IOException
file
- a Fileclosure
- a closure
java.io.IOException
- if an IOException occurs.withStream(java.io.OutputStream, groovy.lang.Closure)
public static java.lang.Object withObjectOutputStream(java.io.OutputStream outputStream, Closure closure) throws java.io.IOException
outputStream
- am output streamclosure
- a closure
java.io.IOException
- if an IOException occurs.withStream(java.io.OutputStream, groovy.lang.Closure)
public static java.io.ObjectInputStream newObjectInputStream(java.io.File file) throws java.io.IOException
file
- a file
java.io.IOException
- if an IOException occurs.public static java.io.ObjectInputStream newObjectInputStream(java.io.InputStream inputStream) throws java.io.IOException
inputStream
- an input stream
java.io.IOException
- if an IOException occurs.public static java.io.ObjectInputStream newObjectInputStream(java.io.InputStream inputStream, java.lang.ClassLoader classLoader) throws java.io.IOException
inputStream
- an input streamclassLoader
- the class loader to use when loading the class
java.io.IOException
- if an IOException occurs.public static java.io.ObjectInputStream newObjectInputStream(java.io.File file, java.lang.ClassLoader classLoader) throws java.io.IOException
file
- a fileclassLoader
- the class loader to use when loading the class
java.io.IOException
- if an IOException occurs.public static void eachObject(java.io.File self, Closure closure) throws java.io.IOException, java.lang.ClassNotFoundException
self
- a Fileclosure
- a closure
java.io.IOException
- if an IOException occurs.
java.lang.ClassNotFoundException
- if the class is not found.eachObject(java.io.ObjectInputStream, groovy.lang.Closure)
public static void eachObject(java.io.ObjectInputStream ois, Closure closure) throws java.io.IOException, java.lang.ClassNotFoundException
ois
- an ObjectInputStream, closed after the operationclosure
- a closure
java.io.IOException
- if an IOException occurs.
java.lang.ClassNotFoundException
- if the class is not found.public static java.lang.Object withObjectInputStream(java.io.File file, Closure closure) throws java.io.IOException
file
- a Fileclosure
- a closure
java.io.IOException
- if an IOException occurs.withStream(java.io.InputStream, groovy.lang.Closure)
public static java.lang.Object withObjectInputStream(java.io.File file, java.lang.ClassLoader classLoader, Closure closure) throws java.io.IOException
file
- a FileclassLoader
- the class loader to use when loading the classclosure
- a closure
java.io.IOException
- if an IOException occurs.withStream(java.io.InputStream, groovy.lang.Closure)
public static java.lang.Object withObjectInputStream(java.io.InputStream inputStream, Closure closure) throws java.io.IOException
inputStream
- an input streamclosure
- a closure
java.io.IOException
- if an IOException occurs.withStream(java.io.InputStream, groovy.lang.Closure)
public static java.lang.Object withObjectInputStream(java.io.InputStream inputStream, java.lang.ClassLoader classLoader, Closure closure) throws java.io.IOException
inputStream
- an input streamclassLoader
- the class loader to use when loading the classclosure
- a closure
java.io.IOException
- if an IOException occurs.withStream(java.io.InputStream, groovy.lang.Closure)
public static java.lang.Object eachLine(java.lang.String self, Closure closure) throws java.io.IOException
self
- a Stringclosure
- a closure
java.io.IOException
- if an error occurseachLine(java.lang.String, int, groovy.lang.Closure)
public static java.lang.Object eachLine(java.lang.String self, int firstLine, Closure closure) throws java.io.IOException
self
- a StringfirstLine
- the line number value used for the first line (default is 1, set to 0 to start counting from 0)closure
- a closure (arg 1 is line, optional arg 2 is line number)
java.io.IOException
- if an error occurspublic static java.lang.Object eachLine(java.io.File self, Closure closure) throws java.io.IOException
self
- a Fileclosure
- a closure (arg 1 is line, optional arg 2 is line number starting at line 1)
java.io.IOException
- if an IOException occurs.eachLine(java.io.File, int, groovy.lang.Closure)
public static java.lang.Object eachLine(java.io.File self, java.lang.String charset, Closure closure) throws java.io.IOException
self
- a Filecharset
- opens the file with a specified charsetclosure
- a closure (arg 1 is line, optional arg 2 is line number starting at line 1)
java.io.IOException
- if an IOException occurs.eachLine(java.io.File, java.lang.String, int, groovy.lang.Closure)
public static java.lang.Object eachLine(java.io.File self, int firstLine, Closure closure) throws java.io.IOException
self
- a FilefirstLine
- the line number value used for the first line (default is 1, set to 0 to start counting from 0)closure
- a closure (arg 1 is line, optional arg 2 is line number)
java.io.IOException
- if an IOException occurs.eachLine(java.io.Reader, int, groovy.lang.Closure)
public static java.lang.Object eachLine(java.io.File self, java.lang.String charset, int firstLine, Closure closure) throws java.io.IOException
self
- a Filecharset
- opens the file with a specified charsetfirstLine
- the line number value used for the first line (default is 1, set to 0 to start counting from 0)closure
- a closure (arg 1 is line, optional arg 2 is line number)
java.io.IOException
- if an IOException occurs.eachLine(java.io.Reader, int, groovy.lang.Closure)
public static java.lang.Object eachLine(java.io.InputStream stream, java.lang.String charset, Closure closure) throws java.io.IOException
stream
- a streamcharset
- opens the stream with a specified charsetclosure
- a closure (arg 1 is line, optional arg 2 is line number starting at line 1)
java.io.IOException
- if an IOException occurs.eachLine(java.io.InputStream, java.lang.String, int, groovy.lang.Closure)
public static java.lang.Object eachLine(java.io.InputStream stream, java.lang.String charset, int firstLine, Closure closure) throws java.io.IOException
stream
- a streamcharset
- opens the stream with a specified charsetfirstLine
- the line number value used for the first line (default is 1, set to 0 to start counting from 0)closure
- a closure (arg 1 is line, optional arg 2 is line number)
java.io.IOException
- if an IOException occurs.eachLine(java.io.Reader, int, groovy.lang.Closure)
public static java.lang.Object eachLine(java.io.InputStream stream, Closure closure) throws java.io.IOException
stream
- a streamclosure
- a closure (arg 1 is line, optional arg 2 is line number starting at line 1)
java.io.IOException
- if an IOException occurs.eachLine(java.io.InputStream, int, groovy.lang.Closure)
public static java.lang.Object eachLine(java.io.InputStream stream, int firstLine, Closure closure) throws java.io.IOException
stream
- a streamfirstLine
- the line number value used for the first line (default is 1, set to 0 to start counting from 0)closure
- a closure (arg 1 is line, optional arg 2 is line number)
java.io.IOException
- if an IOException occurs.eachLine(java.io.Reader, int, groovy.lang.Closure)
public static java.lang.Object eachLine(java.net.URL url, Closure closure) throws java.io.IOException
url
- a URL to open and readclosure
- a closure to apply on each line (arg 1 is line, optional arg 2 is line number starting at line 1)
java.io.IOException
- if an IOException occurs.eachLine(java.net.URL, int, groovy.lang.Closure)
public static java.lang.Object eachLine(java.net.URL url, int firstLine, Closure closure) throws java.io.IOException
url
- a URL to open and readfirstLine
- the line number value used for the first line (default is 1, set to 0 to start counting from 0)closure
- a closure to apply on each line (arg 1 is line, optional arg 2 is line number)
java.io.IOException
- if an IOException occurs.eachLine(java.io.InputStream, int, groovy.lang.Closure)
public static java.lang.Object eachLine(java.net.URL url, java.lang.String charset, Closure closure) throws java.io.IOException
url
- a URL to open and readcharset
- opens the stream with a specified charsetclosure
- a closure to apply on each line (arg 1 is line, optional arg 2 is line number starting at line 1)
java.io.IOException
- if an IOException occurs.eachLine(java.net.URL, java.lang.String, int, groovy.lang.Closure)
public static java.lang.Object eachLine(java.net.URL url, java.lang.String charset, int firstLine, Closure closure) throws java.io.IOException
url
- a URL to open and readcharset
- opens the stream with a specified charsetfirstLine
- the line number value used for the first line (default is 1, set to 0 to start counting from 0)closure
- a closure to apply on each line (arg 1 is line, optional arg 2 is line number)
java.io.IOException
- if an IOException occurs.eachLine(java.io.Reader, int, groovy.lang.Closure)
public static java.lang.Object eachLine(java.io.Reader self, Closure closure) throws java.io.IOException
self
- a Reader, closed after the method returnsclosure
- a closure (arg 1 is line, optional arg 2 is line number starting at line 1)
java.io.IOException
- if an IOException occurs.eachLine(java.io.Reader, int, groovy.lang.Closure)
public static java.lang.Object eachLine(java.io.Reader self, int firstLine, Closure closure) throws java.io.IOException
self
- a Reader, closed after the method returnsfirstLine
- the line number value used for the first line (default is 1, set to 0 to start counting from 0)closure
- a closure which will be passed each line (or for 2 arg closures the line and line count)
java.io.IOException
- if an IOException occurs.public static java.lang.Object splitEachLine(java.io.File self, java.lang.String regex, Closure closure) throws java.io.IOException
self
- a Fileregex
- the delimiting regular expressionclosure
- a closure
java.io.IOException
- if an IOException occurs.
java.util.regex.PatternSyntaxException
- if the regular expression's syntax is invalidsplitEachLine(java.io.Reader, java.lang.String, groovy.lang.Closure)
public static java.lang.Object splitEachLine(java.io.File self, java.util.regex.Pattern pattern, Closure closure) throws java.io.IOException
self
- a Filepattern
- the regular expression Pattern for the delimiterclosure
- a closure
java.io.IOException
- if an IOException occurs.splitEachLine(java.io.Reader, java.util.regex.Pattern, groovy.lang.Closure)
public static java.lang.Object splitEachLine(java.io.File self, java.lang.String regex, java.lang.String charset, Closure closure) throws java.io.IOException
self
- a Fileregex
- the delimiting regular expressioncharset
- opens the file with a specified charsetclosure
- a closure
java.io.IOException
- if an IOException occurs.
java.util.regex.PatternSyntaxException
- if the regular expression's syntax is invalidsplitEachLine(java.io.Reader, java.lang.String, groovy.lang.Closure)
public static java.lang.Object splitEachLine(java.io.File self, java.util.regex.Pattern pattern, java.lang.String charset, Closure closure) throws java.io.IOException
self
- a Filepattern
- the regular expression Pattern for the delimitercharset
- opens the file with a specified charsetclosure
- a closure
java.io.IOException
- if an IOException occurs.splitEachLine(java.io.Reader, java.util.regex.Pattern, groovy.lang.Closure)
public static java.lang.Object splitEachLine(java.net.URL self, java.lang.String regex, Closure closure) throws java.io.IOException
self
- a URL to open and readregex
- the delimiting regular expressionclosure
- a closure
java.io.IOException
- if an IOException occurs.
java.util.regex.PatternSyntaxException
- if the regular expression's syntax is invalidsplitEachLine(java.io.Reader, java.lang.String, groovy.lang.Closure)
public static java.lang.Object splitEachLine(java.net.URL self, java.util.regex.Pattern pattern, Closure closure) throws java.io.IOException
self
- a URL to open and readpattern
- the regular expression Pattern for the delimiterclosure
- a closure
java.io.IOException
- if an IOException occurs.splitEachLine(java.io.Reader, java.util.regex.Pattern, groovy.lang.Closure)
public static java.lang.Object splitEachLine(java.net.URL self, java.lang.String regex, java.lang.String charset, Closure closure) throws java.io.IOException
self
- a URL to open and readregex
- the delimiting regular expressioncharset
- opens the file with a specified charsetclosure
- a closure
java.io.IOException
- if an IOException occurs.
java.util.regex.PatternSyntaxException
- if the regular expression's syntax is invalidsplitEachLine(java.io.Reader, java.lang.String, groovy.lang.Closure)
public static java.lang.Object splitEachLine(java.net.URL self, java.util.regex.Pattern pattern, java.lang.String charset, Closure closure) throws java.io.IOException
self
- a URL to open and readpattern
- the regular expression Pattern for the delimitercharset
- opens the file with a specified charsetclosure
- a closure
java.io.IOException
- if an IOException occurs.splitEachLine(java.io.Reader, java.util.regex.Pattern, groovy.lang.Closure)
public static java.lang.Object splitEachLine(java.io.Reader self, java.lang.String regex, Closure closure) throws java.io.IOException
def s = 'The 3 quick\nbrown 4 fox' def result = '' new StringReader(s).splitEachLine(/\d/){ parts -> result += "${parts[0]}_${parts[1]}|" } assert result == 'The _ quick|brown _ fox|'
self
- a Reader, closed after the method returnsregex
- the delimiting regular expressionclosure
- a closure
java.io.IOException
- if an IOException occurs.
java.util.regex.PatternSyntaxException
- if the regular expression's syntax is invalidString.split(java.lang.String)
public static java.lang.Object splitEachLine(java.io.Reader self, java.util.regex.Pattern pattern, Closure closure) throws java.io.IOException
def s = 'The 3 quick\nbrown 4 fox' def result = '' new StringReader(s).splitEachLine(~/\d/){ parts -> result += "${parts[0]}_${parts[1]}|" } assert result == 'The _ quick|brown _ fox|'
self
- a Reader, closed after the method returnspattern
- the regular expression Pattern for the delimiterclosure
- a closure
java.io.IOException
- if an IOException occurs.
java.util.regex.PatternSyntaxException
- if the regular expression's syntax is invalidString.split(java.lang.String)
public static java.lang.Object splitEachLine(java.io.InputStream stream, java.lang.String regex, java.lang.String charset, Closure closure) throws java.io.IOException
stream
- an InputStreamregex
- the delimiting regular expressioncharset
- opens the stream with a specified charsetclosure
- a closure
java.io.IOException
- if an IOException occurs.
java.util.regex.PatternSyntaxException
- if the regular expression's syntax is invalidsplitEachLine(java.io.Reader, java.lang.String, groovy.lang.Closure)
public static java.lang.Object splitEachLine(java.io.InputStream stream, java.util.regex.Pattern pattern, java.lang.String charset, Closure closure) throws java.io.IOException
stream
- an InputStreampattern
- the regular expression Pattern for the delimitercharset
- opens the stream with a specified charsetclosure
- a closure
java.io.IOException
- if an IOException occurs.splitEachLine(java.io.Reader, java.util.regex.Pattern, groovy.lang.Closure)
public static java.lang.Object splitEachLine(java.io.InputStream stream, java.lang.String regex, Closure closure) throws java.io.IOException
stream
- an InputStreamregex
- the delimiting regular expressionclosure
- a closure
java.io.IOException
- if an IOException occurs.
java.util.regex.PatternSyntaxException
- if the regular expression's syntax is invalidsplitEachLine(java.io.Reader, java.lang.String, groovy.lang.Closure)
public static java.lang.Object splitEachLine(java.io.InputStream stream, java.util.regex.Pattern pattern, Closure closure) throws java.io.IOException
stream
- an InputStreampattern
- the regular expression Pattern for the delimiterclosure
- a closure
java.io.IOException
- if an IOException occurs.splitEachLine(java.io.Reader, java.util.regex.Pattern, groovy.lang.Closure)
public static java.lang.Object splitEachLine(java.lang.String self, java.lang.String regex, Closure closure) throws java.io.IOException
self
- a Stringregex
- the delimiting regular expressionclosure
- a closure
java.io.IOException
- if an error occurs
java.util.regex.PatternSyntaxException
- if the regular expression's syntax is invalidString.split(java.lang.String)
public static java.lang.Object splitEachLine(java.lang.String self, java.util.regex.Pattern pattern, Closure closure) throws java.io.IOException
self
- a Stringpattern
- the regular expression Pattern for the delimiterclosure
- a closure
java.io.IOException
- if an error occursPattern.split(java.lang.CharSequence)
public static java.lang.String readLine(java.io.Reader self) throws java.io.IOException
self
- a Reader
java.io.IOException
- if an IOException occurs.public static java.lang.String readLine(java.io.InputStream stream) throws java.io.IOException
stream
- an InputStream
java.io.IOException
- if an IOException occurs.public static java.lang.String denormalize(java.lang.String self)
self
- a String object
public static java.lang.String normalize(java.lang.String self)
self
- a String object
public static java.util.List<java.lang.String> readLines(java.lang.String self) throws java.io.IOException
self
- a String object
java.io.IOException
- if an error occurspublic static java.util.List<java.lang.String> readLines(java.io.File file) throws java.io.IOException
file
- a File
java.io.IOException
- if an IOException occurs.readLines(java.io.Reader)
public static java.util.List<java.lang.String> readLines(java.io.File file, java.lang.String charset) throws java.io.IOException
file
- a Filecharset
- opens the file with a specified charset
java.io.IOException
- if an IOException occurs.readLines(java.io.Reader)
public static java.util.List<java.lang.String> readLines(java.io.InputStream stream) throws java.io.IOException
stream
- a stream
java.io.IOException
- if an IOException occurs.readLines(java.io.Reader)
public static java.util.List<java.lang.String> readLines(java.io.InputStream stream, java.lang.String charset) throws java.io.IOException
stream
- a streamcharset
- opens the stream with a specified charset
java.io.IOException
- if an IOException occurs.readLines(java.io.Reader)
public static java.util.List<java.lang.String> readLines(java.net.URL self) throws java.io.IOException
self
- a URL
java.io.IOException
- if an IOException occurs.readLines(java.io.Reader)
public static java.util.List<java.lang.String> readLines(java.net.URL self, java.lang.String charset) throws java.io.IOException
self
- a URLcharset
- opens the URL with a specified charset
java.io.IOException
- if an IOException occurs.readLines(java.io.Reader)
public static java.util.List<java.lang.String> readLines(java.io.Reader reader) throws java.io.IOException
reader
- a Reader
java.io.IOException
- if an IOException occurs.public static java.lang.String getText(java.io.File file, java.lang.String charset) throws java.io.IOException
file
- the file whose content we want to readcharset
- the charset used to read the content of the file
java.io.IOException
- if an IOException occurs.public static java.lang.String getText(java.io.File file) throws java.io.IOException
file
- the file whose content we want to read
java.io.IOException
- if an IOException occurs.public static java.lang.String getText(java.net.URL url) throws java.io.IOException
url
- URL to read content from
java.io.IOException
- if an IOException occurs.public static java.lang.String getText(java.net.URL url, java.lang.String charset) throws java.io.IOException
url
- URL to read content fromcharset
- opens the stream with a specified charset
java.io.IOException
- if an IOException occurs.URLConnection.getInputStream()
public static java.lang.String getText(java.io.InputStream is) throws java.io.IOException
is
- an input stream
java.io.IOException
- if an IOException occurs.public static java.lang.String getText(java.io.InputStream is, java.lang.String charset) throws java.io.IOException
is
- an input streamcharset
- opens the stream with a specified charset
java.io.IOException
- if an IOException occurs.public static java.lang.String getText(java.io.Reader reader) throws java.io.IOException
reader
- a Reader whose content we want to read
java.io.IOException
- if an IOException occurs.getText(java.io.BufferedReader)
public static java.lang.String getText(java.io.BufferedReader reader) throws java.io.IOException
reader
- a BufferedReader whose content we want to read
java.io.IOException
- if an IOException occurs.public static byte[] getBytes(java.io.File file) throws java.io.IOException
file
- the file whose content we want to read
java.io.IOException
- if an IOException occurs.public static byte[] getBytes(java.net.URL url) throws java.io.IOException
url
- URL to read content from
java.io.IOException
- if an IOException occurs.public static byte[] getBytes(java.io.InputStream is) throws java.io.IOException
is
- an input stream
java.io.IOException
- if an IOException occurs.public static void setBytes(java.io.File file, byte[] bytes) throws java.io.IOException
file
- the file to write tobytes
- the byte[] to write to the file
java.io.IOException
- if an IOException occurs.public static void setBytes(java.io.OutputStream os, byte[] bytes) throws java.io.IOException
os
- an output streambytes
- the byte[] to write to the output stream
java.io.IOException
- if an IOException occurs.public static void writeLine(java.io.BufferedWriter writer, java.lang.String line) throws java.io.IOException
writer
- a BufferedWriterline
- the line to write
java.io.IOException
- if an IOException occurs.public static void write(java.io.File file, java.lang.String text) throws java.io.IOException
file
- a Filetext
- the text to write to the File
java.io.IOException
- if an IOException occurs.public static void setText(java.io.File file, java.lang.String text) throws java.io.IOException
file
- a Filetext
- the text to write to the File
java.io.IOException
- if an IOException occurs.write(java.io.File, java.lang.String)
public static void setText(java.io.File file, java.lang.String text, java.lang.String charset) throws java.io.IOException
myFile.setText('some text', charset)or with some help from
ExpandoMetaClass
, you could do something like:
myFile.metaClass.setText = { String s -> delegate.setText(s, 'UTF-8') } myfile.text = 'some text'
file
- A Filecharset
- The charset used when writing to the filetext
- The text to write to the File
java.io.IOException
- if an IOException occurs.write(java.io.File, java.lang.String, java.lang.String)
public static java.io.File leftShift(java.io.File file, java.lang.Object text) throws java.io.IOException
file
- a Filetext
- the text to write to the File
java.io.IOException
- if an IOException occurs.public static java.io.File leftShift(java.io.File file, byte[] bytes) throws java.io.IOException
file
- a Filebytes
- the byte array to append to the end of the File
java.io.IOException
- if an IOException occurs.public static java.io.File leftShift(java.io.File file, java.io.InputStream data) throws java.io.IOException
append(java.io.File, java.io.InputStream)
file
- a Filedata
- an InputStream of data to write to the file
java.io.IOException
- if an IOException occurs.public static void write(java.io.File file, java.lang.String text, java.lang.String charset) throws java.io.IOException
file
- a Filetext
- the text to write to the Filecharset
- the charset used
java.io.IOException
- if an IOException occurs.public static void append(java.io.File file, java.lang.Object text) throws java.io.IOException
file
- a Filetext
- the text to append at the end of the File
java.io.IOException
- if an IOException occurs.public static void append(java.io.File file, byte[] bytes) throws java.io.IOException
file
- a Filebytes
- the byte array to append to the end of the File
java.io.IOException
- if an IOException occurs.public static void append(java.io.File self, java.io.InputStream stream) throws java.io.IOException
self
- a Filestream
- stream to read data from.
java.io.IOException
- if an IOException occurs.public static void append(java.io.File file, java.lang.Object text, java.lang.String charset) throws java.io.IOException
file
- a Filetext
- the text to append at the end of the Filecharset
- the charset used
java.io.IOException
- if an IOException occurs.public static void eachFile(java.io.File self, FileType fileType, Closure closure) throws java.io.FileNotFoundException, java.lang.IllegalArgumentException
self
- a file objectfileType
- if normal files or directories or both should be processedclosure
- the closure to invoke
java.io.FileNotFoundException
- if the given directory does not exist
java.lang.IllegalArgumentException
- if the provided File object does not represent a directorypublic static void eachFile(java.io.File self, Closure closure) throws java.io.FileNotFoundException, java.lang.IllegalArgumentException
self
- a File (that happens to be a folder/directory)closure
- a closure (first parameter is the 'child' file)
java.io.FileNotFoundException
- if the given directory does not exist
java.lang.IllegalArgumentException
- if the provided File object does not represent a directoryFile.listFiles()
,
eachFile(java.io.File, groovy.io.FileType, groovy.lang.Closure)
public static void eachDir(java.io.File self, Closure closure) throws java.io.FileNotFoundException, java.lang.IllegalArgumentException
self
- a File (that happens to be a folder/directory)closure
- a closure (first parameter is the subdirectory file)
java.io.FileNotFoundException
- if the given directory does not exist
java.lang.IllegalArgumentException
- if the provided File object does not represent a directoryFile.listFiles()
,
eachFile(java.io.File, groovy.io.FileType, groovy.lang.Closure)
public static void eachFileRecurse(java.io.File self, FileType fileType, Closure closure) throws java.io.FileNotFoundException, java.lang.IllegalArgumentException
self
- a file objectfileType
- if normal files or directories or both should be processedclosure
- the closure to invoke on each file
java.io.FileNotFoundException
- if the given directory does not exist
java.lang.IllegalArgumentException
- if the provided File object does not represent a directorypublic static void traverse(java.io.File self, java.util.Map<java.lang.String,java.lang.Object> options, Closure closure) throws java.io.FileNotFoundException, java.lang.IllegalArgumentException
closure
for each descendant file in this directory tree.
Sub-directories are recursively traversed as found.
The traversal can be adapted by providing various options in the options
Map according
to the following keys:FileType
enum to determine if normal files or directories or both are processedClosure
run before each directory is processed and optionally returning a FileVisitResult
value
which can be used to control subsequent processing.Closure
run after each directory is processed and optionally returning a FileVisitResult
value
which can be used to control subsequent processing.FileType.FILES
)isCase(java.lang.Object, java.lang.Object)
method). If set,
only files/dirs which match are candidates for visiting.isCase(java.lang.Object, java.lang.Object)
method). If set,
only files/dirs which match are candidates for visiting. (Must not be set if 'filter' is set)isCase(java.lang.Object, java.lang.Object)
method).
If set, any candidates which match won't be visited.isCase(java.lang.Object, java.lang.Object)
method).
If set, any candidates which match won't be visited. (Must not be set if 'excludeFilter' is set)Closure
which if set causes the files and subdirectories for each directory to be processed in sorted order.
Note that even when processing only files, the order of visited subdirectories will be affected by this parameter.def totalSize = 0 def count = 0 def sortByTypeThenName = { a, b -> a.isFile() != b.isFile() ? a.isFile() <=> b.isFile() : a.name <=> b.name } rootDir.traverse( type : FILES, nameFilter : ~/.*\.groovy/, preDir : { if (it.name == '.svn') return SKIP_SUBTREE }, postDir : { println "Found $count files in $it.name totalling $totalSize bytes" totalSize = 0; count = 0 }, postRoot : true sort : sortByTypeThenName ) {it -> totalSize += it.size(); count++ }
self
- a Fileoptions
- a Map of options to alter the traversal behaviorclosure
- the Closure to invoke on each file/directory and optionally returning a FileVisitResult
value
which can be used to control subsequent processing
java.io.FileNotFoundException
- if the given directory does not exist
java.lang.IllegalArgumentException
- if the provided File object does not represent a directory or illegal filter combinations are suppliedsort(java.util.Collection, groovy.lang.Closure)
,
FileVisitResult
,
FileType
public static void traverse(java.io.File self, Closure closure) throws java.io.FileNotFoundException, java.lang.IllegalArgumentException
traverse(java.io.File, java.util.Map, groovy.lang.Closure)
when
no options to alter the traversal behavior are required.
self
- a Fileclosure
- the Closure to invoke on each file/directory and optionally returning a FileVisitResult
value
which can be used to control subsequent processing
java.io.FileNotFoundException
- if the given directory does not exist
java.lang.IllegalArgumentException
- if the provided File object does not represent a directorytraverse(java.io.File, java.util.Map, groovy.lang.Closure)
public static void traverse(java.io.File self, java.util.Map<java.lang.String,java.lang.Object> options) throws java.io.FileNotFoundException, java.lang.IllegalArgumentException
traverse(java.io.File, java.util.Map, groovy.lang.Closure)
allowing the 'visit' closure
to be included in the options Map rather than as a parameter.
self
- a Fileoptions
- a Map of options to alter the traversal behavior
java.io.FileNotFoundException
- if the given directory does not exist
java.lang.IllegalArgumentException
- if the provided File object does not represent a directory or illegal filter combinations are suppliedtraverse(java.io.File, java.util.Map, groovy.lang.Closure)
public static void eachFileRecurse(java.io.File self, Closure closure) throws java.io.FileNotFoundException, java.lang.IllegalArgumentException
self
- a Fileclosure
- a closure
java.io.FileNotFoundException
- if the given directory does not exist
java.lang.IllegalArgumentException
- if the provided File object does not represent a directoryeachFileRecurse(java.io.File, groovy.io.FileType, groovy.lang.Closure)
public static void eachDirRecurse(java.io.File self, Closure closure) throws java.io.FileNotFoundException, java.lang.IllegalArgumentException
self
- a directoryclosure
- a closure
java.io.FileNotFoundException
- if the given directory does not exist
java.lang.IllegalArgumentException
- if the provided File object does not represent a directoryeachFileRecurse(java.io.File, groovy.io.FileType, groovy.lang.Closure)
public static void eachFileMatch(java.io.File self, FileType fileType, java.lang.Object nameFilter, Closure closure) throws java.io.FileNotFoundException, java.lang.IllegalArgumentException
isCase(java.lang.Object, java.lang.Object)
method to determine if a match occurs. This method can be used
with different kinds of filters like regular expressions, classes, ranges etc.
Both regular files and subdirectories may be candidates for matching depending
on the value of fileType.
// collect names of files in baseDir matching supplied regex pattern import static groovy.io.FileType.* def names = [] baseDir.eachFileMatch FILES, ~/foo\d\.txt/, { names << it.name } assert names == ['foo1.txt', 'foo2.txt'] // remove all *.bak files in baseDir baseDir.eachFileMatch FILES, ~/.*\.bak/, { File bak -> bak.delete() } // print out files > 4K in size from baseDir baseDir.eachFileMatch FILES, { new File(baseDir, it).size() > 4096 }, { println "$it.name ${it.size()}" }
self
- a filefileType
- whether normal files or directories or both should be processednameFilter
- the filter to perform on the name of the file/directory (using the isCase(java.lang.Object, java.lang.Object)
method)closure
- the closure to invoke
java.io.FileNotFoundException
- if the given directory does not exist
java.lang.IllegalArgumentException
- if the provided File object does not represent a directorypublic static void eachFileMatch(java.io.File self, java.lang.Object nameFilter, Closure closure) throws java.io.FileNotFoundException, java.lang.IllegalArgumentException
isCase(java.lang.Object, java.lang.Object)
method to determine if a match occurs. This method can be used
with different kinds of filters like regular expressions, classes, ranges etc.
Both regular files and subdirectories are matched.
self
- a filenameFilter
- the nameFilter to perform on the name of the file (using the isCase(java.lang.Object, java.lang.Object)
method)closure
- the closure to invoke
java.io.FileNotFoundException
- if the given directory does not exist
java.lang.IllegalArgumentException
- if the provided File object does not represent a directoryeachFileMatch(java.io.File, groovy.io.FileType, java.lang.Object, groovy.lang.Closure)
public static void eachDirMatch(java.io.File self, java.lang.Object nameFilter, Closure closure) throws java.io.FileNotFoundException, java.lang.IllegalArgumentException
isCase(java.lang.Object, java.lang.Object)
method to determine if a match occurs. This method can be used
with different kinds of filters like regular expressions, classes, ranges etc.
Only subdirectories are matched; regular files are ignored.
self
- a filenameFilter
- the nameFilter to perform on the name of the directory (using the isCase(java.lang.Object, java.lang.Object)
method)closure
- the closure to invoke
java.io.FileNotFoundException
- if the given directory does not exist
java.lang.IllegalArgumentException
- if the provided File object does not represent a directoryeachFileMatch(java.io.File, groovy.io.FileType, java.lang.Object, groovy.lang.Closure)
public static boolean deleteDir(java.io.File self)
The method returns
self
- a File
public static boolean renameTo(java.io.File self, java.lang.String newPathName)
File.renameTo(File)
self
- a FilenewPathName
- The new pathname for the named file
true
if and only if the renaming succeeded;
false
otherwisepublic static java.util.TimerTask runAfter(java.util.Timer timer, int delay, Closure closure)
timer
- a timer objectdelay
- the delay in milliseconds before running the closure codeclosure
- the closure to invoke
public static java.io.BufferedReader newReader(java.io.File file) throws java.io.IOException
file
- a File
java.io.IOException
- if an IOException occurs.public static java.io.BufferedReader newReader(java.io.File file, java.lang.String charset) throws java.io.FileNotFoundException, java.io.UnsupportedEncodingException
file
- a Filecharset
- the charset for this File
java.io.FileNotFoundException
- if the File was not found
java.io.UnsupportedEncodingException
- if the encoding specified is not supportedpublic static java.io.BufferedReader newReader(java.io.InputStream self)
self
- an input stream
public static java.io.BufferedReader newReader(java.io.InputStream self, java.lang.String charset) throws java.io.UnsupportedEncodingException
self
- an input streamcharset
- the charset for this input stream
java.io.UnsupportedEncodingException
- if the encoding specified is not supportedpublic static java.lang.Object withReader(java.io.File file, Closure closure) throws java.io.IOException
file
- a file objectclosure
- a closure
java.io.IOException
- if an IOException occurs.public static java.lang.Object withReader(java.io.File file, java.lang.String charset, Closure closure) throws java.io.IOException
file
- a file objectcharset
- the charset for this input streamclosure
- a closure
java.io.IOException
- if an IOException occurs.public static java.io.BufferedOutputStream newOutputStream(java.io.File file) throws java.io.IOException
file
- a file object
java.io.IOException
- if an IOException occurs.public static java.io.DataOutputStream newDataOutputStream(java.io.File file) throws java.io.IOException
file
- a file object
java.io.IOException
- if an IOException occurs.public static java.lang.Object withOutputStream(java.io.File file, Closure closure) throws java.io.IOException
file
- a Fileclosure
- a closure
java.io.IOException
- if an IOException occurs.withStream(java.io.OutputStream, groovy.lang.Closure)
public static java.lang.Object withInputStream(java.io.File file, Closure closure) throws java.io.IOException
file
- a Fileclosure
- a closure
java.io.IOException
- if an IOException occurs.withStream(java.io.InputStream, groovy.lang.Closure)
public static java.lang.Object withInputStream(java.net.URL url, Closure closure) throws java.io.IOException
url
- a URLclosure
- a closure
java.io.IOException
- if an IOException occurs.withStream(java.io.InputStream, groovy.lang.Closure)
public static java.lang.Object withDataOutputStream(java.io.File file, Closure closure) throws java.io.IOException
file
- a Fileclosure
- a closure
java.io.IOException
- if an IOException occurs.withStream(java.io.OutputStream, groovy.lang.Closure)
public static java.lang.Object withDataInputStream(java.io.File file, Closure closure) throws java.io.IOException
file
- a Fileclosure
- a closure
java.io.IOException
- if an IOException occurs.withStream(java.io.InputStream, groovy.lang.Closure)
public static java.io.BufferedWriter newWriter(java.io.File file) throws java.io.IOException
file
- a File
java.io.IOException
- if an IOException occurs.public static java.io.BufferedWriter newWriter(java.io.File file, boolean append) throws java.io.IOException
file
- a Fileappend
- true if data should be appended to the file
java.io.IOException
- if an IOException occurs.public static java.io.BufferedWriter newWriter(java.io.File file, java.lang.String charset, boolean append) throws java.io.IOException
file
- a Filecharset
- the name of the encoding used to write in this fileappend
- true if in append mode
java.io.IOException
- if an IOException occurs.public static java.io.BufferedWriter newWriter(java.io.File file, java.lang.String charset) throws java.io.IOException
file
- a Filecharset
- the name of the encoding used to write in this file
java.io.IOException
- if an IOException occurs.public static java.lang.Object withWriter(java.io.File file, Closure closure) throws java.io.IOException
file
- a Fileclosure
- a closure
java.io.IOException
- if an IOException occurs.public static java.lang.Object withWriter(java.io.File file, java.lang.String charset, Closure closure) throws java.io.IOException
file
- a Filecharset
- the charset usedclosure
- a closure
java.io.IOException
- if an IOException occurs.public static java.lang.Object withWriterAppend(java.io.File file, java.lang.String charset, Closure closure) throws java.io.IOException
file
- a Filecharset
- the charset usedclosure
- a closure
java.io.IOException
- if an IOException occurs.public static java.lang.Object withWriterAppend(java.io.File file, Closure closure) throws java.io.IOException
file
- a Fileclosure
- a closure
java.io.IOException
- if an IOException occurs.public static java.io.PrintWriter newPrintWriter(java.io.File file) throws java.io.IOException
file
- a File
java.io.IOException
- if an IOException occurs.public static java.io.PrintWriter newPrintWriter(java.io.File file, java.lang.String charset) throws java.io.IOException
file
- a Filecharset
- the charset
java.io.IOException
- if an IOException occurs.public static java.io.PrintWriter newPrintWriter(java.io.Writer writer)
writer
- a writer
public static java.lang.Object withPrintWriter(java.io.File file, Closure closure) throws java.io.IOException
file
- a Fileclosure
- the closure to invoke with the PrintWriter
java.io.IOException
- if an IOException occurs.public static java.lang.Object withPrintWriter(java.io.File file, java.lang.String charset, Closure closure) throws java.io.IOException
file
- a Filecharset
- the charsetclosure
- the closure to invoke with the PrintWriter
java.io.IOException
- if an IOException occurs.public static java.lang.Object withPrintWriter(java.io.Writer writer, Closure closure) throws java.io.IOException
writer
- a writerclosure
- the closure to invoke with the PrintWriter
java.io.IOException
- if an IOException occurs.public static java.lang.Object withWriter(java.io.Writer writer, Closure closure) throws java.io.IOException
writer
- the writer which is used and then closedclosure
- the closure that the writer is passed into
java.io.IOException
- if an IOException occurs.public static java.lang.Object withReader(java.io.Reader reader, Closure closure) throws java.io.IOException
reader
- the reader which is used and then closedclosure
- the closure that the writer is passed into
java.io.IOException
- if an IOException occurs.public static java.lang.Object withStream(java.io.InputStream stream, Closure closure) throws java.io.IOException
stream
- the stream which is used and then closedclosure
- the closure that the stream is passed into
java.io.IOException
- if an IOException occurs.public static java.lang.Object withReader(java.net.URL url, Closure closure) throws java.io.IOException
url
- a URLclosure
- the closure to invoke with the reader
java.io.IOException
- if an IOException occurs.public static java.lang.Object withReader(java.net.URL url, java.lang.String charset, Closure closure) throws java.io.IOException
url
- a URLcharset
- the charset usedclosure
- the closure to invoke with the reader
java.io.IOException
- if an IOException occurs.public static java.lang.Object withReader(java.io.InputStream in, Closure closure) throws java.io.IOException
in
- a streamclosure
- the closure to invoke with the InputStream
java.io.IOException
- if an IOException occurs.InputStreamReader
public static java.lang.Object withReader(java.io.InputStream in, java.lang.String charset, Closure closure) throws java.io.IOException
in
- a streamcharset
- the charset used to decode the streamclosure
- the closure to invoke with the reader
java.io.IOException
- if an IOException occurs.InputStreamReader
public static java.lang.Object withWriter(java.io.OutputStream stream, Closure closure) throws java.io.IOException
stream
- the stream which is used and then closedclosure
- the closure that the writer is passed into
java.io.IOException
- if an IOException occurs.withWriter(java.io.Writer, groovy.lang.Closure)
public static java.lang.Object withWriter(java.io.OutputStream stream, java.lang.String charset, Closure closure) throws java.io.IOException
stream
- the stream which is used and then closedcharset
- the charset usedclosure
- the closure that the writer is passed into
java.io.IOException
- if an IOException occurs.withWriter(java.io.Writer, groovy.lang.Closure)
public static java.lang.Object withStream(java.io.OutputStream os, Closure closure) throws java.io.IOException
os
- the stream which is used and then closedclosure
- the closure that the stream is passed into
java.io.IOException
- if an IOException occurs.public static java.io.BufferedInputStream newInputStream(java.io.File file) throws java.io.FileNotFoundException
file
- a File
java.io.FileNotFoundException
- if the file is not found.public static java.io.BufferedInputStream newInputStream(java.net.URL url) throws java.net.MalformedURLException, java.io.IOException
url
- a URL
java.net.MalformedURLException
- is thrown if the URL is not well formed
java.io.IOException
- if an I/O error occurs while creating the input streampublic static java.io.BufferedReader newReader(java.net.URL url) throws java.net.MalformedURLException, java.io.IOException
url
- a URL
java.net.MalformedURLException
- is thrown if the URL is not well formed
java.io.IOException
- if an I/O error occurs while creating the input streampublic static java.io.BufferedReader newReader(java.net.URL url, java.lang.String charset) throws java.net.MalformedURLException, java.io.IOException
url
- a URLcharset
- opens the stream with a specified charset
java.net.MalformedURLException
- is thrown if the URL is not well formed
java.io.IOException
- if an I/O error occurs while creating the input streampublic static java.io.DataInputStream newDataInputStream(java.io.File file) throws java.io.FileNotFoundException
file
- a File
java.io.FileNotFoundException
- if the file is not found.public static void eachByte(java.io.File self, Closure closure) throws java.io.IOException
self
- a Fileclosure
- a closure
java.io.IOException
- if an IOException occurs.eachByte(java.io.InputStream, groovy.lang.Closure)
public static void eachByte(java.io.File self, int bufferLen, Closure closure) throws java.io.IOException
self
- a FilebufferLen
- the length of the buffer to use.closure
- a 2 parameter closure which is passed the byte[] and a number of bytes successfully read.
java.io.IOException
- if an IOException occurs.eachByte(java.io.InputStream, int, groovy.lang.Closure)
public static void eachByte(java.lang.Byte[] self, Closure closure)
self
- a Byte arrayclosure
- a closureeach(java.lang.Object, groovy.lang.Closure)
public static void eachByte(byte[] self, Closure closure)
self
- a byte arrayclosure
- a closureeach(java.lang.Object, groovy.lang.Closure)
public static void eachByte(java.io.InputStream is, Closure closure) throws java.io.IOException
is
- stream to iterate over, closed after the method callclosure
- closure to apply to each byte
java.io.IOException
- if an IOException occurs.public static void eachByte(java.io.InputStream is, int bufferLen, Closure closure) throws java.io.IOException
is
- stream to iterate over, closed after the method call.bufferLen
- the length of the buffer to use.closure
- a 2 parameter closure which is passed the byte[] and a number of bytes successfully read.
java.io.IOException
- if an IOException occurs.public static void eachByte(java.net.URL url, Closure closure) throws java.io.IOException
url
- url to iterate overclosure
- closure to apply to each byte
java.io.IOException
- if an IOException occurs.eachByte(java.io.InputStream, groovy.lang.Closure)
public static void eachByte(java.net.URL url, int bufferLen, Closure closure) throws java.io.IOException
url
- url to iterate overbufferLen
- the length of the buffer to use.closure
- a 2 parameter closure which is passed the byte[] and a number of bytes successfully read.
java.io.IOException
- if an IOException occurs.eachByte(java.io.InputStream, int, groovy.lang.Closure)
public static void transformChar(java.io.Reader self, java.io.Writer writer, Closure closure) throws java.io.IOException
self
- a Reader objectwriter
- a Writer to receive the transformed charactersclosure
- a closure that performs the required transformation
java.io.IOException
- if an IOException occurs.public static void transformLine(java.io.Reader reader, java.io.Writer writer, Closure closure) throws java.io.IOException
reader
- Lines of text to be transformed. Reader is closed afterwards.writer
- Where transformed lines are written. Writer is closed afterwards.closure
- Single parameter closure that is called to transform each line of
text from the reader, before writing it to the writer.
java.io.IOException
- if an IOException occurs.public static void filterLine(java.io.Reader reader, java.io.Writer writer, Closure closure) throws java.io.IOException
reader
- a reader, closed after the callwriter
- a writer, closed after the callclosure
- the closure which returns booleans
java.io.IOException
- if an IOException occurs.public static Writable filterLine(java.io.File self, Closure closure) throws java.io.IOException
self
- a Fileclosure
- a closure which returns a boolean indicating to filter
the line or not
java.io.IOException
- if self
is not readablefilterLine(java.io.Reader, groovy.lang.Closure)
public static Writable filterLine(java.io.File self, java.lang.String charset, Closure closure) throws java.io.IOException
self
- a Filecharset
- opens the file with a specified charsetclosure
- a closure which returns a boolean indicating to filter
the line or not
java.io.IOException
- if an IOException occursfilterLine(java.io.Reader, groovy.lang.Closure)
public static void filterLine(java.io.File self, java.io.Writer writer, Closure closure) throws java.io.IOException
self
- a Filewriter
- a writer destination to write filtered lines toclosure
- a closure which takes each line as a parameter and returns
true
if the line should be written to this writer.
java.io.IOException
- if self
is not readablefilterLine(java.io.Reader, java.io.Writer, groovy.lang.Closure)
public static void filterLine(java.io.File self, java.io.Writer writer, java.lang.String charset, Closure closure) throws java.io.IOException
self
- a Filewriter
- a writer destination to write filtered lines tocharset
- opens the file with a specified charsetclosure
- a closure which takes each line as a parameter and returns
true
if the line should be written to this writer.
java.io.IOException
- if an IO error occursfilterLine(java.io.Reader, java.io.Writer, groovy.lang.Closure)
public static Writable filterLine(java.io.Reader reader, Closure closure)
true
if the line should be passed to the writer.
reader
- this readerclosure
- a closure used for filtering
public static Writable filterLine(java.io.InputStream self, Closure predicate)
true
if the line should be passed to the writer.
self
- an input streampredicate
- a closure which returns boolean and takes a line
filterLine(java.io.Reader, groovy.lang.Closure)
public static Writable filterLine(java.io.InputStream self, java.lang.String charset, Closure predicate) throws java.io.UnsupportedEncodingException
true
if the line should be passed to the writer.
self
- an input streamcharset
- opens the stream with a specified charsetpredicate
- a closure which returns boolean and takes a line
java.io.UnsupportedEncodingException
- if the encoding specified is not supportedfilterLine(java.io.Reader, groovy.lang.Closure)
public static void filterLine(java.io.InputStream self, java.io.Writer writer, Closure predicate) throws java.io.IOException
true
if the line should be passed to the
writer.
self
- the InputStreamwriter
- a writer to write output topredicate
- a closure which returns true if a line should be accepted
java.io.IOException
- if an IOException occurs.filterLine(java.io.Reader, java.io.Writer, groovy.lang.Closure)
public static void filterLine(java.io.InputStream self, java.io.Writer writer, java.lang.String charset, Closure predicate) throws java.io.IOException
true
if the line should be passed to the
writer.
self
- the InputStreamwriter
- a writer to write output tocharset
- opens the stream with a specified charsetpredicate
- a closure which returns true if a line should be accepted
java.io.IOException
- if an IOException occurs.filterLine(java.io.Reader, java.io.Writer, groovy.lang.Closure)
public static Writable filterLine(java.net.URL self, Closure predicate) throws java.io.IOException
true
if the line should be passed to the writer.
self
- a URLpredicate
- a closure which returns boolean and takes a line
java.io.IOException
- if an IO exception occursfilterLine(java.io.Reader, groovy.lang.Closure)
public static Writable filterLine(java.net.URL self, java.lang.String charset, Closure predicate) throws java.io.IOException
true
if the line should be passed to the writer.
self
- the URLcharset
- opens the URL with a specified charsetpredicate
- a closure which returns boolean and takes a line
java.io.IOException
- if an IO exception occursfilterLine(java.io.Reader, groovy.lang.Closure)
public static void filterLine(java.net.URL self, java.io.Writer writer, Closure predicate) throws java.io.IOException
true
if the line should be passed to the
writer.
self
- the URLwriter
- a writer to write output topredicate
- a closure which returns true if a line should be accepted
java.io.IOException
- if an IOException occurs.filterLine(java.io.Reader, java.io.Writer, groovy.lang.Closure)
public static void filterLine(java.net.URL self, java.io.Writer writer, java.lang.String charset, Closure predicate) throws java.io.IOException
true
if the line should be passed to the
writer.
self
- the URLwriter
- a writer to write output tocharset
- opens the URL with a specified charsetpredicate
- a closure which returns true if a line should be accepted
java.io.IOException
- if an IOException occurs.filterLine(java.io.Reader, java.io.Writer, groovy.lang.Closure)
public static byte[] readBytes(java.io.File file) throws java.io.IOException
file
- a File
java.io.IOException
- if an IOException occurs.public static java.lang.Object withStreams(java.net.Socket socket, Closure closure) throws java.io.IOException
socket
- a Socketclosure
- a Closure
java.io.IOException
- if an IOException occurs.public static java.lang.Object withObjectStreams(java.net.Socket socket, Closure closure) throws java.io.IOException
socket
- this Socketclosure
- a Closure
java.io.IOException
- if an IOException occurs.public static java.io.Writer leftShift(java.net.Socket self, java.lang.Object value) throws java.io.IOException
self
- a Socketvalue
- a value to append
java.io.IOException
- if an IOException occurs.public static java.io.OutputStream leftShift(java.net.Socket self, byte[] value) throws java.io.IOException
self
- a Socketvalue
- a value to append
java.io.IOException
- if an IOException occurs.public static java.net.Socket accept(java.net.ServerSocket serverSocket, Closure closure) throws java.io.IOException
serverSocket
- a ServerSocketclosure
- a Closure
java.io.IOException
- if an IOException occurs.ServerSocket.accept()
public static java.io.File asWritable(java.io.File file)
Writable
.
file
- a File
public static java.lang.Object asType(java.io.File f, java.lang.Class c)
Writable
or delegates to default
asType(java.lang.Object, java.lang.Class)
.
f
- a Filec
- the desired class
public static java.io.File asWritable(java.io.File file, java.lang.String encoding)
file
- a Fileencoding
- the encoding to be used when reading the file's contents
public static java.util.List<java.lang.String> toList(java.lang.String self)
self
- a String
public static char[] getChars(java.lang.String self)
self
- a String
String.toCharArray()
public static java.lang.Object asType(GString self, java.lang.Class c)
asType(java.lang.Object, java.lang.Class)
self
- a GStringc
- the desired class
public static java.lang.Object asType(java.lang.String self, java.lang.Class c)
Provides a method to perform custom 'dynamic' type conversion
to the given class using the as
operator.
'123' as Double
By default, the following types are supported:
asType(java.lang.Object, java.lang.Class)
.
self
- a Stringc
- the desired class
public static java.io.InputStream getIn(java.lang.Process self)
self
- a Process instance
public static java.lang.String getText(java.lang.Process self) throws java.io.IOException
self
- a Process instance
java.io.IOException
- if an IOException occurs.public static java.io.InputStream getErr(java.lang.Process self)
self
- a Process instance
public static java.io.OutputStream getOut(java.lang.Process self)
self
- a Process instance
public static java.io.Writer leftShift(java.lang.Process self, java.lang.Object value) throws java.io.IOException
self
- a Process instancevalue
- a value to append
java.io.IOException
- if an IOException occurs.public static java.io.OutputStream leftShift(java.lang.Process self, byte[] value) throws java.io.IOException
self
- a Process instancevalue
- data to append
java.io.IOException
- if an IOException occurs.public static void waitForOrKill(java.lang.Process self, long numberOfMillis)
self
- a ProcessnumberOfMillis
- the number of milliseconds to wait before stopping the processpublic static void consumeProcessOutput(java.lang.Process self)
self
- a Processpublic static void consumeProcessOutput(java.lang.Process self, java.lang.StringBuffer output, java.lang.StringBuffer error)
self
- a Processoutput
- a StringBuffer to capture the process stdouterror
- a StringBuffer to capture the process stderrpublic static void consumeProcessOutput(java.lang.Process self, java.io.OutputStream output, java.io.OutputStream error)
self
- a Processoutput
- an OutputStream to capture the process stdouterror
- an OutputStream to capture the process stderrpublic static void waitForProcessOutput(java.lang.Process self)
self
- a Processpublic static void waitForProcessOutput(java.lang.Process self, java.lang.StringBuffer output, java.lang.StringBuffer error)
self
- a Processoutput
- a StringBuffer to capture the process stdouterror
- a StringBuffer to capture the process stderrpublic static void waitForProcessOutput(java.lang.Process self, java.io.OutputStream output, java.io.OutputStream error)
self
- a Processoutput
- an OutputStream to capture the process stdouterror
- an OutputStream to capture the process stderrpublic static java.lang.Thread consumeProcessErrorStream(java.lang.Process self, java.lang.StringBuffer error)
self
- a Processerror
- a StringBuffer to capture the process stderr
public static java.lang.Thread consumeProcessErrorStream(java.lang.Process self, java.io.OutputStream err)
self
- a Processerr
- an OutputStream to capture the process stderr
public static java.lang.Thread consumeProcessErrorStream(java.lang.Process self, java.io.Writer err)
self
- a Processerr
- a Writer to capture the process stderr
public static java.lang.Thread consumeProcessOutputStream(java.lang.Process self, java.lang.StringBuffer output)
self
- a Processoutput
- a StringBuffer to capture the process stdout
public static java.lang.Thread consumeProcessOutputStream(java.lang.Process self, java.io.OutputStream output)
self
- a Processoutput
- an OutputStream to capture the process stdout
public static java.lang.Thread consumeProcessOutputStream(java.lang.Process self, java.io.Writer output)
self
- a Processoutput
- a Writer to capture the process stdout
public static void withWriter(java.lang.Process self, Closure closure)
self
- a Processclosure
- a closurepublic static void withOutputStream(java.lang.Process self, Closure closure)
self
- a Processclosure
- a closurepublic static java.lang.Process pipeTo(java.lang.Process left, java.lang.Process right) throws java.io.IOException
left
- a Process instanceright
- a Process to pipe output to
java.io.IOException
- if an IOException occurs.public static java.lang.Process or(java.lang.Process left, java.lang.Process right) throws java.io.IOException
left
- a Process instanceright
- a Process to pipe output to
java.io.IOException
- if an IOException occurs.public static java.lang.String eachMatch(java.lang.String self, java.lang.String regex, Closure closure)
self
- the source stringregex
- a Regex stringclosure
- a closure with one parameter or as much parameters as groups
public static java.lang.String eachMatch(java.lang.String self, java.util.regex.Pattern pattern, Closure closure)
self
- the source stringpattern
- a regex Patternclosure
- a closure with one parameter or as much parameters as groups
public static int findIndexOf(java.lang.Object self, Closure closure)
self
- the iteration object over which to iterateclosure
- the filter to perform a match on the collection
public static int findIndexOf(java.lang.Object self, int startIndex, Closure closure)
self
- the iteration object over which to iteratestartIndex
- start matching from this indexclosure
- the filter to perform a match on the collection
public static int findLastIndexOf(java.lang.Object self, Closure closure)
self
- the iteration object over which to iterateclosure
- the filter to perform a match on the collection
public static int findLastIndexOf(java.lang.Object self, int startIndex, Closure closure)
self
- the iteration object over which to iteratestartIndex
- start matching from this indexclosure
- the filter to perform a match on the collection
public static java.util.List<java.lang.Number> findIndexValues(java.lang.Object self, Closure closure)
self
- the iteration object over which to iterateclosure
- the filter to perform a match on the collection
public static java.util.List<java.lang.Number> findIndexValues(java.lang.Object self, java.lang.Number startIndex, Closure closure)
self
- the iteration object over which to iteratestartIndex
- start matching from this indexclosure
- the filter to perform a match on the collection
public static java.lang.ClassLoader getRootLoader(java.lang.ClassLoader self)
null
will be returned. The name is used for comparison because
a direct comparison using == may fail as the class may be loaded through
different classloaders.
self
- a ClassLoader
RootLoader
public static java.lang.Object asType(java.lang.Object obj, java.lang.Class type)
obj
- the object to converttype
- the goal type
public static <T> T newInstance(java.lang.Class<T> c)
c
- a class
public static <T> T newInstance(java.lang.Class<T> c, java.lang.Object[] args)
newInstance(null)
or simply
newInstance()
for the default (no-arg) constructor.
c
- a classargs
- the constructor arguments
public static MetaClass getMetaClass(java.lang.Class c)
String.metaClass.myMethod = { println "foo" }
c
- The java.lang.Class instance
public static MetaClass getMetaClass(java.lang.Object obj)
obj
- The object in question
public static MetaClass getMetaClass(GroovyObject obj)
obj
- The object in question
public static void setMetaClass(java.lang.Class self, MetaClass metaClass)
self
- the class whose metaclass we wish to setmetaClass
- the new MetaClasspublic static void setMetaClass(java.lang.Object self, MetaClass metaClass)
self
- the object whose metaclass we want to setmetaClass
- the new metaclass valuepublic static MetaClass metaClass(java.lang.Class self, Closure closure)
self
- the class whose metaclass we wish to updateclosure
- the closure representing the new metaclass
GroovyRuntimeException
- if the metaclass can't be set for this classpublic static MetaClass metaClass(java.lang.Object self, Closure closure)
self
- the object whose metaclass we wish to updateclosure
- the closure representing the new metaclass
GroovyRuntimeException
- if the metaclass can't be set for this objectpublic static <T> java.util.Iterator<T> iterator(T[] a)
a
- an array
DefaultTypeTransformation.asCollection(java.lang.Object[])
public static java.util.Iterator iterator(java.lang.Object o)
o
- an object
DefaultTypeTransformation.asCollection(java.lang.Object)
public static <T> java.util.Iterator<T> iterator(java.util.Enumeration<T> enumeration)
remove()
method is unsupported since the
underlying Enumeration does not provide a mechanism for removing items.
enumeration
- an Enumeration object
public static java.util.Iterator iterator(java.util.regex.Matcher matcher)
Iterator
which traverses each match.
matcher
- a Matcher object
Matcher.group()
public static java.util.Iterator<java.lang.String> iterator(java.io.Reader self)
self
- a Reader object
BufferedReader.readLine()
public static java.util.Iterator<java.lang.Byte> iterator(java.io.InputStream self)
self
- an InputStream object
public static java.util.Iterator<java.lang.Byte> iterator(java.io.DataInputStream self)
self
- a DataInputStream object
public static java.util.Iterator iterator(java.io.File self) throws java.io.IOException
self
- a file object
java.io.IOException
- if there is a problem processing the file (e.g. file is not found)public static <T> java.util.Iterator<T> iterator(java.util.Iterator<T> self)
self
- an iterator object
public static java.util.List respondsTo(java.lang.Object self, java.lang.String name, java.lang.Object[] argTypes)
Returns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name and arguments types.
Note that this method's return value is based on realised methods and does not take into account objects or classes that implement invokeMethod or methodMissing
This method is "safe" in that it will always return a value and never throw an exception
self
- The object to inspectname
- The name of the method of interestargTypes
- The argument types to match against
MetaObjectProtocol.respondsTo(java.lang.Object, java.lang.String, java.lang.Object[])
public static java.util.List respondsTo(java.lang.Object self, java.lang.String name)
Returns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name regardless of the arguments.
Note that this method's return value is based on realised methods and does not take into account objects or classes that implement invokeMethod or methodMissing
This method is "safe" in that it will always return a value and never throw an exception
self
- The object to inspectname
- The name of the method of interest
MetaObjectProtocol.respondsTo(java.lang.Object, java.lang.String)
public static MetaProperty hasProperty(java.lang.Object self, java.lang.String name)
Returns true of the implementing MetaClass has a property of the given name
Note that this method will only return true for realised properties and does not take into account implementation of getProperty or propertyMissing
self
- The object to inspectname
- The name of the property of interest
MetaObjectProtocol.hasProperty(java.lang.Object, java.lang.String)
@Deprecated public static java.util.Iterator<org.w3c.dom.Node> iterator(org.w3c.dom.NodeList nodeList)
XmlGroovyMethods.iterator(org.w3c.dom.NodeList)
@Deprecated public static GroovyRowResult toRowResult(java.sql.ResultSet rs) throws java.sql.SQLException
SqlGroovyMethods.toRowResult(java.sql.ResultSet)
java.sql.SQLException
@Deprecated public static Writable encodeBase64(java.lang.Byte[] data, boolean chunked)
EncodingGroovyMethods.encodeBase64(java.lang.Byte[], boolean)
@Deprecated public static Writable encodeBase64(java.lang.Byte[] data)
EncodingGroovyMethods.encodeBase64(java.lang.Byte[])
@Deprecated public static Writable encodeBase64(byte[] data, boolean chunked)
EncodingGroovyMethods.encodeBase64(byte[], boolean)
@Deprecated public static Writable encodeBase64(byte[] data)
EncodingGroovyMethods.encodeBase64(byte[])
@Deprecated public static byte[] decodeBase64(java.lang.String value)
EncodingGroovyMethods.decodeBase64(java.lang.String)
@Deprecated public static java.util.Date next(java.util.Date self)
DateGroovyMethods.next(java.util.Date)
@Deprecated public static java.sql.Date next(java.sql.Date self)
DateGroovyMethods.next(java.sql.Date)
@Deprecated public static java.util.Date previous(java.util.Date self)
DateGroovyMethods.previous(java.util.Date)
@Deprecated public static java.sql.Date previous(java.sql.Date self)
DateGroovyMethods.previous(java.sql.Date)
@Deprecated public static java.util.Date plus(java.util.Date self, int days)
DateGroovyMethods.plus(java.util.Date, int)
@Deprecated public static java.sql.Date plus(java.sql.Date self, int days)
DateGroovyMethods.plus(java.sql.Date, int)
@Deprecated public static java.util.Date minus(java.util.Date self, int days)
DateGroovyMethods.minus(java.util.Date, int)
@Deprecated public static java.sql.Date minus(java.sql.Date self, int days)
DateGroovyMethods.minus(java.sql.Date, int)
@Deprecated public static int minus(java.util.Calendar self, java.util.Calendar then)
DateGroovyMethods.minus(java.util.Calendar, java.util.Calendar)
@Deprecated public static int minus(java.util.Date self, java.util.Date then)
DateGroovyMethods.minus(java.util.Date, java.util.Date)
@Deprecated public static java.lang.String format(java.util.Date self, java.lang.String format)
DateGroovyMethods.format(java.util.Date, java.lang.String)
@Deprecated public static java.lang.String getDateString(java.util.Date self)
DateGroovyMethods.getDateString(java.util.Date)
@Deprecated public static java.lang.String getTimeString(java.util.Date self)
DateGroovyMethods.getTimeString(java.util.Date)
@Deprecated public static java.lang.String getDateTimeString(java.util.Date self)
DateGroovyMethods.getDateTimeString(java.util.Date)
@Deprecated public static void clearTime(java.util.Date self)
DateGroovyMethods.clearTime(java.util.Date)
@Deprecated public static void clearTime(java.sql.Date self)
DateGroovyMethods.clearTime(java.sql.Date)
@Deprecated public static void clearTime(java.util.Calendar self)
DateGroovyMethods.clearTime(java.util.Calendar)
@Deprecated public static java.lang.String format(java.util.Calendar self, java.lang.String pattern)
DateGroovyMethods.format(java.util.Calendar, java.lang.String)
@Deprecated public static int getAt(java.util.Date self, int field)
DateGroovyMethods.getAt(java.util.Date, int)
|
Copyright © 2003-2010 The Codehaus. All rights reserved. | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |