org.codehaus.groovy.runtime
Class DefaultGroovyMethods

java.lang.Object
  extended by org.codehaus.groovy.runtime.DefaultGroovyMethodsSupport
      extended by org.codehaus.groovy.runtime.DefaultGroovyMethods

public class DefaultGroovyMethods
extends DefaultGroovyMethodsSupport

This class defines all the new groovy methods which appear on normal JDK classes inside the Groovy environment. Static methods are used with the first parameter the destination class.

Version:
$Revision: 15440 $
Author:
James Strachan, Jeremy Rayner, Sam Pullara, Rod Cope, Guillaume Laforge, John Wilson, Hein Meling, Dierk Koenig, Pilho Kim, Marc Guillemot, Russel Winder, bing ran, Jochen Theodorou, Paul King, Michael Baehr, Joachim Baumann

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
 
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 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)
           
static java.lang.Number and(java.lang.Number left, java.lang.Number right)
          Bitwise AND together two Numbers.
static boolean any(java.util.Map 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 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 java.util.Collection asImmutable(java.util.Collection self)
          A convenience method for creating an immutable Collection.
static java.util.List asImmutable(java.util.List self)
          A convenience method for creating an immutable list
static java.util.Map asImmutable(java.util.Map self)
          A convenience method for creating an immutable map.
static java.util.Set asImmutable(java.util.Set self)
          A convenience method for creating an immutable list.
static java.util.SortedMap asImmutable(java.util.SortedMap self)
          A convenience method for creating an immutable sorted map.
static java.util.SortedSet asImmutable(java.util.SortedSet self)
          A convenience method for creating an immutable sorted set.
static java.util.List asList(java.util.Collection self)
          Converts this collection to a List.
static java.util.Collection asSynchronized(java.util.Collection self)
          A convenience method for creating a synchronized Collection.
static java.util.List asSynchronized(java.util.List self)
          A convenience method for creating a synchronized List.
static java.util.Map asSynchronized(java.util.Map self)
          A convenience method for creating a synchronized Map.
static java.util.Set asSynchronized(java.util.Set self)
          A convenience method for creating a synchronized Set.
static java.util.SortedMap asSynchronized(java.util.SortedMap self)
          A convenience method for creating a synchronized SortedMap.
static java.util.SortedSet asSynchronized(java.util.SortedSet 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(Object,Class).
static java.lang.Object asType(GString self, java.lang.Class c)
          Converts the GString to a File, or delegates to the default asType(Object,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 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 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 void 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 void 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 void 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 void 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 void 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 void 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(Object) to make Strings more polymorphic.
static int count(java.util.Collection self, java.lang.Object value)
          Counts the number of occurrences of the given value inside this collection.
static int 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 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)
          Decode the String from Base64 into a byte array.
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 java.lang.Number div(java.lang.Number left, java.lang.Number right)
          Divide two Numbers.
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 java.util.Map each(java.util.Map self, Closure closure)
          Allows a Map to be iterated through using a closure.
static java.util.regex.Matcher each(java.util.regex.Matcher self, Closure closure)
          Process each matched substring of the given group matcher.
static java.lang.Object each(java.lang.Object 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.InputStream is, Closure closure)
          Traverse through each byte of the specified stream.
static void eachByte(java.net.URL url, Closure closure)
          Reads the InputStream from this URL, passing each byte to the given closure.
static void eachDir(java.io.File self, Closure closure)
          Invokes the closure for each directory in this directory, ignoring regular files.
static void eachDirMatch(java.io.File self, java.lang.Object filter, Closure closure)
          Invokes the closure for each directory whose name (dir.name) matches the given filter in the given directory - calling the isCase() 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 file in the given directory
static void eachFileMatch(java.io.File self, java.lang.Object filter, Closure closure)
          Invokes the closure for each file whose name (file.name) matches the given filter in the given directory - calling the isCase() 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 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.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 void 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 java.lang.Object eachWithIndex(java.util.Map 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)
          Produce a Writable object which writes the Base64 encoding of the byte array.
static Writable encodeBase64(java.lang.Byte[] data)
          Produce a Writable object which writes the Base64 encoding of the byte array.
static Writable encodeBase64(byte[] data, boolean chunked)
          Produce a Writable object which writes the Base64 encoding of the byte array.
static Writable encodeBase64(java.lang.Byte[] data, boolean chunked)
          Produce a Writable object which writes the Base64 encoding of the byte array.
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 boolean every(java.util.Map 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 commandList)
          Executes the command specified by the String list that is the parameter.
static java.lang.Process execute(java.lang.String self)
          Executes the given string as a command line process.
static java.lang.Process execute(java.lang.String[] commandArray)
          Executes the command specified by the String array that is the parameter.
static java.lang.Process execute(java.lang.String self, java.util.List envp, java.io.File dir)
          Executes the command specified by the self with environments envp 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 the self with environments envp under the working directory dir.
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 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 Writable filterLine(java.io.InputStream self, 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 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 java.lang.Object find(java.util.Collection self, Closure closure)
          Finds the first value matching the closure condition.
static java.lang.Object find(java.util.Map 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.util.Collection findAll(java.util.Collection self, Closure closure)
          Finds all values matching the closure condition.
static java.util.Map findAll(java.util.Map 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 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 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 findIndexValues(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 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 java.lang.Object first(java.util.List self)
          Returns the first item from the List.
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.Date self, java.lang.String format)
          Create a String representation of this date according to the given pattern.
static java.lang.Object get(java.util.Map map, java.lang.Object key, java.lang.Object 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.lang.Object getAt(boolean[] array, java.util.Collection indices)
          Support the subscript operator with a collection for a boolean array
static java.lang.Object getAt(boolean[] array, int index)
          Support the subscript operator for a boolean array
static java.lang.Object getAt(boolean[] array, IntRange range)
          Support the subscript operator with an IntRange for a boolean array
static java.lang.Object getAt(boolean[] array, ObjectRange range)
          Support the subscript operator with an ObjectRange for a byte array
static java.lang.Object getAt(boolean[] array, Range range)
          Support the subscript operator with a range for a boolean array
static java.lang.Object getAt(byte[] array, java.util.Collection indices)
          Support the subscript operator with a collection for a byte array
static java.lang.Object getAt(byte[] array, int index)
          Support the subscript operator for a byte array
static java.lang.Object getAt(byte[] array, IntRange range)
          Support the subscript operator with an IntRange for a byte array
static java.lang.Object getAt(byte[] array, ObjectRange range)
          Support the subscript operator with an ObjectRange for a byte array
static java.lang.Object getAt(byte[] array, Range range)
          Support the subscript operator with a range for a byte array
static java.lang.Object getAt(char[] array, java.util.Collection indices)
          Support the subscript operator with a collection for a char array
static java.lang.Object getAt(char[] array, int index)
          Support the subscript operator for a char array
static java.lang.Object getAt(char[] array, IntRange range)
          Support the subscript operator with an IntRange for a char array
static java.lang.Object getAt(char[] array, ObjectRange range)
          Support the subscript operator with an ObjectRange for a char array
static java.lang.Object 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
static int getAt(java.util.Date self, int field)
          Support the subscript operator for a Date.
static java.lang.Object getAt(double[] array, java.util.Collection indices)
          Support the subscript operator with a collection for a double array
static java.lang.Object getAt(double[] array, int index)
          Support the subscript operator for a double array
static java.lang.Object getAt(double[] array, IntRange range)
          Support the subscript operator with an IntRange for a double array
static java.lang.Object getAt(double[] array, ObjectRange range)
          Support the subscript operator with an ObjectRange for a double array
static java.lang.Object getAt(double[] array, Range range)
          Support the subscript operator with a range for a double array
static java.lang.Object getAt(float[] array, java.util.Collection indices)
          Support the subscript operator with a collection for a float array
static java.lang.Object getAt(float[] array, int index)
          Support the subscript operator for a float array
static java.lang.Object getAt(float[] array, IntRange range)
          Support the subscript operator with an IntRange for a float array
static java.lang.Object getAt(float[] array, ObjectRange range)
          Support the subscript operator with an ObjectRange for a float array
static java.lang.Object getAt(float[] array, Range range)
          Support the subscript operator with a range for a float array
static java.lang.Object getAt(int[] array, java.util.Collection indices)
          Support the subscript operator with a collection for an int array
static java.lang.Object getAt(int[] array, int index)
          Support the subscript operator for an int array
static java.lang.Object getAt(int[] array, IntRange range)
          Support the subscript operator with an IntRange for an int array
static java.lang.Object getAt(int[] array, ObjectRange range)
          Support the subscript operator with an ObjectRange for an int array
static java.lang.Object getAt(int[] array, Range range)
          Support the subscript operator with a range for an int array
static java.util.List getAt(java.util.List self, java.util.Collection indices)
          Select a List of items from a List using a Collection to identify the indices to be selected.
static java.lang.Object getAt(java.util.List self, int idx)
          Support the subscript operator for a List.
static java.util.List getAt(java.util.List self, IntRange range)
          Support the range subscript operator for a List
static java.lang.Object getAt(long[] array, java.util.Collection indices)
          Support the subscript operator with a collection for a long array
static java.lang.Object getAt(long[] array, int index)
          Support the subscript operator for a long array
static java.lang.Object getAt(long[] array, IntRange range)
          Support the subscript operator with an IntRange for a long array
static java.lang.Object getAt(long[] array, ObjectRange range)
          Support the subscript operator with an ObjectRange for a long array
static java.lang.Object getAt(long[] array, Range range)
          Support the subscript operator with a range for a long array
static java.lang.Object getAt(java.util.Map self, java.lang.Object key)
          Support the subscript operator for a Map.
static java.lang.String 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.util.List getAt(java.lang.Object[] 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 java.util.List getAt(java.lang.Object[] array, EmptyRange range)
           
static java.lang.Object getAt(java.lang.Object[] array, int idx)
          Support the subscript operator for an Array.
static java.util.List getAt(java.lang.Object[] array, IntRange range)
           
static java.util.List getAt(java.lang.Object[] array, ObjectRange range)
           
static java.util.List getAt(java.lang.Object[] array, Range range)
          Support the range subscript operator for an Array
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.lang.Object getAt(short[] array, java.util.Collection indices)
          Support the subscript operator with a collection for a short array
static java.lang.Object getAt(short[] array, int index)
          Support the subscript operator for a short array
static java.lang.Object getAt(short[] array, IntRange range)
          Support the subscript operator with an IntRange for a short array
static java.lang.Object getAt(short[] array, ObjectRange range)
          Support the subscript operator with an ObjectRange for a short array
static java.lang.Object 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 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)
          Return a string representation of the 'day' portion of this date according to the locale-specific DateFormat.SHORT default format.
static java.lang.String getDateTimeString(java.util.Date self)
          Return a string representation of the date and time time portion of this Date instance, according to the locale-specific format used by DateFormat.
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(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 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(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)
          Return a string representation of the time portion of this date according to the locale-specific DateFormat.MEDIUM default format.
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 isCase(Object,Object) method used by switch statements.
protected static void groupAnswer(java.util.Map answer, java.lang.Object element, java.lang.Object value)
          Groups the current element according to the value
static java.util.Map groupBy(java.util.Collection self, Closure closure)
          Sorts all collection members into groups determined by the supplied mapping closure.
static java.util.Map groupBy(java.util.Map self, Closure closure)
          Groups the members of a map into sub maps determined by the supplied mapping closure.
static java.util.Map groupEntriesBy(java.util.Map 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 java.lang.Object head(java.util.List self)
          Returns the first item from the List.
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 java.util.Collection intersect(java.util.Collection left, java.util.Collection right)
          Create a Collection composed of the intersection of both collections.
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 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(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 iterator(java.io.DataInputStream self)
          Standard iterator for a data input stream which iterates through the stream content a byte at a time.
static java.util.Iterator iterator(java.util.Enumeration 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 iterator(java.io.InputStream self)
          Standard iterator for a input stream which iterates through the stream content in a byte-based fashion.
static java.util.Iterator iterator(java.util.Iterator 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)
          Retuns an Iterator which traverses each match.
static java.util.Iterator iterator(org.w3c.dom.NodeList nodeList)
          Makes NodeList iterable by returning a read-only Iterator which traverses over each Node.
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 iterator(java.io.Reader self)
          Creates an iterator which will traverse through the reader a line at a time.
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 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 java.lang.Object last(java.util.List self)
          Returns the last item from the List.
static java.util.Collection leftShift(java.util.Collection self, java.lang.Object 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.lang.Object text)
          Write the text to the File.
static java.util.Map leftShift(java.util.Map self, java.util.Map.Entry entry)
          Overloads the left shift operator to provide an easy way to append Map.Entry values to a 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 java.lang.Object max(java.util.Collection self)
          Adds max() method to Collection objects.
static java.lang.Object max(java.util.Collection self, Closure closure)
          Selects the maximum value found in the collection using the given closure as a comparator.
static java.lang.Object max(java.util.Collection self, java.util.Comparator comparator)
          Selects the maximum value found in the collection using the given comparator.
static java.lang.Object max(java.util.Iterator self)
          Adds max() method to Iterator objects.
static java.lang.Object max(java.util.Iterator self, Closure closure)
          Selects the maximum value found from the Iterator using the given closure as a comparator.
static java.lang.Object max(java.util.Iterator self, java.util.Comparator comparator)
          Selects the maximum value found from the Iterator using the given comparator.
static java.lang.Object max(java.lang.Object[] self)
          Adds max() method to Object arrays.
static java.lang.Object max(java.lang.Object[] self, Closure closure)
          Selects the maximum value found from the Object array using the given closure as a comparator.
static java.lang.Object max(java.lang.Object[] self, java.util.Comparator comparator)
          Selects the maximum value found from the Object array using the given comparator.
static java.lang.Object min(java.util.Collection self)
          Adds min() method to Collection objects.
static java.lang.Object min(java.util.Collection self, Closure closure)
          Selects the minimum value found in the collection using the given closure as a comparator.
static java.lang.Object min(java.util.Collection self, java.util.Comparator comparator)
          Selects the minimum value found in the collection using the given comparator.
static java.lang.Object min(java.util.Iterator self)
          Adds min() method to Iterator objects.
static java.lang.Object min(java.util.Iterator self, Closure closure)
          Selects the minimum value found from the Iterator using the given closure as a comparator.
static java.lang.Object min(java.util.Iterator self, java.util.Comparator comparator)
          Selects the minimum value found from the Iterator using the given comparator.
static java.lang.Object min(java.lang.Object[] self)
          Adds min() method to Object arrays.
static java.lang.Object min(java.lang.Object[] self, Closure closure)
          Selects the minimum value found from the Object array using the given closure as a comparator.
static java.lang.Object min(java.lang.Object[] self, java.util.Comparator 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)
          Subtract another date from this one and return the number of days of the difference.
static java.lang.Number minus(java.lang.Character left, java.lang.Character right)
          Subtract one Characters from another by converting them both to their Integer representations.
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)
          Subtract another Date from this one and return the number of days of the difference.
static java.util.Date minus(java.util.Date self, int days)
          Subtract a number of days from this date and returns the new date.
static java.sql.Date minus(java.sql.Date self, int days)
          Subtract a number of days from this date and returns the new date.
static java.util.List minus(java.util.List self, java.util.Collection removeMe)
          Create a List composed of the elements of the first list minus the elements of the given collection.
static java.util.List minus(java.util.List self, java.lang.Object operand)
          Create a new List composed of the elements of the first list minus the operand.
static java.lang.Number minus(java.lang.Number left, java.lang.Character right)
          Subtract a Character from a Number.
static java.lang.Number minus(java.lang.Number left, java.lang.Number right)
          Substraction of two Numbers.
static java.lang.Object[] minus(java.lang.Object[] self, java.util.Collection removeMe)
          Create an array composed of the elements of the first array minus the elements of the given collection.
static java.lang.Object[] minus(java.lang.Object[] self, java.lang.Object operand)
          Create a new object array composed of the elements of the first array minus the operand.
static java.lang.Object[] minus(java.lang.Object[] self, java.lang.Object[] removeMe)
          Create an array composed of the elements of the first array minus the elements of the given array.
static java.util.Set minus(java.util.Set self, java.util.Collection operands)
          Create a Set composed of the elements of the first set minus the elements of the given collection.
static java.util.Set minus(java.util.Set 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 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 java.util.List multiply(java.util.Collection 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.Number multiply(java.lang.Number left, java.lang.Number right)
          Multiply two Numbers.
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 java.lang.Object newInstance(java.lang.Class c)
          Convenience method to dynamically create a new instance of this class.
static java.lang.Object newInstance(java.lang.Class 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.ObjectOutputStream newObjectOutputStream(java.io.File file)
          Create an object output stream for this file.
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.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)
          Increment a Date by one day.
static java.sql.Date next(java.sql.Date self)
          Increment a java.sql.Date by one day.
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)
           
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 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 two Characters.
static java.lang.Number plus(java.lang.Character left, java.lang.Number right)
          Add a Character and a Number.
static java.util.Collection plus(java.util.Collection left, java.util.Collection right)
          Create a Collection as a union of two collections.
static java.util.Collection plus(java.util.Collection left, java.lang.Object right)
          Create a collection as a union of a Collection and an Object.
static java.util.Date plus(java.util.Date self, int days)
          Add a number of days to this date and returns the new date.
static java.sql.Date plus(java.sql.Date self, int days)
          Add a number of days to this date and returns the new date.
static java.util.Map plus(java.util.Map left, java.util.Map 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.Number plus(java.lang.Number left, java.lang.Number right)
          Add two numbers and return the result.
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 java.lang.Object pop(java.util.List 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)
          Decrement a Date by one day.
static java.sql.Date previous(java.sql.Date self)
          Decrement a java.sql.Date by one day.
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 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 printf(java.lang.Object self, java.lang.String format, java.lang.Object arg)
          Prints a formatted string using the specified format string and arguments (Only works with JDK1.5 or later).
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 (followed by a newline) to the standard output stream.
static void println(java.lang.Object self, java.io.PrintWriter out)
          Print to a console in interactive format.
static boolean push(java.util.List self, java.lang.Object value)
          Appends an item to the List.
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 java.lang.Boolean putAt(boolean[] array, int idx, java.lang.Boolean newValue)
           
static java.lang.Byte putAt(byte[] array, int idx, java.lang.Object newValue)
           
static java.lang.Character putAt(char[] array, int idx, java.lang.Object newValue)
           
static java.lang.Double putAt(double[] array, int idx, java.lang.Object newValue)
           
static java.lang.Float putAt(float[] array, int idx, java.lang.Object newValue)
           
static java.lang.Integer putAt(int[] array, int idx, java.lang.Object newValue)
           
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, int idx, 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)
          Deprecated. replace with putAt(List self, Range range, List value)
static void putAt(java.util.List self, java.util.List splice, java.lang.Object value)
          Deprecated. replace with putAt(List self, Range range, Object value)
static java.lang.Long putAt(long[] array, int idx, java.lang.Object newValue)
           
static java.lang.Object putAt(java.util.Map self, java.lang.Object key, java.lang.Object value)
          A helper method to allow lists to work with subscript operators
static void putAt(java.lang.Object[] array, int idx, java.lang.Object value)
          Support the subscript operator for an Array.
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 java.lang.Short putAt(short[] array, int idx, java.lang.Object newValue)
           
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 readLines(java.io.File file)
          Reads the file into a list of Strings, with one item for each line.
static java.util.List readLines(java.io.InputStream stream)
          Reads the stream into a list, with one element for each line.
static java.util.List readLines(java.io.Reader reader)
          Reads the reader into a list of Strings, with one entry for each line.
static java.util.List readLines(java.lang.String self)
          Return the lines of a String as a List of Strings.
static java.lang.String replace(java.lang.String self, java.lang.CharSequence target, java.lang.CharSequence replacement)
          Replaces all occurrences of a literal string with another literal string.
static java.lang.String replaceAll(java.lang.String self, java.lang.String regex, Closure closure)
          Replaces all occurrances of a captured group by the result of a closure on that text.
static java.util.Iterator reverse(java.util.Iterator self)
          Reverses the iterator.
static java.util.List reverse(java.util.List self)
          Reverses the list.
static java.lang.Object[] reverse(java.lang.Object[] self)
          Reverse the items in an Object array.
static java.lang.String reverse(java.lang.String self)
          Creates a new string which is the reverse (backwards) of this string
static java.util.List reverseEach(java.util.List self, Closure closure)
          Iterate over each element of the list in the reverse order.
static java.lang.Object[] reverseEach(java.lang.Object[] 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 int round(java.lang.Float number)
          Get the absolute value
static java.util.TimerTask runAfter(java.util.Timer timer, int delay, Closure closure)
          Allows a simple syntax for using timers.
static void setIndex(java.util.regex.Matcher matcher, int idx)
          Set the position of the given Matcher to the given index.
static void setText(java.io.File file, java.lang.String text)
          Synonym for write(text) allowing file.text = 'foo'.
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 java.util.List sort(java.util.Collection self)
          Sorts the given collection into a sorted list.
static java.util.List sort(java.util.Collection self, Closure closure)
          Sorts this Collection using the given closure as a comparator.
static java.util.List sort(java.util.Collection self, java.util.Comparator comparator)
          Sorts the Collection using the given comparator.
static java.util.Iterator sort(java.util.Iterator self)
          Sorts the given iterator items into a sorted iterator.
static java.util.Iterator sort(java.util.Iterator self, Closure closure)
          Sorts the given iterator items into a sorted iterator using the closure as a comparator.
static java.util.Iterator sort(java.util.Iterator self, java.util.Comparator comparator)
          Sorts the given iterator items into a sorted iterator using the comparator.
static java.util.Map sort(java.util.Map self, Closure closure)
          Sorts the given map into a sorted map using the closure as a comparator.
static java.lang.Object[] sort(java.lang.Object[] self)
          Sorts the given Object array into sorted order.
static java.lang.Object[] sort(java.lang.Object[] self, Closure closure)
          Sorts the given Object array into a newly created array using the given comparator.
static java.lang.Object[] sort(java.lang.Object[] self, java.util.Comparator comparator)
          Sorts the given Object array into sorted order using the given comparator.
static java.util.SortedSet sort(java.util.SortedSet self)
          Avoids doing unnecessary work when sorting an already sorted set.
static java.util.Collection split(java.util.Collection 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.lang.String sep, Closure closure)
          Iterates through this file line by line, splitting on the seperator.
static java.lang.Object splitEachLine(java.io.InputStream stream, java.lang.String sep, 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 sep, 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.lang.String sep, Closure closure)
          Iterates through the given reader line by line, splitting each line using the given separator.
static java.lang.Object splitEachLine(java.lang.String self, java.lang.String sep, Closure closure)
          Iterates through the given String line by line, splitting each line using the given separator.
static SpreadMap spread(java.util.Map self)
          Synonym for toSpreadMap(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.util.Map subMap(java.util.Map map, java.util.Collection keys)
          Creates a sub-Map containing the given keys.
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 apply a closure to each item of a collection to sum intial value.
static java.lang.Object sum(java.util.Iterator self)
          Sums the items from an Iterator.
static java.lang.Object sum(java.util.Iterator self, java.lang.Object initialValue)
          Sums the items from an Iterator.
static java.util.List tail(java.util.List self)
          Returns the items from the List 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.String token)
          Tokenize a String based on the given string delimiter.
static java.util.List toList(boolean[] array)
          Converts this array to a List of the same size, with each element added to the list.
static java.util.List toList(byte[] array)
          Converts this array to a List of the same size, with each element added to the list.
static java.util.List toList(char[] array)
          Converts this array to a List of the same size, with each element added to the list.
static java.util.List toList(java.util.Collection self)
          Convert a collection to a List.
static java.util.List toList(double[] array)
          Converts this array to a List of the same size, with each element added to the list.
static java.util.List toList(java.util.Enumeration self)
          Convert an enumeration to a List.
static java.util.List toList(float[] array)
          Converts this array to a List of the same size, with each element added to the list.
static java.util.List toList(int[] array)
          Converts this array to a List of the same size, with each element added to the list.
static java.util.List toList(java.util.Iterator self)
          Convert an iterator to a List.
static java.util.List toList(long[] array)
          Converts this array to a List of the same size, with each element added to the list.
static java.util.List toList(java.lang.Object[] array)
          Allows conversion of arrays into a mutable List.
static java.util.List toList(short[] array)
          Converts this array to a List of the same size, with each element added to the list.
static java.util.List toList(java.lang.String self)
          Converts the given String into a List of strings of one character.
static java.lang.String toListString(java.util.Collection self)
          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 GroovyRowResult toRowResult(java.sql.ResultSet rs)
          Returns a GroovyRowResult given a 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.Collection self)
          Returns the string representation of the given collection.
static java.lang.String toString(java.util.Map self)
          Returns the string representation of the given map.
protected 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 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 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 java.lang.Number unaryMinus(java.lang.Number left)
          Negates the number.
static java.util.Collection unique(java.util.Collection self)
          Modifies this collection to remove all duplicated items, using the default comparator.
static java.util.Collection unique(java.util.Collection self, Closure closure)
          A convenience method for making a collection unique using a closure as a comparator.
static java.util.Collection unique(java.util.Collection self, java.util.Comparator comparator)
          Remove all duplicates from a given Collection.
static java.util.Iterator unique(java.util.Iterator self)
          Returns an iterator equivalent to this iterator all duplicated items removed by using the default comparator.
static java.util.Iterator unique(java.util.Iterator self, Closure closure)
          Returns an iterator equivalent to this iterator all duplicated items removed by using a closure as a comparator.
static java.util.Iterator unique(java.util.Iterator self, java.util.Comparator 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 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 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 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, 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 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 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)
           
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, createSimilarCollection, createSimilarCollection, createSimilarList, createSimilarOrDefaultCollection, createSimilarSet, normaliseIndex, sameType, subListBorders, subListBorders
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultGroovyMethods

public DefaultGroovyMethods()
Method Detail

is

public static boolean is(java.lang.Object self,
                         java.lang.Object other)
Identity check. Since == is overridden in Groovy with the meaning of equality we need some fallback to check for object identity. Invoke using the 'is' operator, like so: def same = (this is that)

Parameters:
self - an object
other - an object to compare identity with
Returns:
true if self and other are both references to the same instance, false otherwise

identity

public 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()'.

Parameters:
self - the object to have a closure act upon
closure - the closure to call on the object
Returns:
result of calling the closure

with

public static java.lang.Object with(java.lang.Object self,
                                    Closure closure)
Allows the closure to be called for the object reference self

Parameters:
self - the object to have a closure act upon
closure - the closure to call on the object
Returns:
result of calling the closure

getAt

public static java.lang.Object getAt(java.lang.Object self,
                                     java.lang.String property)
Allows the subscript operator to be used to lookup dynamic property values. bean[somePropertyNameExpression]. The normal property notation of groovy is neater and more concise but only works with compile-time known property names.

Parameters:
self - the object to act upon
property - the property name of interest
Returns:
the property value

putAt

public static void putAt(java.lang.Object self,
                         java.lang.String property,
                         java.lang.Object newValue)
Allows the subscript operator to be used to set dynamically named property values. bean[somePropertyNameExpression] = foo. The normal property notation of groovy is neater and more concise but only works with property names which are known at compile time.

Parameters:
self - the object to act upon
property - the name of the property to set
newValue - the value to set

dump

public static java.lang.String dump(java.lang.Object self)
Generates a detailed dump string of an object showing its class, hashCode and fields.

Parameters:
self - an object
Returns:
the dump representation

getMetaPropertyValues

public static java.util.List 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'.

Parameters:
self - the receiver object
Returns:
list of PropertyValue objects
See Also:
Expando.getMetaPropertyValues()

getProperties

public static java.util.Map getProperties(java.lang.Object self)
Convenience method that calls getMetaPropertyValues(Object)(self) and provides the data in form of simple key/value pairs, i.e.&nsbp;without type() information.

Parameters:
self - the receiver object
Returns:
meta properties as Map of key/value pairs

use

public static java.lang.Object use(java.lang.Object self,
                                   java.lang.Class categoryClass,
                                   Closure closure)
Scoped use method

Parameters:
self - any Object
categoryClass - a category class to use
closure - the closure to invoke with the category in place
Returns:
the value returned from the closure

use

public static java.lang.Object use(java.lang.Object self,
                                   java.util.List categoryClassList,
                                   Closure closure)
Scoped use method with list of categories.

Parameters:
self - any Object
categoryClassList - a list of category classes
closure - the closure to invoke with the categories in place
Returns:
the value returned from the closure

addShutdownHook

public static void addShutdownHook(java.lang.Object self,
                                   Closure closure)
Allows the usage of addShutdownHook without getting the runtime first.

Parameters:
self - the object the method is called on (ignored)
closure - the shutdown hook action

use

public static java.lang.Object use(java.lang.Object self,
                                   java.lang.Object[] array)
Allows you to use a list of categories, specifying the list as varargs. use(CategoryClass1, CategoryClass2) { ... } This method saves having to wrap the the category classes in a list.

Parameters:
self - any Object
array - a list of category classes and a Closure
Returns:
the value returned from the closure

print

public static void print(java.lang.Object self,
                         java.lang.Object value)
Print a value to the standard output stream.

Parameters:
self - any Object
value - the value to print

print

public static void print(Closure self,
                         java.lang.Object value)
Print a value to the standard output stream. This method delegates to the owner to execute the method.

Parameters:
self - a generated closure
value - the value to print

println

public static void println(java.lang.Object self)
Print a linebreak to the standard output stream.

Parameters:
self - any Object

println

public static void println(Closure self)
Print a linebreak to the standard output stream. This method delegates to the owner to execute the method.

Parameters:
self - a closure

println

public static void println(java.lang.Object self,
                           java.lang.Object value)
Print a value (followed by a newline) to the standard output stream.

Parameters:
self - any Object
value - the value to print

println

public static void println(Closure self,
                           java.lang.Object value)
Print a value (followed by a newline) to the standard output stream. This method delegates to the owner to execute the method.

Parameters:
self - a closure
value - the value to print

printf

public 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).

Parameters:
self - any Object
format - a format string
values - values referenced by the format specifiers in the format string.

sprintf

public 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).

Parameters:
self - any Object
format - a format string
values - values referenced by the format specifiers in the format string.
Returns:
the resulting formatted string

printf

public static void printf(java.lang.Object self,
                          java.lang.String format,
                          java.lang.Object arg)
Prints a formatted string using the specified format string and arguments (Only works with JDK1.5 or later).

For examples,

     printf ( "Hello, %s!\n" , [ "world" ] as String[] )
     printf ( "Hello, %s!\n" , [ "Groovy" ])
     printf ( "%d + %d = %d\n" , [ 1 , 2 , 1+2 ] as Integer[] )
     printf ( "%d + %d = %d\n" , [ 3 , 3 , 3+3 ])
 

( 1..5 ).each { printf ( "-- %d\n" , [ it ] as Integer[] ) } ( 1..5 ).each { printf ( "-- %d\n" , [ it ] as int[] ) } ( 0x41..0x45 ).each { printf ( "-- %c\n" , [ it ] as char[] ) } ( 07..011 ).each { printf ( "-- %d\n" , [ it ] as byte[] ) } ( 7..11 ).each { printf ( "-- %d\n" , [ it ] as short[] ) } ( 7..11 ).each { printf ( "-- %d\n" , [ it ] as long[] ) } ( 7..11 ).each { printf ( "-- %5.2f\n" , [ it ] as float[] ) } ( 7..11 ).each { printf ( "-- %5.2g\n" , [ it ] as double[] ) }

Parameters:
self - any Object
format - A format string
arg - 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[].

sprintf

public static java.lang.String sprintf(java.lang.Object self,
                                       java.lang.String format,
                                       java.lang.Object arg)
Returns a formatted string using the specified format string and arguments.

TODO: remove duplication with printf

Parameters:
self - any Object
format - A format string
arg - 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[].
Returns:
the resulting printf'd string

inspect

public static java.lang.String inspect(java.lang.Object self)
Inspects returns the String that matches what would be typed into a terminal to create this object.

Parameters:
self - any Object
Returns:
a String that matches what would be typed into a terminal to create this object. e.g. [1, 'hello'].inspect() -> [1, "hello"]

print

public static void print(java.lang.Object self,
                         java.io.PrintWriter out)
Print to a console in interactive format.

Parameters:
self - any Object
out - the PrintWriter used for printing

println

public static void println(java.lang.Object self,
                           java.io.PrintWriter out)
Print to a console in interactive format.

Parameters:
self - any Object
out - the PrintWriter used for printing

invokeMethod

public static java.lang.Object invokeMethod(java.lang.Object object,
                                            java.lang.String method,
                                            java.lang.Object arguments)
Provide a dynamic method invocation method which can be overloaded in classes to implement dynamic proxies easily.

Parameters:
object - any Object
method - the name of the method to call
arguments - the arguments to use
Returns:
the result of the method call

isCase

public static boolean isCase(java.lang.Object caseValue,
                             java.lang.Object switchValue)
Method for overloading the behavior of the 'case' method in switch statements. The default implementation handles arrays types but otherwise simply delegates to Object#equals, but this may be overridden for other types. In this example:
 switch( a ) {
   case b: //some code
 }
"some code" is called when b.isCase( a ) returns true.

Parameters:
caseValue - the case value
switchValue - the switch value
Returns:
true if the switchValue is deemed to be equal to the caseValue

isCase

public 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. For example:
switch( str ) {
   case 'one' :
   // etc...
 }
Note that this returns true for the case where both the 'switch' and 'case' operand is null.

Parameters:
caseValue - the case value
switchValue - the switch value
Returns:
true if the switchValue's toString() equals the caseValue

isCase

public 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. For example:
switch( obj ) {
   case List :
     // obj is a list
     break;
   case Set :
     // etc
 }

Parameters:
caseValue - the case value
switchValue - the switch value
Returns:
true if the switchValue is deemed to be assignable from the given class

isCase

public static boolean isCase(java.util.Collection caseValue,
                             java.lang.Object switchValue)
'Case' implementation for collections which tests if the 'switch' operand is contained in any of the 'case' values. For example:
switch( item ) {
   case firstList :
     // item is contained in this list
     // etc
 }

Parameters:
caseValue - the case value
switchValue - the switch value
Returns:
true if the caseValue is deemed to contain the switchValue
See Also:
Collection.contains(Object)

isCase

public 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. 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.

Parameters:
caseValue - the case value
switchValue - the switch value
Returns:
true if the switchValue is deemed to match the caseValue

isCase

public 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.

Parameters:
caseValue - the case value
switchValue - the switch value
Returns:
true if the numbers are deemed equal

unique

public static java.util.Iterator unique(java.util.Iterator self)
Returns an iterator equivalent to this iterator all duplicated items removed by using the default comparator. The original iterator will become exhausted of elements after determining the unique values. A new iterator for the unique values will be returned.

Parameters:
self - an Iterator
Returns:
the modified Iterator

unique

public static java.util.Collection unique(java.util.Collection self)
Modifies this collection to remove all duplicated items, using the default comparator.

Parameters:
self - a collection
Returns:
the now modified collection

numberAwareCompareTo

public static int numberAwareCompareTo(java.lang.Comparable self,
                                       java.lang.Comparable other)
Provides a method that compares two comparables using Groovy's default number aware comparator.

Parameters:
self - a Comparable
other - another Comparable
Returns:
a -ve number, 0 or a +ve number according to Groovy's compareTo contract

unique

public static java.util.Iterator unique(java.util.Iterator self,
                                        Closure closure)
Returns an iterator equivalent to this iterator all duplicated items removed by using a closure as a comparator. If the closure takes a single parameter, the argument passed will be each element, and the closure should return a value used for comparison (either using Comparable.compareTo(Object) or Object#equals() ).

Parameters:
self - an Iterator
closure - a Closure used as a comparator
Returns:
the modified Iterator

unique

public static java.util.Collection unique(java.util.Collection self,
                                          Closure closure)
A convenience method for making a collection unique using a closure as a comparator. If the closure takes a single parameter, the argument passed will be each element, and the closure should return a value used for comparison (either using Comparable.compareTo(Object) or Object#equals() ). 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).

Parameters:
self - a Collection
closure - a Closure used as a comparator
Returns:
self without any duplicates

unique

public static java.util.Iterator unique(java.util.Iterator self,
                                        java.util.Comparator comparator)
Returns an iterator equivalent to this iterator with all duplicated items removed by using the supplied comparator.

Parameters:
self - an Iterator
comparator - a Comparator
Returns:
the modified Iterator

unique

public static java.util.Collection unique(java.util.Collection self,
                                          java.util.Comparator comparator)
Remove all duplicates from a given Collection. Works on the receiver object and returns it. The order of members in the Collection are compared by the given Comparator. For each duplicate, the first member which is returned by the given Collection's iterator is retained, but all other ones are removed. The given Collection's original order is preserved.

     class Person {
         def fname, lname
         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] )

Parameters:
self - a Collection
comparator - a Comparator
Returns:
self the now modified collection without duplicates

each

public static java.lang.Object each(java.lang.Object self,
                                    Closure closure)
Iterates through an aggregate type or data structure, passing each item to the given closure. Custom types may utilize this method by simply providing an "iterator()" method. The items returned from the resulting iterator will be passed to the closure.

Parameters:
self - the object over which we iterate
closure - the closure applied on each element found
Returns:
the self Object

eachWithIndex

public 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.

Parameters:
self - an Object
closure - a Closure to operate on each item
Returns:
the self Object

each

public static java.util.Map each(java.util.Map self,
                                 Closure closure)
Allows a Map to be iterated through using a closure. If the closure takes one parameter then it will be passed the Map.Entry otherwise if the closure takes two parameters then it will be passed the key and the value.

Parameters:
self - the map over which we iterate
closure - the closure applied on each entry of the map
Returns:
returns the self parameter

eachWithIndex

public static java.lang.Object eachWithIndex(java.util.Map self,
                                             Closure closure)
Allows a Map to be iterated through using a closure. If the closure takes two parameters then it will be passed the Map.Entry and the item's index (a counter starting at zero) otherwise if the closure takes three parameters then it will be passed the key, the value, and the index.

Parameters:
self - the map over which we iterate
closure - a Closure to operate on each item
Returns:
the self Object

reverseEach

public static java.util.List reverseEach(java.util.List self,
                                         Closure closure)
Iterate over each element of the list in the reverse order.

Parameters:
self - a List
closure - a closure to which each item is passed.
Returns:
the original list

reverseEach

public static java.lang.Object[] reverseEach(java.lang.Object[] self,
                                             Closure closure)
Iterate over each element of the array in the reverse order.

Parameters:
self - an Object array
closure - a closure to which each item is passed
Returns:
the original array

reverse

public static java.lang.Object[] reverse(java.lang.Object[] self)
Reverse the items in an Object array.

Parameters:
self - an Object array
Returns:
an array containing the reversed items

every

public 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). A simple example for a list:
def list = [3,4,5]
 def greaterThanTwo = list.every { it > 2 }
 

Parameters:
self - the object over which we iterate
closure - the closure predicate used for matching
Returns:
true if every iteration of the object matches the closure predicate

every

public static boolean every(java.util.Map self,
                            Closure closure)
Iterates over the entries of a map, and checks whether a predicate is valid for all entries.

Parameters:
self - the map over which we iterate
closure - the closure predicate used for matching
Returns:
true if every entry of the map matches the closure predicate

every

public 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. Equivalent to self.every({element -> element})

Parameters:
self - the object over which we iterate
Returns:
true if every item in the collection matches the closure predicate

any

public 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.

Parameters:
self - the object over which we iterate
closure - the closure predicate used for matching
Returns:
true if any iteration for the object matches the closure predicate

any

public static boolean any(java.util.Map self,
                          Closure closure)
Iterates over the entries of a map, and checks whether a predicate is valid for at least one entry

Parameters:
self - the map over which we iterate
closure - the closure predicate used for matching
Returns:
true if any entry in the map matches the closure predicate

any

public static boolean any(java.lang.Object self)
Iterates over the elements of a collection, and checks whether at least one element is true according to the Groovy Truth. Equivalent to self.any({element -> element})

Parameters:
self - the object over which we iterate
Returns:
true if any item in the collection matches the closure predicate

grep

public 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 isCase(Object,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'
 

Parameters:
self - the object over which we iterate
filter - the filter to perform on the collection (using the isCase(object) method)
Returns:
a collection of objects which match the filter

count

public static int count(java.util.Iterator self,
                        java.lang.Object value)
Counts the number of occurrences of the given value from the items within this Iterator. Comparison is done using Groovy's == operator (using compareTo(value) == 0 or equals(value) ). The iterator will become exhausted of elements after determining the count value.

Parameters:
self - the Iterator from which we count the number of matching occurrences
value - the value being searched for
Returns:
the number of occurrences

count

public static int count(java.util.Collection self,
                        java.lang.Object value)
Counts the number of occurrences of the given value inside this collection. Comparison is done using Groovy's == operator (using compareTo(value) == 0 or equals(value) ).

Parameters:
self - the collection within which we count the number of occurrences
value - the value being searched for
Returns:
the number of occurrences

toList

public static java.util.List toList(java.util.Collection self)
Convert a collection to a List.

Parameters:
self - a collection
Returns:
a List

toList

public static java.util.List toList(java.util.Iterator self)
Convert an iterator to a List. The iterator will become exhausted of elements after making this conversion.

Parameters:
self - an iterator
Returns:
a List

toList

public static java.util.List toList(java.util.Enumeration self)
Convert an enumeration to a List.

Parameters:
self - an enumeration
Returns:
a List

collect

public 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. Example:
def list = [1, 'a', 1.23, true ]
 def types = list.collect { it.class }
 

Parameters:
self - the values of the object to transform
closure - the closure used to transform each element of the collection
Returns:
a List of the transformed values

collect

public 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.

Parameters:
self - the values of the object to transform
collection - the Collection to which the transformed values are added
closure - the closure used to map each element of the collection
Returns:
the given collection after the transformed values are added

collect

public 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.

Parameters:
self - a collection
closure - the closure used for mapping
Returns:
a List of the transformed values

collect

public 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.

Parameters:
self - a collection
collection - an initial Collection to which the transformed values are added
closure - the closure used to transform each element of the collection
Returns:
the resulting collection of transformed values

collectAll

public 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. Returns a potentially nested list of transformed values.

Parameters:
self - a collection
closure - the closure used to transform each element of the collection
Returns:
the resultant collection

collectAll

public 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. Returns a potentially nested collection of transformed values.

Parameters:
self - a collection
collection - an initial Collection to which the transformed values are added
closure - the closure used to transform each element of the collection
Returns:
the resultant collection

collect

public 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.

Parameters:
self - a Map
collection - the Collection to which the mapped values are added
closure - the closure used for mapping, which can take one (Map.Entry) or two (key, value) parameters
Returns:
a List of the mapped values

collect

public 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.

Parameters:
self - a Map
closure - the closure used to map each element of the collection
Returns:
the resultant collection

find

public static java.lang.Object find(java.lang.Object self,
                                    Closure closure)
Finds the first value matching the closure condition

Parameters:
self - an Object with an iterator returning its values
closure - a closure condition
Returns:
the first Object found

find

public static java.lang.Object find(java.util.Collection self,
                                    Closure closure)
Finds the first value matching the closure condition. Example:
def list = [1,2,3]
 list.find { it > 1 } // returns 2
 

Parameters:
self - a Collection
closure - a closure condition
Returns:
the first Object found

find

public static java.lang.Object find(java.util.Map self,
                                    Closure closure)
Finds the first entry matching the closure condition. If the closure takes two parameters, the entry key and value are passed. If the closure takes one parameter, the Map.Entry object is passed.

Parameters:
self - a Map
closure - a closure condition
Returns:
the first Object found

findAll

public static java.util.Collection findAll(java.lang.Object self,
                                           Closure closure)
Finds all items matching the closure condition.

Parameters:
self - an Object with an Iterator returning its values
closure - a closure condition
Returns:
a List of the values found

findAll

public static java.util.Collection findAll(java.util.Collection self,
                                           Closure closure)
Finds all values matching the closure condition.

Parameters:
self - a Collection
closure - a closure condition
Returns:
a Collection of matching values

split

public static java.util.Collection split(java.lang.Object self,
                                         Closure closure)
Splits all items into two lists based on the closure condition. The first list contains all items matching the closure expression. The second list all those that don't.

Parameters:
self - an Object with an Iterator returning its values
closure - a closure condition
Returns:
a List containing whose first item is the accepted values and whose second item is the rejected values

split

public static java.util.Collection split(java.util.Collection self,
                                         Closure closure)
Splits all items into two collections based on the closure condition. The first list contains all items which match the closure expression. The second list all those that don't.

Parameters:
self - a Collection of values
closure - a closure condition
Returns:
a List containing whose first item is the accepted values and whose second item is the rejected values

combinations

public static java.util.List combinations(java.util.Collection self)
Adds GroovyCollections#combinations(Collection) as a method on collections.

Parameters:
self - a Collection of lists
Returns:
a List of the combinations found
See Also:
GroovyCollections.combinations(java.util.Collection)

transpose

public static java.util.List transpose(java.util.List self)
Adds GroovyCollections#transpose(List) as a method on lists.

Parameters:
self - a List of lists
Returns:
a List of the transposed lists
See Also:
GroovyCollections.transpose(java.util.List)

findAll

public static java.util.Map findAll(java.util.Map self,
                                    Closure closure)
Finds all entries matching the closure condition. If the closure takes one parameter then it will be passed the Map.Entry. Otherwise if the closure should take two parameters, which will be the key and the value.

Parameters:
self - a Map
closure - a closure condition applying on the entries
Returns:
a new subMap

groupBy

public static java.util.Map groupBy(java.util.Collection self,
                                    Closure closure)
Sorts all collection members into groups determined by the supplied mapping closure. The closure should return the key that this item should be grouped by. The returned Map will have an entry for each distinct key returned from the closure, with each value being a list of items for that group.

Parameters:
self - a collection to group (no map)
closure - a closure mapping entries on keys
Returns:
a new Map grouped by keys

groupEntriesBy

public static java.util.Map groupEntriesBy(java.util.Map self,
                                           Closure closure)
Groups all map entries into groups determined by the supplied mapping closure. The closure will be passed a Map.Entry or key and value (depending on the number of parameters the closure accepts) and should return the key that each item should be grouped under. The resulting map will have an entry for each 'group' key returned by the closure, with values being the list of map entries that belong to each group.

Parameters:
self - a map to group
closure - a closure mapping entries on keys
Returns:
a new Map grouped by keys

groupBy

public static java.util.Map groupBy(java.util.Map self,
                                    Closure closure)
Groups the members of a map into sub maps determined by the supplied mapping closure. The closure will be passed a Map.Entry or key and value (depending on the number of parameters the closure accepts) and should return the key that each item should be grouped under. The resulting map will have an entry for each 'group' key returned by the closure, with values being the map members from the original map that belong to each group.

Parameters:
self - a map to group
closure - a closure mapping entries on keys
Returns:
a new Map grouped by keys

groupAnswer

protected static void groupAnswer(java.util.Map answer,
                                  java.lang.Object element,
                                  java.lang.Object value)
Groups the current element according to the value

Parameters:
answer - the map containing the results
element - the element to be placed
value - the value according to which the element will be placed

callClosureForMapEntry

protected static java.lang.Object callClosureForMapEntry(Closure closure,
                                                         java.util.Map.Entry entry)

callClosureForLine

protected static java.lang.Object callClosureForLine(Closure closure,
                                                     java.lang.String line,
                                                     int counter)

callClosureForMapEntryAndCounter

protected static java.lang.Object callClosureForMapEntryAndCounter(Closure closure,
                                                                   java.util.Map.Entry entry,
                                                                   int counter)

inject

public 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.

Parameters:
self - a Collection
value - a value
closure - a closure
Returns:
the last value of the last iteration

inject

public 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.

Parameters:
self - a Collection
value - a value
closure - a closure
Returns:
the last value of the last iteration

inject

public 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.

Parameters:
self - a Collection
value - a value
closure - a closure
Returns:
the last value of the last iteration

inject

public 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.

Parameters:
self - an Object[]
initialValue - an initialValue
closure - a closure
Returns:
the last value of the last iteration

sum

public static java.lang.Object sum(java.util.Collection self)
Sums the items in a collection. This is equivalent to invoking the "plus" method on all items in the collection.

Parameters:
self - Collection of values to add together
Returns:
The sum of all of the items

sum

public static java.lang.Object sum(java.util.Iterator self)
Sums the items from an Iterator. This is equivalent to invoking the "plus" method on all items from the Iterator. The iterator will become exhausted of elements after determining the sum value.

Parameters:
self - an Iterator for the values to add together
Returns:
The sum of all of the items

sum

public 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.

Parameters:
self - a collection of values to sum
initialValue - the items in the collection will be summed to this initial value
Returns:
The sum of all of the collection items.

sum

public static java.lang.Object sum(java.util.Iterator self,
                                   java.lang.Object initialValue)
Sums the items from an Iterator. This is equivalent to invoking the "plus" method on all items from the Iterator.

Parameters:
self - an Iterator for the values to add together
initialValue - the items in the collection will be summed to this initial value
Returns:
The sum of all of the items

sum

public static java.lang.Object sum(java.util.Collection self,
                                   Closure closure)
Sums the result of apply a closure to each item of a collection. coll.sum(closure) is equivalent to: coll.collect(closure).sum().

Parameters:
self - a Collection
closure - a single parameter closure that returns a numeric value.
Returns:
The sum of the values returned by applying the closure to each item of the list.

sum

public static java.lang.Object sum(java.util.Collection self,
                                   java.lang.Object initialValue,
                                   Closure closure)
Sums the result of apply a closure to each item of a collection to sum intial value. coll.sum(closure) is equivalent to: coll.collect(closure).sum().

Parameters:
self - a Collection
closure - a single parameter closure that returns a numeric value.
initialValue - the closure results will be summed to this initial value
Returns:
The sum of the values returned by applying the closure to each item of the list.

join

public static java.lang.String join(java.util.Iterator 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. The iterator will become exhausted of elements after determining the resulting conjoined value.

Parameters:
self - an Iterator of items
separator - a String separator
Returns:
the joined String

join

public 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.

Parameters:
self - a Collection of objects
separator - a String separator
Returns:
the joined String

join

public 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.

Parameters:
self - an array of Object
separator - a String separator
Returns:
the joined String

min

public static java.lang.Object min(java.util.Collection self)
Adds min() method to Collection objects.

Parameters:
self - a Collection
Returns:
the minimum value
See Also:
GroovyCollections.min(java.util.Collection)

min

public static java.lang.Object min(java.util.Iterator self)
Adds min() method to Iterator objects. The iterator will become exhausted of elements after determining the minimum value.

Parameters:
self - an Iterator
Returns:
the minimum value
See Also:
min(java.util.Collection)

min

public static java.lang.Object min(java.lang.Object[] self)
Adds min() method to Object arrays.

Parameters:
self - an Object array
Returns:
the minimum value
See Also:
min(java.util.Collection)

min

public static java.lang.Object min(java.util.Collection self,
                                   java.util.Comparator comparator)
Selects the minimum value found in the collection using the given comparator.

Parameters:
self - a Collection
comparator - a Comparator
Returns:
the minimum value

min

public static java.lang.Object min(java.util.Iterator self,
                                   java.util.Comparator comparator)
Selects the minimum value found from the Iterator using the given comparator.

Parameters:
self - an Iterator
comparator - a Comparator
Returns:
the minimum value
See Also:
min(java.util.Collection, java.util.Comparator)

min

public static java.lang.Object min(java.lang.Object[] self,
                                   java.util.Comparator comparator)
Selects the minimum value found from the Object array using the given comparator.

Parameters:
self - an Object array
comparator - a Comparator
Returns:
the minimum value
See Also:
min(java.util.Collection, java.util.Comparator)

min

public static java.lang.Object min(java.util.Collection self,
                                   Closure closure)
Selects the minimum value found in the collection using the given closure as a comparator. The closure should return a comparable value (i.e. a number) for each item passed. The collection item for which the closure returns the smallest comparable value will be returned from this method as the minimum.

Parameters:
self - a Collection
closure - a closure used as a comparator
Returns:
the minimum value

min

public static java.lang.Object min(java.util.Iterator self,
                                   Closure closure)
Selects the minimum value found from the Iterator using the given closure as a comparator. The closure should return a comparable value (i.e. a number) for each item passed. The iterator will become exhausted of elements after this operation.

Parameters:
self - an Iterator
closure - a closure used as a comparator
Returns:
the minimum value
See Also:
min(java.util.Collection, groovy.lang.Closure)

min

public static java.lang.Object min(java.lang.Object[] self,
                                   Closure closure)
Selects the minimum value found from the Object array using the given closure as a comparator. The closure should return a comparable value (i.e. a number) for each item passed.

Parameters:
self - an Object array
closure - a closure used as a comparator
Returns:
the minimum value
See Also:
min(java.util.Collection, groovy.lang.Closure)

max

public static java.lang.Object max(java.util.Collection self)
Adds max() method to Collection objects.

Parameters:
self - a Collection
Returns:
the maximum value
See Also:
GroovyCollections.max(java.util.Collection)

max

public static java.lang.Object max(java.util.Iterator self)
Adds max() method to Iterator objects. The iterator will become exhausted of elements after determining the maximum value.

Parameters:
self - an Iterator
Returns:
the maximum value
See Also:
GroovyCollections.max(java.util.Collection)

max

public static java.lang.Object max(java.lang.Object[] self)
Adds max() method to Object arrays.

Parameters:
self - an Object array
Returns:
the maximum value
See Also:
max(java.util.Collection)

max

public static java.lang.Object max(java.util.Collection self,
                                   Closure closure)
Selects the maximum value found in the collection using the given closure as a comparator. The closure should return a comparable value (i.e. a number) for each item passed. The collection item for which the closure returns the largest comparable value will be returned from this method as the maximum.

Parameters:
self - a Collection
closure - a closure used as a comparator
Returns:
the maximum value

max

public static java.lang.Object max(java.util.Iterator self,
                                   Closure closure)
Selects the maximum value found from the Iterator using the given closure as a comparator. The closure should return a comparable value (i.e. a number) for each item passed. The iterator will become exhausted of elements after this operation.

Parameters:
self - an Iterator
closure - a closure used as a comparator
Returns:
the maximum value
See Also:
max(java.util.Collection, groovy.lang.Closure)

max

public static java.lang.Object max(java.lang.Object[] self,
                                   Closure closure)
Selects the maximum value found from the Object array using the given closure as a comparator. The closure should return a comparable value (i.e. a number) for each item passed.

Parameters:
self - an Object array
closure - a closure used as a comparator
Returns:
the maximum value
See Also:
max(java.util.Collection, groovy.lang.Closure)

max

public static java.lang.Object max(java.util.Collection self,
                                   java.util.Comparator comparator)
Selects the maximum value found in the collection using the given comparator.

Parameters:
self - a Collection
comparator - a Comparator
Returns:
the maximum value

max

public static java.lang.Object max(java.util.Iterator self,
                                   java.util.Comparator comparator)
Selects the maximum value found from the Iterator using the given comparator.

Parameters:
self - an Iterator
comparator - a Comparator
Returns:
the maximum value

max

public static java.lang.Object max(java.lang.Object[] self,
                                   java.util.Comparator comparator)
Selects the maximum value found from the Object array using the given comparator.

Parameters:
self - an Object array
comparator - a Comparator
Returns:
the maximum value

size

public static int size(java.util.Iterator self)
Provide the standard Groovy size() method for Iterator. The iterator will become exhausted of elements after determining the size value.

Parameters:
self - an Iterator
Returns:
the length of the Iterator

size

public static int size(java.lang.String text)
Provide the standard Groovy size() method for String.

Parameters:
text - a String
Returns:
the length of the String

size

public static int size(java.lang.StringBuffer buffer)
Provide the standard Groovy size() method for StringBuffer.

Parameters:
buffer - a StringBuffer
Returns:
the length of the StringBuffer

size

public static long size(java.io.File self)
Provide the standard Groovy size() method for File.

Parameters:
self - a file object
Returns:
the file's size (length)

size

public static long size(java.util.regex.Matcher self)
Provide the standard Groovy size() method for Matcher.

Parameters:
self - a matcher object
Returns:
the matcher's size (count)

size

public static int size(java.lang.Object[] self)
Provide the standard Groovy size() method for an array.

Parameters:
self - an Array of objects
Returns:
the size (length) of the Array

getAt

public static java.lang.CharSequence getAt(java.lang.CharSequence text,
                                           int index)
Support the subscript operator for CharSequence.

Parameters:
text - a CharSequence
index - the index of the Character to get
Returns:
the Character at the given index

getAt

public static java.lang.String getAt(java.lang.String text,
                                     int index)
Support the subscript operator for String.

Parameters:
text - a String
index - the index of the Character to get
Returns:
the Character at the given index

getAt

public static java.lang.CharSequence getAt(java.lang.CharSequence text,
                                           Range range)
Support the range subscript operator for CharSequence

Parameters:
text - a CharSequence
range - a Range
Returns:
the subsequence CharSequence

getAt

public static java.lang.CharSequence getAt(java.lang.CharSequence text,
                                           IntRange range)
Support the range subscript operator for CharSequence or StringBuffer with IntRange

Parameters:
text - a CharSequence
range - an IntRange
Returns:
the subsequence CharSequence

getAt

public static java.lang.CharSequence getAt(java.lang.CharSequence text,
                                           EmptyRange range)
Support the range subscript operator for CharSequence or StringBuffer with EmptyRange

Parameters:
text - a CharSequence
range - an EmptyRange
Returns:
the subsequence CharSequence

getAt

public static java.lang.String getAt(java.lang.String text,
                                     IntRange range)
Support the range subscript operator for String with IntRange

Parameters:
text - a String
range - an IntRange
Returns:
the resulting String

getAt

public static java.lang.String getAt(java.lang.String text,
                                     EmptyRange range)
Support the range subscript operator for String with EmptyRange

Parameters:
text - a String
range - an EmptyRange
Returns:
the resulting String

getAt

public static java.lang.String getAt(java.lang.String text,
                                     Range range)
Support the range subscript operator for String

Parameters:
text - a String
range - a Range
Returns:
a substring corresponding to the Range

reverse

public static java.lang.String reverse(java.lang.String self)
Creates a new string which is the reverse (backwards) of this string

Parameters:
self - a String
Returns:
a new string with all the characters reversed.

toURL

public static java.net.URL toURL(java.lang.String self)
                          throws java.net.MalformedURLException
Transforms a String representing a URL into a URL object.

Parameters:
self - the String representing a URL
Returns:
a URL
Throws:
java.net.MalformedURLException - is thrown if the URL is not well formed.

toURI

public static java.net.URI toURI(java.lang.String self)
                          throws java.net.URISyntaxException
Transforms a String representing a URI into a URI object.

Parameters:
self - the String representing a URI
Returns:
a URI
Throws:
java.net.URISyntaxException - is thrown if the URI is not well formed.

bitwiseNegate

public static java.util.regex.Pattern bitwiseNegate(java.lang.String self)
Turns a String into a regular expression pattern

Parameters:
self - a String to convert into a regular expression
Returns:
the regular expression pattern

replaceAll

public static java.lang.String replaceAll(java.lang.String self,
                                          java.lang.String regex,
                                          Closure closure)
Replaces all occurrances of a captured group by the result of a closure on that text.

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 pattern, 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.

Parameters:
self - a String
regex - the capturing regex
closure - the closure to apply on each captured group
Returns:
a String with replaced content
Since:
1.0
See Also:
java.util.regex.Matcher.quoteReplacement(String)

replace

public static java.lang.String replace(java.lang.String self,
                                       java.lang.CharSequence target,
                                       java.lang.CharSequence replacement)
Replaces all occurrences of a literal string with another literal string. This provides backwards compatibility for the JDK 1.5 method String.replace(CharSequence, CharSequence). This will only be invoked on a JDK 1.4 JVM.

Parameters:
self - a String
target - the character sequence to search for
replacement - the character sequence to replace the matches with
Returns:
a String with replaced content
Since:
1.5.8
See Also:
java.lang.String.replace(CharSequence, CharSequence)

padLeft

public 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

Parameters:
self - a String object
numberOfChars - the total number of characters
padding - the charaters used for padding
Returns:
the String padded to the left

padLeft

public static java.lang.String padLeft(java.lang.String self,
                                       java.lang.Number numberOfChars)
Pad a String with the spaces appended to the left

Parameters:
self - a String object
numberOfChars - the total number of characters
Returns:
the String padded to the left

padRight

public 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

Parameters:
self - a String object
numberOfChars - the total number of characters
padding - the charaters used for padding
Returns:
the String padded to the right

padRight

public static java.lang.String padRight(java.lang.String self,
                                        java.lang.Number numberOfChars)
Pad a String with the spaces appended to the right

Parameters:
self - a String object
numberOfChars - the total number of characters
Returns:
the String padded to the right

center

public 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

Parameters:
self - a String object
numberOfChars - the total number of characters
padding - the charaters used for padding
Returns:
the String centered with padded character around

center

public static java.lang.String center(java.lang.String self,
                                      java.lang.Number numberOfChars)
Center a String and pad it with spaces appended around it

Parameters:
self - a String object
numberOfChars - the total number of characters
Returns:
the String centered with padded character around

getAt

public static java.lang.Object getAt(java.util.regex.Matcher matcher,
                                     int idx)
Support the subscript operator, e.g. matcher[index], for a regex Matcher.

For an example using no group match,

    def p = /ab[d|f]/
    def m = "abcabdabeabf" =~ p
    for (i in 0..<m.count) {
        println( "m.groupCount() = " + m.groupCount())
        println( "  " + i + ": " + m[i] )   // m[i] is a String
    }
 

For an example using group matches,

    def p = /(?:ab([c|d|e|f]))/
    def m = "abcabdabeabf" =~ p
    for (i in 0..<m.count) {
        println( "m.groupCount() = " + m.groupCount())
        println( "  " + i + ": " + m[i] )   // m[i] is a List
    }
 

For another example using group matches,

    def m = "abcabdabeabfabxyzabx" =~ /(?:ab([d|x-z]+))/
    m.count.times {
        println( "m.groupCount() = " + m.groupCount())
        println( "  " + it + ": " + m[it] )   // m[it] is a List
    }
 

Parameters:
matcher - a Matcher
idx - an index
Returns:
object a matched String if no groups matched, list of matched groups otherwise.

setIndex

public static void setIndex(java.util.regex.Matcher matcher,
                            int idx)
Set the position of the given Matcher to the given index.

Parameters:
matcher - a Matcher
idx - the index number

getCount

public static int getCount(java.util.regex.Matcher matcher)
Find the number of Strings matched to the given Matcher.

Parameters:
matcher - a Matcher
Returns:
int the number of Strings matched to the given matcher.

hasGroup

public static boolean hasGroup(java.util.regex.Matcher matcher)
Check whether a Matcher contains a group or not.

Parameters:
matcher - a Matcher
Returns:
boolean true if matcher contains at least one group.

getAt

public static java.util.List getAt(java.util.List self,
                                   IntRange range)
Support the range subscript operator for a List

Parameters:
self - a List
range - a Range indicating the items to get
Returns:
a sublist based on range borders or a new list if range is reversed
See Also:
List.subList(int,int)

getAt

public static java.util.List getAt(java.util.List self,
                                   java.util.Collection indices)
Select a List of items from a List using a Collection to identify the indices to be selected.

Parameters:
self - a List
indices - a Collection of indices
Returns:
a new list of the values at the given indices

getAt

public static java.util.List getAt(java.lang.Object[] self,
                                   java.util.Collection indices)
Select a List of items from an Object array using a Collection to identify the indices to be selected.

Parameters:
self - an Array of Objects
indices - a Collection of indices
Returns:
a new list of the values at the given indices

getAt

public 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.

Parameters:
self - a CharSequence
indices - a Collection of indices
Returns:
a CharSequence consisting of the characters at the given indices

getAt

public 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.

Parameters:
self - a String
indices - a Collection of indices
Returns:
a String consisting of the characters at the given indices

getAt

public static java.lang.String 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.

Parameters:
self - a Matcher
indices - a Collection of indices
Returns:
a String of the values at the given indices

subMap

public static java.util.Map subMap(java.util.Map map,
                                   java.util.Collection keys)
Creates a sub-Map containing the given keys. This method is similar to List.subList() but uses keys rather than index ranges.

Parameters:
map - a Map
keys - a Collection of keys
Returns:
a new Map containing the given keys

get

public static java.lang.Object get(java.util.Map map,
                                   java.lang.Object key,
                                   java.lang.Object 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.

Parameters:
map - a Map
key - the key to lookup the value of
defaultValue - the value to return and add to the map for this key if there is no entry for the given key
Returns:
the value of the given key or the default value, added to the map if the key did not exist

getAt

public static java.util.List getAt(java.lang.Object[] array,
                                   Range range)
Support the range subscript operator for an Array

Parameters:
array - an Array of Objects
range - a Range
Returns:
a range of a list from the range's from index up to but not including the ranges's to value

getAt

public static java.util.List getAt(java.lang.Object[] array,
                                   IntRange range)

getAt

public static java.util.List getAt(java.lang.Object[] array,
                                   EmptyRange range)

getAt

public static java.util.List getAt(java.lang.Object[] array,
                                   ObjectRange range)

getAt

public static java.lang.Object getAt(java.lang.Object[] array,
                                     int idx)
Support the subscript operator for an Array.

Parameters:
array - an Array of Objects
idx - an index
Returns:
the value at the given index

putAt

public static void putAt(java.lang.Object[] array,
                         int idx,
                         java.lang.Object value)
Support the subscript operator for an Array.

Parameters:
array - an Array of Objects
idx - an index
value - an Object to put at the given index

toList

public static java.util.List toList(java.lang.Object[] array)
Allows conversion of arrays into a mutable List.

Parameters:
array - an Array of Objects
Returns:
the array as a List

getAt

public static java.lang.Object getAt(java.util.List self,
                                     int idx)
Support the subscript operator for a List.

Parameters:
self - a List
idx - an index
Returns:
the value at the given index

getAt

public static int getAt(java.util.Date self,
                        int field)
Support the subscript operator for a Date.

Parameters:
self - a Date
field - a Calendar field, e.g. MONTH
Returns:
the value for the given field, e.g. FEBRUARY
See Also:
Calendar

putAt

public static void putAt(java.util.List self,
                         int idx,
                         java.lang.Object value)
A helper method to allow lists to work with subscript operators.

Parameters:
self - a List
idx - an index
value - the value to put at the given index

putAt

public static void putAt(java.lang.StringBuffer self,
                         IntRange range,
                         java.lang.Object value)
Support the range subscript operator for StringBuffer. Index values are treated as characters within the buffer.

Parameters:
self - a StringBuffer
range - a Range
value - the object that's toString() will be inserted

putAt

public static void putAt(java.lang.StringBuffer self,
                         EmptyRange range,
                         java.lang.Object value)
Support the range subscript operator for StringBuffer.

Parameters:
self - a StringBuffer
range - a Range
value - the object that's toString() will be inserted

putAt

public static void putAt(java.util.List self,
                         EmptyRange range,
                         java.lang.Object value)
A helper method to allow lists to work with subscript operators.

Parameters:
self - a List
range - the subset of the list to set
value - the values to put at the given sublist or a Collection of values

putAt

public 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. Example: myList[3..5] = anotherList. Items in the given range are relaced with items from the collection.

Parameters:
self - a List
range - the subset of the list to set
col - the collection of values to put at the given sublist

putAt

public static void putAt(java.util.List self,
                         IntRange range,
                         java.lang.Object value)
List subscript assignment operator when given a range as the index. Example: myList[3..5] = newItem. Items in the given range are relaced with the operand. The value operand is always treated as a single value.

Parameters:
self - a List
range - the subset of the list to set
value - the value to put at the given sublist

putAt

public static void putAt(java.util.List self,
                         java.util.List splice,
                         java.util.List values)
Deprecated. replace with putAt(List self, Range range, List value)

A helper method to allow lists to work with subscript operators.

Parameters:
self - a List
splice - the subset of the list to set
values - the value to put at the given sublist

putAt

public static void putAt(java.util.List self,
                         java.util.List splice,
                         java.lang.Object value)
Deprecated. replace with putAt(List self, Range range, Object value)

A helper method to allow lists to work with subscript operators.

Parameters:
self - a List
splice - the subset of the list to set
value - the value to put at the given sublist

getSubList

protected static java.util.List getSubList(java.util.List self,
                                           java.util.List splice)

getAt

public static java.lang.Object getAt(java.util.Map self,
                                     java.lang.Object key)
Support the subscript operator for a Map.

Parameters:
self - a Map
key - an Object as a key for the map
Returns:
the value corresponding to the given key

plus

public static java.util.Map plus(java.util.Map left,
                                 java.util.Map right)

Returns a new Map containing all entries from left and right, giving precedence to right. Any keys appearing in both Maps will appear in the resultant map with values from the right operand. If the left map is one of TreeMap, LinkedHashMap, Hashtable or Properties, the returned Map will preserve that type, otherwise a HashMap will be returned.

Roughly equivalent to Map m = new HashMap(); m.putAll(left); m.putAll(right); return m; but with some additional logic to preserve the left Map type for common cases as described above.

Parameters:
left - a Map
right - a Map
Returns:
a new Map containing all entries from left and right

putAt

public static java.lang.Object putAt(java.util.Map self,
                                     java.lang.Object key,
                                     java.lang.Object value)
A helper method to allow lists to work with subscript operators

Parameters:
self - a Map
key - an Object as a key for the map
value - the value to put into the map
Returns:
the value corresponding to the given key

getAt

public static java.util.List getAt(java.util.Collection coll,
                                   java.lang.String property)
Support the subscript operator for List

Parameters:
coll - a Collection
property - a String
Returns:
a List

asImmutable

public static java.util.Map asImmutable(java.util.Map self)
A convenience method for creating an immutable map.

Parameters:
self - a Map
Returns:
an immutable Map
See Also:
Collections.unmodifiableMap(java.util.Map)

asImmutable

public static java.util.SortedMap asImmutable(java.util.SortedMap self)
A convenience method for creating an immutable sorted map.

Parameters:
self - a SortedMap
Returns:
an immutable SortedMap
See Also:
Collections.unmodifiableSortedMap(java.util.SortedMap)

asImmutable

public static java.util.List asImmutable(java.util.List self)
A convenience method for creating an immutable list

Parameters:
self - a List
Returns:
an immutable List
See Also:
Collections.unmodifiableList(java.util.List)

asImmutable

public static java.util.Set asImmutable(java.util.Set self)
A convenience method for creating an immutable list.

Parameters:
self - a Set
Returns:
an immutable Set
See Also:
Collections.unmodifiableSet(java.util.Set)

asImmutable

public static java.util.SortedSet asImmutable(java.util.SortedSet self)
A convenience method for creating an immutable sorted set.

Parameters:
self - a SortedSet
Returns:
an immutable SortedSet
See Also:
Collections.unmodifiableSortedSet(java.util.SortedSet)

asImmutable

public static java.util.Collection asImmutable(java.util.Collection self)
A convenience method for creating an immutable Collection.

Parameters:
self - a Collection
Returns:
an immutable Collection
See Also:
Collections.unmodifiableCollection(java.util.Collection)

asSynchronized

public static java.util.Map asSynchronized(java.util.Map self)
A convenience method for creating a synchronized Map.

Parameters:
self - a Map
Returns:
a synchronized Map
See Also:
Collections.synchronizedMap(java.util.Map)

asSynchronized

public static java.util.SortedMap asSynchronized(java.util.SortedMap self)
A convenience method for creating a synchronized SortedMap.

Parameters:
self - a SortedMap
Returns:
a synchronized SortedMap
See Also:
Collections.synchronizedSortedMap(java.util.SortedMap)

asSynchronized

public static java.util.Collection asSynchronized(java.util.Collection self)
A convenience method for creating a synchronized Collection.

Parameters:
self - a Collection
Returns:
a synchronized Collection
See Also:
Collections.synchronizedCollection(java.util.Collection)

asSynchronized

public static java.util.List asSynchronized(java.util.List self)
A convenience method for creating a synchronized List.

Parameters:
self - a List
Returns:
a synchronized List
See Also:
Collections.synchronizedList(java.util.List)

asSynchronized

public static java.util.Set asSynchronized(java.util.Set self)
A convenience method for creating a synchronized Set.

Parameters:
self - a Set
Returns:
a synchronized Set
See Also:
Collections.synchronizedSet(java.util.Set)

asSynchronized

public static java.util.SortedSet asSynchronized(java.util.SortedSet self)
A convenience method for creating a synchronized SortedSet.

Parameters:
self - a SortedSet
Returns:
a synchronized SortedSet
See Also:
Collections.synchronizedSortedSet(java.util.SortedSet)

spread

public static SpreadMap spread(java.util.Map self)
Synonym for toSpreadMap(Map).

Parameters:
self - a map
Returns:
a newly created Spreadmap

toSpreadMap

public static SpreadMap toSpreadMap(java.util.Map self)
Returns a new SpreadMap from this map.

For examples, if there is defined a function like as

     def fn(a, b, c, d) { return a + b + c + d }
 
, then all of the following three have the same meaning.
     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)
 

Parameters:
self - a list to be converted into a spreadmap
Returns:
a newly created Spreadmap if this list is not null and its size is positive.
See Also:
SpreadMap.SpreadMap(java.util.Map)

toSpreadMap

public static SpreadMap toSpreadMap(java.lang.Object[] self)
Creates a spreadable map from this array.

Parameters:
self - an object array
Returns:
a newly created Spreadmap
See Also:
SpreadMap.SpreadMap(java.lang.Object[])

sort

public static java.util.List sort(java.util.Collection self)
Sorts the given collection into a sorted list. The collection items are assumed to be comparable.

Parameters:
self - the collection to be sorted
Returns:
the sorted collection as a List

sort

public static java.util.Map sort(java.util.Map self,
                                 Closure closure)
Sorts the given map into a sorted map using the closure as a comparator.

Parameters:
self - the map to be sorted
closure - a Closure used as a comparator
Returns:
the sorted map

sort

public static java.lang.Object[] sort(java.lang.Object[] self)
Sorts the given Object array into sorted order. The array items are assumed to be comparable.

Parameters:
self - the array to be sorted
Returns:
the sorted array

sort

public static java.util.Iterator sort(java.util.Iterator self)
Sorts the given iterator items into a sorted iterator. The items are assumed to be comparable. The original iterator will become exhausted of elements after completing this method call. A new iterator is produced that traverses the items in sorted order.

Parameters:
self - the Iterator to be sorted
Returns:
the sorted items as an Iterator

sort

public static java.util.Iterator sort(java.util.Iterator self,
                                      java.util.Comparator comparator)
Sorts the given iterator items into a sorted iterator using the comparator.

Parameters:
self - the Iterator to be sorted
comparator - a Comparator used for comparing items
Returns:
the sorted items as an Iterator

sort

public static java.util.List sort(java.util.Collection self,
                                  java.util.Comparator comparator)
Sorts the Collection using the given comparator. The elements are sorted into a new list, and the existing collection is unchanged.

Parameters:
self - a collection to be sorted
comparator - a Comparator used for the comparison
Returns:
a newly created sorted List

sort

public static java.lang.Object[] sort(java.lang.Object[] self,
                                      java.util.Comparator comparator)
Sorts the given Object array into sorted order using the given comparator.

Parameters:
self - the array to be sorted
comparator - a Comparator used for the comparison
Returns:
the sorted array

sort

public static java.util.Iterator sort(java.util.Iterator self,
                                      Closure closure)
Sorts the given iterator items into a sorted iterator using the closure as a comparator.

Parameters:
self - the Iterator to be sorted
closure - a Closure used as a comparator
Returns:
the sorted items as an Iterator

sort

public static java.lang.Object[] sort(java.lang.Object[] self,
                                      Closure closure)
Sorts the given Object array into a newly created array using the given comparator.

Parameters:
self - the array to be sorted
closure - a Closure used as a comparator
Returns:
the sorted array

sort

public static java.util.List sort(java.util.Collection self,
                                  Closure closure)
Sorts this Collection using the given closure as a comparator. The closure is passed each item from the collection, and is assumed to return a comparable value (i.e. an int).

Parameters:
self - a Collection to be sorted
closure - a Closure used as a comparator
Returns:
a newly created sorted List

sort

public static java.util.SortedSet sort(java.util.SortedSet self)
Avoids doing unnecessary work when sorting an already sorted set.

Parameters:
self - an identity function for an already sorted set
Returns:
the sorted set

pop

public static java.lang.Object pop(java.util.List self)
Removes the last item from the List. Using add() and pop() is similar to push and pop on a Stack.

Parameters:
self - a List
Returns:
the item removed from the List
Throws:
java.util.NoSuchElementException - if the list is empty and you try to pop() it.

push

public static boolean push(java.util.List self,
                           java.lang.Object value)
Appends an item to the List. Synonym for add().

Parameters:
self - a List
value - element to be appended to this list.
Returns:
true (as per the general contract of the Collection.add method).
Throws:
java.util.NoSuchElementException - if the list is empty and you try to pop() it.

last

public static java.lang.Object last(java.util.List self)
Returns the last item from the List.

Parameters:
self - a List
Returns:
the last item from the List
Throws:
java.util.NoSuchElementException - if the list is empty and you try to access the last() item.

first

public static java.lang.Object first(java.util.List self)
Returns the first item from the List.

Parameters:
self - a List
Returns:
the first item from the List
Throws:
java.util.NoSuchElementException - if the list is empty and you try to access the first() item.

head

public static java.lang.Object head(java.util.List self)
Returns the first item from the List.

Parameters:
self - a List
Returns:
the first item from the List
Throws:
java.util.NoSuchElementException - if the list is empty and you try to access the head() item.

tail

public static java.util.List tail(java.util.List self)
Returns the items from the List excluding the first item.

Parameters:
self - a List
Returns:
a list without its first element
Throws:
java.util.NoSuchElementException - if the list is empty and you try to access the tail() item.

asList

public static java.util.List asList(java.util.Collection self)
Converts this collection to a List.

Parameters:
self - a collection to be converted into a List
Returns:
a newly created List if this collection is not already a List

asType

public static java.lang.Object asType(java.util.Collection col,
                                      java.lang.Class clazz)
Converts the given collection to another type. A default concrete type is used for List, Set, or SortedSet. If the given type has a constructor taking a collection, that is used. Otherwise, the call is deferred to {link #asType(Object,Class)}. If this collection is already of the given type, the same instance is returned.

Parameters:
col - a collection
clazz - the desired class
Returns:
the object resulting from this type conversion
See Also:
asType(Object,Class)

asType

public static java.lang.Object asType(java.lang.Object[] ary,
                                      java.lang.Class clazz)
Converts the given array to either a List, Set, or SortedSet. If the given class is something else, the call is deferred to {link #asType(Object,Class)}.

Parameters:
ary - an array
clazz - the desired class
Returns:
the object resulting from this type conversion
See Also:
asType(Object,Class)

asType

public static java.lang.Object asType(Closure cl,
                                      java.lang.Class clazz)
Coerces the closure to an implementation of the given class. The class is assumed to be an interface or class with a single method definition. The closure is used as the implementation of that single method.

Parameters:
cl - the implementation of the single method
clazz - the target type
Returns:
a Proxy of the given type which wraps this closure.

asType

public 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. Typically the value would be a closure which behaves like the method implementation.

Parameters:
map - this map
clazz - the target type
Returns:
a Proxy of the given type, which defers calls to this map's elements.

reverse

public static java.util.List reverse(java.util.List self)
Reverses the list. The result is a new List with the identical contents in reverse order.

Parameters:
self - a List
Returns:
a reversed List

reverse

public static java.util.Iterator reverse(java.util.Iterator self)
Reverses the iterator. The original iterator will become exhausted of elements after determining the reversed values. A new iterator for iterating through the reversed values is returned.

Parameters:
self - an Iterator
Returns:
a reversed Iterator

plus

public static java.util.Collection plus(java.util.Collection left,
                                        java.util.Collection right)
Create a Collection as a union of two collections. If the left collection is a Set, then the returned collection will be a Set otherwise a List. This operation will always create a new object for the result, while the operands remain unchanged.

Parameters:
left - the left Collection
right - the right Collection
Returns:
the merged Collection

plus

public static java.util.Collection plus(java.util.Collection left,
                                        java.lang.Object right)
Create a collection as a union of a Collection and an Object. If the collection is a Set, then the returned collection will be a Set otherwise a List. This operation will always create a new object for the result, while the operands remain unchanged.

Parameters:
left - a Collection
right - an object to add/append
Returns:
the resulting Collection

multiply

public static java.util.List multiply(java.util.Collection self,
                                      java.lang.Number factor)
Create a List composed of the elements of this list, repeated a certain number of times. Note that for non-primitive elements, multiple references to the same instance will be added.

Parameters:
self - a Collection
factor - the number of times to append
Returns:
the multiplied list

intersect

public static java.util.Collection intersect(java.util.Collection left,
                                             java.util.Collection right)
Create a Collection composed of the intersection of both collections. Any elements that exist in both collections are added to the resultant collection.

Parameters:
left - a Collection
right - a Collection
Returns:
a Collection as an intersection of both collections

disjoint

public static boolean disjoint(java.util.Collection left,
                               java.util.Collection right)
Returns true if the intersection of two collections is empty.

Parameters:
left - a Collection
right - a Collection
Returns:
boolean true if the intersection of two collections is empty, false otherwise.

equals

public static boolean equals(int[] left,
                             int[] right)
Compare the contents of this array to the contents of the given array.

Parameters:
left - an int array
right - the operand array.
Returns:
true if the contents of both arrays are equal.

equals

public 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. This returns false if either collection is null.

Parameters:
left - this array
right - the list being compared
Returns:
true if the contents of both collections are equal

equals

public 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. This returns false if either collection is null.

Parameters:
left - this List
right - this Object[] being compared to
Returns:
true if the contents of both collections are equal

equals

public static boolean equals(java.util.List left,
                             java.util.List right)
Compare the contents of two Lists. Order matters. If numbers exist in the Lists, then they are compared as numbers, for example 2 == 2L. If either list is null, the result is false.

Parameters:
left - this List
right - the List being compared to.
Returns:
boolean true if the contents of both lists are identical, false otherwise.

minus

public static java.util.Set minus(java.util.Set self,
                                  java.util.Collection operands)
Create a Set composed of the elements of the first set minus the elements of the given collection.

TODO: remove using number comparator?

Parameters:
self - a set object
operands - the items to remove from the set
Returns:
the resulting set

minus

public static java.util.Set minus(java.util.Set self,
                                  java.lang.Object operand)
Create a Set composed of the elements of the first set minus the operand.

Parameters:
self - a set object
operand - the operand to remove from the set
Returns:
the resulting set

minus

public static java.lang.Object[] minus(java.lang.Object[] self,
                                       java.util.Collection removeMe)
Create an array composed of the elements of the first array minus the elements of the given collection.

Parameters:
self - an object array
removeMe - a Collection of elements to remove
Returns:
an array with the supplied elements removed

minus

public static java.lang.Object[] minus(java.lang.Object[] self,
                                       java.lang.Object[] removeMe)
Create an array composed of the elements of the first array minus the elements of the given array.

Parameters:
self - an object array
removeMe - an array of elements to remove
Returns:
an array with the supplied elements removed

minus

public static java.util.List minus(java.util.List self,
                                   java.util.Collection removeMe)
Create a List composed of the elements of the first list minus the elements of the given collection.

Parameters:
self - a List
removeMe - a Collection of elements to remove
Returns:
a List with the supplied elements removed

minus

public static java.util.List minus(java.util.List self,
                                   java.lang.Object operand)
Create a new List composed of the elements of the first list minus the operand.

Parameters:
self - a List object
operand - an element to remove from the list
Returns:
the resulting List with the operand removed

minus

public static java.lang.Object[] minus(java.lang.Object[] self,
                                       java.lang.Object operand)
Create a new object array composed of the elements of the first array minus the operand.

Parameters:
self - an object array
operand - an element to remove from the array
Returns:
a new array with the operand removed

flatten

public static java.util.Collection flatten(java.util.Collection self)
Flatten a collection. This collection and any nested arrays or collections have their contents (recursively) added to the new collection. WARNING: Any Maps found in the collection are flattened to the Map's values and merged into the flattened collection. This behavior may change in a future release. If you don't want Maps to be flattened use flatten(Collection, Closure) with an identity closure.

Parameters:
self - a Collection to flatten
Returns:
a flattened Collection

flatten

public static java.util.Collection flatten(java.lang.Object[] self)
Flatten an array. This array and any nested arrays or collections have their contents (recursively) added to the new collection.

Parameters:
self - an Array to flatten
Returns:
a flattened Collection
Since:
1.6.0

flatten

public static java.util.Collection flatten(boolean[] self)
Flatten an array. This array and any nested arrays or collections have their contents (recursively) added to the new collection.

Parameters:
self - a boolean Array to flatten
Returns:
a flattened Collection
Since:
1.6.0

flatten

public static java.util.Collection flatten(byte[] self)
Flatten an array. This array and any nested arrays or collections have their contents (recursively) added to the new collection.

Parameters:
self - a byte Array to flatten
Returns:
a flattened Collection
Since:
1.6.0

flatten

public static java.util.Collection flatten(char[] self)
Flatten an array. This array and any nested arrays or collections have their contents (recursively) added to the new collection.

Parameters:
self - a char Array to flatten
Returns:
a flattened Collection
Since:
1.6.0

flatten

public static java.util.Collection flatten(short[] self)
Flatten an array. This array and any nested arrays or collections have their contents (recursively) added to the new collection.

Parameters:
self - a short Array to flatten
Returns:
a flattened Collection
Since:
1.6.0

flatten

public static java.util.Collection flatten(int[] self)
Flatten an array. This array and any nested arrays or collections have their contents (recursively) added to the new collection.

Parameters:
self - an int Array to flatten
Returns:
a flattened Collection
Since:
1.6.0

flatten

public static java.util.Collection flatten(long[] self)
Flatten an array. This array and any nested arrays or collections have their contents (recursively) added to the new collection.

Parameters:
self - a long Array to flatten
Returns:
a flattened Collection
Since:
1.6.0

flatten

public static java.util.Collection flatten(float[] self)
Flatten an array. This array and any nested arrays or collections have their contents (recursively) added to the new collection.

Parameters:
self - a float Array to flatten
Returns:
a flattened Collection
Since:
1.6.0

flatten

public static java.util.Collection flatten(double[] self)
Flatten an array. This array and any nested arrays or collections have their contents (recursively) added to the new collection.

Parameters:
self - a double Array to flatten
Returns:
a flattened Collection
Since:
1.6.0

flatten

public static java.util.Collection flatten(java.util.Collection self,
                                           Closure flattenUsing)
Flatten a collection. This collection and any nested arrays or collections have their contents (recursively) added to the new collection. For any non-Array, non-Collection object which represents some sort of collective type, the supplied closure should yield the contained items; otherwise, the closure should just return any element which corresponds to a leaf.

Parameters:
self - a Collection
flattenUsing - a closure to determine how to flatten non-Array, non-Collection elements
Returns:
a flattened Collection

leftShift

public static java.util.Collection leftShift(java.util.Collection self,
                                             java.lang.Object value)
Overloads the left shift operator to provide an easy way to append objects to a Collection.

Parameters:
self - a Collection
value - an Object to be added to the collection.
Returns:
same collection, after the value was added to it.

leftShift

public static java.util.Map leftShift(java.util.Map self,
                                      java.util.Map.Entry entry)
Overloads the left shift operator to provide an easy way to append Map.Entry values to a Map.

Parameters:
self - a Map
entry - a Map.Entry to be added to the Map.
Returns:
same map, after the value has been added to it.

leftShift

public 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.

Parameters:
self - a String
value - an Obect
Returns:
a StringBuffer built from this string

createStringWriter

protected static java.io.StringWriter createStringWriter(java.lang.String self)

createStringBufferWriter

protected static StringBufferWriter createStringBufferWriter(java.lang.StringBuffer self)

leftShift

public 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.

Parameters:
self - a StringBuffer
value - a value to append
Returns:
the StringBuffer on which this operation was invoked

leftShift

public static java.io.Writer leftShift(java.io.Writer self,
                                       java.lang.Object value)
                                throws java.io.IOException
Overloads the left shift operator to provide a mechanism to append values to a writer.

Parameters:
self - a Writer
value - a value to append
Returns:
the writer on which this operation was invoked
Throws:
java.io.IOException - if an I/O error occurs.

leftShift

public static java.lang.Number leftShift(java.lang.Number self,
                                         java.lang.Number operand)
Implementation of the left shift operator for integral types. Non integral Number types throw UnsupportedOperationException.

Parameters:
self - a Number object
operand - the shift distance by which to left shift the number
Returns:
the resulting number

rightShift

public static java.lang.Number rightShift(java.lang.Number self,
                                          java.lang.Number operand)
Implementation of the right shift operator for integral types. Non integral Number types throw UnsupportedOperationException.

Parameters:
self - a Number object
operand - the shift distance by which to right shift the number
Returns:
the resulting number

rightShiftUnsigned

public static java.lang.Number rightShiftUnsigned(java.lang.Number self,
                                                  java.lang.Number operand)
Implementation of the right shift (unsigned) operator for integral types. Non integral Number types throw UnsupportedOperationException.

Parameters:
self - a Number object
operand - the shift distance by which to right shift (unsigned) the number
Returns:
the resulting number

write

public static void write(java.io.Writer self,
                         Writable writable)
                  throws java.io.IOException
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.

Parameters:
self - a Writer
writable - an object implementing the Writable interface
Throws:
java.io.IOException - if an I/O error occurs.

leftShift

public static java.io.Writer leftShift(java.io.OutputStream self,
                                       java.lang.Object value)
                                throws java.io.IOException
Overloads the leftShift operator to provide an append mechanism to add values to a stream.

Parameters:
self - an OutputStream
value - a value to append
Returns:
a Writer
Throws:
java.io.IOException - if an I/O error occurs.

leftShift

public static void leftShift(java.io.ObjectOutputStream self,
                             java.lang.Object value)
                      throws java.io.IOException
Overloads the leftShift operator to add objects to an ObjectOutputStream.

Parameters:
self - an ObjectOutputStream
value - an object to write to the stream
Throws:
java.io.IOException - if an I/O error occurs.
Since:
1.1 beta 2

leftShift

public static java.io.OutputStream leftShift(java.io.OutputStream self,
                                             java.io.InputStream in)
                                      throws java.io.IOException
Pipe an InputStream into an OutputStream for efficient stream copying.

Parameters:
self - stream on which to write
in - stream to read from
Returns:
the outputstream itself
Throws:
java.io.IOException - if an I/O error occurs.

leftShift

public static java.io.OutputStream leftShift(java.io.OutputStream self,
                                             byte[] value)
                                      throws java.io.IOException
Overloads the leftShift operator to provide an append mechanism to add bytes to a stream.

Parameters:
self - an OutputStream
value - a value to append
Returns:
an OutputStream
Throws:
java.io.IOException - if an I/O error occurs.

getAt

public static java.lang.Object getAt(byte[] array,
                                     int index)
Support the subscript operator for a byte array

Parameters:
array - a byte array
index - the index of the item to retrieve
Returns:
the byte at the given index

getAt

public static java.lang.Object getAt(char[] array,
                                     int index)
Support the subscript operator for a char array

Parameters:
array - a char array
index - the index of the item to retrieve
Returns:
the char at the given index

getAt

public static java.lang.Object getAt(short[] array,
                                     int index)
Support the subscript operator for a short array

Parameters:
array - a short array
index - the index of the item to retrieve
Returns:
the short at the given index

getAt

public static java.lang.Object getAt(int[] array,
                                     int index)
Support the subscript operator for an int array

Parameters:
array - an int array
index - the index of the item to retrieve
Returns:
the int at the given index

getAt

public static java.lang.Object getAt(long[] array,
                                     int index)
Support the subscript operator for a long array

Parameters:
array - a long array
index - the index of the item to retrieve
Returns:
the long at the given index

getAt

public static java.lang.Object getAt(float[] array,
                                     int index)
Support the subscript operator for a float array

Parameters:
array - a float array
index - the index of the item to retrieve
Returns:
the float at the given index

getAt

public static java.lang.Object getAt(double[] array,
                                     int index)
Support the subscript operator for a double array

Parameters:
array - a double array
index - the index of the item to retrieve
Returns:
the double at the given index

getAt

public static java.lang.Object getAt(boolean[] array,
                                     int index)
Support the subscript operator for a boolean array

Parameters:
array - a boolean array
index - the index of the item to retrieve
Returns:
the boolean at the given index

getAt

public static java.lang.Object getAt(byte[] array,
                                     Range range)
Support the subscript operator with a range for a byte array

Parameters:
array - a byte array
range - a range indicating the indices for the items to retrieve
Returns:
list of the retrieved bytes

getAt

public static java.lang.Object getAt(char[] array,
                                     Range range)
Support the subscript operator with a range for a char array

Parameters:
array - a char array
range - a range indicating the indices for the items to retrieve
Returns:
list of the retrieved chars

getAt

public static java.lang.Object getAt(short[] array,
                                     Range range)
Support the subscript operator with a range for a short array

Parameters:
array - a short array
range - a range indicating the indices for the items to retrieve
Returns:
list of the retrieved shorts

getAt

public static java.lang.Object getAt(int[] array,
                                     Range range)
Support the subscript operator with a range for an int array

Parameters:
array - an int array
range - a range indicating the indices for the items to retrieve
Returns:
list of the ints at the given indices

getAt

public static java.lang.Object getAt(long[] array,
                                     Range range)
Support the subscript operator with a range for a long array

Parameters:
array - a long array
range - a range indicating the indices for the items to retrieve
Returns:
list of the retrieved longs

getAt

public static java.lang.Object getAt(float[] array,
                                     Range range)
Support the subscript operator with a range for a float array

Parameters:
array - a float array
range - a range indicating the indices for the items to retrieve
Returns:
list of the retrieved floats

getAt

public static java.lang.Object getAt(double[] array,
                                     Range range)
Support the subscript operator with a range for a double array

Parameters:
array - a double array
range - a range indicating the indices for the items to retrieve
Returns:
list of the retrieved doubles

getAt

public static java.lang.Object getAt(boolean[] array,
                                     Range range)
Support the subscript operator with a range for a boolean array

Parameters:
array - a boolean array
range - a range indicating the indices for the items to retrieve
Returns:
list of the retrieved booleans

getAt

public static java.lang.Object getAt(byte[] array,
                                     IntRange range)
Support the subscript operator with an IntRange for a byte array

Parameters:
array - a byte array
range - an IntRange indicating the indices for the items to retrieve
Returns:
list of the retrieved bytes

getAt

public static java.lang.Object getAt(char[] array,
                                     IntRange range)
Support the subscript operator with an IntRange for a char array

Parameters:
array - a char array
range - an IntRange indicating the indices for the items to retrieve
Returns:
list of the retrieved chars

getAt

public static java.lang.Object getAt(short[] array,
                                     IntRange range)
Support the subscript operator with an IntRange for a short array

Parameters:
array - a short array
range - an IntRange indicating the indices for the items to retrieve
Returns:
list of the retrieved shorts

getAt

public static java.lang.Object getAt(int[] array,
                                     IntRange range)
Support the subscript operator with an IntRange for an int array

Parameters:
array - an int array
range - an IntRange indicating the indices for the items to retrieve
Returns:
list of the retrieved ints

getAt

public static java.lang.Object getAt(long[] array,
                                     IntRange range)
Support the subscript operator with an IntRange for a long array

Parameters:
array - a long array
range - an IntRange indicating the indices for the items to retrieve
Returns:
list of the retrieved longs

getAt

public static java.lang.Object getAt(float[] array,
                                     IntRange range)
Support the subscript operator with an IntRange for a float array

Parameters:
array - a float array
range - an IntRange indicating the indices for the items to retrieve
Returns:
list of the retrieved floats

getAt

public static java.lang.Object getAt(double[] array,
                                     IntRange range)
Support the subscript operator with an IntRange for a double array

Parameters:
array - a double array
range - an IntRange indicating the indices for the items to retrieve
Returns:
list of the retrieved doubles

getAt

public static java.lang.Object getAt(boolean[] array,
                                     IntRange range)
Support the subscript operator with an IntRange for a boolean array

Parameters:
array - a boolean array
range - an IntRange indicating the indices for the items to retrieve
Returns:
list of the retrieved booleans

getAt

public static java.lang.Object getAt(byte[] array,
                                     ObjectRange range)
Support the subscript operator with an ObjectRange for a byte array

Parameters:
array - a byte array
range - an ObjectRange indicating the indices for the items to retrieve
Returns:
list of the retrieved bytes

getAt

public static java.lang.Object getAt(char[] array,
                                     ObjectRange range)
Support the subscript operator with an ObjectRange for a char array

Parameters:
array - a char array
range - an ObjectRange indicating the indices for the items to retrieve
Returns:
list of the retrieved chars

getAt

public static java.lang.Object getAt(short[] array,
                                     ObjectRange range)
Support the subscript operator with an ObjectRange for a short array

Parameters:
array - a short array
range - an ObjectRange indicating the indices for the items to retrieve
Returns:
list of the retrieved shorts

getAt

public static java.lang.Object getAt(int[] array,
                                     ObjectRange range)
Support the subscript operator with an ObjectRange for an int array

Parameters:
array - an int array
range - an ObjectRange indicating the indices for the items to retrieve
Returns:
list of the retrieved ints

getAt

public static java.lang.Object getAt(long[] array,
                                     ObjectRange range)
Support the subscript operator with an ObjectRange for a long array

Parameters:
array - a long array
range - an ObjectRange indicating the indices for the items to retrieve
Returns:
list of the retrieved longs

getAt

public static java.lang.Object getAt(float[] array,
                                     ObjectRange range)
Support the subscript operator with an ObjectRange for a float array

Parameters:
array - a float array
range - an ObjectRange indicating the indices for the items to retrieve
Returns:
list of the retrieved floats

getAt

public static java.lang.Object getAt(double[] array,
                                     ObjectRange range)
Support the subscript operator with an ObjectRange for a double array

Parameters:
array - a double array
range - an ObjectRange indicating the indices for the items to retrieve
Returns:
list of the retrieved doubles

getAt

public static java.lang.Object getAt(boolean[] array,
                                     ObjectRange range)
Support the subscript operator with an ObjectRange for a byte array

Parameters:
array - a byte array
range - an ObjectRange indicating the indices for the items to retrieve
Returns:
list of the retrieved bytes

getAt

public static java.lang.Object getAt(byte[] array,
                                     java.util.Collection indices)
Support the subscript operator with a collection for a byte array

Parameters:
array - a byte array
indices - a collection of indices for the items to retrieve
Returns:
list of the bytes at the given indices

getAt

public static java.lang.Object getAt(char[] array,
                                     java.util.Collection indices)
Support the subscript operator with a collection for a char array

Parameters:
array - a char array
indices - a collection of indices for the items to retrieve
Returns:
list of the chars at the given indices

getAt

public static java.lang.Object getAt(short[] array,
                                     java.util.Collection indices)
Support the subscript operator with a collection for a short array

Parameters:
array - a short array
indices - a collection of indices for the items to retrieve
Returns:
list of the shorts at the given indices

getAt

public static java.lang.Object getAt(int[] array,
                                     java.util.Collection indices)
Support the subscript operator with a collection for an int array

Parameters:
array - an int array
indices - a collection of indices for the items to retrieve
Returns:
list of the ints at the given indices

getAt

public static java.lang.Object getAt(long[] array,
                                     java.util.Collection indices)
Support the subscript operator with a collection for a long array

Parameters:
array - a long array
indices - a collection of indices for the items to retrieve
Returns:
list of the longs at the given indices

getAt

public static java.lang.Object getAt(float[] array,
                                     java.util.Collection indices)
Support the subscript operator with a collection for a float array

Parameters:
array - a float array
indices - a collection of indices for the items to retrieve
Returns:
list of the floats at the given indices

getAt

public static java.lang.Object getAt(double[] array,
                                     java.util.Collection indices)
Support the subscript operator with a collection for a double array

Parameters:
array - a double array
indices - a collection of indices for the items to retrieve
Returns:
list of the doubles at the given indices

getAt

public static java.lang.Object getAt(boolean[] array,
                                     java.util.Collection indices)
Support the subscript operator with a collection for a boolean array

Parameters:
array - a boolean array
indices - a collection of indices for the items to retrieve
Returns:
list of the booleans at the given indices

getAt

public static boolean getAt(java.util.BitSet self,
                            int index)
Support the subscript operator for a Bitset

Parameters:
self - a BitSet
index - index to retrieve
Returns:
value of the bit at the given index
See Also:
BitSet

getAt

public static java.util.BitSet getAt(java.util.BitSet self,
                                     IntRange range)
Support retrieving a subset of a BitSet using a Range

Parameters:
self - a BitSet
range - a Range defining the desired subset
Returns:
a new BitSet that represents the requested subset
See Also:
BitSet, IntRange

putAt

public static java.lang.Boolean putAt(boolean[] array,
                                      int idx,
                                      java.lang.Boolean newValue)

putAt

public static java.lang.Byte putAt(byte[] array,
                                   int idx,
                                   java.lang.Object newValue)

putAt

public static java.lang.Character putAt(char[] array,
                                        int idx,
                                        java.lang.Object newValue)

putAt

public static java.lang.Short putAt(short[] array,
                                    int idx,
                                    java.lang.Object newValue)

putAt

public static java.lang.Integer putAt(int[] array,
                                      int idx,
                                      java.lang.Object newValue)

putAt

public static java.lang.Long putAt(long[] array,
                                   int idx,
                                   java.lang.Object newValue)

putAt

public static java.lang.Float putAt(float[] array,
                                    int idx,
                                    java.lang.Object newValue)

putAt

public static java.lang.Double putAt(double[] array,
                                     int idx,
                                     java.lang.Object newValue)

putAt

public static void putAt(java.util.BitSet self,
                         IntRange range,
                         boolean value)
Support assigning a range of values with a single assignment statement.

Parameters:
self - a BitSet
range - the range of values to set
value - value
See Also:
BitSet, Range

putAt

public static void putAt(java.util.BitSet self,
                         int index,
                         boolean value)
Support subscript-style assignment for a BitSet.

Parameters:
self - a BitSet
index - index of the entry to set
value - value
See Also:
BitSet

size

public static int size(boolean[] array)
Allows arrays to behave similar to collections.

Parameters:
array - a boolean array
Returns:
the length of the array
See Also:
Array.getLength(Object)

size

public static int size(byte[] array)
Allows arrays to behave similar to collections.

Parameters:
array - a byte array
Returns:
the length of the array
See Also:
Array.getLength(Object)

size

public static int size(char[] array)
Allows arrays to behave similar to collections.

Parameters:
array - a char array
Returns:
the length of the array
See Also:
Array.getLength(Object)

size

public static int size(short[] array)
Allows arrays to behave similar to collections.

Parameters:
array - a short array
Returns:
the length of the array
See Also:
Array.getLength(Object)

size

public static int size(int[] array)
Allows arrays to behave similar to collections.

Parameters:
array - an int array
Returns:
the length of the array
See Also:
Array.getLength(Object)

size

public static int size(long[] array)
Allows arrays to behave similar to collections.

Parameters:
array - a long array
Returns:
the length of the array
See Also:
Array.getLength(Object)

size

public static int size(float[] array)
Allows arrays to behave similar to collections.

Parameters:
array - a float array
Returns:
the length of the array
See Also:
Array.getLength(Object)

size

public static int size(double[] array)
Allows arrays to behave similar to collections.

Parameters:
array - a double array
Returns:
the length of the array
See Also:
Array.getLength(Object)

toList

public static java.util.List toList(byte[] array)
Converts this array to a List of the same size, with each element added to the list.

Parameters:
array - an array
Returns:
a list containing the contents of this array.

toList

public static java.util.List toList(boolean[] array)
Converts this array to a List of the same size, with each element added to the list.

Parameters:
array - a boolean array
Returns:
a list containing the contents of this array.
Since:
1.6.0

toList

public static java.util.List toList(char[] array)
Converts this array to a List of the same size, with each element added to the list.

Parameters:
array - a char array
Returns:
a list containing the contents of this array.
Since:
1.0

toList

public static java.util.List toList(short[] array)
Converts this array to a List of the same size, with each element added to the list.

Parameters:
array - a short array
Returns:
a list containing the contents of this array.

toList

public static java.util.List toList(int[] array)
Converts this array to a List of the same size, with each element added to the list.

Parameters:
array - an int array
Returns:
a list containing the contents of this array.

toList

public static java.util.List toList(long[] array)
Converts this array to a List of the same size, with each element added to the list.

Parameters:
array - a long array
Returns:
a list containing the contents of this array.

toList

public static java.util.List toList(float[] array)
Converts this array to a List of the same size, with each element added to the list.

Parameters:
array - a float array
Returns:
a list containing the contents of this array.

toList

public static java.util.List toList(double[] array)
Converts this array to a List of the same size, with each element added to the list.

Parameters:
array - a double array
Returns:
a list containing the contents of this array.

encodeBase64

public static Writable encodeBase64(java.lang.Byte[] data,
                                    boolean chunked)
Produce a Writable object which writes the Base64 encoding of the byte array. Calling toString() on the result returns the encoding as a String. For more information on Base64 encoding and chunking see RFC 4648.

Parameters:
data - Byte array to be encoded
chunked - whether or not the Base64 encoded data should be MIME chunked
Returns:
object which will write the Base64 encoding of the byte array

encodeBase64

public static Writable encodeBase64(java.lang.Byte[] data)
Produce a Writable object which writes the Base64 encoding of the byte array. Calling toString() on the result returns the encoding as a String. For more information on Base64 encoding and chunking see RFC 4648.

Parameters:
data - Byte array to be encoded
Returns:
object which will write the Base64 encoding of the byte array

encodeBase64

public static Writable encodeBase64(byte[] data,
                                    boolean chunked)
Produce a Writable object which writes the Base64 encoding of the byte array. Calling toString() on the result returns the encoding as a String. For more information on Base64 encoding and chunking see RFC 4648.

Parameters:
data - byte array to be encoded
chunked - whether or not the Base64 encoded data should be MIME chunked
Returns:
object which will write the Base64 encoding of the byte array

encodeBase64

public static Writable encodeBase64(byte[] data)
Produce a Writable object which writes the Base64 encoding of the byte array. Calling toString() on the result returns the encoding as a String. For more information on Base64 encoding and chunking see RFC 4648.

Parameters:
data - byte array to be encoded
Returns:
object which will write the Base64 encoding of the byte array

decodeBase64

public static byte[] decodeBase64(java.lang.String value)
Decode the String from Base64 into a byte array.

Parameters:
value - the string to be decoded
Returns:
the decoded bytes as an array

primitiveArrayGet

protected static java.lang.Object primitiveArrayGet(java.lang.Object self,
                                                    int idx)
Implements the getAt(int) method for primitve type arrays.

Parameters:
self - an array object
idx - the index of interest
Returns:
the returned value from the array

primitiveArrayGet

protected static java.util.List primitiveArrayGet(java.lang.Object self,
                                                  Range range)
Implements the getAt(Range) method for primitve type arrays.

Parameters:
self - an array object
range - the range of indices of interest
Returns:
the returned values from the array corresponding to the range

primitiveArrayGet

protected static java.util.List primitiveArrayGet(java.lang.Object self,
                                                  java.util.Collection indices)
Implements the getAt(Collection) method for primitve type arrays. Each value in the collection argument is assumed to be a valid array index. The value at each index is then added to a list which is returned.

Parameters:
self - an array object
indices - the indices of interest
Returns:
the returned values from the array

primitiveArrayPut

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.

Parameters:
self - an object
idx - the index of interest
newValue - the new value to be put into the index of interest
Returns:
the added value

toCharacter

public static java.lang.Character toCharacter(java.lang.String self)
Converts the given string into a Character object using the first character in the string.

Parameters:
self - a String
Returns:
the first Character

toBoolean

public static java.lang.Boolean toBoolean(java.lang.String self)
Converts the given string into a Boolean object. If the trimmed string is "true", "y" or "1" (ignoring case) then the result is true othewrwise it is false.

Parameters:
self - a String
Returns:
The Boolean value

split

public 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

Parameters:
self - the string to split
Returns:
String[] result of split

split

public static java.lang.String[] split(GString self)
Convenience method to split a GString (with whitespace as delimiter).

Parameters:
self - the GString to split
Returns:
String[] result of split
Since:
1.6.1
See Also:
split(String)

tokenize

public static java.util.List tokenize(java.lang.String self,
                                      java.lang.String token)
Tokenize a String based on the given string delimiter.

Parameters:
self - a String
token - the delimiter
Returns:
a List of tokens
See Also:
StringTokenizer.StringTokenizer(java.lang.String, java.lang.String)

tokenize

public static java.util.List tokenize(java.lang.String self)
Tokenize a String (with a whitespace as the delimiter).

Parameters:
self - a String
Returns:
a List of tokens
See Also:
StringTokenizer.StringTokenizer(java.lang.String)

plus

public static java.lang.String plus(java.lang.String left,
                                    java.lang.Object value)
Appends the String representation of the given operand to this string.

Parameters:
left - a String
value - any Object
Returns:
the new string with the object appended

plus

public static java.lang.String plus(java.lang.Number value,
                                    java.lang.String right)
Appends a String to the string representation of this number.

Parameters:
value - a Number
right - a String
Returns:
a String

plus

public static java.lang.String plus(java.lang.StringBuffer left,
                                    java.lang.String value)
Appends a String to this StringBuffer.

Parameters:
left - a StringBuffer
value - a String
Returns:
a String

minus

public static java.lang.String minus(java.lang.String self,
                                     java.lang.Object target)
Remove a part of a String. This replaces the first occurrence of target within self with '' and returns the result. If target is a regex Pattern, the first occurrence of that pattern will be removed (using regex matching), otherwise the first occurrence of target.toString() will be removed.

Parameters:
self - a String
target - an object representing the part to remove
Returns:
a String minus the part to be removed

contains

public static boolean contains(java.lang.String self,
                               java.lang.String text)
Provide an implementation of contains() like Collection.contains(Object) to make Strings more polymorphic. This method is not required on JDK 1.5 onwards

Parameters:
self - a String
text - a String to look for
Returns:
true if this string contains the given text

count

public static int count(java.lang.String self,
                        java.lang.String text)
Count the number of occurencies of a substring.

Parameters:
self - a String
text - a substring
Returns:
the number of occurrencies of the given string inside this String

next

public static java.lang.String next(java.lang.String self)
This method is called by the ++ operator for the class String. It increments the last character in the given string. If the character in the string is Character.MAX_VALUE a Character.MIN_VALUE will be appended. The empty string is incremented to a string consisting of the character Character.MIN_VALUE.

Parameters:
self - a String
Returns:
an incremented String

previous

public static java.lang.String previous(java.lang.String self)
This method is called by the -- operator for the class String. It decrements the last character in the given string. If the character in the string is Character.MIN_VALUE it will be deleted. The empty string can't be decremented.

Parameters:
self - a String
Returns:
a String with a decremented digit at the end

execute

public static java.lang.Process execute(java.lang.String self)
                                 throws java.io.IOException
Executes the given string as a command line process. For more control over the process mechanism in JDK 1.5 you can use java.lang.ProcessBuilder.

Parameters:
self - a command line String
Returns:
the Process which has just started for this command line string
Throws:
java.io.IOException - if an IOException occurs.

execute

public static java.lang.Process execute(java.lang.String[] commandArray)
                                 throws java.io.IOException
Executes the command specified by the String array that is the parameter. The first item in the array is the command the others are the parameters. For more control over the process mechanism in JDK 1.5 you can use java.lang.ProcessBuilder.

Parameters:
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 string.
Throws:
java.io.IOException - if an IOException occurs.

execute

public static java.lang.Process execute(java.lang.String self,
                                        java.lang.String[] envp,
                                        java.io.File dir)
                                 throws java.io.IOException
Executes the command specified by the self with environments envp under the working directory dir. For more control over the process mechanism in JDK 1.5 you can use java.lang.ProcessBuilder.

Parameters:
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.
Returns:
the Process which has just started for this command line string.
Throws:
java.io.IOException - if an IOException occurs.

execute

public static java.lang.Process execute(java.util.List commandList)
                                 throws java.io.IOException
Executes the command specified by the String list that is the parameter. The first item in the array is the command the others are the parameters. All entries must be Strings. For more control over the process mechanism in JDK 1.5 you can use java.lang.ProcessBuilder.

Parameters:
commandList - a list of String containing the command name and parameters as separate items in the list.
Returns:
the Process which has just started for this command line string.
Throws:
java.io.IOException - if an IOException occurs.

execute

public static java.lang.Process execute(java.lang.String self,
                                        java.util.List envp,
                                        java.io.File dir)
                                 throws java.io.IOException
Executes the command specified by the self with environments envp under the working directory dir. For more control over the process mechanism in JDK 1.5 you can use java.lang.ProcessBuilder.

Parameters:
self - a command line String to be executed.
envp - a List 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 string.
Throws:
java.io.IOException - if an IOException occurs.

multiply

public static java.lang.String multiply(java.lang.String self,
                                        java.lang.Number factor)
Repeat a String a certain number of times.

Parameters:
self - a String to be repeated
factor - the number of times the String should be repeated
Returns:
a String composed of a repetition
Throws:
java.lang.IllegalArgumentException - if the number of repetitions is < 0

toString

public static java.lang.String toString(java.util.Map self)
Returns the string representation of the given map.

Parameters:
self - a Map
Returns:
the string representation
See Also:
toMapString(Map)

toMapString

public static java.lang.String toMapString(java.util.Map self)
Returns the string representation of this map. The string displays the contents of the map, i.e. {one=1, two=2, three=3}.

Parameters:
self - a Map
Returns:
the string representation

toString

public static java.lang.String toString(java.util.Collection self)
Returns the string representation of the given collection. The string displays the contents of the collection, i.e. [1, 2, a].

Parameters:
self - a Collection
Returns:
the string representation
See Also:
toListString(Collection)

toListString

public static java.lang.String toListString(java.util.Collection self)
Returns the string representation of the given list. The string displays the contents of the list, similar to a list literal, i.e. [1, 2, a].

Parameters:
self - a Collection
Returns:
the string representation

toString

public static java.lang.String toString(java.lang.Object[] self)
Returns the string representation of this array's contents.

Parameters:
self - an Object[]
Returns:
the string representation
See Also:
toArrayString(Object[])

toArrayString

public static java.lang.String toArrayString(java.lang.Object[] self)
Returns the string representation of the given array. The string displays the contents of the array, similar to an array literal, i.e. {1, 2, "a"}.

Parameters:
self - an Object[]
Returns:
the string representation

toString

protected static java.lang.String toString(java.lang.Object value)
Create a String representation of this object.

Parameters:
value - an object
Returns:
a string.

next

public static java.lang.Character next(java.lang.Character self)
Increment a Character by one.

Parameters:
self - a Character
Returns:
an incremented Number

next

public static java.lang.Number next(java.lang.Number self)
Increment a Number by one.

Parameters:
self - a Number
Returns:
an incremented Number

previous

public static java.lang.Character previous(java.lang.Character self)
Decrement a Character by one.

Parameters:
self - a Character
Returns:
a decremented Number

previous

public static java.lang.Number previous(java.lang.Number self)
Decrement a Number by one.

Parameters:
self - a Number
Returns:
a decremented Number

plus

public static java.lang.Number plus(java.lang.Character left,
                                    java.lang.Number right)
Add a Character and a Number. This operation will always create a new object for the result, while the operands remain unchanged. This character should be one of the digits '0' through '9', and the result is addition of the integer conversion of this character plus the operand.

Parameters:
left - a Character
right - a Number
Returns:
the Number corresponding to the addition of left and right
See Also:
Integer.valueOf(String)

plus

public static java.lang.Number plus(java.lang.Number left,
                                    java.lang.Character right)
Add a Number and a Character. This assumes the character is one of the digits '0' through '9'.

Parameters:
left - a Number
right - a Character
Returns:
The Number corresponding to the addition of left and right
See Also:
Integer.valueOf(String)

plus

public static java.lang.Number plus(java.lang.Character left,
                                    java.lang.Character right)
Add two Characters. Both characters are assumed to represent digits ('0' through '9') and add the results. This operation will always create a new object for the result, while the operands remain unchanged.

Parameters:
left - a Character
right - a Character
Returns:
the Number corresponding to the addition of left and right
See Also:
plus(Number, Character)

plus

public static java.lang.Number plus(java.lang.Number left,
                                    java.lang.Number right)
Add two numbers and return the result.

Parameters:
left - a Number
right - another Number to add
Returns:
the addition of both Numbers

compareTo

public static int compareTo(java.lang.Character left,
                            java.lang.Number right)
Compare a Character and a Number. The character is assumed to be a digit (i.e. '0' through '9') which is converted to its Integer representation.

Parameters:
left - a Character
right - a Number
Returns:
the result of the comparison

compareTo

public static int compareTo(java.lang.Number left,
                            java.lang.Character right)
Compare a Number and a Character. The character is assumed to be a digit (i.e. '0' through '9') which is converted to its Integer representation.

Parameters:
left - a Number
right - a Character
Returns:
the result of the comparison

compareTo

public static int compareTo(java.lang.Character left,
                            java.lang.Character right)
Compare two Characters. Each character is assumed to be a digit (i.e. '0' through '9') which is converted to its Integer representation.

Parameters:
left - a Character
right - a Character
Returns:
the result of the comparison

compareTo

public static int compareTo(java.lang.Number left,
                            java.lang.Number right)
Compare two Numbers. Equality (==) for numbers dispatches to this.

Parameters:
left - a Number
right - another Number to compare to
Returns:
the comparision of both numbers

minus

public static java.lang.Number minus(java.lang.Character left,
                                     java.lang.Number right)
Subtract a Number from a Character. The character is assumed to be a digit (i.e. '0' through '9') which is converted to its Integer representation.

Parameters:
left - a Character
right - a Number
Returns:
the Number corresponding to the subtraction of right from left

minus

public static java.lang.Number minus(java.lang.Number left,
                                     java.lang.Character right)
Subtract a Character from a Number. The character is assumed to be a digit (i.e. '0' through '9') which is converted to its Integer representation.

Parameters:
left - a Number
right - a Character
Returns:
the Number corresponding to the subtraction of right from left

minus

public static java.lang.Number minus(java.lang.Character left,
                                     java.lang.Character right)
Subtract one Characters from another by converting them both to their Integer representations. Each character is assumed to be a digit (i.e. '0' through '9') which is converted to its Integer representation.

Parameters:
left - a Character
right - a Character
Returns:
the Number corresponding to the subtraction of right from left

minus

public static java.lang.Number minus(java.lang.Number left,
                                     java.lang.Number right)
Substraction of two Numbers.

Parameters:
left - a Number
right - another Number to substract to the first one
Returns:
the substraction

multiply

public static java.lang.Number multiply(java.lang.Character left,
                                        java.lang.Number right)
Multiply a Character by a Number. The character is assumed to be a digit (i.e. '0' through '9') which is converted to its Integer representation.

Parameters:
left - a Character
right - a Number
Returns:
the Number corresponding to the multiplication of left by right

multiply

public static java.lang.Number multiply(java.lang.Number left,
                                        java.lang.Character right)
Multiply a Number by a Character. The character is assumed to be a digit (i.e. '0' through '9') which is converted to its Integer representation.

Parameters:
left - a Number
right - a Character
Returns:
the multiplication of left by right

multiply

public static java.lang.Number multiply(java.lang.Character left,
                                        java.lang.Character right)
Multiply two Characters. Each character is assumed to be a digit (i.e. '0' through '9') which is converted to its Integer representation.

Parameters:
left - a Character
right - another Character
Returns:
the Number corresponding to the multiplication of left by right

multiply

public static java.lang.Number multiply(java.lang.Number left,
                                        java.lang.Number right)
Multiply two Numbers.

Parameters:
left - a Number
right - another Number
Returns:
the multiplication of both

multiply

public static java.lang.Number multiply(java.math.BigDecimal left,
                                        java.lang.Double right)
Multiply a BigDecimal and a Double. Note: This method was added to enforce the Groovy rule of BigDecimal*Double == Double. Without this method, the multiply(BigDecimal) method in BigDecimal would respond and return a BigDecimal instead. Since BigDecimal is prefered over Number, the Number*Number method is not choosen as in older versions of Groovy.

Parameters:
left - a BigDecimal
right - a Double
Returns:
the multiplication of left by right

multiply

public static java.lang.Number multiply(java.math.BigDecimal left,
                                        java.math.BigInteger right)
Multiply a BigDecimal and a BigInteger. Note: This method was added to enforce the Groovy rule of BigDecimal*long == long. Without this method, the multiply(BigDecimal) method in BigDecimal would respond and return a BigDecimal instead. Since BigDecimal is prefered over Number, the Number*Number method is not choosen as in older versions of Groovy. Biginteger is the fallback for all integer types in Groovy

Parameters:
left - a BigDecimal
right - a BigInteger
Returns:
the multiplication of left by right

power

public static java.lang.Number power(java.lang.Number self,
                                     java.lang.Number exponent)
Power of a Number to a certain exponent. Called by the '**' operator.

Parameters:
self - a Number
exponent - a Number exponent
Returns:
a Number to the power of a certain exponent

div

public static java.lang.Number div(java.lang.Character left,
                                   java.lang.Number right)
Divide a Character by a Number. The character is assumed to be a digit (i.e. '0' through '9') which is converted to its Integer representation.

Parameters:
left - a Character
right - a Number
Returns:
the Number corresponding to the division of left by right

div

public static java.lang.Number div(java.lang.Number left,
                                   java.lang.Character right)
Divide a Number by a Character. The character is assumed to be a digit (i.e. '0' through '9') which is converted to its Integer representation.

Parameters:
left - a Number
right - a Character
Returns:
the Number corresponding to the division of left by right

div

public static java.lang.Number div(java.lang.Character left,
                                   java.lang.Character right)
Divide one Character by another. Each character is assumed to be a digit (i.e. '0' through '9') which is converted to its Integer representation.

Parameters:
left - a Character
right - another Character
Returns:
the Number corresponding to the division of left by right

div

public static java.lang.Number div(java.lang.Number left,
                                   java.lang.Number right)
Divide two Numbers.

Parameters:
left - a Number
right - another Number
Returns:
a Number resulting of the divide operation

intdiv

public static java.lang.Number intdiv(java.lang.Character left,
                                      java.lang.Number right)
Integer Divide a Character by a Number.

Parameters:
left - a Character
right - a Number
Returns:
a Number (an Integer) resulting from the integer division operation

intdiv

public static java.lang.Number intdiv(java.lang.Number left,
                                      java.lang.Character right)
Integer Divide a Number by a Character.

Parameters:
left - a Number
right - a Character
Returns:
a Number (an Integer) resulting from the integer division operation

intdiv

public static java.lang.Number intdiv(java.lang.Character left,
                                      java.lang.Character right)
Integer Divide two Characters.

Parameters:
left - a Character
right - another Character
Returns:
a Number (an Integer) resulting from the integer division operation

intdiv

public static java.lang.Number intdiv(java.lang.Number left,
                                      java.lang.Number right)
Integer Divide two Numbers.

Parameters:
left - a Number
right - another Number
Returns:
a Number (an Integer) resulting from the integer division operation

or

public static java.lang.Number or(java.lang.Number left,
                                  java.lang.Number right)
Bitwise OR together two numbers.

Parameters:
left - a Number
right - another Number to bitwise OR
Returns:
the bitwise OR of both Numbers

and

public static java.lang.Number and(java.lang.Number left,
                                   java.lang.Number right)
Bitwise AND together two Numbers.

Parameters:
left - a Number
right - another Number to bitwise AND
Returns:
the bitwise AND of both Numbers

and

public static java.util.BitSet and(java.util.BitSet left,
                                   java.util.BitSet right)
Bitwise AND together two BitSets.

Parameters:
left - a BitSet
right - another BitSet to bitwise AND
Returns:
the bitwise AND of both BitSets

xor

public static java.util.BitSet xor(java.util.BitSet left,
                                   java.util.BitSet right)
Bitwise XOR together two BitSets. Called when the '^' operator is used between two bit sets.

Parameters:
left - a BitSet
right - another BitSet to bitwise AND
Returns:
the bitwise XOR of both BitSets

bitwiseNegate

public static java.util.BitSet bitwiseNegate(java.util.BitSet self)
Bitwise NEGATE a BitSet.

Parameters:
self - a BitSet
Returns:
the bitwise NEGATE of the BitSet

or

public static java.util.BitSet or(java.util.BitSet left,
                                  java.util.BitSet right)
Bitwise OR together two BitSets. Called when the '|' operator is used between two bit sets.

Parameters:
left - a BitSet
right - another BitSet to bitwise AND
Returns:
the bitwise OR of both BitSets

xor

public static java.lang.Number xor(java.lang.Number left,
                                   java.lang.Number right)
Bitwise XOR together two Numbers. Called when the '|' operator is used.

Parameters:
left - a Number
right - another Number to bitwse XOR
Returns:
the bitwise XOR of both Numbers

mod

public static java.lang.Number mod(java.lang.Number left,
                                   java.lang.Number right)
Performs a division modulus operation. Called by the '%' operator.

Parameters:
left - a Number
right - another Number to mod
Returns:
the modulus result

unaryMinus

public static java.lang.Number unaryMinus(java.lang.Number left)
Negates the number. Equivalent to the '-' operator when it preceeds a single operand, i.e. -10

Parameters:
left - a Number
Returns:
the negation of the number

times

public static void times(java.lang.Number self,
                         Closure closure)
Executes the closure this many times, starting from zero. The current index is passed to the closure each time. Example:
10.times {
   println it
 }
Prints the numbers 0 through 9.

Parameters:
self - a Number
closure - the closure to call a number of times

upto

public 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.

Parameters:
self - a Number
to - another Number to go up to
closure - the closure to call

upto

public 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.

Parameters:
self - a long
to - the end number
closure - the code to execute for each number

upto

public 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.

Parameters:
self - a Long
to - the end number
closure - the code to execute for each number

upto

public 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.

Parameters:
self - a float
to - the end number
closure - the code to execute for each number

upto

public 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.

Parameters:
self - a Float
to - the end number
closure - the code to execute for each number

upto

public 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.

Parameters:
self - a double
to - the end number
closure - the code to execute for each number

upto

public 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.

Parameters:
self - a Double
to - the end number
closure - the code to execute for each number

upto

public 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. Example:
0.upto( 10 ) {
   println it
 }
Prints numbers 0 to 10

Parameters:
self - a BigInteger
to - the end number
closure - the code to execute for each number

upto

public 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.
0.upto( 10 ) {
   println it
 }
Prints numbers 0.1, 1.1, 2.1... to 9.1

Parameters:
self - a BigDecimal
to - the end number
closure - the code to execute for each number

downto

public 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.

Parameters:
self - a Number
to - another Number to go down to
closure - the closure to call

downto

public 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.

Parameters:
self - a long
to - the end number
closure - the code to execute for each number

downto

public 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.

Parameters:
self - a Long
to - the end number
closure - the code to execute for each number

downto

public 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.

Parameters:
self - a float
to - the end number
closure - the code to execute for each number

downto

public 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.

Parameters:
self - a Float
to - the end number
closure - the code to execute for each number

downto

public 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.

Parameters:
self - a double
to - the end number
closure - the code to execute for each number

downto

public 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.

Parameters:
self - a Double
to - the end number
closure - the code to execute for each number

downto

public 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.

Parameters:
self - a BigInteger
to - the end number
closure - the code to execute for each number

downto

public 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. Each number is passed to the closure. Example:
10.5.downto(0) {
   println it
 }
Prints numbers 10.5, 9.5 ... to 0.5.

Parameters:
self - a BigDecimal
to - the end number
closure - the code to execute for each number

step

public 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. Each intermediate number is passed to the given closure. Example:
0.step( 10, 2 ) {
   println it
 }
Prints even numbers 0 through 8.

Parameters:
self - a Number to start with
to - a Number to go up to, exclusive
stepNumber - a Number representing the step increment
closure - the closure to call

abs

public static int abs(java.lang.Number number)
Get the absolute value

Parameters:
number - a Number
Returns:
the absolute value of that Number

abs

public static long abs(java.lang.Long number)
Get the absolute value

Parameters:
number - a Long
Returns:
the absolute value of that Long

abs

public static float abs(java.lang.Float number)
Get the absolute value

Parameters:
number - a Float
Returns:
the absolute value of that Float

abs

public static double abs(java.lang.Double number)
Get the absolute value

Parameters:
number - a Double
Returns:
the absolute value of that Double

round

public static int round(java.lang.Float number)
Get the absolute value

Parameters:
number - a Float
Returns:
the absolute value of that Float

round

public static long round(java.lang.Double number)
Round the value

Parameters:
number - a Double
Returns:
the absolute value of that Double

toInteger

public static java.lang.Integer toInteger(java.lang.String self)
Parse a String into an Integer

Parameters:
self - a String
Returns:
an Integer

toLong

public static java.lang.Long toLong(java.lang.String self)
Parse a String into a Long

Parameters:
self - a String
Returns:
a Long

toShort

public static java.lang.Short toShort(java.lang.String self)
Parse a String into a Short

Parameters:
self - a String
Returns:
a Short

toFloat

public static java.lang.Float toFloat(java.lang.String self)
Parse a String into a Float

Parameters:
self - a String
Returns:
a Float

toDouble

public static java.lang.Double toDouble(java.lang.String self)
Parse a String into a Double

Parameters:
self - a String
Returns:
a Double

toBigInteger

public static java.math.BigInteger toBigInteger(java.lang.String self)
Parse a String into a BigInteger

Parameters:
self - a String
Returns:
a BigInteger

toBigDecimal

public static java.math.BigDecimal toBigDecimal(java.lang.String self)
Parse a String into a BigDecimal

Parameters:
self - a String
Returns:
a BigDecimal

isInteger

public static boolean isInteger(java.lang.String self)
Determine if a String can be parsed into an Integer.

Parameters:
self - a String
Returns:
true if the string can be parsed

isLong

public static boolean isLong(java.lang.String self)
Determine if a String can be parsed into a Long.

Parameters:
self - a String
Returns:
true if the string can be parsed

isFloat

public static boolean isFloat(java.lang.String self)
Determine if a String can be parsed into a Float.

Parameters:
self - a String
Returns:
true if the string can be parsed

isDouble

public static boolean isDouble(java.lang.String self)
Determine if a String can be parsed into a Double.

Parameters:
self - a String
Returns:
true if the string can be parsed

isBigInteger

public static boolean isBigInteger(java.lang.String self)
Determine if a String can be parsed into a BigInteger.

Parameters:
self - a String
Returns:
true if the string can be parsed

isBigDecimal

public static boolean isBigDecimal(java.lang.String self)
Determine if a String can be parsed into a BigDecimal.

Parameters:
self - a String
Returns:
true if the string can be parsed

isNumber

public static boolean isNumber(java.lang.String self)
Determine if a String can be parsed into a Number. Synonym for 'isBigDecimal()'.

Parameters:
self - a String
Returns:
true if the string can be parsed
See Also:
isBigDecimal(String)

isUpperCase

public static boolean isUpperCase(java.lang.Character self)
Determine if a Character is uppercase. Synonym for 'Character.isUpperCase(this)'.

Parameters:
self - a Character
Returns:
true if the character is uppercase
See Also:
Character.isUpperCase(char)

isLowerCase

public static boolean isLowerCase(java.lang.Character self)
Determine if a Character is lowercase. Synonym for 'Character.isLowerCase(this)'.

Parameters:
self - a Character
Returns:
true if the character is lowercase
See Also:
Character.isLowerCase(char)

isLetter

public static boolean isLetter(java.lang.Character self)
Determines if a character is a letter. Synonym for 'Character.isLetter(this)'.

Parameters:
self - a Character
Returns:
true if the character is a letter
See Also:
Character.isLetter(char)

isDigit

public static boolean isDigit(java.lang.Character self)
Determines if a character is a digit. Synonym for 'Character.isDigit(this)'.

Parameters:
self - a Character
Returns:
true if the character is a digit
See Also:
Character.isDigit(char)

isLetterOrDigit

public static boolean isLetterOrDigit(java.lang.Character self)
Determines if a character is a letter or digit. Synonym for 'Character.isLetterOrDigit(this)'.

Parameters:
self - a Character
Returns:
true if the character is a letter or digit
See Also:
Character.isLetterOrDigit(char)

isWhitespace

public static boolean isWhitespace(java.lang.Character self)
Determines if a character is a whitespace character. Synonym for 'Character.isWhitespace(this)'.

Parameters:
self - a Character
Returns:
true if the character is a whitespace character
See Also:
Character.isWhitespace(char)

toUpperCase

public static char toUpperCase(java.lang.Character self)
Converts the character to uppercase. Synonym for 'Character.toUpperCase(this)'.

Parameters:
self - a Character to convert
Returns:
the uppercase equivalent of the character, if any; otherwise, the character itself.
See Also:
Character.isUpperCase(char), String.toUpperCase()

toLowerCase

public static char toLowerCase(java.lang.Character self)
Converts the character to lowercase. Synonym for 'Character.toLowerCase(this)'.

Parameters:
self - a Character to convert
Returns:
the lowercase equivalent of the character, if any; otherwise, the character itself.
See Also:
Character.isLowerCase(char), String.toLowerCase()

toInteger

public static java.lang.Integer toInteger(java.lang.Number self)
Transform a Number into an Integer

Parameters:
self - a Number
Returns:
an Integer

toLong

public static java.lang.Long toLong(java.lang.Number self)
Transform a Number into a Long

Parameters:
self - a Number
Returns:
an Long

toFloat

public static java.lang.Float toFloat(java.lang.Number self)
Transform a Number into a Float

Parameters:
self - a Number
Returns:
an Float

toDouble

public static java.lang.Double toDouble(java.lang.Number self)
Transform a Number into a Double

Parameters:
self - a Number
Returns:
an Double

toBigDecimal

public static java.math.BigDecimal toBigDecimal(java.lang.Number self)
Transform a Number into a BigDecimal

Parameters:
self - a Number
Returns:
an BigDecimal

asType

public 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. The following types are supported in addition to the default asType(Object,Class):
  • BigDecimal
  • BigInteger
  • Double
  • Float

Parameters:
self - this number
c - the desired type of the transformed result
Returns:
an instance of the given type

toBigInteger

public static java.math.BigInteger toBigInteger(java.lang.Number self)
Transform this Number into a BigInteger.

Parameters:
self - a Number
Returns:
an BigInteger

next

public static java.util.Date next(java.util.Date self)
Increment a Date by one day.

Parameters:
self - a Date
Returns:
the next days date

next

public static java.sql.Date next(java.sql.Date self)
Increment a java.sql.Date by one day.

Parameters:
self - a java.sql.Date
Returns:
the next days date

previous

public static java.util.Date previous(java.util.Date self)
Decrement a Date by one day.

Parameters:
self - a Date
Returns:
the previous days date

previous

public static java.sql.Date previous(java.sql.Date self)
Decrement a java.sql.Date by one day.

Parameters:
self - a java.sql.Date
Returns:
the previous days date

plus

public static java.util.Date plus(java.util.Date self,
                                  int days)
Add a number of days to this date and returns the new date.

Parameters:
self - a Date
days - the number of days to increase
Returns:
the new date

plus

public static java.sql.Date plus(java.sql.Date self,
                                 int days)
Add a number of days to this date and returns the new date.

Parameters:
self - a java.sql.Date
days - the number of days to increase
Returns:
the new date

minus

public static java.util.Date minus(java.util.Date self,
                                   int days)
Subtract a number of days from this date and returns the new date.

Parameters:
self - a Date
days - the number of days to subtract
Returns:
the new date

minus

public static java.sql.Date minus(java.sql.Date self,
                                  int days)
Subtract a number of days from this date and returns the new date.

Parameters:
self - a java.sql.Date
days - the number of days to subtract
Returns:
the new date

minus

public static int minus(java.util.Calendar self,
                        java.util.Calendar then)
Subtract another date from this one and return the number of days of the difference. Date self = Date then + (Date self - Date then) IOW, if self is before then the result is a negative value.

Parameters:
self - a Calendar
then - another Calendar
Returns:
number of days

minus

public static int minus(java.util.Date self,
                        java.util.Date then)
Subtract another Date from this one and return the number of days of the difference. Date self = Date then + (Date self - Date then) IOW, if self is before then the result is a negative value.

Parameters:
self - a Date
then - another Date
Returns:
number of days

format

public static java.lang.String format(java.util.Date self,
                                      java.lang.String format)

Create a String representation of this date according to the given pattern.

For example, if the system timezone is GMT, new Date(0).format('MM/dd/yy') would return the string "01/01/70". See documentation for SimpleDateFormat for format pattern use.

Note that a new DateFormat instance is created for every invocation of this method (for thread safety).

Parameters:
self -
format - the format pattern to use according to SimpleDateFormat
Returns:
a string representation of this date.
See Also:
SimpleDateFormat

getDateString

public static java.lang.String getDateString(java.util.Date self)

Return a string representation of the 'day' portion of this date according to the locale-specific DateFormat.SHORT default format. For an "en_UK" system locale, this would be dd/MM/yy.

Note that a new DateFormat instance is created for every invocation of this method (for thread safety).

Parameters:
self -
Returns:
a string representation of this date
See Also:
DateFormat.getDateInstance(int), DateFormat.SHORT

getTimeString

public static java.lang.String getTimeString(java.util.Date self)

Return a string representation of the time portion of this date according to the locale-specific DateFormat.MEDIUM default format. For an "en_UK" system locale, this would be HH:MM:ss.

Note that a new DateFormat instance is created for every invocation of this method (for thread safety).

Parameters:
self -
Returns:
a string representing the time portion of this date
See Also:
DateFormat.getTimeInstance(int), DateFormat.MEDIUM

getDateTimeString

public static java.lang.String getDateTimeString(java.util.Date self)

Return a string representation of the date and time time portion of this Date instance, according to the locale-specific format used by DateFormat. This method uses the DateFormat.SHORT preset for the day portion and DateFormat.MEDIUM for the time portion of the output string.

Note that a new DateFormat instance is created for every invocation of this method (for thread safety).

Parameters:
self -
Returns:
a string representation of this date and time
See Also:
DateFormat.getDateTimeInstance(int, int)

and

public static java.lang.Boolean and(java.lang.Boolean left,
                                    java.lang.Boolean right)

or

public static java.lang.Boolean or(java.lang.Boolean left,
                                   java.lang.Boolean right)

xor

public static java.lang.Boolean xor(java.lang.Boolean left,
                                    java.lang.Boolean right)

newObjectInputStream

public static java.io.ObjectInputStream newObjectInputStream(java.io.File file)
                                                      throws java.io.IOException
Create an object input stream for this file.

Parameters:
file - a file
Returns:
an object input stream
Throws:
java.io.IOException - if an IOException occurs.

newObjectOutputStream

public static java.io.ObjectOutputStream newObjectOutputStream(java.io.File file)
                                                        throws java.io.IOException
Create an object output stream for this file.

Parameters:
file - a file
Returns:
an object output stream
Throws:
java.io.IOException - if an IOException occurs.

eachObject

public static void eachObject(java.io.File self,
                              Closure closure)
                       throws java.io.IOException,
                              java.lang.ClassNotFoundException
Iterates through the given file object by object.

Parameters:
self - a File
closure - a closure
Throws:
java.io.IOException - if an IOException occurs.
java.lang.ClassNotFoundException - if the class is not found.
See Also:
eachObject(ObjectInputStream,Closure)

eachObject

public static void eachObject(java.io.ObjectInputStream ois,
                              Closure closure)
                       throws java.io.IOException,
                              java.lang.ClassNotFoundException
Iterates through the given object stream object by object. The ObjectInputStream is closed afterwards.

Parameters:
ois - an ObjectInputStream, closed after the operation
closure - a closure
Throws:
java.io.IOException - if an IOException occurs.
java.lang.ClassNotFoundException - if the class is not found.

withObjectInputStream

public static java.lang.Object withObjectInputStream(java.io.File file,
                                                     Closure closure)
                                              throws java.io.IOException
Create a new ObjectInputStream for this file and pass it to the closure. This method ensures the stream is closed after the closure returns.

Parameters:
file - a File
closure - a closure
Returns:
the value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.
See Also:
withStream(InputStream,Closure)

withObjectOutputStream

public static java.lang.Object withObjectOutputStream(java.io.File file,
                                                      Closure closure)
                                               throws java.io.IOException
Create a new ObjectOutputStream for this file and then pass it to the closure. This method ensures the stream is closed after the closure returns.

Parameters:
file - a File
closure - a closure
Returns:
the value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.
See Also:
withStream(OutputStream,Closure)

eachLine

public static java.lang.Object eachLine(java.lang.String self,
                                        Closure closure)
                                 throws java.io.IOException
Iterates through this String line by line. Each line is passed to the given 1 or 2 arg closure. If a 2 arg closure is found the line count is passed as the second argument.

Parameters:
self - a String
closure - a closure
Returns:
the last value returned by the closure
Throws:
java.io.IOException - if an error occurs
See Also:
eachLine(String, int, groovy.lang.Closure)

eachLine

public static java.lang.Object eachLine(java.lang.String self,
                                        int firstLine,
                                        Closure closure)
                                 throws java.io.IOException
Iterates through this String line by line. Each line is passed to the given 1 or 2 arg closure. If a 2 arg closure is found the line count is passed as the second argument.

Parameters:
self - a String
firstLine - the count of the first line
closure - a closure
Returns:
the last value returned by the closure
Throws:
java.io.IOException - if an error occurs
Since:
1.5.7

eachLine

public static java.lang.Object eachLine(java.io.File self,
                                        Closure closure)
                                 throws java.io.IOException
Iterates through this file line by line. Each line is passed to the given 1 or 2 arg closure. The file reader is closed before this method returns.

Parameters:
self - a File
closure - a closure
Returns:
the last value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.
See Also:
eachLine(java.io.File, int, groovy.lang.Closure)

eachLine

public static java.lang.Object eachLine(java.io.File self,
                                        int firstLine,
                                        Closure closure)
                                 throws java.io.IOException
Iterates through this file line by line. Each line is passed to the given 1 or 2 arg closure. The file reader is closed before this method returns.

Parameters:
self - a File
firstLine - the count of the first line
closure - a closure
Returns:
the last value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.
See Also:
eachLine(java.io.Reader, int, groovy.lang.Closure)

eachLine

public static java.lang.Object eachLine(java.io.InputStream stream,
                                        java.lang.String charset,
                                        Closure closure)
                                 throws java.io.IOException
Iterates through this stream reading with the provided charset, passing each line to the given 1 or 2 arg closure. The stream is closed before this method returns.

Parameters:
stream - a stream
charset - opens the stream with a specified charset
closure - a closure
Returns:
the last value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.
See Also:
eachLine(java.io.InputStream, String, int, groovy.lang.Closure)

eachLine

public static java.lang.Object eachLine(java.io.InputStream stream,
                                        java.lang.String charset,
                                        int firstLine,
                                        Closure closure)
                                 throws java.io.IOException
Iterates through this stream reading with the provided charset, passing each line to the given 1 or 2 arg closure. The stream is closed after this method returns.

Parameters:
stream - a stream
charset - opens the stream with a specified charset
firstLine - the count of the first line
closure - a closure
Returns:
the last value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.
See Also:
eachLine(Reader,Closure)

eachLine

public static java.lang.Object eachLine(java.io.InputStream stream,
                                        Closure closure)
                                 throws java.io.IOException
Iterates through this stream, passing each line to the given 1 or 2 arg closure. The stream is closed before this method returns.

Parameters:
stream - a stream
closure - a closure
Returns:
the last value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.
See Also:
eachLine(java.io.InputStream, int, groovy.lang.Closure)

eachLine

public static java.lang.Object eachLine(java.io.InputStream stream,
                                        int firstLine,
                                        Closure closure)
                                 throws java.io.IOException
Iterates through this stream, passing each line to the given 1 or 2 arg closure. The stream is closed before this method returns.

Parameters:
stream - a stream
firstLine - the count of the first line
closure - a closure
Returns:
the last value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.
See Also:
eachLine(java.io.Reader, int, groovy.lang.Closure)

eachLine

public static java.lang.Object eachLine(java.net.URL url,
                                        Closure closure)
                                 throws java.io.IOException
Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure. The stream is closed before this method returns.

Parameters:
url - a URL to open and read
closure - a closure to apply on each line
Returns:
the last value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.
See Also:
eachLine(java.net.URL, int, groovy.lang.Closure)

eachLine

public static java.lang.Object eachLine(java.net.URL url,
                                        int firstLine,
                                        Closure closure)
                                 throws java.io.IOException
Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure. The stream is closed before this method returns.

Parameters:
url - a URL to open and read
firstLine - the count of the first line
closure - a closure to apply on each line
Returns:
the last value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.
See Also:
eachLine(java.io.InputStream, int, groovy.lang.Closure)

eachLine

public static java.lang.Object eachLine(java.net.URL url,
                                        java.lang.String charset,
                                        Closure closure)
                                 throws java.io.IOException
Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure. The stream is closed before this method returns.

Parameters:
url - a URL to open and read
charset - opens the stream with a specified charset
closure - a closure to apply on each line
Returns:
the last value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.
See Also:
eachLine(java.net.URL, String, int, groovy.lang.Closure)

eachLine

public static java.lang.Object eachLine(java.net.URL url,
                                        java.lang.String charset,
                                        int firstLine,
                                        Closure closure)
                                 throws java.io.IOException
Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure. The stream is closed before this method returns.

Parameters:
url - a URL to open and read
charset - opens the stream with a specified charset
firstLine - the count of the first line
closure - a closure to apply on each line
Returns:
the last value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.
See Also:
eachLine(java.io.Reader, int, groovy.lang.Closure)

eachLine

public static java.lang.Object eachLine(java.io.Reader self,
                                        Closure closure)
                                 throws java.io.IOException
Iterates through the given reader line by line. Each line is passed to the given 1 or 2 arg closure. If the closure has two arguments, the line count is passed as the second argument. The Reader is closed before this method returns.

Parameters:
self - a Reader, closed after the method returns
closure - a closure
Returns:
the last value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.

eachLine

public static java.lang.Object eachLine(java.io.Reader self,
                                        int firstLine,
                                        Closure closure)
                                 throws java.io.IOException
Iterates through the given reader line by line. Each line is passed to the given 1 or 2 arg closure. If the closure has two arguments, the line count is passed as the second argument. The Reader is closed before this method returns.

Parameters:
self - a Reader, closed after the method returns
firstLine - the count of the first line
closure - a closure which will be passed each line (or for 2 argument closures the line and count)
Returns:
the last value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.

splitEachLine

public static java.lang.Object splitEachLine(java.io.File self,
                                             java.lang.String sep,
                                             Closure closure)
                                      throws java.io.IOException
Iterates through this file line by line, splitting on the seperator. The list of tokens for each line is then passed to the given closure. Finally the resources used for processing the file are closed.

Parameters:
self - a File
sep - a String separator
closure - a closure
Returns:
the last value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.
See Also:
splitEachLine(Reader,String,Closure)

splitEachLine

public static java.lang.Object splitEachLine(java.io.Reader self,
                                             java.lang.String sep,
                                             Closure closure)
                                      throws java.io.IOException
Iterates through the given reader line by line, splitting each line using the given separator. The list of tokens for each line is then passed to the given closure. The Reader is closed afterwards.

Parameters:
self - a Reader, closed after the method returns
sep - a String separator
closure - a closure
Returns:
the last value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.
See Also:
String.split(String)

splitEachLine

public static java.lang.Object splitEachLine(java.io.InputStream stream,
                                             java.lang.String sep,
                                             java.lang.String charset,
                                             Closure closure)
                                      throws java.io.IOException
Iterates through the given InputStream line by line using the specified encoding, splitting each line using the given separator. The list of tokens for each line is then passed to the given closure. Finally, the stream is closed.

Parameters:
stream - an InputStream
sep - a String separator
charset - opens the stream with a specified charset
closure - a closure
Returns:
the last value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.
See Also:
splitEachLine(Reader,String,Closure)

splitEachLine

public static java.lang.Object splitEachLine(java.io.InputStream stream,
                                             java.lang.String sep,
                                             Closure closure)
                                      throws java.io.IOException
Iterates through the given InputStream line by line, splitting each line using the given separator. The list of tokens for each line is then passed to the given closure. The stream is closed before the method returns.

Parameters:
stream - an InputStream
sep - a String separator
closure - a closure
Returns:
the last value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.
See Also:
splitEachLine(Reader,String,Closure)

splitEachLine

public static java.lang.Object splitEachLine(java.lang.String self,
                                             java.lang.String sep,
                                             Closure closure)
                                      throws java.io.IOException
Iterates through the given String line by line, splitting each line using the given separator. The list of tokens for each line is then passed to the given closure.

Parameters:
self - a String
sep - a String separator
closure - a closure
Returns:
the last value returned by the closure
Throws:
java.io.IOException - if an error occurs
See Also:
String.split(String)

readLine

public static java.lang.String readLine(java.io.Reader self)
                                 throws java.io.IOException
Read a single, whole line from the given Reader.

Parameters:
self - a Reader
Returns:
a line
Throws:
java.io.IOException - if an IOException occurs.

readLine

public static java.lang.String readLine(java.io.InputStream stream)
                                 throws java.io.IOException
Deprecated. use Reader#readLine instead please

Just throws a DeprecationException. DO NOT USE. It used to read a single, whole line from the given InputStream.

Parameters:
stream - an InputStream
Returns:
a line
Throws:
java.io.IOException - if an IOException occurs.

readLines

public static java.util.List readLines(java.lang.String self)
                                throws java.io.IOException
Return the lines of a String as a List of Strings.

Parameters:
self - a String object
Returns:
a list of lines
Throws:
java.io.IOException - if an error occurs
Since:
1.5.5

denormalize

public 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.

Parameters:
self - a String object
Returns:
the denormalized string
Since:
1.6.0

normalize

public static java.lang.String normalize(java.lang.String self)
Return a String with linefeeds and carriage returns normalized to linefeeds.

Parameters:
self - a String object
Returns:
the normalized string
Since:
1.5.8

readLines

public static java.util.List readLines(java.io.File file)
                                throws java.io.IOException
Reads the file into a list of Strings, with one item for each line.

Parameters:
file - a File
Returns:
a List of lines
Throws:
java.io.IOException - if an IOException occurs.

getText

public static java.lang.String getText(java.io.File file,
                                       java.lang.String charset)
                                throws java.io.IOException
Read the content of the File using the specified encoding and return it as a String.

Parameters:
file - the file whose content we want to read
charset - the charset used to read the content of the file
Returns:
a String containing the content of the file
Throws:
java.io.IOException - if an IOException occurs.

getText

public static java.lang.String getText(java.io.File file)
                                throws java.io.IOException
Read the content of the File and returns it as a String.

Parameters:
file - the file whose content we want to read
Returns:
a String containing the content of the file
Throws:
java.io.IOException - if an IOException occurs.

getText

public static java.lang.String getText(java.net.URL url)
                                throws java.io.IOException
Read the content of this URL and returns it as a String.

Parameters:
url - URL to read content from
Returns:
the text from that URL
Throws:
java.io.IOException - if an IOException occurs.

getText

public static java.lang.String getText(java.net.URL url,
                                       java.lang.String charset)
                                throws java.io.IOException
Read the data from this URL and return it as a String. The connection stream is closed before this method returns.

Parameters:
url - URL to read content from
charset - opens the stream with a specified charset
Returns:
the text from that URL
Throws:
java.io.IOException - if an IOException occurs.
See Also:
URLConnection.getInputStream()

getText

public static java.lang.String getText(java.io.InputStream is)
                                throws java.io.IOException
Read the content of this InputStream and return it as a String. The stream is closed before this method returns.

Parameters:
is - an input stream
Returns:
the text from that URL
Throws:
java.io.IOException - if an IOException occurs.

getText

public static java.lang.String getText(java.io.InputStream is,
                                       java.lang.String charset)
                                throws java.io.IOException
Read the content of this InputStream using specified charset and return it as a String. The stream is closed before this method returns.

Parameters:
is - an input stream
charset - opens the stream with a specified charset
Returns:
the text from that URL
Throws:
java.io.IOException - if an IOException occurs.

getText

public static java.lang.String getText(java.io.Reader reader)
                                throws java.io.IOException
Read the content of the Reader and return it as a String. The reader is closed before this method returns.

Parameters:
reader - a Reader whose content we want to read
Returns:
a String containing the content of the buffered reader
Throws:
java.io.IOException - if an IOException occurs.
See Also:
getText(BufferedReader)

getText

public static java.lang.String getText(java.io.BufferedReader reader)
                                throws java.io.IOException
Read the content of the BufferedReader and return it as a String. The BufferedReader is closed afterwards.

Parameters:
reader - a BufferedReader whose content we want to read
Returns:
a String containing the content of the buffered reader
Throws:
java.io.IOException - if an IOException occurs.

writeLine

public static void writeLine(java.io.BufferedWriter writer,
                             java.lang.String line)
                      throws java.io.IOException
Write the text and append a newline (using the platform's line-ending).

Parameters:
writer - a BufferedWriter
line - the line to write
Throws:
java.io.IOException - if an IOException occurs.

write

public static void write(java.io.File file,
                         java.lang.String text)
                  throws java.io.IOException
Write the text to the File.

Parameters:
file - a File
text - the text to write to the File
Throws:
java.io.IOException - if an IOException occurs.

setText

public static void setText(java.io.File file,
                           java.lang.String text)
                    throws java.io.IOException
Synonym for write(text) allowing file.text = 'foo'.

Parameters:
file - a File
text - the text to write to the File
Throws:
java.io.IOException - if an IOException occurs.
See Also:
write(File, String)

leftShift

public static java.io.File leftShift(java.io.File file,
                                     java.lang.Object text)
                              throws java.io.IOException
Write the text to the File.

Parameters:
file - a File
text - the text to write to the File
Returns:
the original file
Throws:
java.io.IOException - if an IOException occurs.

leftShift

public static java.io.File leftShift(java.io.File file,
                                     byte[] bytes)
                              throws java.io.IOException
Write bytes to a File.

Parameters:
file - a File
bytes - the byte array to append to the end of the File
Returns:
the original file
Throws:
java.io.IOException - if an IOException occurs.

write

public static void write(java.io.File file,
                         java.lang.String text,
                         java.lang.String charset)
                  throws java.io.IOException
Write the text to the File, using the specified encoding.

Parameters:
file - a File
text - the text to write to the File
charset - the charset used
Throws:
java.io.IOException - if an IOException occurs.

append

public static void append(java.io.File file,
                          java.lang.Object text)
                   throws java.io.IOException
Append the text at the end of the File.

Parameters:
file - a File
text - the text to append at the end of the File
Throws:
java.io.IOException - if an IOException occurs.

append

public static void append(java.io.File file,
                          byte[] bytes)
                   throws java.io.IOException
Append bytes to the end of a File.

Parameters:
file - a File
bytes - the byte array to append to the end of the File
Throws:
java.io.IOException - if an IOException occurs.

append

public static void append(java.io.File file,
                          java.lang.Object text,
                          java.lang.String charset)
                   throws java.io.IOException
Append the text at the end of the File, using a specified encoding.

Parameters:
file - a File
text - the text to append at the end of the File
charset - the charset used
Throws:
java.io.IOException - if an IOException occurs.

readLines

public static java.util.List readLines(java.io.Reader reader)
                                throws java.io.IOException
Reads the reader into a list of Strings, with one entry for each line. The reader is closed before this method returns.

Parameters:
reader - a Reader
Returns:
a List of lines
Throws:
java.io.IOException - if an IOException occurs.

eachFile

public static void eachFile(java.io.File self,
                            Closure closure)
                     throws java.io.FileNotFoundException,
                            java.lang.IllegalArgumentException
Invokes the closure for each file in the given directory

Parameters:
self - a File
closure - a closure
Throws:
java.io.FileNotFoundException - if the given directory does not exist
java.lang.IllegalArgumentException - if the provided File object does not represent a directory
See Also:
File.listFiles()

eachDir

public static void eachDir(java.io.File self,
                           Closure closure)
                    throws java.io.FileNotFoundException,
                           java.lang.IllegalArgumentException
Invokes the closure for each directory in this directory, ignoring regular files.

Parameters:
self - a directory
closure - a closure
Throws:
java.io.FileNotFoundException - if the given directory does not exist
java.lang.IllegalArgumentException - if the provided File object does not represent a directory

eachFileRecurse

public static void eachFileRecurse(java.io.File self,
                                   Closure closure)
                            throws java.io.FileNotFoundException,
                                   java.lang.IllegalArgumentException
Invokes the closure for each descendant file in this directory. Sub-directories are recursively searched in a depth-first fashion.

Parameters:
self - a File
closure - a closure
Throws:
java.io.FileNotFoundException - if the given directory does not exist
java.lang.IllegalArgumentException - if the provided File object does not represent a directory

eachDirRecurse

public static void eachDirRecurse(java.io.File self,
                                  Closure closure)
                           throws java.io.FileNotFoundException,
                                  java.lang.IllegalArgumentException
Invokes the closure for each descendant directory of this directory. Sub-directories are recursively searched in a depth-first fashion. Only directories are passed to the closure; regular files are ignored.

Parameters:
self - a directory
closure - a closure
Throws:
java.io.FileNotFoundException - if the given directory does not exist
java.lang.IllegalArgumentException - if the provided File object does not represent a directory
Since:
1.1 beta 1
See Also:
eachFileRecurse(File,Closure,boolean)

eachFileMatch

public static void eachFileMatch(java.io.File self,
                                 java.lang.Object filter,
                                 Closure closure)
                          throws java.io.FileNotFoundException,
                                 java.lang.IllegalArgumentException
Invokes the closure for each file whose name (file.name) matches the given filter in the given directory - calling the isCase() method to determine if a match occurs. This method can be used with different kinds of filters like regular expressions, classes, ranges etc.

Parameters:
self - a file
filter - the filter to perform on the directory (using the isCase(object) method)
closure - the closure to invoke
Throws:
java.io.FileNotFoundException - if the given directory does not exist
java.lang.IllegalArgumentException - if the provided File object does not represent a directory

eachDirMatch

public static void eachDirMatch(java.io.File self,
                                java.lang.Object filter,
                                Closure closure)
                         throws java.io.FileNotFoundException,
                                java.lang.IllegalArgumentException
Invokes the closure for each directory whose name (dir.name) matches the given filter in the given directory - calling the isCase() method to determine if a match occurs. This method can be used with different kinds of filters like regular expressions, classes, ranges etc.

Parameters:
self - a file
filter - the filter to perform on the directory (using the isCase(object) method)
closure - the closure to invoke
Throws:
java.io.FileNotFoundException - if the given directory does not exist
java.lang.IllegalArgumentException - if the provided File object does not represent a directory
Since:
1.1 beta 1

deleteDir

public static boolean deleteDir(java.io.File self)
Deletes a directory with all contained files and subdirectories.

The method returns

  • true, when deletion was successful
  • true, when it is called for a non existing directory
  • false, when it is called for a file which isn't a directory
  • false, when directory couldn't be deleted

Returns:
true if deletion was successful

runAfter

public static java.util.TimerTask runAfter(java.util.Timer timer,
                                           int delay,
                                           Closure closure)
Allows a simple syntax for using timers. This timer will execute the given closure after the given delay.

Parameters:
timer - a timer object
delay - the delay in milliseconds before running the closure code
closure - the closure to invoke
Returns:
The timer task which has been scheduled.

newReader

public static java.io.BufferedReader newReader(java.io.File file)
                                        throws java.io.IOException
Create a buffered reader for this file.

Parameters:
file - a File
Returns:
a BufferedReader
Throws:
java.io.IOException - if an IOException occurs.

newReader

public static java.io.BufferedReader newReader(java.io.File file,
                                               java.lang.String charset)
                                        throws java.io.FileNotFoundException,
                                               java.io.UnsupportedEncodingException
Create a buffered reader for this file, using the specified charset as the encoding.

Parameters:
file - a File
charset - the charset for this File
Returns:
a BufferedReader
Throws:
java.io.FileNotFoundException - if the File was not found
java.io.UnsupportedEncodingException - if the encoding specified is not supported

newReader

public static java.io.BufferedReader newReader(java.io.InputStream self)
Creates a reader for this input stream.

Parameters:
self - an input stream
Returns:
a reader

newReader

public static java.io.BufferedReader newReader(java.io.InputStream self,
                                               java.lang.String charset)
                                        throws java.io.UnsupportedEncodingException
Creates a reader for this input stream, using the specified charset as the encoding.

Parameters:
self - an input stream
charset - the charset for this input stream
Returns:
a reader
Throws:
java.io.UnsupportedEncodingException - if the encoding specified is not supported

withReader

public static java.lang.Object withReader(java.io.File file,
                                          Closure closure)
                                   throws java.io.IOException
Create a new BufferedReader for this file and then passes it into the closure, ensuring the reader is closed after the closure returns.

Parameters:
file - a file object
closure - a closure
Returns:
the value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.

withReader

public static java.lang.Object withReader(java.io.File file,
                                          java.lang.String charset,
                                          Closure closure)
                                   throws java.io.IOException
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.

Parameters:
file - a file object
charset - the charset for this input stream
closure - a closure
Returns:
the value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.

newOutputStream

public static java.io.BufferedOutputStream newOutputStream(java.io.File file)
                                                    throws java.io.IOException
Create a buffered output stream for this file.

Parameters:
file - a file object
Returns:
the created OutputStream
Throws:
java.io.IOException - if an IOException occurs.

newDataOutputStream

public static java.io.DataOutputStream newDataOutputStream(java.io.File file)
                                                    throws java.io.IOException
Creates a new data output stream for this file.

Parameters:
file - a file object
Returns:
the created DataOutputStream
Throws:
java.io.IOException - if an IOException occurs.

withOutputStream

public static java.lang.Object withOutputStream(java.io.File file,
                                                Closure closure)
                                         throws java.io.IOException
Creates a new OutputStream for this file and passes it into the closure. This method ensures the stream is closed after the closure returns.

Parameters:
file - a File
closure - a closure
Returns:
the value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.
See Also:
withStream(OutputStream,Closure)

withInputStream

public static java.lang.Object withInputStream(java.io.File file,
                                               Closure closure)
                                        throws java.io.IOException
Create a new InputStream for this file and passes it into the closure. This method ensures the stream is closed after the closure returns.

Parameters:
file - a File
closure - a closure
Returns:
the value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.
See Also:
withStream(InputStream,Closure)

withInputStream

public static java.lang.Object withInputStream(java.net.URL url,
                                               Closure closure)
                                        throws java.io.IOException
Creates a new InputStream for this URL and passes it into the closure. This method ensures the stream is closed after the closure returns.

Parameters:
url - a URL
closure - a closure
Returns:
the value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.
See Also:
withStream(InputStream,Closure)

withDataOutputStream

public static java.lang.Object withDataOutputStream(java.io.File file,
                                                    Closure closure)
                                             throws java.io.IOException
Create a new DataOutputStream for this file and passes it into the closure. This method ensures the stream is closed after the closure returns.

Parameters:
file - a File
closure - a closure
Returns:
the value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.
See Also:
withStream(OutputStream,Closure)

withDataInputStream

public static java.lang.Object withDataInputStream(java.io.File file,
                                                   Closure closure)
                                            throws java.io.IOException
Create a new DataInputStream for this file and passes it into the closure. This method ensures the stream is closed after the closure returns.

Parameters:
file - a File
closure - a closure
Returns:
the value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.
See Also:
withStream(InputStream,Closure)

newWriter

public static java.io.BufferedWriter newWriter(java.io.File file)
                                        throws java.io.IOException
Create a buffered writer for this file.

Parameters:
file - a File
Returns:
a BufferedWriter
Throws:
java.io.IOException - if an IOException occurs.

newWriter

public static java.io.BufferedWriter newWriter(java.io.File file,
                                               boolean append)
                                        throws java.io.IOException
Creates a buffered writer for this file, optionally appending to the existing file content.

Parameters:
file - a File
append - true if data should be appended to the file
Returns:
a BufferedWriter
Throws:
java.io.IOException - if an IOException occurs.

newWriter

public static java.io.BufferedWriter newWriter(java.io.File file,
                                               java.lang.String charset,
                                               boolean append)
                                        throws java.io.IOException
Helper method to create a buffered writer for a file. If the given charset is "UTF-16BE" or "UTF-16LE", the requisite byte order mark is written to the stream before the writer is returned.

Parameters:
file - a File
charset - the name of the encoding used to write in this file
append - true if in append mode
Returns:
a BufferedWriter
Throws:
java.io.IOException - if an IOException occurs.

newWriter

public static java.io.BufferedWriter newWriter(java.io.File file,
                                               java.lang.String charset)
                                        throws java.io.IOException
Creates a buffered writer for this file, writing data using the given encoding.

Parameters:
file - a File
charset - the name of the encoding used to write in this file
Returns:
a BufferedWriter
Throws:
java.io.IOException - if an IOException occurs.

withWriter

public static java.lang.Object withWriter(java.io.File file,
                                          Closure closure)
                                   throws java.io.IOException
Creates a new BufferedWriter for this file, passes it to the closure, and ensures the stream is flushed and closed after the closure returns.

Parameters:
file - a File
closure - a closure
Returns:
the value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.

withWriter

public static java.lang.Object withWriter(java.io.File file,
                                          java.lang.String charset,
                                          Closure closure)
                                   throws java.io.IOException
Creates a new BufferedWriter for this file, passes it to the closure, and ensures the stream is flushed and closed after the closure returns. The writer will use the given charset encoding.

Parameters:
file - a File
charset - the charset used
closure - a closure
Returns:
the value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.

withWriterAppend

public static java.lang.Object withWriterAppend(java.io.File file,
                                                java.lang.String charset,
                                                Closure closure)
                                         throws java.io.IOException
Create a new BufferedWriter which will append to this file. The writer is passed to the closure and will be closed before this method returns.

Parameters:
file - a File
charset - the charset used
closure - a closure
Returns:
the value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.

withWriterAppend

public static java.lang.Object withWriterAppend(java.io.File file,
                                                Closure closure)
                                         throws java.io.IOException
Create a new BufferedWriter for this file in append mode. The writer is passed to the closure and is closed after the closure returns.

Parameters:
file - a File
closure - a closure
Returns:
the value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.

newPrintWriter

public static java.io.PrintWriter newPrintWriter(java.io.File file)
                                          throws java.io.IOException
Create a new PrintWriter for this file.

Parameters:
file - a File
Returns:
the created PrintWriter
Throws:
java.io.IOException - if an IOException occurs.

newPrintWriter

public static java.io.PrintWriter newPrintWriter(java.io.File file,
                                                 java.lang.String charset)
                                          throws java.io.IOException
Create a new PrintWriter for this file, using specified charset.

Parameters:
file - a File
charset - the charset
Returns:
a PrintWriter
Throws:
java.io.IOException - if an IOException occurs.

withPrintWriter

public static java.lang.Object withPrintWriter(java.io.File file,
                                               Closure closure)
                                        throws java.io.IOException
Create a new PrintWriter for this file which is then passed it into the given closure. This method ensures its the writer is closed after the closure returns.

Parameters:
file - a File
closure - the closure to invoke with the PrintWriter
Returns:
the value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.

withPrintWriter

public static java.lang.Object withPrintWriter(java.io.File file,
                                               java.lang.String charset,
                                               Closure closure)
                                        throws java.io.IOException
Create a new PrintWriter with a specified charset for this file. The writer is passed to the closure, and will be closed before this method returns.

Parameters:
file - a File
charset - the charset
closure - the closure to invoke with the PrintWriter
Returns:
the value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.

withWriter

public static java.lang.Object withWriter(java.io.Writer writer,
                                          Closure closure)
                                   throws java.io.IOException
Allows this writer to be used within the closure, ensuring that it is flushed and closed before this method returns.

Parameters:
writer - the writer which is used and then closed
closure - the closure that the writer is passed into
Returns:
the value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.

withReader

public static java.lang.Object withReader(java.io.Reader reader,
                                          Closure closure)
                                   throws java.io.IOException
Allows this reader to be used within the closure, ensuring that it is closed before this method returns.

Parameters:
reader - the reader which is used and then closed
closure - the closure that the writer is passed into
Returns:
the value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.

withStream

public static java.lang.Object withStream(java.io.InputStream stream,
                                          Closure closure)
                                   throws java.io.IOException
Allows this input stream to be used within the closure, ensuring that it is flushed and closed before this method returns.

Parameters:
stream - the stream which is used and then closed
closure - the closure that the stream is passed into
Returns:
the value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.

readLines

public static java.util.List readLines(java.io.InputStream stream)
                                throws java.io.IOException
Reads the stream into a list, with one element for each line.

Parameters:
stream - a stream
Returns:
a List of lines
Throws:
java.io.IOException - if an IOException occurs.
See Also:
readLines(Reader)

withReader

public static java.lang.Object withReader(java.net.URL url,
                                          Closure closure)
                                   throws java.io.IOException
Helper method to create a new BufferedReader for a URL and then passes it to the closure. The reader is closed after the closure returns.

Parameters:
url - a URL
closure - the closure to invoke with the reader
Returns:
the value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.

withReader

public static java.lang.Object withReader(java.net.URL url,
                                          java.lang.String charset,
                                          Closure closure)
                                   throws java.io.IOException
Helper method to create a new Reader for a URL and then passes it to the closure. The reader is closed after the closure returns.

Parameters:
url - a URL
charset - the charset used
closure - the closure to invoke with the reader
Returns:
the value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.

withReader

public static java.lang.Object withReader(java.io.InputStream in,
                                          Closure closure)
                                   throws java.io.IOException
Helper method to create a new Reader for a stream and then passes it into the closure. The reader (and this stream) is closed after the closure returns.

Parameters:
in - a stream
closure - the closure to invoke with the InputStream
Returns:
the value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.
See Also:
InputStreamReader

withReader

public static java.lang.Object withReader(java.io.InputStream in,
                                          java.lang.String charset,
                                          Closure closure)
                                   throws java.io.IOException
Helper method to create a new Reader for a stream and then passes it into the closure. The reader (and this stream) is closed after the closure returns.

Parameters:
in - a stream
charset - the charset used to decode the stream
closure - the closure to invoke with the reader
Returns:
the value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.
See Also:
InputStreamReader

withWriter

public static java.lang.Object withWriter(java.io.OutputStream stream,
                                          Closure closure)
                                   throws java.io.IOException
Creates a writer from this stream, passing it to the given closure. This method ensures the stream is closed after the closure returns.

Parameters:
stream - the stream which is used and then closed
closure - the closure that the writer is passed into
Returns:
the value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.
See Also:
withWriter(Writer,Closure)

withWriter

public static java.lang.Object withWriter(java.io.OutputStream stream,
                                          java.lang.String charset,
                                          Closure closure)
                                   throws java.io.IOException
Creates a writer from this stream, passing it to the given closure. This method ensures the stream is closed after the closure returns.

Parameters:
stream - the stream which is used and then closed
charset - the charset used
closure - the closure that the writer is passed into
Returns:
the value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.
See Also:
withWriter(Writer,Closure)

withStream

public static java.lang.Object withStream(java.io.OutputStream os,
                                          Closure closure)
                                   throws java.io.IOException
Passes this OutputStream to the closure, ensuring that the stream is closed after the closure returns, regardless of errors.

Parameters:
os - the stream which is used and then closed
closure - the closure that the stream is passed into
Returns:
the value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.

newInputStream

public static java.io.BufferedInputStream newInputStream(java.io.File file)
                                                  throws java.io.FileNotFoundException
Creates a buffered input stream for this file.

Parameters:
file - a File
Returns:
a BufferedInputStream of the file
Throws:
java.io.FileNotFoundException - if the file is not found.

newInputStream

public static java.io.BufferedInputStream newInputStream(java.net.URL url)
                                                  throws java.net.MalformedURLException,
                                                         java.io.IOException
Creates a buffered input stream for this URL.

Parameters:
url - a URL
Returns:
a BufferedInputStream for the URL
Throws:
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 stream

newReader

public static java.io.BufferedReader newReader(java.net.URL url)
                                        throws java.net.MalformedURLException,
                                               java.io.IOException
Creates a buffered reader for this URL.

Parameters:
url - a URL
Returns:
a BufferedReader for the URL
Throws:
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 stream

newReader

public static java.io.BufferedReader newReader(java.net.URL url,
                                               java.lang.String charset)
                                        throws java.net.MalformedURLException,
                                               java.io.IOException
Creates a buffered reader for this URL using the given encoding.

Parameters:
url - a URL
charset - opens the stream with a specified charset
Returns:
a BufferedReader for the URL
Throws:
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 stream

newDataInputStream

public static java.io.DataInputStream newDataInputStream(java.io.File file)
                                                  throws java.io.FileNotFoundException
Create a data input stream for this file

Parameters:
file - a File
Returns:
a DataInputStream of the file
Throws:
java.io.FileNotFoundException - if the file is not found.

eachByte

public static void eachByte(java.io.File self,
                            Closure closure)
                     throws java.io.IOException
Traverse through each byte of this File

Parameters:
self - a File
closure - a closure
Throws:
java.io.IOException - if an IOException occurs.
See Also:
eachByte(InputStream,Closure)

eachByte

public static void eachByte(java.lang.Byte[] self,
                            Closure closure)
Traverse through each byte of this Byte array. Alias for each.

Parameters:
self - a Byte array
closure - a closure
See Also:
each(Object,Closure)

eachByte

public static void eachByte(byte[] self,
                            Closure closure)
Traverse through each byte of this byte array. Alias for each.

Parameters:
self - a byte array
closure - a closure
See Also:
each(Object,Closure)

eachByte

public static void eachByte(java.io.InputStream is,
                            Closure closure)
                     throws java.io.IOException
Traverse through each byte of the specified stream. The stream is closed after the closure returns.

Parameters:
is - stream to iterate over, closed after the method call
closure - closure to apply to each byte
Throws:
java.io.IOException - if an IOException occurs.

eachByte

public static void eachByte(java.net.URL url,
                            Closure closure)
                     throws java.io.IOException
Reads the InputStream from this URL, passing each byte to the given closure. The URL stream will be closed before this method returns.

Parameters:
url - url to iterate over
closure - closure to apply to each byte
Throws:
java.io.IOException - if an IOException occurs.
See Also:
eachByte(InputStream,Closure)

transformChar

public static void transformChar(java.io.Reader self,
                                 java.io.Writer writer,
                                 Closure closure)
                          throws java.io.IOException
Transforms each character from this reader by passing it to the given closure. The Closure should return each transformed character, which will be passed to the Writer. The reader and writer will be both be closed before this method returns.

Parameters:
self - a Reader object
writer - a Writer to receive the transformed characters
closure - a closure that performs the required transformation
Throws:
java.io.IOException - if an IOException occurs.

transformLine

public static void transformLine(java.io.Reader reader,
                                 java.io.Writer writer,
                                 Closure closure)
                          throws java.io.IOException
Transforms the lines from a reader with a Closure and write them to a writer. Both Reader and Writer are closed after the operation.

Parameters:
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.
Throws:
java.io.IOException - if an IOException occurs.

filterLine

public static void filterLine(java.io.Reader reader,
                              java.io.Writer writer,
                              Closure closure)
                       throws java.io.IOException
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. Both Reader and Writer are closed after the operation.

Parameters:
reader - a reader, closed after the call
writer - a writer, closed after the call
closure - the closure which returns booleans
Throws:
java.io.IOException - if an IOException occurs.

filterLine

public static Writable filterLine(java.io.File self,
                                  Closure closure)
                           throws java.io.IOException
Filters the lines of a File and creates a Writeable in return to stream the filtered lines.

Parameters:
self - a File
closure - a closure which returns a boolean indicating to filter the line or not
Returns:
a Writable closure
Throws:
java.io.IOException - if self is not readable
See Also:
filterLine(Reader,Closure)

filterLine

public static void filterLine(java.io.File self,
                              java.io.Writer writer,
                              Closure closure)
                       throws java.io.IOException
Filter the lines from this File, and write them to the given writer based on the given closure predicate.

Parameters:
self - a File
writer - a writer destination to write filtered lines to
closure - a closure which takes each line as a parameter and returns true if the line should be written to this writer.
Throws:
java.io.IOException - if self is not readable
See Also:
filterLine(Reader,Writer,Closure)

filterLine

public 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. The closure should return true if the line should be passed to the writer.

Parameters:
reader - this reader
closure - a closure used for filtering
Returns:
a Writable which will use the closure to filter each line from the reader when the Writable#writeTo(Writer) is called.

toRowResult

public static GroovyRowResult toRowResult(java.sql.ResultSet rs)
                                   throws java.sql.SQLException
Returns a GroovyRowResult given a ResultSet.

Parameters:
rs - a ResultSet
Returns:
the resulting GroovyRowResult
Throws:
java.sql.SQLException - if a database error occurs

filterLine

public static Writable filterLine(java.io.InputStream self,
                                  Closure predicate)
Filter lines from an input stream using a closure predicate. The closure will be passed each line as a String, and it should return true if the line should be passed to the writer.

Parameters:
self - an input stream
predicate - a closure which returns boolean and takes a line
Returns:
a writable which writes out the filtered lines
See Also:
filterLine(Reader, Closure)

filterLine

public static void filterLine(java.io.InputStream self,
                              java.io.Writer writer,
                              Closure predicate)
                       throws java.io.IOException
Uses a closure to filter lines from this InputStream and pass them to the given writer. The closure will be passed each line as a String, and it should return true if the line should be passed to the writer.

Parameters:
self - the InputStream
writer - a writer to write output to
predicate - a closure which returns true if a line should be accepted
Throws:
java.io.IOException - if an IOException occurs.
See Also:
filterLine(Reader,Writer,Closure)

readBytes

public static byte[] readBytes(java.io.File file)
                        throws java.io.IOException
Reads the content of the file into a byte array.

Parameters:
file - a File
Returns:
a byte array with the contents of the file.
Throws:
java.io.IOException - if an IOException occurs.

withStreams

public static java.lang.Object withStreams(java.net.Socket socket,
                                           Closure closure)
                                    throws java.io.IOException
Passes the Socket's InputStream and OutputStream to the closure. The streams will be closed after the closure returns, even if an exception is thrown.

Parameters:
socket - a Socket
closure - a Closure
Returns:
the value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.

withObjectStreams

public static java.lang.Object withObjectStreams(java.net.Socket socket,
                                                 Closure closure)
                                          throws java.io.IOException
Creates an InputObjectStream and an OutputObjectStream from a Socket, and passes them to the closure. The streams will be closed after the closure returns, even if an exception is thrown.

Parameters:
socket - this Socket
closure - a Closure
Returns:
the value returned by the closure
Throws:
java.io.IOException - if an IOException occurs.
Since:
1.1 beta 2

leftShift

public static java.io.Writer leftShift(java.net.Socket self,
                                       java.lang.Object value)
                                throws java.io.IOException
Overloads the left shift operator to provide an append mechanism to add things to the output stream of a socket

Parameters:
self - a Socket
value - a value to append
Returns:
a Writer
Throws:
java.io.IOException - if an IOException occurs.

leftShift

public static java.io.OutputStream leftShift(java.net.Socket self,
                                             byte[] value)
                                      throws java.io.IOException
Overloads the left shift operator to provide an append mechanism to add bytes to the output stream of a socket

Parameters:
self - a Socket
value - a value to append
Returns:
an OutputStream
Throws:
java.io.IOException - if an IOException occurs.

accept

public static java.net.Socket accept(java.net.ServerSocket serverSocket,
                                     Closure closure)
                              throws java.io.IOException
Accepts a connection and passes the resulting Socket to the closure which runs in a new Thread.

Parameters:
serverSocket - a ServerSocket
closure - a Closure
Returns:
a Socket
Throws:
java.io.IOException - if an IOException occurs.
See Also:
ServerSocket.accept()

asWritable

public static java.io.File asWritable(java.io.File file)
Converts this File to a Writable.

Parameters:
file - a File
Returns:
a File which wraps the input file and which implements Writable

asType

public static java.lang.Object asType(java.io.File f,
                                      java.lang.Class c)
Converts this File to a Writable or delegates to default asType(Object,Class).

Parameters:
f - a File
c - the desired class
Returns:
the converted object

asWritable

public 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.

Parameters:
file - a File
encoding - the encoding to be used when reading the file's contents
Returns:
File which wraps the input file and which implements Writable

toList

public static java.util.List toList(java.lang.String self)
Converts the given String into a List of strings of one character.

Parameters:
self - a String
Returns:
a List of characters (a 1-character String)

getChars

public static char[] getChars(java.lang.String self)
Converts the given String into an array of characters. Alias for toCharArray.

Parameters:
self - a String
Returns:
an array of characters
See Also:
String.toCharArray()

asType

public static java.lang.Object asType(GString self,
                                      java.lang.Class c)
Converts the GString to a File, or delegates to the default asType(Object,Class)

Parameters:
self - a GString
c - the desired class
Returns:
the converted object

asType

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.

Example: '123' as Double

By default, the following types are supported:

  • List
  • BigDecimal
  • BigInteger
  • Long
  • Integer
  • Short
  • Byte
  • Character
  • Double
  • Float
  • File
  • Subclasses of Enum (Java 5 and above)
If any other type is given, the call is delegated to asType(Object,Class).

Parameters:
self - a String
c - the desired class
Returns:
the converted object

getIn

public 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.

Parameters:
self - a Process instance
Returns:
the InputStream for the process

getText

public static java.lang.String getText(java.lang.Process self)
                                throws java.io.IOException
Read the text of the output stream of the Process.

Parameters:
self - a Process instance
Returns:
the text of the output
Throws:
java.io.IOException - if an IOException occurs.

getErr

public 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.

Parameters:
self - a Process instance
Returns:
the error InputStream for the process

getOut

public 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.

Parameters:
self - a Process instance
Returns:
the OutputStream for the process

leftShift

public static java.io.Writer leftShift(java.lang.Process self,
                                       java.lang.Object value)
                                throws java.io.IOException
Overloads the left shift operator (<<) to provide an append mechanism to pipe data to a Process.

Parameters:
self - a Process instance
value - a value to append
Returns:
a Writer
Throws:
java.io.IOException - if an IOException occurs.

leftShift

public static java.io.OutputStream leftShift(java.lang.Process self,
                                             byte[] value)
                                      throws java.io.IOException
Overloads the left shift operator to provide an append mechanism to pipe into a Process

Parameters:
self - a Process instance
value - data to append
Returns:
an OutputStream
Throws:
java.io.IOException - if an IOException occurs.

waitForOrKill

public 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.

Parameters:
self - a Process
numberOfMillis - the number of milliseconds to wait before stopping the process

consumeProcessOutput

public 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. For this, two Threads are started, so this method will return immediately.

Parameters:
self - a Process

consumeProcessOutput

public 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. The processed stream data is appended to the supplied StringBuffer. For this, two Threads are started, so this method will return immediately.

Parameters:
self - a Process
output - a StringBuffer to capture the process stdout
error - a StringBuffer to capture the process stderr

consumeProcessOutput

public 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. The processed stream data is appended to the supplied OutputStream. For this, two Threads are started, so this method will return immediately.

Parameters:
self - a Process
output - an OutputStream to capture the process stdout
error - an OutputStream to capture the process stderr

consumeProcessErrorStream

public static void 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. The processed stream data is appended to the supplied StringBuffer. A new Thread is started, so this method will return immediately.

Parameters:
self - a Process
error - a StringBuffer to capture the process stderr

consumeProcessErrorStream

public static void 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. The processed stream data is appended to the supplied OutputStream. A new Thread is started, so this method will return immediately.

Parameters:
self - a Process
err - an OutputStream to capture the process stderr

consumeProcessErrorStream

public static void 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. The processed stream data is appended to the supplied Writer. A new Thread is started, so this method will return immediately.

Parameters:
self - a Process
err - a Writer to capture the process stderr

consumeProcessOutputStream

public static void 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. The processed stream data is appended to the supplied StringBuffer. A new Thread is started, so this method will return immediately.

Parameters:
self - a Process
output - a StringBuffer to capture the process stdout

consumeProcessOutputStream

public static void 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. The processed stream data is appended to the supplied OutputStream. A new Thread is started, so this method will return immediately.

Parameters:
self - a Process
output - an OutputStream to capture the process stdout

consumeProcessOutputStream

public static void 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. The processed stream data is appended to the supplied Writer. A new Thread is started, so this method will return immediately.

Parameters:
self - a Process
output - a Writer to capture the process stdout

withWriter

public 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. A new Thread is started, so this method will return immediately.

Parameters:
self - a Process
closure - a closure

withOutputStream

public 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. A new Thread is started, so this method will return immediately.

Parameters:
self - a Process
closure - a closure

pipeTo

public static java.lang.Process pipeTo(java.lang.Process left,
                                       java.lang.Process right)
                                throws java.io.IOException
Allows one Process to asynchronously pipe data to another Process.

Parameters:
left - a Process instance
right - a Process to pipe output to
Returns:
the second Process to allow chaining
Throws:
java.io.IOException - if an IOException occurs.

or

public static java.lang.Process or(java.lang.Process left,
                                   java.lang.Process right)
                            throws java.io.IOException
Overrides the or operator to allow one Process to asynchronously pipe data to another Process.

Parameters:
left - a Process instance
right - a Process to pipe output to
Returns:
the second Process to allow chaining
Throws:
java.io.IOException - if an IOException occurs.

eachMatch

public static void eachMatch(java.lang.String self,
                             java.lang.String regex,
                             Closure closure)
Process each regex group matched substring of the given string. If the closure parameter takes one argument, an array with all match groups is passed to it. If the closure takes as many arguments as there are match groups, then each parameter will be one match group.

Parameters:
self - the source string
regex - a Regex string
closure - a closure with one parameter or as much parameters as groups

each

public static java.util.regex.Matcher each(java.util.regex.Matcher self,
                                           Closure closure)
Process each matched substring of the given group matcher. The object passed to the closure is an array of strings, matched per a successful match.

Parameters:
self - the source matcher
closure - a closure
Returns:
the matcher

findIndexOf

public 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.

Parameters:
self - the iteration object over which to iterate
closure - the filter to perform a match on the collection
Returns:
an integer that is the index of the first matched object or -1 if no match was found

findIndexOf

public 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.

Parameters:
self - the iteration object over which to iterate
startIndex - start matching from this index
closure - the filter to perform a match on the collection
Returns:
an integer that is the index of the first matched object or -1 if no match was found

findLastIndexOf

public 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.

Parameters:
self - the iteration object over which to iterate
closure - the filter to perform a match on the collection
Returns:
an integer that is the index of the last matched object or -1 if no match was found

findLastIndexOf

public 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.

Parameters:
self - the iteration object over which to iterate
startIndex - start matching from this index
closure - the filter to perform a match on the collection
Returns:
an integer that is the index of the last matched object or -1 if no match was found

findIndexValues

public static java.util.List 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.

Parameters:
self - the iteration object over which to iterate
closure - the filter to perform a match on the collection
Returns:
a list of integers corresponding to the index values of all matched objects

findIndexValues

public static java.util.List findIndexValues(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 values of the items that match the condition specified in the closure.

Parameters:
self - the iteration object over which to iterate
startIndex - start matching from this index
closure - the filter to perform a match on the collection
Returns:
a list of integers corresponding to the index values of all matched objects

getRootLoader

public 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". If there is no such class 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.

Parameters:
self - a ClassLoader
Returns:
the rootLoader for the ClassLoader
See Also:
RootLoader

asType

public static java.lang.Object asType(java.lang.Object obj,
                                      java.lang.Class type)
Converts a given object to a type. This method is used through the "as" operator and is overloadable as any other operator.

Parameters:
obj - the object to convert
type - the goal type
Returns:
the resulting object

newInstance

public static java.lang.Object newInstance(java.lang.Class c)
Convenience method to dynamically create a new instance of this class. Calls the default constructor.

Parameters:
c - a class
Returns:
a new instance of this class

newInstance

public static java.lang.Object newInstance(java.lang.Class c,
                                           java.lang.Object[] args)
Helper to construct a new instance from the given arguments. The constructor is called based on the number and types in the args array. Use newInstance(null) or simply newInstance() for the default (no-arg) constructor.

Parameters:
c - a class
args - the constructor arguments
Returns:
a new instance of this class.

getMetaClass

public 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" }

Parameters:
c - The java.lang.Class instance
Returns:
An MetaClass instance

getMetaClass

public 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.

Parameters:
obj - The object in question
Returns:
The MetaClass

iterator

public 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.

Parameters:
o - an object
Returns:
an Iterator for the given Object.
See Also:
DefaultTypeTransformation.asCollection(Object)

iterator

public static java.util.Iterator iterator(java.util.Enumeration enumeration)
Allows an Enumeration to behave like an Iterator. Note that the remove() method is unsupported since the underlying Enumeration does not provide a mechanism for removing items.

Parameters:
enumeration - an Enumeration object
Returns:
an Iterator for the given Enumeration

iterator

public static java.util.Iterator iterator(org.w3c.dom.NodeList nodeList)
Makes NodeList iterable by returning a read-only Iterator which traverses over each Node.

Parameters:
nodeList - a NodeList
Returns:
an Iterator for a NodeList

iterator

public static java.util.Iterator iterator(java.util.regex.Matcher matcher)
Retuns an Iterator which traverses each match.

Parameters:
matcher - a Matcher object
Returns:
an Iterator for a Matcher
See Also:
Matcher.group()

iterator

public static java.util.Iterator iterator(java.io.Reader self)
Creates an iterator which will traverse through the reader a line at a time.

Parameters:
self - a Reader object
Returns:
an Iterator for the Reader
See Also:
BufferedReader.readLine()

iterator

public static java.util.Iterator iterator(java.io.InputStream self)
Standard iterator for a input stream which iterates through the stream content in a byte-based fashion.

Parameters:
self - an InputStream object
Returns:
an Iterator for the InputStream

iterator

public static java.util.Iterator iterator(java.io.DataInputStream self)
Standard iterator for a data input stream which iterates through the stream content a byte at a time.

Parameters:
self - a DataInputStream object
Returns:
an Iterator for the DataInputStream

iterator

public static java.util.Iterator iterator(java.io.File self)
                                   throws java.io.IOException
Deprecated. use File#eachLine instead please

Just throws a DeprecationException. DO NOT USE. It used to provide an iterator for text file content one line at a time.

Parameters:
self - a file object
Returns:
a line-based iterator
Throws:
java.io.IOException - if there is a problem processing the file (e.g. file is not found)

iterator

public static java.util.Iterator iterator(java.util.Iterator 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.

Parameters:
self - an iterator object
Returns:
itself

Copyright © 2003-2008 The Codehaus. All rights reserved.