org.codehaus.groovy.runtime
Class DefaultGroovyMethods

java.lang.Object
  |
  +--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: 1.28 $
Author:
James Strachan

Constructor Summary
DefaultGroovyMethods()
           
 
Method Summary
static double abs(Double number)
           
static float abs(Float number)
           
static long abs(Long number)
           
static int abs(Number number)
           
static boolean any(Object self, groovy.lang.Closure closure)
           
static Number decrement(Number self)
           
static Number divide(Number left, Number right)
           
static void each(Collection self, groovy.lang.Closure closure)
          Allows objects to be iterated through using a closure
static void each(Map self, groovy.lang.Closure closure)
          Allows objects to be iterated through using a closure
static void each(Object self, groovy.lang.Closure closure)
          Allows objects to be iterated through using a closure
static void eachFile(File self, groovy.lang.Closure closure)
          Invokes the closure for each file in the given directory
static void eachLine(File self, groovy.lang.Closure closure)
          Iterates through the given file line by line
static boolean every(Object self, groovy.lang.Closure closure)
           
static Object find(Collection self, groovy.lang.Closure closure)
          Finds the first value matching the closure condition
static Object find(Map self, groovy.lang.Closure closure)
          Finds the first value matching the closure condition
static Object find(Object self, groovy.lang.Closure closure)
          Finds the first value matching the closure condition
static List findAll(Collection self, groovy.lang.Closure closure)
          Finds all values matching the closure condition
static List findAll(Map self, groovy.lang.Closure closure)
          Finds all values matching the closure condition
static Object findAll(Object self, groovy.lang.Closure closure)
          Finds all values matching the closure condition
static List flatten(List self)
           
static List get(Collection coll, String property)
          Support the subscript operator for List
static Object get(List list, groovy.lang.Range range)
          Support the range subscript operator for a List
static Object get(String text, int index)
          Support the subscript operator for String
static Object get(String text, groovy.lang.Range range)
          Support the range subscript operator for String
static List immutable(List self)
          A convenience method for creating an immutable list
static Map immutable(Map self)
          A convenience method for creating an immutable map
static Set immutable(Set self)
          A convenience method for creating an immutable list
static SortedMap immutable(SortedMap self)
          A convenience method for creating an immutable sorted map
static SortedSet immutable(SortedSet self)
          A convenience method for creating an immutable sorted set
static Number increment(Number self)
           
