org.codehaus.groovy.runtime
Class DefaultGroovyMethods

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

public class DefaultGroovyMethods
extends Object

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: 9504 $
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.
protected static class DefaultGroovyMethods.RangeInfo
           
 
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, 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 with 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)
          Convenience method which coerces the closure to an implementation of the given class.
static Object asType(Collection col, Class clazz)
          Converts the given collection to either a List, Set, or SortedSet.
static Object asType(File f, Class c)
          Converts this File to a Writable or delegates to default Object#asType(Class).
static Object asType(GString self, Class c)
          Converts the GString to a File, or delegates to the default Object#asType(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)
           
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 or delegates to default Object#asType(Class).
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 callClosureForMapEntry(Closure closure, Map.Entry entry)
           
static String center(String self, Number numberOfChars)
          Center a String and padd it with spaces appended around it
static String center(String self, Number numberOfChars, String padding)
          Center a String and padd 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 entry into a new value using the closure as a transformer, returning a list of 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 item 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 combinations(Collection self)
          Adds combinations() 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 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 ouput buffer.
static boolean contains(String self, String text)
          Provide an implementation of contains() like Collection to make Strings more polymorphic This method is not required on JDK 1.5 onwards
static int count(Collection self, Object value)
          Counts the number of occurrences of the given value inside this collection.
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 Sting 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 two Characters
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 Number div(Number left, Number right)
          Divide two Numbers
static void downto(BigDecimal self, Number to, Closure closure)
           
static void downto(BigInteger self, Number to, Closure closure)
           
static void downto(double self, Number to, Closure closure)
           
static void downto(Double self, Number to, Closure closure)
           
static void downto(float self, Number to, Closure closure)
           
static void downto(Float self, Number to, Closure closure)
           
static void downto(long self, Number to, Closure closure)
           
static void downto(Long self, Number to, Closure closure)
           
