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: 13688 $
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, Alex Tkachman

Nested Class Summary
protected static class DefaultGroovyMethods.ProcessRunner
          A Runnable which waits for a process to complete together with a notification scheme allowing another thread to wait a maximum number of seconds for the process to complete before killing it.
 
Nested classes/interfaces inherited from class org.codehaus.groovy.runtime.DefaultGroovyMethodsSupport
DefaultGroovyMethodsSupport.RangeInfo
 
Field Summary
static Class[] additionals
           
 
Constructor Summary
DefaultGroovyMethods()
           
 
Method Summary
static double abs(Double number)
          Get the absolute value
static float abs(Float number)
          Get the absolute value
static long abs(Long number)
          Get the absolute value
static int abs(Number number)
          Get the absolute value
static Socket accept(ServerSocket serverSocket, Closure closure)
          Accepts a connection and passes the resulting Socket to the closure which runs in a new Thread.
static void addShutdownHook(Object self, Closure closure)
          Allows the usage of addShutdownHook without getting the runtime first.
static BitSet and(BitSet left, BitSet right)
          Bitwise AND together two BitSets.
static Boolean and(Boolean left, Boolean right)
           
static Number and(Number left, Number right)
          Bitwise AND together two Numbers.
static boolean any(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(Object self)
          Iterates over the elements of a collection, and checks whether at least one element is true according to the Groovy Truth.
static boolean any(Object self, Closure closure)
          Iterates over the contents of an object or collection, and checks whether a predicate is valid for at least one element.
static void append(File file, byte[] bytes)
          Append bytes to the end of a File.
static void append(File file, Object text)
          Append the text at the end of the File.
static void append(File file, Object text, String charset)
          Append the text at the end of the File, using a specified encoding.
static Collection asImmutable(Collection self)
          A convenience method for creating an immutable Collection.
static List asImmutable(List self)
          A convenience method for creating an immutable list
static Map asImmutable(Map self)
          A convenience method for creating an immutable map.
static Set asImmutable(Set self)
          A convenience method for creating an immutable list.
static SortedMap asImmutable(SortedMap self)
          A convenience method for creating an immutable sorted map.
static SortedSet asImmutable(SortedSet self)
          A convenience method for creating an immutable sorted set.
static List asList(Collection self)
          Converts this collection to a List.
static Collection asSynchronized(Collection self)
          A convenience method for creating a synchronized Collection.
static List asSynchronized(List self)
          A convenience method for creating a synchronized List.
static Map asSynchronized(Map self)
          A convenience method for creating a synchronized Map.
static Set asSynchronized(Set self)
          A convenience method for creating a synchronized Set.
static SortedMap asSynchronized(SortedMap self)
          A convenience method for creating a synchronized SortedMap.
static SortedSet asSynchronized(SortedSet self)
          A convenience method for creating a synchronized SortedSet.
static Object asType(Closure cl, Class clazz)
          Coerces the closure to an implementation of the given class.
static Object asType(Collection col, Class clazz)
          Converts the given collection to another type.
static Object asType(File f, Class c)
          Converts this File to a Writable or delegates to default asType(Object,Class).
static Object asType(GString self, Class c)
          Converts the GString to a File, or delegates to the default asType(Object,Class)
static Object asType(Map map, 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 Object asType(Number self, Class c)
          Transform this number to a the given type, using the 'as' operator.
static Object asType(Object[] ary, Class clazz)
          Converts the given array to either a List, Set, or SortedSet.
static Object asType(Object obj, Class type)
          Converts a given object to a type.
static Object asType(String self, Class c)
          Provides a method to perform custom 'dynamic' type conversion to the given class using the as operator.
static File asWritable(File file)
          Converts this File to a Writable.
static File asWritable(File file, String encoding)
          Allows a file to return a Writable implementation that can output itself to a Writer stream.
static BitSet bitwiseNegate(BitSet self)
          Bitwise NEGATE a BitSet.
static Pattern bitwiseNegate(String self)
          Turns a String into a regular expression pattern
protected static Object callClosureForLine(Closure closure, String line, int counter)
           
protected static Object callClosureForMapEntry(Closure closure, Map.Entry entry)
           
protected static Object callClosureForMapEntryAndCounter(Closure closure, Map.Entry entry, int counter)
           
static String center(String self, Number numberOfChars)
          Center a String and pad it with spaces appended around it
static String center(String self, Number numberOfChars, String padding)
          Center a String and pad it with the characters appended around it
static List collect(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 Collection collect(Collection self, 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 List collect(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 Collection collect(Map self, 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 List collect(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 Collection collect(Object self, 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 List collectAll(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 Collection collectAll(Collection self, 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 List combinations(Collection self)
          Adds GroovyCollections#combinations(Collection) as a method on collections.
static int compareTo(Character left, Character right)
          Compare two Characters.
static int compareTo(Character left, Number right)
          Compare a Character and a Number.
static int compareTo(Number left, Character right)
          Compare a Number and a Character.
static int compareTo(Number left, Number right)
          Compare two Numbers.
static void consumeProcessErrorStream(Process self, 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(Process self, 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(Process self, 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(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(Process self, OutputStream output, 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(Process self, StringBuffer output, 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(Process self, 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(Process self, 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(Process self, 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(String self, String text)
          Provide an implementation of contains() like Collection.contains(Object) to make Strings more polymorphic.
static int count(Collection self, Object value)
          Counts the number of occurrences of the given value inside this collection.
static int count(Iterator self, Object value)
          Counts the number of occurrences of the given value from the items within this Iterator.
static int count(String self, String text)
          Count the number of occurencies of a substring.
protected static StringBufferWriter createStringBufferWriter(StringBuffer self)
           
protected static StringWriter createStringWriter(String self)
           
static byte[] decodeBase64(String value)
          Decode the String from Base64 into a byte array.
static boolean disjoint(Collection left, Collection right)
          Returns true if the intersection of two collections is empty.
static Number div(Character left, Character right)
          Divide one Character by another.
static Number div(Character left, Number right)
          Divide a Character by a Number.
static Number div(Number left, Character right)
          Divide a Number by a Character.
static void downto(BigDecimal self, Number to, Closure closure)
          Iterates from this number down to the given number, inclusive, decrementing by one each time.
static void downto(BigInteger self, Number to, Closure closure)
          Iterates from this number down to the given number, inclusive, decrementing by one each time.
static void downto(double self, Number to, Closure closure)
          Iterates from this number down to the given number, inclusive, decrementing by one each time.
static void downto(Double self, Number to, Closure closure)
          Iterates from this number down to the given number, inclusive, decrementing by one each time.
static void downto(float self, Number to, Closure closure)
          Iterates from this number down to the given number, inclusive, decrementing by one each time.
static void downto(Float self, Number to, Closure closure)
          Iterates from this number down to the given number, inclusive, decrementing by one each time.
static void downto(long self, Number to, Closure closure)
          Iterates from this number down to the given number, inclusive, decrementing by one each time.
static void downto(Long self, Number to, Closure closure)
          Iterates from this number down to the given number, inclusive, decrementing by one each time.
static void downto(Number self, Number to, Closure closure)
          Iterates from this number down to the given number, inclusive, decrementing by one each time.
static String dump(Object self)
          Generates a detailed dump string of an object showing its class, hashCode and fields.
static Map each(Map self, Closure closure)
          Allows a Map to be iterated through using a closure.
static Object each(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(Byte[] self, Closure closure)
          Traverse through each byte of this Byte array.
static void eachByte(File self, Closure closure)
          Traverse through each byte of this File
static void eachByte(InputStream is, Closure closure)
          Traverse through each byte of the specified stream.
static void eachByte(URL url, Closure closure)
          Reads the InputStream from this URL, passing each byte to the given closure.
static void eachDir(File self, Closure closure)
          Invokes the closure for each directory in this directory, ignoring regular files.
static void eachDirMatch(File self, 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(File self, Closure closure)
          Invokes the closure for each descendant directory of this directory.
static void eachFile(File self, Closure closure)
          Invokes the closure for each file in the given directory
static void eachFileMatch(File self, 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(File self, Closure closure)
          Invokes the closure for each descendant file in this directory.
static Object eachLine(File self, Closure closure)
          Iterates through this file line by line.
static Object eachLine(File self, int firstLine, Closure closure)
          Iterates through this file line by line.
static Object eachLine(InputStream stream, Closure closure)
          Iterates through this stream, passing each line to the given 1 or 2 arg closure.
static Object eachLine(InputStream stream, int firstLine, Closure closure)
          Iterates through this stream, passing each line to the given 1 or 2 arg closure.
static Object eachLine(InputStream stream, 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 Object eachLine(InputStream stream, 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 Object eachLine(Reader self, Closure closure)
          Iterates through the given reader line by line.
static Object eachLine(Reader self, int firstLine, Closure closure)
          Iterates through the given reader line by line.
static Object eachLine(String self, Closure closure)
          Iterates through this String line by line.
static Object eachLine(String self, int firstLine, Closure closure)
          Iterates through this String line by line.
static Object eachLine(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 Object eachLine(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 Object eachLine(URL url, 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 Object eachLine(URL url, 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 String eachMatch(String self, String regex, Closure closure)
          Process each regex group matched substring of the given string.
static void eachObject(File self, Closure closure)
          Iterates through the given file object by object.
static void eachObject(ObjectInputStream ois, Closure closure)
          Iterates through the given object stream object by object.
static Object eachWithIndex(Map self, Closure closure)
          Allows a Map to be iterated through using a closure.
static Object eachWithIndex(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(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(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(List left, List right)
          Compare the contents of two Lists.
static boolean equals(List left, Object[] right)
          Determines if the contents of this list are equal to the contents of the given array in the same order.
static boolean equals(Object[] left, List right)
          Determines if the contents of this array are equal to the contents of the given list, in the same order.
static boolean every(Map self, Closure closure)
          Iterates over the entries of a map, and checks whether a predicate is valid for all entries.
static boolean every(Object self)
          Iterates over every element of a collection, and checks whether all elements are true according to the Groovy Truth.
static boolean every(Object self, Closure closure)
          Used to determine if the given predicate closure is valid (i.e.
static Process execute(List commandList)
          Executes the command specified by the String list that is the parameter.
static Process execute(String self)
          Executes the given string as a command line process.
static Process execute(String[] commandArray)
          Executes the command specified by the String array that is the parameter.
static Process execute(String self, List envp, File dir)
          Executes the command specified by the self with environments envp under the working directory dir.
static Process execute(String self, String[] envp, File dir)
          Executes the command specified by the self with environments envp under the working directory dir.
static Writable filterLine(File self, Closure closure)
          Filters the lines of a File and creates a Writeable in return to stream the filtered lines.
static void filterLine(File self, 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(InputStream self, Closure predicate)
          Filter lines from an input stream using a closure predicate.
static void filterLine(InputStream self, Writer writer, Closure predicate)
          Uses a closure to filter lines from this InputStream and pass them to the given writer.
static Writable filterLine(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(Reader reader, 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 Object find(Collection self, Closure closure)
          Finds the first value matching the closure condition.
static Object find(Map self, Closure closure)
          Finds the first entry matching the closure condition.
static Object find(Object self, Closure closure)
          Finds the first value matching the closure condition
static Collection findAll(Collection self, Closure closure)
          Finds all values matching the closure condition.
static Map findAll(Map self, Closure closure)
          Finds all entries matching the closure condition.
static List findAll(Object self, Closure closure)
          Finds all items matching the closure condition.
static int