static Object inject(Collection self, Object value, groovy.lang.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 String inspect(Object self)
          Generates a detailed inspection string of an object showing its class, hashCode and fields
static List intersect(List left, Collection right)
           
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 isCase(Class caseValue, Object switchValue)
           
static boolean isCase(Collection caseValue, Object switchValue)
           
static boolean isCase(Object caseValue, Object switchValue)
           
static boolean isCase(Pattern caseValue, Object switchValue)
           
static boolean isCase(String caseValue, Object switchValue)
           
static boolean isFloatingPoint(Number number)
           
static boolean isLong(Number number)
           
static String join(Collection self, String separator)
          Concatenates all of the items of the collection together with the given string as a separator
static List map(Collection self, groovy.lang.Closure closure)
          Collects the values of the closure
static List map(Map self, groovy.lang.Closure closure)
          Collects the values of the closure
static List map(Object self, groovy.lang.Closure closure)
          Maps the values of a collection to new values using the
static Object max(Collection self)
          Selects the maximum value found in the collection
static Object max(Collection self, groovy.lang.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)
          Selects the minimum value found in the collection
static Object min(Collection self, groovy.lang.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 List minus(List self, Collection removeMe)
           
static Number minus(Number left, Number right)
           
static String minus(String left, Object value)
           
static List multiply(List self, Number factor)
           
static Number multiply(Number left, Number right)
           
static String multiply(String self, Number factor)
           
static BufferedReader newReader(File file)
          Helper method to create a buffered reader for a file
static BufferedWriter newWriter(File file)
          Helper method to create a buffered writer for a file
static List plus(List left, Collection right)
           
static List plus(List left, Object right)
           
static Number plus(Number left, Number right)
           
static String plus(String left, Object value)
           
static Number power(Number self, Number exponent)
           
static void print(Object self, Object value)
          Print to a console in interactive format
static void print(Object self, PrintWriter out)
          Print to a console in interactive format
static void println(Object self, Object value)
          Print to a console in interactive format along with a newline
static void println(Object self, PrintWriter out)
          Print to a console in interactive format
static void put(List self, Number n, Object value)
          A helper method to allow lists to work with subscript operators
static void query(Connection connection, groovy.lang.GString gstring, groovy.lang.Closure closure)
          Iterates through the result set of an SQL query passing the result set into the closure
static List readLines(File file)
          Reads the file into a list of Strings for each line
static List reverse(List self)
          Reverses the list
static long round(Double number)
           
static int round(Float number)
           
static int size(String text)
          Makes a String look like a Collection by adding support for the size() method
static List sort(List self)
          A convenience method for sorting a List
static List sort(List self, groovy.lang.Closure closure)
          A convenience method for sorting a List using a closure as a comparator
static List sort(List self, Comparator comparator)
          A convenience method for sorting a List with a specific comparator
static void step(Number self, Number to, Number stepNumber, groovy.lang.Closure closure)
          Iterates from this number up to the given number using a step increment
static void times(Number self, groovy.lang.Closure closure)
          Iterates a number of times
static String toConsoleOutput(Object self)
           
static Object tokenize(String self)
           
static Object tokenize(String self, String token)
           
protected static String toString(Object value)
           
static void upto(Number self, Number to, groovy.lang.Closure closure)
          Iterates from this number up to the given number
 
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

inspect

public static String inspect(Object self)
Generates a detailed inspection string of an object showing its class, hashCode and fields


print

public static void print(Object self,
                         Object value)
Print to a console in interactive format


println

public static void println(Object self,
                           Object value)
Print to a console in interactive format along with a newline


toConsoleOutput

public static String toConsoleOutput(Object self)
Returns:
the String that would be printend on the console if the object were displayed in interactive mode

print

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


println

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


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.


isCase

public static boolean isCase(Object caseValue,
                             Object switchValue)

isCase

public static boolean isCase(String caseValue,
                             Object switchValue)

isCase

public static boolean isCase(Class caseValue,
                             Object switchValue)

isCase

public static boolean isCase(Collection caseValue,
                             Object switchValue)

isCase

public static boolean isCase(Pattern caseValue,
                             Object switchValue)

put

public static void put(List self,
                       Number n,
                       Object value)
A helper method to allow lists to work with subscript operators


each

public static void each(Object self,
                        groovy.lang.Closure closure)
Allows objects to be iterated through using a closure

Parameters:
closure -

each

public static void each(Collection self,
                        groovy.lang.Closure closure)
Allows objects to be iterated through using a closure

Parameters:
closure -

each

public static void each(Map self,
                        groovy.lang.Closure closure)
Allows objects to be iterated through using a closure

Parameters:
closure -

every

public static boolean every(Object self,
                            groovy.lang.Closure closure)
Returns:
true if every item in the collection matches the closure predicate

any

public static boolean any(Object self,
                          groovy.lang.Closure closure)
Returns:
true if any item in the collection matches the closure predicate

map

public static List map(Object self,
                       groovy.lang.Closure closure)
Maps the values of a collection to new values using the

Parameters:
closure -

map

public static List map(Collection self,
                       groovy.lang.Closure closure)
Collects the values of the closure

Parameters:
closure -

map

public static List map(Map self,
                       groovy.lang.Closure closure)
Collects the values of the closure

Parameters:
closure -

find

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

Parameters:
closure -

find

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

Parameters:
closure -

find

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

Parameters:
closure -

findAll

public static Object findAll(Object self,
                             groovy.lang.Closure closure)
Finds all values matching the closure condition

Parameters:
closure -

findAll

public static List findAll(Collection self,
                           groovy.lang.Closure closure)
Finds all values matching the closure condition

Parameters:
closure -

findAll

public static List findAll(Map self,
                           groovy.lang.Closure closure)
Finds all values matching the closure condition

Parameters:
closure -

inject

public static Object inject(Collection self,
                            Object value,
                            groovy.lang.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:
closure -

join

public static String join(Collection self,
                          String separator)
Concatenates all of the items of the collection together with the given string as a separator


max

public static Object max(Collection self)
Selects the maximum value found in the collection


max

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


min

public static Object min(Collection self)
Selects the minimum value found in the collection


min

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


min

public static Object min(Collection self,
                         groovy.lang.Closure closure)
Selects the minimum value found in the collection using the given closure as a comparator


max

public static Object max(Collection self,
                         groovy.lang.Closure closure)
Selects the maximum value found in the collection using the given closure as a comparator


size

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

Parameters:
text -
Returns:

get

public static Object get(String text,
                         int index)
Support the subscript operator for String

Parameters:
text -
Returns:
the Character object at the given index

get

public static Object get(String text,
                         groovy.lang.Range range)
Support the range subscript operator for String


get

public static Object get(List list,
                         groovy.lang.Range range)
Support the range subscript operator for a List


get

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

Returns:

immutable

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


immutable

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


immutable

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


immutable

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


immutable

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


sort

public static List sort(List self)
A convenience method for sorting a List


sort

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


sort

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


reverse

public static List reverse(List self)
Reverses the list


plus

public static List plus(List left,
                        Collection right)

plus

public static List plus(List left,
                        Object right)

multiply

public static List multiply(List self,
                            Number factor)

intersect

public static List intersect(List left,
                             Collection right)

minus

public static List minus(List self,
                         Collection removeMe)

flatten

public static List flatten(List self)

tokenize

public static Object tokenize(String self,
                              String token)

tokenize

public static Object tokenize(String self)

plus

public static String plus(String left,
                          Object value)

minus

public static String minus(String left,
                           Object value)

multiply

public static String multiply(String self,
                              Number factor)

toString

protected static String toString(Object value)

increment

public static Number increment(Number self)

decrement

public static Number decrement(Number self)

plus

public static Number plus(Number left,
                          Number right)

minus

public static Number minus(Number left,
                           Number right)

multiply

public static Number multiply(Number left,
                              Number right)

power

public static Number power(Number self,
                           Number exponent)

divide

public static Number divide(Number left,
                            Number right)

isLong

public static boolean isLong(Number number)

isFloatingPoint

public static boolean isFloatingPoint(Number number)

times

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


upto

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


step

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


abs

public static int abs(Number number)

abs

public static long abs(Long number)

abs

public static float abs(Float number)

abs

public static double abs(Double number)

round

public static int round(Float number)

round

public static long round(Double number)

eachLine

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

IOException

readLines

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

IOException

eachFile

public static void eachFile(File self,
                            groovy.lang.Closure closure)
Invokes the closure for each file in the given directory


newReader

public static BufferedReader newReader(File file)
                                throws FileNotFoundException
Helper method to create a buffered reader for a file

Parameters:
file -
Returns:
Throws:
FileNotFoundException

newWriter

public static BufferedWriter newWriter(File file)
                                throws IOException
Helper method to create a buffered writer for a file

Parameters:
file -
Returns:
Throws:
FileNotFoundException
IOException

query

public static void query(Connection connection,
                         groovy.lang.GString gstring,
                         groovy.lang.Closure closure)
                  throws SQLException
Iterates through the result set of an SQL query passing the result set into the closure

Parameters:
connection -
closure -
SQLException


Copyright © 2003 The Codehaus. All Rights Reserved.