static void downto(Number self, Number to, Closure closure)
          Iterates from this number down to the given number
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 Matcher each(Matcher self, Closure closure)
          Process each matched substring of the given group matcher.
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(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 the given directory, ignoring regular files.
static void eachDirMatch(File self, Object filter, Closure closure)
          Invokes the closure for each directory matching the given filter in the given directory - calling the isCase() method used by switch statements.
static void eachDirRecurse(File self, Closure closure)
          Invokes the closure for each directory in the given directory and recursively ignoring regular files.
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 matching the given filter in the given directory - calling the isCase() method used by switch statements.
static void eachFileRecurse(File self, Closure closure)
          Invokes the closure for each file in the given directory and recursively.
static void eachLine(File self, Closure closure)
          Iterates through the given file line by line
static void eachLine(InputStream stream, Closure closure)
          Iterates through this stream, passing each line to the closure.
static void eachLine(Reader self, Closure closure)
          Iterates through the given reader line by line.
static void eachLine(URL url, Closure closure)
          Iterates through the lines read from the URL's associated input stream
static void 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(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 Calling toString() on the result rerurns the encoding as a String
static Writable encodeBase64(Byte[] data)
           
static boolean equals(int[] left, int[] right)
           
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 List 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 findIndexOf(Object self, Closure closure)
          Iterates over every element of the collection and returns the index of the first object that matches the condition specified in the closure
static List flatten(List self)
          Flatten a list
static Set flatten(Set self)
          Flatten a set
static Object get(Map map, Object key, 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(BitSet self, int index)
          Support the subscript operator for a Bitset
static BitSet getAt(BitSet self, IntRange range)
          Support retrieving a subset of a BitSet using a Range
static Object getAt(boolean[] array, Collection indices)
           
static Object getAt(boolean[] array, int idx)
           
static Object getAt(boolean[] array, IntRange range)
           
static Object getAt(boolean[] array, ObjectRange range)
           
static Object getAt(boolean[] array, Range range)
           
static Object getAt(byte[] array, Collection indices)
           
static Object getAt(byte[] array, int idx)
           
static Object getAt(byte[] array, IntRange range)
           
static Object getAt(byte[] array, ObjectRange range)
           
static Object getAt(byte[] array, Range range)
           
static Object getAt(char[] array, Collection indices)
           
static Object getAt(char[] array, int idx)
           
static Object getAt(char[] array, IntRange range)
           
static Object getAt(char[] array, ObjectRange range)
           
static Object getAt(char[] array, Range range)
           
static CharSequence getAt(CharSequence self, Collection indices)
          Allows a List to be used as the indices to be used on a CharSequence
static CharSequence getAt(CharSequence text, EmptyRange range)
          Support the range subscript operator for CharSequence or StringBuffer with EmptyRange
static CharSequence getAt(CharSequence text, int index)
          Support the subscript operator for CharSequence.
static CharSequence getAt(CharSequence text, IntRange range)
          Support the range subscript operator for CharSequence or StringBuffer with IntRange
static CharSequence getAt(CharSequence text, Range range)
          Support the range subscript operator for CharSequence
static List getAt(Collection coll, String property)
          Support the subscript operator for List
static Object getAt(double[] array, Collection indices)
           
static Object getAt(double[] array, int idx)
           
static Object getAt(double[] array, IntRange range)
           
static Object getAt(double[] array, ObjectRange range)
           
static Object getAt(double[] array, Range range)
           
static Object getAt(float[] array, Collection indices)
           
static Object getAt(float[] array, int idx)
           
static Object getAt(float[] array, IntRange range)
           
static Object getAt(float[] array, ObjectRange range)
           
static Object getAt(float[] array, Range range)
           
static Object getAt(int[] array, Collection indices)
           
static Object getAt(int[] array, int idx)
           
static Object getAt(int[] array, IntRange range)
           
static Object getAt(int[] array, ObjectRange range)
           
static Object getAt(int[] array, Range range)
           
static List getAt(List self, Collection indices)
          Allows a List to be used as the indices to be used on a List
static Object getAt(List self, int idx)
          Support the subscript operator for a List
static List getAt(List self, IntRange range)
          Support the range subscript operator for a List
static Object getAt(long[] array, Collection indices)
           
static Object getAt(long[] array, int idx)
           
static Object getAt(long[] array, IntRange range)
           
static Object getAt(long[] array, ObjectRange range)
           
static Object getAt(long[] array, Range range)
           
static Object getAt(Map self, Object key)
          Support the subscript operator for a List
static String getAt(Matcher self, Collection indices)
          Allows a List to be used as the indices to be used on a Matcher
static Object getAt(Matcher matcher, int idx)
          Support the subscript operator, e.g.
static List getAt(Object[] self, Collection indices)
          Allows a List to be used as the indices to be used on a List
static List getAt(Object[] array, EmptyRange range)
           
static Object getAt(Object[] array, int idx)
          Support the subscript operator for an Array
static List getAt(Object[] array, IntRange range)
           
static List getAt(Object[] array, ObjectRange range)
           
static List getAt(Object[] array, Range range)
          Support the range subscript operator for an Array
static Object getAt(Object self, String property)
          Allows the subscript operator to be used to lookup dynamic property values.
static Object getAt(short[] array, Collection indices)
           
static Object getAt(short[] array, int idx)
           
static Object getAt(short[] array, IntRange range)
           
static Object getAt(short[] array, ObjectRange range)
           
static Object getAt(short[] array, Range range)
           
static String getAt(String self, Collection indices)
          Allows a List to be used as the indices to be used on a String
static String getAt(String text, EmptyRange range)
          Support the range subscript operator for String with EmptyRange
static String getAt(String text, int index)
          Support the subscript operator for String.
static String getAt(String text, IntRange range)
          Support the range subscript operator for String with IntRange
static String getAt(String text, Range range)
          Support the range subscript operator for String
static int getCount(Matcher matcher)
          Find the number of Strings matched to the given Matcher.
static InputStream getErr(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 InputStream getIn(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(Class c)
          Adds a "metaClass" property to all class objects so you can use the syntax String.metaClass.myMethod = { println "foo" }
static MetaClass getMetaClass(Object obj)
          Obtains a MetaClass for an object either from the registry or in the case of a GroovyObject from the object itself.
static List getMetaPropertyValues(Object self)
          Retrieves the list of MetaProperty objects for 'self' and wraps it in a list of PropertyValue objects that additionally provide the value for each property of 'self'.
static OutputStream getOut(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 Map getProperties(Object self)
          Convenience method that calls getMetaPropertyValues(Object)(self) and provides the data in form of simple key/value pairs, i.e.
static ClassLoader getRootLoader(ClassLoader self)
          Iterates through the classloader parents until it finds a loader with a class named "org.codehaus.groovy.tools.RootLoader".
protected static List getSubList(List self, List splice)
           
static String getText(BufferedReader reader)
          Reads the content of the BufferedReader and returns it as a String.
static String getText(File file)
          Reads the content of the File and returns it as a String
static String getText(File file, String charset)
          Reads the content of the File opened with the specified encoding and returns it as a String
static String getText(InputStream is)
          Reads the content of this InputStream and returns it as a String
static String getText(InputStream is, String charset)
          Reads the content of this InputStream with a specified charset and returns it as a String
static String getText(Process self)
          Read the text of the output stream of the Process.
static String getText(Reader reader)
          Reads the content of the Reader and returns it as a String
static String getText(URL url)
          Reads the content of this URL and returns it as a String
static String getText(URL url, String charset)
          Reads the content of this URL and returns it as a String
static List grep(Object self, 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(Map answer, Object element, Object value)
          Groups the current element according to the value
static Map groupBy(Collection self, Closure closure)
          Sorts all collection members into groups determined by the supplied mapping closure.
static Map groupBy(Map self, Closure closure)
          Groups all map members into groups determined by the supplied mapping closure.
static boolean hasGroup(Matcher matcher)
          Check whether a Matcher contains a group or not.
static Object identity(Object self, Closure closure)
          Allows the closure to be called for the object reference self synonym for 'with()'.
static Object inject(Collection self, 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 Object inject(Iterator self, 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 Object inject(Object[] self, 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 Object inject(Object self, 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 String inspect(Object self)
           
static Number intdiv(Character left, Character right)
          Integer Divide two Characters
static Number intdiv(Character left, Number right)
          Integer Divide a Character by a Number
static Number intdiv(Number left, Character right)
          Integer Divide a Number by a Character
static Number intdiv(Number left, Number right)
          Integer Divide two Numbers
static List intersect(Collection left, Collection right)
          Create a List composed of the intersection of both collections.
static Object invokeMethod(Object object, String method, Object arguments)
          Provide a dynamic method invocation method which can be overloaded in classes to implement dynamic proxies easily.
static boolean is(Object self, Object other)
          Identity check.
static boolean isCase(Class caseValue, Object switchValue)
          Special 'Case' implementation for Class, which allows testing for a certain class in a switch statement.
static boolean isCase(Collection caseValue, Object switchValue)
          'Case' implementation for collections which tests if the 'switch' operand is contained in any of the 'case' values.
static boolean isCase(Number caseValue, Number switchValue)
          Special 'case' implementation for all numbers, which delegates to the compareTo() method for comparing numbers of different types.
static boolean isCase(Object caseValue, Object switchValue)
          Method for overloading the behavior of the 'case' method in switch statements.
static boolean isCase(Pattern caseValue, Object switchValue)
          'Case' implementation for the Pattern class, which allows testing a String against a number of regular expressions.
static boolean isCase(String caseValue, Object switchValue)
          'Case' implementation for a String, which uses String#equals(Object) in order to allow Strings to be used in switch statements.
static Iterator iterator(DataInputStream self)
          Standard iterator for a data input stream which iterates through the stream content a byte at a time.
static Iterator iterator(Enumeration enumeration)
          Allows an Enumeration to behave like an Iterator.
static Iterator iterator(File self)
          Deprecated. use File#eachLine instead please
static Iterator iterator(InputStream self)
          Standard iterator for a input stream which iterates through the stream content in a byte-based fashion.
static Iterator iterator(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 Iterator iterator(Matcher matcher)
          Retuns an Iterator which traverses each match.
static Iterator iterator(NodeList nodeList)
          Makes NodeList iterable by returning a read-only Iterator which traverses over each Node.
static Iterator iterator(Object o)
          Attempts to create an Iterator for the given object by first converting it to a Collection.
static Iterator iterator(Reader self)
          Creates an iterator which will traverse through the reader a line at a time.
static String join(Collection self, String separator)
          Concatenates the toString() representation of each item in this collection, with the given String as a separator between each item.
static String join(Object[] self, String separator)
          Concatenates the toString() representation of each items in this array, with the given String as a separator between each item.
static Collection leftShift(Collection self, Object value)
          Overloads the left shift operator to provide an easy way to append objects to a Collection.
static File leftShift(File file, Object text)
          Write the text to the File.
static Number leftShift(Number self, Number operand)
          Implementation of the left shift operator for integral types.
static void leftShift(ObjectOutputStream self, Object value)
          Overloads the leftShift operator to add objects to an ObjectOutputStream.
static OutputStream leftShift(OutputStream self, byte[] value)
          Overloads the leftShift operator to provide an append mechanism to add bytes to a stream.
static OutputStream leftShift(OutputStream self, InputStream in)
          Pipe an InputStream into an OutputStream for efficient stream copying.
static Writer leftShift(OutputStream self, Object value)
          Overloads the leftShift operator to provide an append mechanism to add values to a stream.
static OutputStream leftShift(Process self, byte[] value)
          Overloads the left shift operator to provide an append mechanism to pipe into a Process
static Writer leftShift(Process self, Object value)
          Overloads the left shift operator (<<) to provide an append mechanism to pipe data to a Process.
static OutputStream leftShift(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 Writer leftShift(Socket self, Object value)
          Overloads the left shift operator to provide an append mechanism to add things to the output stream of a socket
static StringBuffer leftShift(StringBuffer self, Object value)
          Overloads the left shift operator to provide an easy way to append multiple objects as string representations to a StringBuffer.
static StringBuffer leftShift(String self, Object value)
          Overloads the left shift operator to provide an easy way to append multiple objects as string representations to a String.
static Writer leftShift(Writer self, Object value)
          Overloads the left shift operator to provide a mechanism to append values to a writer.
static Object max(Collection self)
          Adds max() method to Collection objects.
static Object max(Collection self, Closure closure)
          Selects the maximum value found in the collection using the given closure as a comparator.
static Object max(Collection self, Comparator comparator)
          Selects the maximum value found in the collection using the given comparator.
static Object min(Collection self)
          Adds min() method to Collection objects.
static Object min(Collection self, Closure closure)
          Selects the minimum value found in the collection using the given closure as a comparator.
static Object min(Collection self, Comparator comparator)
          Selects the minimum value found in the collection using the given comparator.
static Number minus(Character left, Character right)
          Subtraction two Characters
static Number minus(Character left, Number right)
          Subtract a Number from a Character
static Date minus(Date self, int days)
          Subtracts a number of days from this date and returns the new date
static Date minus(Date self, int days)
          Subtracts a number of days from this date and returns the new date
static List minus(List self, Collection removeMe)
          Create a List composed of the elements of the first list minus the elements of the collection
static List minus(List self, Object operand)
          Create a new List composed of the elements of the first list minus the operand
static Number minus(Number left, Character right)
          Subtract a Character from a Number
static Number minus(Number left, Number right)
          Substraction of two Numbers
static Set minus(Set self, Collection operands)
          Create a Set composed of the elements of the first set minus the elements of the collection.
static Set minus(Set self, Object operand)
          Create a Set composed of the elements of the first set minus the operand.
static String minus(String left, Object value)
          Remove a part of a String
static Number mod(Number left, Number right)
          Performs a division modulus operation
static Number multiply(BigDecimal left, BigInteger right)
          Multiply a BigDecimal and a BigInteger.
static Number multiply(BigDecimal left, Double right)
          Multiply a BigDecimal and a Double.
static Number multiply(Character left, Character right)
          Multiply two Characters
static Number multiply(Character left, Number right)
          Multiply a Character by a Number
static List multiply(Collection self, Number factor)
          Create a List composed of the elements of this list, repeated a certain number of times.
static Number multiply(Number left, Character right)
          Multiply a Number by a Character
static Number multiply(Number left, Number right)
          Multiply two Numbers
static String multiply(String self, Number factor)
          Repeat a String a certain number of times
static DataInputStream newDataInputStream(File file)
          Create a data input stream for this file
static DataOutputStream newDataOutputStream(File file)
          Creates a new data output stream for this file.
static BufferedInputStream newInputStream(File file)
          Creates a buffered input stream for this file.
static Object newInstance(Class c)
          Convenience method to dynamically create a new instance of this class.
static Object newInstance(Class c, Object[] args)
          Helper to construct a new instance from the given arguments.
static ObjectInputStream newObjectInputStream(File file)
          Helper method to create an object input stream from the given file.
static ObjectOutputStream newObjectOutputStream(File file)
          Helper method to create an object output stream from the given file.
static BufferedOutputStream newOutputStream(File file)
          Create a buffered output stream for this file.
static PrintWriter newPrintWriter(File file)
          Create a new PrintWriter for this file.
static PrintWriter newPrintWriter(File file, String charset)
          Create a new PrintWriter for this file, using specified charset.
static BufferedReader newReader(File file)
          Create a buffered reader for this file.
static BufferedReader newReader(File file, String charset)
          Create a buffered reader for this file, with using specified charset as the encoding.
static BufferedReader newReader(InputStream self)
          Creates a reader for this input stream.
static BufferedWriter newWriter(File file)
          Creates a buffered writer for this file.
static BufferedWriter newWriter(File file, boolean append)
          Creates a buffered writer for this file, optionally appending to the existing file content.
static BufferedWriter newWriter(File file, String charset)
          Creates a buffered writer for this file, writing data using the given encoding.
static BufferedWriter newWriter(File file, String charset, boolean append)
          Helper method to create a buffered writer for a file.
static Number next(Character self)
          Increment a Character by one
static Date next(Date self)
          Increments a Date by a day
static Date next(Date self)
          Increments a java.sql.Date by a day
static Number next(Number self)
          Increment a Number by one
static String next(String self)
          This method is called by the ++ operator for the class String.
protected static int normaliseIndex(int i, int size)
          This converts a possibly negative index to a real index into the array.
static BitSet or(BitSet left, BitSet right)
          Bitwise OR together two BitSets
static Boolean or(Boolean left, Boolean right)
           
static Number or(Number left, Number right)
          Bitwise OR together two numbers
static String padLeft(String self, Number numberOfChars)
          Pad a String with the spaces appended to the left
static String padLeft(String self, Number numberOfChars, String padding)
          Pad a String with the characters appended to the left
static String padRight(String self, Number numberOfChars)
          Pad a String with the spaces appended to the right
static String padRight(String self, Number numberOfChars, String padding)
          Pad a String with the characters appended to the right
static Number plus(Character left, Character right)
          Add two Characters
static Number plus(Character left, Number right)
          Add a Character and a Number
static Collection plus(Collection left, Collection right)
          Create a Collection as a union of two collections.
static Collection plus(Collection left, Object right)
          Create a collection as a union of a Collection and an Object.
static Date plus(Date self, int days)
          Adds a number of days to this date and returns the new date
static Date plus(Date self, int days)
          Adds a number of days to this date and returns the new date
static Map plus(Map left, Map right)
          

Returns a new Map containg all entries from left and right, giving precedence to right.

static Number plus(Number left, Character right)
          Add a Number and a Character
static Number plus(Number left, Number right)
          Add two numbers and return the result.
static String plus(Number value, String right)
          Appends a String
static String plus(StringBuffer left, String value)
          Appends a String
static String plus(String left, Object value)
          Appends a String
static Object pop(List self)
          Removes the last item from the List.
static Number power(Number self, Number exponent)
          Power of a Number to a certain exponent
static Number previous(Character self)
          Decrement a Character by one
static Date previous(Date self)
          Decrement a Date by a day
static Date previous(Date self)
          Decrement a java.sql.Date by a day
static Number previous(Number self)
          Decrement a Number by one
static String previous(String self)
          This method is called by the -- operator for the class String.
protected static List primitiveArrayGet(Object self, Collection indices)
          Implements the getAt(Collection) method for primitve type arrays.
protected static Object primitiveArrayGet(Object self, int idx)
          Implements the getAt(int) method for primitve type arrays.
protected static List primitiveArrayGet(Object self, Range range)
          Implements the getAt(Range) method for primitve type arrays.
protected static Object primitiveArrayPut(Object self, int idx, Object newValue)
          Implements the set(int idx) method for primitve type arrays.
static void print(Object self, Object value)
          Print a value to the standard output stream.
static void print(Object self, PrintWriter out)
          Print to a console in interactive format.
static void printf(Object self, String format, Object arg)
          Prints a formatted string using the specified format string and arguments.
static void printf(Object self, String format, Object[] values)
          Printf to a console.
static void println(Object self)
          Print a linebreak to the standard output stream.
static void println(Object self, Object value)
          Print a value (followed by a newline) to the standard output stream.
static void println(Object self, PrintWriter out)
          Print to a console in interactive format.
static void putAt(BitSet self, int index, boolean value)
          Support subscript style assignment for a BitSet
static void putAt(BitSet self, IntRange range, boolean value)
          Support assigning a range of values with a single assignment statement
static Boolean putAt(boolean[] array, int idx, Boolean newValue)
           
static Byte putAt(byte[] array, int idx, Object newValue)
           
static Character putAt(char[] array, int idx, Object newValue)
           
static Double putAt(double[] array, int idx, Object newValue)
           
static Float putAt(float[] array, int idx, Object newValue)
           
static Integer putAt(int[] array, int idx, Object newValue)
           
static void putAt(List self, EmptyRange range, Object value)
          A helper method to allow lists to work with subscript operators
static void putAt(List self, int idx, Object value)
          A helper method to allow lists to work with subscript operators
static void putAt(List self, IntRange range, Collection col)
          A helper method to allow lists to work with subscript operators
static void putAt(List self, IntRange range, Object value)
          A helper method to allow lists to work with subscript operators
static void putAt(List self, List splice, List values)
          Deprecated. replace with putAt(List self, Range range, List value)
static void putAt(List self, List splice, Object value)
          Deprecated. replace with putAt(List self, Range range, Object value)
static Long putAt(long[] array, int idx, Object newValue)
           
static Object putAt(Map self, Object key, Object value)
          A helper method to allow lists to work with subscript operators
static void putAt(Object[] array, int idx, Object value)
          Support the subscript operator for an Array
static void putAt(Object self, String property, Object newValue)
          Allows the subscript operator to be used to set dynamically named property values.
static Short putAt(short[] array, int idx, Object newValue)
           
static void putAt(StringBuffer self, EmptyRange range, Object value)
          Support the range subscript operator for StringBuffer
static void putAt(StringBuffer self, IntRange range, Object value)
          Support the range subscript operator for StringBuffer
static byte[] readBytes(File file)
          Reads the content of the file into a byte array.
static String readLine(InputStream stream)
          Deprecated. use Reader#readLine instead please
static String readLine(Reader self)
          Read a single, whole line from the given Reader
static List readLines(File file)
          Reads the file into a list of Strings for each line
static List readLines(InputStream stream)
          Reads the stream into a list, with one element for each line.
static List readLines(Reader reader)
          Reads the reader into a list of Strings for each line
static String replaceAll(String self, String regex, Closure closure)
          Replaces all occurrencies of a captured group by the result of a closure on that text.
static List reverse(List self)
          Reverses the list.
static String reverse(String self)
          Creates a new string which is the reverse (backwards) of this string
static List reverseEach(List self, Closure closure)
          Iterate over each element of the list in the reverse order.
static Number rightShift(Number self, Number operand)
          Implementation of the right shift operator for integral types.
static Number rightShiftUnsigned(Number self, Number operand)
          Implementation of the right shift (unsigned) operator for integral types.
static long round(Double number)
          Round the value
static int round(Float number)
          Get the absolute value
static TimerTask runAfter(Timer timer, int delay, Closure closure)
          Allows a simple syntax for using timers.
static void setIndex(Matcher matcher, int idx)
          Set the position of the given Matcher to the given index.
static int size(boolean[] array)
           
static int size(byte[] array)
           
static int size(char[] array)
           
static int size(double[] array)
           
static long size(File self)
          Provide the standard Groovy size method for a file.
static int size(float[] array)
           
static int size(int[] array)
           
static int size(long[] array)
           
static long size(Matcher self)
          Provide the standard Groovy size method for a matcher.
static int size(Object[] self)
          Provide the standard Groovy size method for an array.
static int size(short[] array)
           
static int size(String text)
          Makes a String look like a Collection by adding support for the size() method
static int size(StringBuffer buffer)
          Provide standard Groovy size() method for StringBuffers
static List sort(Collection self)
          Sorts the given collection into a sorted list.
static List sort(Collection self, Closure closure)
          A convenience method for sorting a Collection using a closure as a comparator
static List sort(Collection self, Comparator comparator)
          A convenience method for sorting a Collection with a specific comparator
static SortedSet sort(SortedSet self)
          Avoids doing unnecessary work when sorting an already sorted set.
static void splitEachLine(File self, String sep, Closure closure)
          Iterates through the given file line by line, splitting on the seperator
static void splitEachLine(Reader self, String sep, Closure closure)
          Iterates through the given reader line by line, splitting on the separator.
static SpreadMap spread(Map self)
           
static String sprintf(Object self, String format, Object arg)
          Returns a formatted string using the specified format string and arguments.
static String sprintf(Object self, String format, Object[] values)
          Sprintf to a string.
static void step(Number self, Number to, Number stepNumber, Closure closure)
          Iterates from this number up to the given number using a step increment
protected static DefaultGroovyMethods.RangeInfo subListBorders(int size, EmptyRange range)
           
protected static DefaultGroovyMethods.RangeInfo subListBorders(int size, IntRange range)
           
static Map subMap(Map map, Collection keys)
          Creates a sub-Map containing the given keys.
static Object sum(Collection self)
          Sums the items in a collection.
static Object sum(Collection self, Closure closure)
          Sums the result of apply a closure to each item of a collection.
static Object sum(Collection self, Object initialValue)
          Sums the items in a collection, adding the result to some initial value.
static Object sum(Collection self, Object initialValue, Closure closure)
          Sums the result of apply a closure to each item of a collection to sum intial value.
static void times(Number self, Closure closure)
          Iterates a number of times
static String toArrayString(Object[] self)
          Returns the string representation of the given array with the brace boundaries.
static BigDecimal toBigDecimal(Number self)
          Transform a Number into a BigDecimal
static BigDecimal toBigDecimal(String self)
          Parse a String into a BigDecimal
static BigInteger toBigInteger(Number self)
          Transform a Number into a BigInteger
static BigInteger toBigInteger(String self)
          Parse a String into a BigInteger
static Boolean toBoolean(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.
static Character toCharacter(String self)
          Converts the given string into a Character object using the first character in the string
static Double toDouble(Number self)
          Transform a Number into a Double
static Double toDouble(String self)
          Parse a String into a Double
static Float toFloat(Number self)
          Transform a Number into a Float
static Float toFloat(String self)
          Parse a String into a Float
static Integer toInteger(Number self)
          Transform a Number into an Integer
static Integer toInteger(String self)
          Parse a String into an Integer
static List tokenize(String self)
          Tokenize a String (with a whitespace as delimiter)
static List tokenize(String self, String token)
          Tokenize a String based on the given string delimiter.
static List toList(byte[] array)
           
static List toList(char[] array)
           
static List toList(Collection self)
          Convert a collection to a List.
static List toList(double[] array)
           
static List toList(float[] array)
           
static List toList(int[] array)
           
static List toList(long[] array)
           
static List toList(Object[] array)
          Allows conversion of arrays into a mutable List
static List toList(short[] array)
           
static List toList(String self)
          Converts the given String into a List of strings of one character.
static String toListString(Collection self)
          Returns the string representation of the given collection with the bracket boundaries.
static Long toLong(Number self)
          Transform a Number into a Long
static Long toLong(String self)
          Parse a String into a Long
static String toMapString(Map self)
          Returns the string representation of the given map with bracket boundaries.
static SpreadMap toSpreadMap(Map self)
          Returns the converted SpreadLMap of the given self.
static SpreadMap toSpreadMap(Object[] self)
           
static String toString(Collection self)
          Returns the string representation of the given collection with the bracket boundaries.
static String toString(Map self)
          Returns the string representation of the given map with bracket boundaries.
protected static String toString(Object value)
           
static String toString(Object[] self)
          Returns the string representation of the given array with the brace boundaries.
static URI toURI(String self)
          Transforms a String representing a URI into a URI object.
static URL toURL(String self)
          Transforms a String representing a URL into a URL object.
static void transformChar(Reader self, Writer writer, Closure closure)
          Transforms each character from this reader by passing it to the given closure.
static void transformLine(Reader reader, Writer writer, Closure closure)
          Transforms the lines from a reader with a Closure and write them to a writer.
static List transpose(Collection self)
          Adds transpose() as a method on collections.
static Number unaryMinus(Number left)
          Negates the number
static Collection unique(Collection self)
          Modifies this collection to remove all duplicated items, using the default comparator.
static Collection unique(Collection self, Closure closure)
          A convenience method for making a collection unique using a closure as a comparator.
static Collection unique(Collection self, Comparator comparator)
          Remove all duplicates from a given Collection.
static void upto(BigDecimal self, Number to, Closure closure)
           
static void upto(BigInteger self, Number to, Closure closure)
           
static void upto(Double self, Number to, Closure closure)
           
static void upto(float self, Number to, Closure closure)
           
static void upto(Float self, Number to, Closure closure)
           
static void upto(long self, Number to, Closure closure)
           
static void upto(Long self, Number to, Closure closure)
           
static void upto(Number self, Number to, Closure closure)
          Iterates from this number up to the given number
static Object use(Object self, Class categoryClass, Closure closure)
          Scoped use method
static Object use(Object self, List categoryClassList, Closure closure)
          Scoped use method with list of categories.
static Object use(Object self, Object[] array)
          use() a list of categories, specifying the list as varargs:
use(CategoryClass1, CategoryClass2) { ...
static void waitForOrKill(Process self, long numberOfMillis)
          Wait for the process to finish during a certain amount of time, otherwise stops the process.
static Object with(Object self, Closure closure)
          Allows the closure to be called for the object reference self
static void withDataInputStream(File file, Closure closure)
          Create a new DataInputStream for this file and passes it into the closure.
static void withDataOutputStream(File file, Closure closure)
          Create a new DataOutputStream for this file and passes it into the closure.
static void withInputStream(File file, Closure closure)
          Create a new InputStream for this file and passes it into the closure.
static void withObjectInputStream(File file, Closure closure)
          Helper method to create a new ObjectInputStream for a file and then passes it into the closure and ensures its closed again afterwords
static void withObjectOutputStream(File file, Closure closure)
          Helper method to create a new ObjectOutputStream for a file and then passes it into the closure and ensures its closed again afterwords
static void withObjectStreams(Socket socket, Closure closure)
          Creates an InputObjectStream and an OutputObjectStream from a Socket, and passes them to the closure.
static void withOutputStream(File file, Closure closure)
          Creates a new OutputStream for this file and passes it into the closure.
static void withPrintWriter(File file, Closure closure)
          Create a new PrintWriter for this file which is then passed it into the given closure.
static void withPrintWriter(File file, String charset, Closure closure)
          Create a new PrintWriter with a specified charset for this file.
static void withReader(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 void withReader(InputStream in, Closure closure)
          Helper method to create a new BufferedReader for a stream and then passes it into the closure.
static void withReader(Reader reader, Closure closure)
          Allows this reader to be used within the closure, ensuring that it is closed before this method returns.
static void withReader(URL url, Closure closure)
          Helper method to create a new BufferedReader for a URL and then passes it to the closure.
static void withStream(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 void withStream(OutputStream os, Closure closure)
          Passes this OutputStream to the closure, ensuring that the stream is closed after the closure returns, regardless of errors.
static void withStreams(Socket socket, Closure closure)
          Passes the Socket's InputStream and OutputStream to the closure.
static void withWriter(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 void withWriter(File file, 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 void withWriter(OutputStream stream, Closure closure)
          Creates a writer from this stream, passing it to the given closure.
static void withWriter(OutputStream stream, String charset, Closure closure)
          Creates a writer from this stream, passing it to the given closure.
static void withWriter(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 void withWriterAppend(File file, Closure closure)
          Create a new BufferedWriter for this file in append mode.
static void withWriterAppend(File file, String charset, Closure closure)
          Create a new BufferedWriter which will append to this file.
static void write(File file, String text)
          Write the text to the File.
static void write(File file, String text, String charset)
          Write the text to the File with a specified encoding.
static void write(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(BufferedWriter writer, String line)
          Write the text and append a new line (depending on the platform line-ending)
static BitSet xor(BitSet left, BitSet right)
          Bitwise XOR together two BitSets
static Boolean xor(Boolean left, Boolean right)
           
static Number xor(Number left, Number right)
          Bitwise XOR together two Numbers
 
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(Object self,
                         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 Object identity(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 Object with(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 Object getAt(Object self,
                           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(Object self,
                         String property,
                         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 String dump(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 List getMetaPropertyValues(Object self)
Retrieves the list of MetaProperty objects for 'self' and wraps it in a list of PropertyValue objects that additionally provide the value for each property of 'self'.

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

getProperties

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

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

use

public static Object use(Object self,
                         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 Object use(Object self,
                         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(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 Object use(Object self,
                         Object[] array)
use() a list of categories, specifying the list as varargs:
use(CategoryClass1, CategoryClass2) { ... }
This method prevents the error of forgetting 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(Object self,
                         Object value)
Print a value to the standard output stream.

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

println

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

Parameters:
self - any Object

println

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

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

printf

public static void printf(Object self,
                          String format,
                          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 String sprintf(Object self,
                             String format,
                             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(Object self,
                          String format,
                          Object arg)
Prints a formatted string using the specified format string and arguments.

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 String sprintf(Object self,
                             String format,
                             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 String inspect(Object self)
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(Object self,
                         PrintWriter out)
Print to a console in interactive format.

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

println

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

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

invokeMethod

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

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(Object caseValue,
                             Object switchValue)
Method for overloading the behavior of the 'case' method in switch statements. The default implementation 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.


isCase

public static boolean isCase(String caseValue,
                             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.


isCase

public static boolean isCase(Class caseValue,
                             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
 }


isCase

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

See Also:
Collection.contains(Object)

isCase

public static boolean isCase(Pattern caseValue,
                             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.


isCase

public static boolean isCase(Number caseValue,
                             Number switchValue)
Special 'case' implementation for all numbers, which delegates to the compareTo() method for comparing numbers of different types.


unique

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

Returns:
this collection

unique

public static Collection unique(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 Collection unique(Collection self,
                                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 without duplicates

each

public static Object each(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 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.

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

each

public static Map each(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

reverseEach

public static List reverseEach(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.

every

public static boolean every(Object self,
                            Closure closure)
Used to determine if the given predicate closure is valid (i.e. 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(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(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(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(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(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 List grep(Object self,
                        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 list of objects which match the filter

count

public static int count(Collection self,
                        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 List toList(Collection self)
Convert a collection to a List.

Parameters:
self - a collection
Returns:
a List

collect

public static List collect(Object self,
                           Closure closure)
Iterates through this object transforming each item 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 map
closure - the closure used to transform each element of the collection
Returns:
a List of the mapped values

collect

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

Parameters:
self - the values of the object to map
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 items are added

collect

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

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

collect

public static Collection collect(Collection self,
                                 Collection collection,
                                 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
collection - the Collection to which the mapped values are added
closure - the closure used to map each element of the collection
Returns:
the resultant collection

collect

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

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

collect

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

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

find

public static Object find(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 Object find(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 Object find(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 List findAll(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 List findAll(Collection self,
                           Closure closure)
Finds all values matching the closure condition.

Parameters:
self - a Collection
closure - a closure condition
Returns:
a List of the values found

combinations

public static List combinations(Collection self)
Adds combinations() as a method on collections.

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

transpose

public static List transpose(Collection self)
Adds transpose() as a method on collections.

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

findAll

public static Map findAll(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 Map groupBy(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

groupBy

public static Map groupBy(Map self,
                          Closure closure)
Groups all map members 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 a 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

groupAnswer

protected static void groupAnswer(Map answer,
                                  Object element,
                                  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 Object callClosureForMapEntry(Closure closure,
                                               Map.Entry entry)

inject

public static Object inject(Collection self,
                            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 Object inject(Iterator self,
                            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 Object inject(Object self,
                            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 Object inject(Object[] self,
                            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 Object sum(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 list itmems.

sum

public static Object sum(Collection self,
                         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 Object sum(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 Object sum(Collection self,
                         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 String join(Collection self,
                          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 String join(Object[] self,
                          String separator)
Concatenates the toString() representation of each items in this array, with the given String as a separator between each item.

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

max

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

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

max

public static Object max(Collection self,
                         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

min

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

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

min

public static Object min(Collection self,
                         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 Object min(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

max

public static Object max(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

size

public static int size(String text)
Makes a String look like a Collection by adding support for the size() method

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

size

public static int size(StringBuffer buffer)
Provide standard Groovy size() method for StringBuffers

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

size

public static long size(File self)
Provide the standard Groovy size method for a file.

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

size

public static long size(Matcher self)
Provide the standard Groovy size method for a matcher.

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

size

public static int size(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 CharSequence getAt(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 String getAt(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 CharSequence getAt(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 CharSequence getAt(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 CharSequence getAt(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 String getAt(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 String getAt(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 String getAt(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 String reverse(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 URL toURL(String self)
                 throws MalformedURLException
Transforms a String representing a URL into a URL object.

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

toURI

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

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

bitwiseNegate

public static Pattern bitwiseNegate(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 String replaceAll(String self,
                                String regex,
                                Closure closure)
Replaces all occurrencies 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

Parameters:
self - a String
regex - the capturing regex
closure - the closure to apply on each captured group
Returns:
a String with replaced content

padLeft

public static String padLeft(String self,
                             Number numberOfChars,
                             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 String padLeft(String self,
                             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 String padRight(String self,
                              Number numberOfChars,
                              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 String padRight(String self,
                              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 String center(String self,
                            Number numberOfChars,
                            String padding)
Center a String and padd 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 String center(String self,
                            Number numberOfChars)
Center a String and padd 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 Object getAt(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..
 

For an example using group matches,

    def p = /(?:ab([c|d|e|f]))/
    def m = "abcabdabeabf" =~ p
    for (i in 0..
 

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(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(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(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 List getAt(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)

subListBorders

protected static DefaultGroovyMethods.RangeInfo subListBorders(int size,
                                                               IntRange range)

subListBorders

protected static DefaultGroovyMethods.RangeInfo subListBorders(int size,
                                                               EmptyRange range)

getAt

public static List getAt(List self,
                         Collection indices)
Allows a List to be used as the indices to be used on a List

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

getAt

public static List getAt(Object[] self,
                         Collection indices)
Allows a List to be used as the indices to be used on a List

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 CharSequence getAt(CharSequence self,
                                 Collection indices)
Allows a List to be used as the indices to be used on a CharSequence

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

getAt

public static String getAt(String self,
                           Collection indices)
Allows a List to be used as the indices to be used on a String

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

getAt

public static String getAt(Matcher self,
                           Collection indices)
Allows a List to be used as the indices to be used on a Matcher

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

subMap

public static Map subMap(Map map,
                         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 Object get(Map map,
                         Object key,
                         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 List getAt(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 List getAt(Object[] array,
                         IntRange range)

getAt

public static List getAt(Object[] array,
                         EmptyRange range)

getAt

public static List getAt(Object[] array,
                         ObjectRange range)

getAt

public static Object getAt(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(Object[] array,
                         int idx,
                         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 List toList(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 Object getAt(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

putAt

public static void putAt(List self,
                         int idx,
                         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(StringBuffer self,
                         IntRange range,
                         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(StringBuffer self,
                         EmptyRange range,
                         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(List self,
                         EmptyRange range,
                         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(List self,
                         IntRange range,
                         Collection col)
A helper method to allow lists to work with subscript operators

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(List self,
                         IntRange range,
                         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 value to put at the given sublist

putAt

public static void putAt(List self,
                         List splice,
                         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(List self,
                         List splice,
                         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 List getSubList(List self,
                                 List splice)

getAt

public static Object getAt(Map self,
                           Object key)
Support the subscript operator for a List

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

plus

public static Map plus(Map left,
                       Map right)

Returns a new Map containg all entries from left and right, giving precedence to right.

Equivalent to Map m = new HashMap(); m.putAll(left); m.putAll(right); return m;

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

putAt

public static Object putAt(Map self,
                           Object key,
                           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

normaliseIndex

protected static int normaliseIndex(int i,
                                    int size)
This converts a possibly negative index to a real index into the array.

Parameters:
i - the unnormalised index
size - the array size
Returns:
the normalised index

getAt

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

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

asImmutable

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

Parameters:
self - a Map
Returns:
an immutable Map

asImmutable

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

Parameters:
self - a SortedMap
Returns:
an immutable SortedMap

asImmutable

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

Parameters:
self - a List
Returns:
an immutable List

asImmutable

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

Parameters:
self - a Set
Returns:
an immutable Set

asImmutable

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

Parameters:
self - a SortedSet
Returns:
an immutable SortedSet

asImmutable

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

Parameters:
self - a Collection
Returns:
an immutable Collection

asSynchronized

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

Parameters:
self - a Map
Returns:
a synchronized Map

asSynchronized

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

Parameters:
self - a SortedMap
Returns:
a synchronized SortedMap

asSynchronized

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

Parameters:
self - a Collection
Returns:
a synchronized Collection

asSynchronized

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

Parameters:
self - a List
Returns:
a synchronized List

asSynchronized

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

Parameters:
self - a Set
Returns:
a synchronized Set

asSynchronized

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

Parameters:
self - a SortedSet
Returns:
a synchronized SortedSet

spread

public static SpreadMap spread(Map self)

toSpreadMap

public static SpreadMap toSpreadMap(Map self)
Returns the converted SpreadLMap of the given self.

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.

toSpreadMap

public static SpreadMap toSpreadMap(Object[] self)

sort

public static List sort(Collection self)
Sorts the given collection into a sorted list.

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

sort

public static SortedSet sort(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 Object pop(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:
NoSuchElementException - if the list is empty and you try to pop() it.

sort

public static List sort(Collection self,
                        Comparator comparator)
A convenience method for sorting a Collection with a specific comparator

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

sort

public static List sort(Collection self,
                        Closure closure)
A convenience method for sorting a Collection using a closure as a comparator

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

asList

public static List asList(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 Object asType(Collection col,
                            Class clazz)
Converts the given collection to either a List, Set, or SortedSet. If the given class is something else, the call is defered to {link #asType(Object,Class)}. If this collection is already of the given type, the same instance is returned.

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

asType

public static Object asType(Closure cl,
                            Class clazz)
Convenience method which 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.

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

asType

public 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. 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 List reverse(List self)
Reverses the list. The result is a new List with the same items in reverse order.

Parameters:
self - a List
Returns:
a reversed List

plus

public static Collection plus(Collection left,
                              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. TODO: remove equivalent numbers after merge, e.g. 1L and 1G?

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

plus

public static Collection plus(Collection left,
                              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. TODO: remove equivalent numbers after merge, e.g. 1L and 1G?

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

multiply

public static List multiply(Collection self,
                            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 List intersect(Collection left,
                             Collection right)
Create a List composed of the intersection of both collections.

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

disjoint

public static boolean disjoint(Collection left,
                               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)

equals

public 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. 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(List left,
                             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(List left,
                             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 Set minus(Set self,
                        Collection operands)
Create a Set composed of the elements of the first set minus the elements of the 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 Set minus(Set self,
                        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 List minus(List self,
                         Collection removeMe)
Create a List composed of the elements of the first list minus the elements of the collection

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

minus

public static List minus(List self,
                         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

flatten

public static List flatten(List self)
Flatten a list

Parameters:
self - a List
Returns:
a flattened List

flatten

public static Set flatten(Set self)
Flatten a set

Parameters:
self - a Set
Returns:
a flattened Set

leftShift

public static Collection leftShift(Collection self,
                                   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 StringBuffer leftShift(String self,
                                     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 StringWriter createStringWriter(String self)

createStringBufferWriter

protected static StringBufferWriter createStringBufferWriter(StringBuffer self)

leftShift

public static StringBuffer leftShift(StringBuffer self,
                                     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 Writer leftShift(Writer self,
                               Object value)
                        throws 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:
IOException - if an I/O error occurs.

leftShift

public static Number leftShift(Number self,
                               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 Number rightShift(Number self,
                                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 Number rightShiftUnsigned(Number self,
                                        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(Writer self,
                         Writable writable)
                  throws 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:
IOException - if an I/O error occurs.

leftShift

public static Writer leftShift(OutputStream self,
                               Object value)
                        throws 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:
IOException - if an I/O error occurs.

leftShift

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

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

leftShift

public static OutputStream leftShift(OutputStream self,
                                     InputStream in)
                              throws 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:
IOException - if an I/O error occurs.

leftShift

public static OutputStream leftShift(OutputStream self,
                                     byte[] value)
                              throws 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:
IOException - if an I/O error occurs.

getAt

public static Object getAt(byte[] array,
                           int idx)

getAt

public static Object getAt(char[] array,
                           int idx)

getAt

public static Object getAt(short[] array,
                           int idx)

getAt

public static Object getAt(int[] array,
                           int idx)

getAt

public static Object getAt(long[] array,
                           int idx)

getAt

public static Object getAt(float[] array,
                           int idx)

getAt

public static Object getAt(double[] array,
                           int idx)

getAt

public static Object getAt(boolean[] array,
                           int idx)

getAt

public static Object getAt(byte[] array,
                           Range range)

getAt

public static Object getAt(char[] array,
                           Range range)

getAt

public static Object getAt(short[] array,
                           Range range)

getAt

public static Object getAt(int[] array,
                           Range range)

getAt

public static Object getAt(long[] array,
                           Range range)

getAt

public static Object getAt(float[] array,
                           Range range)

getAt

public static Object getAt(double[] array,
                           Range range)

getAt

public static Object getAt(boolean[] array,
                           Range range)

getAt

public static Object getAt(byte[] array,
                           IntRange range)

getAt

public static Object getAt(char[] array,
                           IntRange range)

getAt

public static Object getAt(short[] array,
                           IntRange range)

getAt

public static Object getAt(int[] array,
                           IntRange range)

getAt

public static Object getAt(long[] array,
                           IntRange range)

getAt

public static Object getAt(float[] array,
                           IntRange range)

getAt

public static Object getAt(double[] array,
                           IntRange range)

getAt

public static Object getAt(boolean[] array,
                           IntRange range)

getAt

public static Object getAt(byte[] array,
                           ObjectRange range)

getAt

public static Object getAt(char[] array,
                           ObjectRange range)

getAt

public static Object getAt(short[] array,
                           ObjectRange range)

getAt

public static Object getAt(int[] array,
                           ObjectRange range)

getAt

public static Object getAt(long[] array,
                           ObjectRange range)

getAt

public static Object getAt(float[] array,
                           ObjectRange range)

getAt

public static Object getAt(double[] array,
                           ObjectRange range)

getAt

public static Object getAt(boolean[] array,
                           ObjectRange range)

getAt

public static Object getAt(byte[] array,
                           Collection indices)

getAt

public static Object getAt(char[] array,
                           Collection indices)

getAt

public static Object getAt(short[] array,
                           Collection indices)

getAt

public static Object getAt(int[] array,
                           Collection indices)

getAt

public static Object getAt(long[] array,
                           Collection indices)

getAt

public static Object getAt(float[] array,
                           Collection indices)

getAt

public static Object getAt(double[] array,
                           Collection indices)

getAt

public static Object getAt(boolean[] array,
                           Collection indices)

getAt

public static boolean getAt(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 BitSet getAt(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 Boolean putAt(boolean[] array,
                            int idx,
                            Boolean newValue)

putAt

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

putAt

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

putAt

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

putAt

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

putAt

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

putAt

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

putAt

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

putAt

public static void putAt(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(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)

size

public static int size(byte[] array)

size

public static int size(char[] array)

size

public static int size(short[] array)

size

public static int size(int[] array)

size

public static int size(long[] array)

size

public static int size(float[] array)

size

public static int size(double[] array)

toList

public static List toList(byte[] array)

toList

public static List toList(char[] array)

toList

public static List toList(short[] array)

toList

public static List toList(int[] array)

toList

public static List toList(long[] array)

toList

public static List toList(float[] array)

toList

public static List toList(double[] array)

encodeBase64

public static Writable encodeBase64(Byte[] data)

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 rerurns the encoding as a String

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

decodeBase64

public static byte[] decodeBase64(String value)
Decode the Sting from base64 into a byte array

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

primitiveArrayGet

protected static Object primitiveArrayGet(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 List primitiveArrayGet(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 List primitiveArrayGet(Object self,
                                        Collection indices)
Implements the getAt(Collection) method for primitve type arrays.

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

primitiveArrayPut

protected static Object primitiveArrayPut(Object self,
                                          int idx,
                                          Object newValue)
Implements the set(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

toCharacter

public static Character toCharacter(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 Boolean toBoolean(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

tokenize

public static List tokenize(String self,
                            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 List tokenize(String self)
Tokenize a String (with a whitespace as delimiter)

Parameters:
self - a String
Returns:
a List of tokens

plus

public static String plus(String left,
                          Object value)
Appends a String

Parameters:
left - a String
value - any Object
Returns:
a String

plus

public static String plus(Number value,
                          String right)
Appends a String

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

plus

public static String plus(StringBuffer left,
                          String value)
Appends a String

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

minus

public static String minus(String left,
                           Object value)
Remove a part of a String

Parameters:
left - a String
value - a String part to remove
Returns:
a String minus the part to be removed

contains

public static boolean contains(String self,
                               String text)
Provide an implementation of contains() like Collection 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(String self,
                        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 String next(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 String previous(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 Process execute(String self)
                       throws 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:
IOException - if an IOException occurs.

execute

public static Process execute(String[] commandArray)
                       throws 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:
IOException - if an IOException occurs.

execute

public static Process execute(String self,
                              String[] envp,
                              File dir)
                       throws 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:
IOException - if an IOException occurs.

execute

public static Process execute(List commandList)
                       throws 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:
IOException - if an IOException occurs.

execute

public static Process execute(String self,
                              List envp,
                              File dir)
                       throws 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:
IOException - if an IOException occurs.

multiply

public static String multiply(String self,
                              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 repeatition
Throws:
IllegalArgumentException - if the number of repeatition is < 0

toString

public static String toString(Map self)
Returns the string representation of the given map with bracket boundaries.

Parameters:
self - a Map
Returns:
the string representation

toMapString

public static String toMapString(Map self)
Returns the string representation of the given map with bracket boundaries.

Parameters:
self - a Map
Returns:
the string representation

toString

public static String toString(Collection self)
Returns the string representation of the given collection with the bracket boundaries.

Parameters:
self - a Collection
Returns:
the string representation

toListString

public static String toListString(Collection self)
Returns the string representation of the given collection with the bracket boundaries.

Parameters:
self - a Collection
Returns:
the string representation

toString

public static String toString(Object[] self)
Returns the string representation of the given array with the brace boundaries.

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

toArrayString

public static String toArrayString(Object[] self)
Returns the string representation of the given array with the brace boundaries.

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

toString

protected static String toString(Object value)

next

public static Number next(Character self)
Increment a Character by one

Parameters:
self - a Character
Returns:
an incremented Number

next

public static Number next(Number self)
Increment a Number by one

Parameters:
self - a Number
Returns:
an incremented Number

previous

public static Number previous(Character self)
Decrement a Character by one

Parameters:
self - a Character
Returns:
a decremented Number

previous

public static Number previous(Number self)
Decrement a Number by one

Parameters:
self - a Number
Returns:
a decremented Number

plus

public static Number plus(Character left,
                          Number right)
Add a Character and a Number

Parameters:
left - a Character
right - a Number
Returns:
the addition of the Character and the Number

plus

public static Number plus(Number left,
                          Character right)
Add a Number and a Character

Parameters:
left - a Number
right - a Character
Returns:
the addition of the Character and the Number

plus

public static Number plus(Character left,
                          Character right)
Add two Characters

Parameters:
left - a Character
right - a Character
Returns:
the addition of both Characters

plus

public static Number plus(Number left,
                          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(Character left,
                            Number right)
Compare a Character and a Number

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

compareTo

public static int compareTo(Number left,
                            Character right)
Compare a Number and a Character

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

compareTo

public static int compareTo(Character left,
                            Character right)
Compare two Characters

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

compareTo

public static int compareTo(Number left,
                            Number right)
Compare two Numbers

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

minus

public static Number minus(Character left,
                           Number right)
Subtract a Number from a Character

Parameters:
left - a Character
right - a Number
Returns:
the addition of the Character and the Number

minus

public static Number minus(Number left,
                           Character right)
Subtract a Character from a Number

Parameters:
left - a Number
right - a Character
Returns:
the addition of the Character and the Number

minus

public static Number minus(Character left,
                           Character right)
Subtraction two Characters

Parameters:
left - a Character
right - a Character
Returns:
the addition of both Characters

minus

public static Number minus(Number left,
                           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 Number multiply(Character left,
                              Number right)
Multiply a Character by a Number

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

multiply

public static Number multiply(Number left,
                              Character right)
Multiply a Number by a Character

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

multiply

public static Number multiply(Character left,
                              Character right)
Multiply two Characters

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

multiply

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

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

multiply

public static Number multiply(BigDecimal left,
                              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 both

multiply

public static Number multiply(BigDecimal left,
                              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 both

power

public static Number power(Number self,
                           Number exponent)
Power of a Number to a certain exponent

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

div

public static Number div(Character left,
                         Number right)
Divide a Character by a Number

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

div

public static Number div(Number left,
                         Character right)
Divide a Number by a Character

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

div

public static Number div(Character left,
                         Character right)
Divide two Characters

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

div

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

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

intdiv

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

Parameters:
left - a Character
right - a Number
Returns:
the integer division of both

intdiv

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

Parameters:
left - a Number
right - a Character
Returns:
the integer division of both

intdiv

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

Parameters:
left - a Character
right - another Character
Returns:
the integer division of both

intdiv

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

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

or

public static Number or(Number left,
                        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 Number and(Number left,
                         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 BitSet and(BitSet left,
                         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 BitSet xor(BitSet left,
                         BitSet right)
Bitwise XOR together two BitSets

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

bitwiseNegate

public static BitSet bitwiseNegate(BitSet self)
Bitwise NEGATE a BitSet

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

or

public static BitSet or(BitSet left,
                        BitSet right)
Bitwise OR together two BitSets

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

xor

public static Number xor(Number left,
                         Number right)
Bitwise XOR together two Numbers

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

mod

public static Number mod(Number left,
                         Number right)
Performs a division modulus operation

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

unaryMinus

public static Number unaryMinus(Number left)
Negates the number

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

times

public static void times(Number self,
                         Closure closure)
Iterates a number of times

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

upto

public static void upto(Number self,
                        Number to,
                        Closure closure)
Iterates from this number up to the given number

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

upto

public static void upto(long self,
                        Number to,
                        Closure closure)

upto

public static void upto(Long self,
                        Number to,
                        Closure closure)

upto

public static void upto(float self,
                        Number to,
                        Closure closure)

upto

public static void upto(Float self,
                        Number to,
                        Closure closure)

upto

public static void upto(Double self,
                        Number to,
                        Closure closure)

upto

public static void upto(BigInteger self,
                        Number to,
                        Closure closure)

upto

public static void upto(BigDecimal self,
                        Number to,
                        Closure closure)

downto

public static void downto(Number self,
                          Number to,
                          Closure closure)
Iterates from this number down to the given number

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

downto

public static void downto(long self,
                          Number to,
                          Closure closure)

downto

public static void downto(Long self,
                          Number to,
                          Closure closure)

downto

public static void downto(float self,
                          Number to,
                          Closure closure)

downto

public static void downto(Float self,
                          Number to,
                          Closure closure)

downto

public static void downto(double self,
                          Number to,
                          Closure closure)

downto

public static void downto(Double self,
                          Number to,
                          Closure closure)

downto

public static void downto(BigInteger self,
                          Number to,
                          Closure closure)

downto

public static void downto(BigDecimal self,
                          Number to,
                          Closure closure)

step

public static void step(Number self,
                        Number to,
                        Number stepNumber,
                        Closure closure)
Iterates from this number up to the given number using a step increment

Parameters:
self - a Number to start with
to - a Number to go up to
stepNumber - a Number representing the step increment
closure - the closure to call

abs

public static int abs(Number number)
Get the absolute value

Parameters:
number - a Number
Returns:
the absolute value of that Number

abs

public static long abs(Long number)
Get the absolute value

Parameters:
number - a Long
Returns:
the absolute value of that Long

abs

public static float abs(Float number)
Get the absolute value

Parameters:
number - a Float
Returns:
the absolute value of that Float

abs

public static double abs(Double number)
Get the absolute value

Parameters:
number - a Double
Returns:
the absolute value of that Double

round

public static int round(Float number)
Get the absolute value

Parameters:
number - a Float
Returns:
the absolute value of that Float

round

public static long round(Double number)
Round the value

Parameters:
number - a Double
Returns:
the absolute value of that Double

toInteger

public static Integer toInteger(String self)
Parse a String into an Integer

Parameters:
self - a String
Returns:
an Integer

toLong

public static Long toLong(String self)
Parse a String into a Long

Parameters:
self - a String
Returns:
a Long

toFloat

public static Float toFloat(String self)
Parse a String into a Float

Parameters:
self - a String
Returns:
a Float

toDouble

public static Double toDouble(String self)
Parse a String into a Double

Parameters:
self - a String
Returns:
a Double

toBigInteger

public static BigInteger toBigInteger(String self)
Parse a String into a BigInteger

Parameters:
self - a String
Returns:
a BigInteger

toBigDecimal

public static BigDecimal toBigDecimal(String self)
Parse a String into a BigDecimal

Parameters:
self - a String
Returns:
a BigDecimal

toInteger

public static Integer toInteger(Number self)
Transform a Number into an Integer

Parameters:
self - a Number
Returns:
an Integer

toLong

public static Long toLong(Number self)
Transform a Number into a Long

Parameters:
self - a Number
Returns:
an Long

toFloat

public static Float toFloat(Number self)
Transform a Number into a Float

Parameters:
self - a Number
Returns:
an Float

toDouble

public static Double toDouble(Number self)
Transform a Number into a Double

Parameters:
self - a Number
Returns:
an Double

toBigDecimal

public static BigDecimal toBigDecimal(Number self)
Transform a Number into a BigDecimal

Parameters:
self - a Number
Returns:
an BigDecimal

asType

public static Object asType(Number self,
                            Class c)

toBigInteger

public static BigInteger toBigInteger(Number self)
Transform a Number into a BigInteger

Parameters:
self - a Number
Returns:
an BigInteger

next

public static Date next(Date self)
Increments a Date by a day

Parameters:
self - a Date
Returns:
the next days date

next

public static Date next(Date self)
Increments a java.sql.Date by a day

Parameters:
self - a java.sql.Date
Returns:
the next days date

previous

public static Date previous(Date self)
Decrement a Date by a day

Parameters:
self - a Date
Returns:
the previous days date

previous

public static Date previous(Date self)
Decrement a java.sql.Date by a day

Parameters:
self - a java.sql.Date
Returns:
the previous days date

plus

public static Date plus(Date self,
                        int days)
Adds 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 Date plus(Date self,
                        int days)
Adds 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 Date minus(Date self,
                         int days)
Subtracts 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 Date minus(Date self,
                         int days)
Subtracts 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

and

public static Boolean and(Boolean left,
                          Boolean right)

or

public static Boolean or(Boolean left,
                         Boolean right)

xor

public static Boolean xor(Boolean left,
                          Boolean right)

newObjectInputStream

public static ObjectInputStream newObjectInputStream(File file)
                                              throws IOException
Helper method to create an object input stream from the given file.

Parameters:
file - a file
Returns:
an object input stream
Throws:
IOException - if an IOException occurs.

newObjectOutputStream

public static ObjectOutputStream newObjectOutputStream(File file)
                                                throws IOException
Helper method to create an object output stream from the given file.

Parameters:
file - a file
Returns:
an object output stream
Throws:
IOException - if an IOException occurs.

eachObject

public static void eachObject(File self,
                              Closure closure)
                       throws IOException,
                              ClassNotFoundException
Iterates through the given file object by object

Parameters:
self - a File
closure - a closure
Throws:
IOException - if an IOException occurs.
ClassNotFoundException - if the class is not found.

eachObject

public static void eachObject(ObjectInputStream ois,
                              Closure closure)
                       throws IOException,
                              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:
IOException - if an IOException occurs.
ClassNotFoundException - if the class is not found.

withObjectInputStream

public static void withObjectInputStream(File file,
                                         Closure closure)
                                  throws IOException
Helper method to create a new ObjectInputStream for a file and then passes it into the closure and ensures its closed again afterwords

Parameters:
file - a File
closure - a closure
Throws:
IOException - if an IOException occurs.

withObjectOutputStream

public static void withObjectOutputStream(File file,
                                          Closure closure)
                                   throws IOException
Helper method to create a new ObjectOutputStream for a file and then passes it into the closure and ensures its closed again afterwords

Parameters:
file - a File
closure - a closure
Throws:
IOException - if an IOException occurs.

eachLine

public static void eachLine(File self,
                            Closure closure)
                     throws IOException
Iterates through the given file line by line

Parameters:
self - a File
closure - a closure
Throws:
IOException - if an IOException occurs.

eachLine

public static void eachLine(Reader self,
                            Closure closure)
                     throws IOException
Iterates through the given reader line by line. The Reader is closed afterwards

Parameters:
self - a Reader, closed after the method returns
closure - a closure
Throws:
IOException - if an IOException occurs.

splitEachLine

public static void splitEachLine(File self,
                                 String sep,
                                 Closure closure)
                          throws IOException
Iterates through the given file line by line, splitting on the seperator

Parameters:
self - a File
sep - a String separator
closure - a closure
Throws:
IOException - if an IOException occurs.

splitEachLine

public static void splitEachLine(Reader self,
                                 String sep,
                                 Closure closure)
                          throws IOException
Iterates through the given reader line by line, splitting on the separator. The Reader is closed afterwards.

Parameters:
self - a Reader, closed after the method returns
sep - a String separator
closure - a closure
Throws:
IOException - if an IOException occurs.

readLine

public static String readLine(Reader self)
                       throws IOException
Read a single, whole line from the given Reader

Parameters:
self - a Reader
Returns:
a line
Throws:
IOException - if an IOException occurs.

readLine

public static String readLine(InputStream stream)
                       throws IOException
Deprecated. use Reader#readLine instead please

Read a single, whole line from the given InputStream

Parameters:
stream - an InputStream
Returns:
a line
Throws:
IOException - if an IOException occurs.

readLines

public static List readLines(File file)
                      throws IOException
Reads the file into a list of Strings for each line

Parameters:
file - a File
Returns:
a List of lines
Throws:
IOException - if an IOException occurs.

getText

public static String getText(File file,
                             String charset)
                      throws IOException
Reads the content of the File opened with the specified encoding and returns 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:
IOException - if an IOException occurs.

getText

public static String getText(File file)
                      throws IOException
Reads 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:
IOException - if an IOException occurs.

getText

public static String getText(URL url)
                      throws IOException
Reads 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:
IOException - if an IOException occurs.

getText

public static String getText(URL url,
                             String charset)
                      throws IOException
Reads the content of this URL and returns it as a String

Parameters:
url - URL to read content from
charset - opens the stream with a specified charset
Returns:
the text from that URL
Throws:
IOException - if an IOException occurs.

getText

public static String getText(InputStream is)
                      throws IOException
Reads the content of this InputStream and returns it as a String

Parameters:
is - an input stream
Returns:
the text from that URL
Throws:
IOException - if an IOException occurs.

getText

public static String getText(InputStream is,
                             String charset)
                      throws IOException
Reads the content of this InputStream with a specified charset and returns it as a String

Parameters:
is - an input stream
charset - opens the stream with a specified charset
Returns:
the text from that URL
Throws:
IOException - if an IOException occurs.

getText

public static String getText(Reader reader)
                      throws IOException
Reads the content of the Reader and returns it as a String

Parameters:
reader - a Reader whose content we want to read
Returns:
a String containing the content of the buffered reader
Throws:
IOException - if an IOException occurs.

getText

public static String getText(BufferedReader reader)
                      throws IOException
Reads the content of the BufferedReader and returns 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:
IOException - if an IOException occurs.

writeLine

public static void writeLine(BufferedWriter writer,
                             String line)
                      throws IOException
Write the text and append a new line (depending on the platform line-ending)

Parameters:
writer - a BufferedWriter
line - the line to write
Throws:
IOException - if an IOException occurs.

write

public static void write(File file,
                         String text)
                  throws IOException
Write the text to the File.

Parameters:
file - a File
text - the text to write to the File
Throws:
IOException - if an IOException occurs.

leftShift

public static File leftShift(File file,
                             Object text)
                      throws IOException
Write the text to the File.

Parameters:
file - a File
text - the text to write to the File
Returns:
the original file
Throws:
IOException - if an IOException occurs.

write

public static void write(File file,
                         String text,
                         String charset)
                  throws IOException
Write the text to the File with a specified encoding.

Parameters:
file - a File
text - the text to write to the File
charset - the charset used
Throws:
IOException - if an IOException occurs.

append

public static void append(File file,
                          Object text)
                   throws 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:
IOException - if an IOException occurs.

append

public static void append(File file,
                          Object text,
                          String charset)
                   throws IOException
Append the text at the end of the File with a specified encoding

Parameters:
file - a File
text - the text to append at the end of the File
charset - the charset used
Throws:
IOException - if an IOException occurs.

readLines

public static List readLines(Reader reader)
                      throws IOException
Reads the reader into a list of Strings for each line

Parameters:
reader - a Reader
Returns:
a List of lines
Throws:
IOException - if an IOException occurs.

eachFile

public static void eachFile(File self,
                            Closure closure)
                     throws FileNotFoundException,
                            IllegalArgumentException
Invokes the closure for each file in the given directory

Parameters:
self - a File
closure - a closure
Throws:
FileNotFoundException - if the given directory does not exist
IllegalArgumentException - if the provided File object does not represent a directory

eachDir

public static void eachDir(File self,
                           Closure closure)
                    throws FileNotFoundException,
                           IllegalArgumentException
Invokes the closure for each directory in the given directory, ignoring regular files.

Parameters:
self - a directory
closure - a closure
Throws:
FileNotFoundException - if the given directory does not exist
IllegalArgumentException - if the provided File object does not represent a directory

eachFileRecurse

public static void eachFileRecurse(File self,
                                   Closure closure)
                            throws FileNotFoundException,
                                   IllegalArgumentException
Invokes the closure for each file in the given directory and recursively. It is a depth-first exploration, directories are included in the search.

Parameters:
self - a File
closure - a closure
Throws:
FileNotFoundException - if the given directory does not exist
IllegalArgumentException - if the provided File object does not represent a directory

eachDirRecurse

public static void eachDirRecurse(File self,
                                  Closure closure)
                           throws FileNotFoundException,
                                  IllegalArgumentException
Invokes the closure for each directory in the given directory and recursively ignoring regular files. It is a depth-first exploration, directories are included in the search.

Parameters:
self - a directory
closure - a closure
Throws:
FileNotFoundException - if the given directory does not exist
IllegalArgumentException - if the provided File object does not represent a directory
Since:
1.1 beta 1

eachFileMatch

public static void eachFileMatch(File self,
                                 Object filter,
                                 Closure closure)
                          throws FileNotFoundException,
                                 IllegalArgumentException
Invokes the closure for each file matching the given filter in the given directory - calling the isCase() method used by switch statements. This method can be used with different kinds of filters like regular expresions, 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:
FileNotFoundException - if the given directory does not exist
IllegalArgumentException - if the provided File object does not represent a directory

eachDirMatch

public static void eachDirMatch(File self,
                                Object filter,
                                Closure closure)
                         throws FileNotFoundException,
                                IllegalArgumentException
Invokes the closure for each directory matching the given filter in the given directory - calling the isCase() method used by switch statements. This method can be used with different kinds of filters like regular expresions, 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:
FileNotFoundException - if the given directory does not exist
IllegalArgumentException - if the provided File object does not represent a directory
Since:
1.1 beta 1

runAfter

public static TimerTask runAfter(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 BufferedReader newReader(File file)
                                throws IOException
Create a buffered reader for this file.

Parameters:
file - a File
Returns:
a BufferedReader
Throws:
IOException - if an IOException occurs.

newReader

public static BufferedReader newReader(File file,
                                       String charset)
                                throws FileNotFoundException,
                                       UnsupportedEncodingException
Create a buffered reader for this file, with using specified charset as the encoding.

Parameters:
file - a File
charset - the charset with which we want to write in the File
Returns:
a BufferedReader
Throws:
FileNotFoundException - if the File was not found
UnsupportedEncodingException - if the encoding specified is not supported

newReader

public static BufferedReader newReader(InputStream self)
Creates a reader for this input stream.

Parameters:
self - an input stream
Returns:
a reader

withReader

public static void withReader(File file,
                              Closure closure)
                       throws 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
Throws:
IOException - if an IOException occurs.

newOutputStream

public static BufferedOutputStream newOutputStream(File file)
                                            throws IOException
Create a buffered output stream for this file.

Parameters:
file - a file object
Returns:
the created OutputStream
Throws:
IOException - if an IOException occurs.

newDataOutputStream

public static DataOutputStream newDataOutputStream(File file)
                                            throws IOException
Creates a new data output stream for this file.

Parameters:
file - a file object
Returns:
the created DataOutputStream
Throws:
IOException - if an IOException occurs.

withOutputStream

public static void withOutputStream(File file,
                                    Closure closure)
                             throws 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
Throws:
IOException - if an IOException occurs.
See Also:
withStream(OutputStream,Closure)

withInputStream

public static void withInputStream(File file,
                                   Closure closure)
                            throws 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
Throws:
IOException - if an IOException occurs.
See Also:
withStream(InputStream,Closure)

withDataOutputStream

public static void withDataOutputStream(File file,
                                        Closure closure)
                                 throws 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
Throws:
IOException - if an IOException occurs.
See Also:
withStream(OutputStream,Closure)

withDataInputStream

public static void withDataInputStream(File file,
                                       Closure closure)
                                throws 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
Throws:
IOException - if an IOException occurs.
See Also:
withStream(InputStream,Closure)

newWriter

public static BufferedWriter newWriter(File file)
                                throws IOException
Creates a buffered writer for this file.

Parameters:
file - a File
Returns:
a BufferedWriter
Throws:
IOException - if an IOException occurs.

newWriter

public static BufferedWriter newWriter(File file,
                                       boolean append)
                                throws 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:
IOException - if an IOException occurs.

newWriter

public static BufferedWriter newWriter(File file,
                                       String charset,
                                       boolean append)
                                throws 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:
IOException - if an IOException occurs.

newWriter

public static BufferedWriter newWriter(File file,
                                       String charset)
                                throws 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:
IOException - if an IOException occurs.

withWriter

public static void withWriter(File file,
                              Closure closure)
                       throws 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
Throws:
IOException - if an IOException occurs.

withWriter

public static void withWriter(File file,
                              String charset,
                              Closure closure)
                       throws 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
Throws:
IOException - if an IOException occurs.

withWriterAppend

public static void withWriterAppend(File file,
                                    String charset,
                                    Closure closure)
                             throws 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
Throws:
IOException - if an IOException occurs.

withWriterAppend

public static void withWriterAppend(File file,
                                    Closure closure)
                             throws 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
Throws:
IOException - if an IOException occurs.

newPrintWriter

public static PrintWriter newPrintWriter(File file)
                                  throws IOException
Create a new PrintWriter for this file.

Parameters:
file - a File
Returns:
the created PrintWriter
Throws:
IOException - if an IOException occurs.

newPrintWriter

public static PrintWriter newPrintWriter(File file,
                                         String charset)
                                  throws IOException
Create a new PrintWriter for this file, using specified charset.

Parameters:
file - a File
charset - the charset
Returns:
a PrintWriter
Throws:
IOException - if an IOException occurs.

withPrintWriter

public static void withPrintWriter(File file,
                                   Closure closure)
                            throws 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
Throws:
IOException - if an IOException occurs.

withPrintWriter

public static void withPrintWriter(File file,
                                   String charset,
                                   Closure closure)
                            throws 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
Throws:
IOException - if an IOException occurs.

withWriter

public static void withWriter(Writer writer,
                              Closure closure)
                       throws 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
Throws:
IOException - if an IOException occurs.

withReader

public static void withReader(Reader reader,
                              Closure closure)
                       throws 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
Throws:
IOException - if an IOException occurs.

withStream

public static void withStream(InputStream stream,
                              Closure closure)
                       throws 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
Throws:
IOException - if an IOException occurs.

readLines

public static List readLines(InputStream stream)
                      throws IOException
Reads the stream into a list, with one element for each line.

Parameters:
stream - a stream
Returns:
a List of lines
Throws:
IOException - if an IOException occurs.
See Also:
readLines(Reader)

eachLine

public static void eachLine(InputStream stream,
                            Closure closure)
                     throws IOException
Iterates through this stream, passing each line to the closure. The stream is closed after the closure returns.

Parameters:
stream - a stream
closure - a closure
Throws:
IOException - if an IOException occurs.
See Also:
eachLine(Reader,Closure)

eachLine

public static void eachLine(URL url,
                            Closure closure)
                     throws IOException
Iterates through the lines read from the URL's associated input stream

Parameters:
url - a URL to open and read
closure - a closure to apply on each line
Throws:
IOException - if an IOException occurs.

withReader

public static void withReader(URL url,
                              Closure closure)
                       throws 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
Throws:
IOException - if an IOException occurs.

withReader

public static void withReader(InputStream in,
                              Closure closure)
                       throws IOException
Helper method to create a new BufferedReader for a stream and then passes it into the closure. The reader is closed after the closure returns.

Parameters:
in - a stream
closure - the closure to invoke with the InputStream
Throws:
IOException - if an IOException occurs.

withWriter

public static void withWriter(OutputStream stream,
                              Closure closure)
                       throws 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
Throws:
IOException - if an IOException occurs.
See Also:
withWriter(Writer,Closure)

withWriter

public static void withWriter(OutputStream stream,
                              String charset,
                              Closure closure)
                       throws 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
Throws:
IOException - if an IOException occurs.
See Also:
withWriter(Writer,Closure)

withStream

public static void withStream(OutputStream os,
                              Closure closure)
                       throws 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
Throws:
IOException - if an IOException occurs.

newInputStream

public static BufferedInputStream newInputStream(File file)
                                          throws FileNotFoundException
Creates a buffered input stream for this file.

Parameters:
file - a File
Returns:
a BufferedInputStream of the file
Throws:
FileNotFoundException - if the file is not found.

newDataInputStream

public static DataInputStream newDataInputStream(File file)
                                          throws FileNotFoundException
Create a data input stream for this file

Parameters:
file - a File
Returns:
a DataInputStream of the file
Throws:
FileNotFoundException - if the file is not found.

eachByte

public static void eachByte(File self,
                            Closure closure)
                     throws IOException
Traverse through each byte of this File

Parameters:
self - a File
closure - a closure
Throws:
IOException - if an IOException occurs.
See Also:
eachByte(InputStream,Closure), eachByte(InputStream,Closure)

eachByte

public static void eachByte(InputStream is,
                            Closure closure)
                     throws 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:
IOException - if an IOException occurs.

eachByte

public static void eachByte(URL url,
                            Closure closure)
                     throws 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:
IOException - if an IOException occurs.
See Also:
eachByte(InputStream,Closure), eachByte(InputStream,Closure)

transformChar

public static void transformChar(Reader self,
                                 Writer writer,
                                 Closure closure)
                          throws 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:
IOException - if an IOException occurs.

transformLine

public static void transformLine(Reader reader,
                                 Writer writer,
                                 Closure closure)
                          throws 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:
IOException - if an IOException occurs.

filterLine

public static void filterLine(Reader reader,
                              Writer writer,
                              Closure closure)
                       throws 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:
IOException - if an IOException occurs.

filterLine

public static Writable filterLine(File self,
                                  Closure closure)
                           throws 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:
IOException - if self is not readable
See Also:
filterLine(Reader,Closure), filterLine(Reader,Closure)

filterLine

public static void filterLine(File self,
                              Writer writer,
                              Closure closure)
                       throws 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:
IOException - if self is not readable
See Also:
filterLine(Reader,Writer,Closure), filterLine(Reader,Writer,Closure)

filterLine

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

filterLine

public static Writable filterLine(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(InputStream self,
                              Writer writer,
                              Closure predicate)
                       throws 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:
IOException - if an IOException occurs.
See Also:
filterLine(Reader,Writer,Closure), filterLine(Reader,Writer,Closure)

readBytes

public static byte[] readBytes(File file)
                        throws 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:
IOException - if an IOException occurs.

withStreams

public static void withStreams(Socket socket,
                               Closure closure)
                        throws 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
Throws:
IOException - if an IOException occurs.

withObjectStreams

public static void withObjectStreams(Socket socket,
                                     Closure closure)
                              throws 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
Throws:
IOException - if an IOException occurs.
Since:
1.1 beta 2

leftShift

public static Writer leftShift(Socket self,
                               Object value)
                        throws 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:
IOException - if an IOException occurs.

leftShift

public static OutputStream leftShift(Socket self,
                                     byte[] value)
                              throws 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:
IOException - if an IOException occurs.

accept

public static Socket accept(ServerSocket serverSocket,
                            Closure closure)
                     throws 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:
IOException - if an IOException occurs.
See Also:
ServerSocket.accept(), ServerSocket.accept()

asWritable

public static File asWritable(File file)
Converts this File to a Writable or delegates to default Object#asType(Class).

Parameters:
this - file
Returns:
a File which wraps the input file and which implements Writable

asType

public static Object asType(File f,
                            Class c)
Converts this File to a Writable or delegates to default Object#asType(Class).

Parameters:
c - the desired class
Returns:
the converted object

asWritable

public static File asWritable(File file,
                              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 List toList(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)

asType

public static Object asType(GString self,
                            Class c)
Converts the GString to a File, or delegates to the default Object#asType(Class)


asType

public static Object asType(String self,
                            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
  • Character
  • Character
  • Double
  • Float
  • File
If any other type is given, the call is delegated to asType(Object,Class).


getIn

public static InputStream getIn(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 String getText(Process self)
                      throws IOException
Read the text of the output stream of the Process.

Parameters:
self - a Process instance
Returns:
the text of the output
Throws:
IOException - if an IOException occurs.

getErr

public static InputStream getErr(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 OutputStream getOut(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 Writer leftShift(Process self,
                               Object value)
                        throws 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:
IOException - if an IOException occurs.

leftShift

public static OutputStream leftShift(Process self,
                                     byte[] value)
                              throws 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:
IOException - if an IOException occurs.

waitForOrKill

public static void waitForOrKill(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(Process self)
Gets the output and error streams from a process and reads them to keep the process from blocking due to a full ouput buffer. For this two Threads are started, so this method will return immediately.

Parameters:
self - a Process

eachMatch

public static void eachMatch(String self,
                             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 Matcher each(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(Object self,
                              Closure closure)
Iterates over every element of the collection and returns the index of the first object that matches the condition specified in the closure

Parameters:
self - the iteration object over which we iterate
closure - the filter to perform a match on the collection
Returns:
an integer that is the index of the first macthed object.

getRootLoader

public static ClassLoader getRootLoader(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 Object asType(Object obj,
                            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 Object newInstance(Class c)
Convenience method to dynamically create a new instance of this class. Calls the default constructor.

Returns:
a new instance of this class

newInstance

public static Object newInstance(Class c,
                                 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.

Returns:
a new instance of this class.

getMetaClass

public static MetaClass getMetaClass(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(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 Iterator iterator(Object o)
Attempts to create an Iterator for the given object by first converting it to a Collection.

Returns:
an Iterator for the given Object.
See Also:
DefaultTypeTransformation.asCollection(Object)

iterator

public static Iterator iterator(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 Iterator iterator(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 Iterator iterator(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 Iterator iterator(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 Iterator iterator(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 Iterator iterator(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 Iterator iterator(File self)
                         throws IOException
Deprecated. use File#eachLine instead please

Standard iterator for a text file which iterates through the file content one line at a time.

Parameters:
self - a file object
Returns:
a line-based iterator
Throws:
IOException - if there is a problem processing the file (e.g. file is not found)

iterator

public static Iterator iterator(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-2007 The Codehaus. All rights reserved.