|
Groovy JDK |
Method Summary | |
---|---|
void
|
addShutdownHook(Closure)
Allows the usage of addShutdownHook without getting the runtime first. |
boolean
|
any(Closure)
Iterates over the contents of an object or collection, and checks whether a predicate is valid for at least one element. |
boolean
|
any()
Iterates over the elements of a collection, and checks whether at least one element is true according to the Groovy Truth. |
boolean
|
asBoolean()
Coerce an object instance to a boolean value. |
Object
|
asType(Class)
Converts a given object to a type. |
List
|
collect(Closure)
Iterates through this object transforming each value into a new value using the closure as a transformer, returning a list of transformed values. |
Collection
|
collect(Collection, 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. |
String
|
dump()
Generates a detailed dump string of an object showing its class, hashCode and fields. |
Object
|
each(Closure)
Iterates through an aggregate type or data structure, passing each item to the given closure. |
Object
|
eachWithIndex(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. |
boolean
|
every(Closure)
Used to determine if the given predicate closure is valid (i.e. |
boolean
|
every()
Iterates over every element of a collection, and checks whether all elements are true according to the Groovy Truth.
|
Object
|
find(Closure)
Finds the first value matching the closure condition |
Collection
|
findAll(Closure)
Finds all items matching the closure condition. |
int
|
findIndexOf(Closure)
Iterates over the elements of an iterable collection of items and returns the index of the first item that matches the condition specified in the closure. |
int
|
findIndexOf(int, Closure)
Iterates over the elements of an iterable collection of items, starting from a specified startIndex, and returns the index of the first item that matches the condition specified in the closure. |
List
|
findIndexValues(Closure)
Iterates over the elements of an iterable collection of items and returns the index values of the items that match the condition specified in the closure. |
List
|
findIndexValues(Number, Closure)
Iterates over the elements of an iterable collection of items, starting from a specified startIndex, and returns the index values of the items that match the condition specified in the closure. |
int
|
findLastIndexOf(Closure)
Iterates over the elements of an iterable collection of items and returns the index of the last item that matches the condition specified in the closure. |
int
|
findLastIndexOf(int, Closure)
Iterates over the elements of an iterable collection of items, starting from a specified startIndex, and returns the index of the last item that matches the condition specified in the closure. |
Object
|
getAt(String)
Allows the subscript operator to be used to lookup dynamic property values. |
MetaClass
|
getMetaClass()
Obtains a MetaClass for an object either from the registry or in the case of a GroovyObject from the object itself. |
List
|
getMetaPropertyValues()
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'. |
Map
|
getProperties()
Convenience method that calls Object#getMetaPropertyValues(self) and provides the data in form of simple key/value pairs, i.e. |
Collection
|
grep(Object)
Iterates over every element of the collection and returns each item that matches the given filter - calling the Object#isCase
method used by switch statements.
|
MetaProperty
|
hasProperty(String)
Returns true of the implementing MetaClass has a property of the given name Note that this method will only return true for realised properties and does not take into account implementation of getProperty or propertyMissing |
Object
|
identity(Closure)
Allows the closure to be called for the object reference self synonym for 'with()'. |
Object
|
inject(Object, 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. |
String
|
inspect()
Inspects returns the String that matches what would be typed into a terminal to create this object. |
Object
|
invokeMethod(String, Object)
Provide a dynamic method invocation method which can be overloaded in classes to implement dynamic proxies easily. |
boolean
|
is(Object)
Identity check. |
boolean
|
isCase(Object)
Method for overloading the behavior of the 'case' method in switch statements. |
Iterator
|
iterator()
Attempts to create an Iterator for the given object by first converting it to a Collection. |
MetaClass
|
metaClass(Closure)
Sets/updates the metaclass for a given object to a closure. |
void
|
print(Object)
Print a value formatted Groovy style to self if it is a Writer, otherwise to the standard output stream. |
void
|
print(PrintWriter)
Print to a console in interactive format. |
void
|
printf(String, Object[])
Printf to a console (Only works with JDK1.5 or later). |
void
|
printf(String, Object)
Prints a formatted string using the specified format string and arguments. |
void
|
println()
Print a linebreak to the standard output stream. |
void
|
println(Object)
Print a value formatted Groovy style (followed by a newline) to self if it is a Writer, otherwise to the standard output stream. |
void
|
println(PrintWriter)
Print to a console in interactive format. |
void
|
putAt(String, Object)
Allows the subscript operator to be used to set dynamically named property values. |
List
|
respondsTo(String, Object[])
Returns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name and arguments types. |
List
|
respondsTo(String)
Returns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name regardless of the arguments. |
void
|
setMetaClass(MetaClass)
Set the metaclass for an object |
static void
|
sleep(long)
Sleep for so many milliseconds, even if interrupted. |
static void
|
sleep(long, Closure)
Sleep for so many milliseconds, using a given closure for interrupt processing. |
Collection
|
split(Closure)
Splits all items into two lists based on the closure condition. |
String
|
sprintf(String, Object[])
Sprintf to a string (Only works with JDK1.5 or later). |
String
|
sprintf(String, Object)
Returns a formatted string using the specified format string and arguments. |
String
|
toString()
Create a String representation of this object. |
Object
|
use(Class, Closure)
Scoped use method |
Object
|
use(List, Closure)
Scoped use method with list of categories. |
Object
|
use(Object[])
Allows you to use a list of categories, specifying the list as varargs. |
Object
|
with(Closure)
Allows the closure to be called for the object reference self |
Method Detail |
---|
public void addShutdownHook(Closure)
closure
- the shutdown hook action.public boolean any(Closure)
closure
- the closure predicate used for matching.public boolean any()
public boolean asBoolean()
public Object asType(Class)
type
- the goal type.public List collect(Closure)
def list = [1, 'a', 1.23, true ] def types = list.collect { it.class } assert types == [Integer, String, BigDecimal, Boolean]
closure
- the closure used to transform each element of the collection.public Collection collect(Collection, Closure)
collection
- the Collection to which the transformed values are added.closure
- the closure used to map each element of the collection.public String dump()
public Object each(Closure)
closure
- the closure applied on each element found.public Object eachWithIndex(Closure)
closure
- a Closure to operate on each item.public boolean every(Closure)
true
for all items in this data structure).
A simple example for a list:
def list = [3,4,5] def greaterThanTwo = list.every { it > 2 }
closure
- the closure predicate used for matching.public boolean every()
true
according to the Groovy Truth.
Equivalent to self.every({element -> element})
public Object find(Closure)
closure
- a closure condition.public Collection findAll(Closure)
closure
- a closure condition.public int findIndexOf(Closure)
closure
- the filter to perform a match on the collection.public int findIndexOf(int, Closure)
startIndex
- start matching from this index.closure
- the filter to perform a match on the collection.public List findIndexValues(Closure)
closure
- the filter to perform a match on the collection.public List findIndexValues(Number, Closure)
startIndex
- start matching from this index.closure
- the filter to perform a match on the collection.public int findLastIndexOf(Closure)
closure
- the filter to perform a match on the collection.public int findLastIndexOf(int, Closure)
startIndex
- start matching from this index.closure
- the filter to perform a match on the collection.public Object getAt(String)
bean[somePropertyNameExpression]
. The normal property notation
of groovy is neater and more concise but only works with compile-time known
property names.property
- the property name of interest.public MetaClass getMetaClass()
public List getMetaPropertyValues()
public Map getProperties()
public Collection grep(Object)
Object#isCase
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'
filter
- the filter to perform on the object (using the {@link #isCase(java.lang.Object, java.lang.Object)} method).public MetaProperty hasProperty(String)
Returns true of the implementing MetaClass has a property of the given name
Note that this method will only return true for realised properties and does not take into account implementation of getProperty or propertyMissing
name
- The name of the property of interest.public Object identity(Closure)
closure
- the closure to call on the object.public Object inject(Object, Closure)
value
- a value.closure
- a closure.public String inspect()
public Object invokeMethod(String, Object)
method
- the name of the method to call.arguments
- the arguments to use.public boolean is(Object)
def same = this.is(that)
other
- an object to compare identity with.public boolean isCase(Object)
switch( a ) { case b: //some code }"some code" is called when
b.isCase( a )
returns
true
.switchValue
- the switch value.public Iterator iterator()
public MetaClass metaClass(Closure)
closure
- the closure representing the new metaclass.public void print(Object)
value
- the value to print.public void print(PrintWriter)
out
- the PrintWriter used for printing.public void printf(String, Object[])
format
- a format string.values
- values referenced by the format specifiers in the format string..public void printf(String, Object)
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[] ) }
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[]..public void println()
public void println(Object)
value
- the value to print.public void println(PrintWriter)
out
- the PrintWriter used for printing.public void putAt(String, Object)
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.property
- the name of the property to set.newValue
- the value to set.public List respondsTo(String, Object[])
Returns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name and arguments types.
Note that this method's return value is based on realised methods and does not take into account objects or classes that implement invokeMethod or methodMissing
This method is "safe" in that it will always return a value and never throw an exception
name
- The name of the method of interest.argTypes
- The argument types to match against.public List respondsTo(String)
Returns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name regardless of the arguments.
Note that this method's return value is based on realised methods and does not take into account objects or classes that implement invokeMethod or methodMissing
This method is "safe" in that it will always return a value and never throw an exception
name
- The name of the method of interest.public void setMetaClass(MetaClass)
metaClass
- the new metaclass value.public static void sleep(long)
milliseconds
- the number of milliseconds to sleep.public static void sleep(long, Closure)
milliseconds
- the number of milliseconds to sleep.onInterrupt
- interrupt handler, InterruptedException is passed to the Closure
as long as it returns false, the sleep continues.public Collection split(Closure)
closure
- a closure condition.public String sprintf(String, Object[])
format
- a format string.values
- values referenced by the format specifiers in the format string..public String sprintf(String, 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[]..public String toString()
public Object use(Class, Closure)
categoryClass
- a category class to use.closure
- the closure to invoke with the category in place.public Object use(List, Closure)
categoryClassList
- a list of category classes.closure
- the closure to invoke with the categories in place.public Object use(Object[])
use(CategoryClass1, CategoryClass2) { ... }
This method saves having to wrap the the category
classes in a list.array
- a list of category classes and a Closure.public Object with(Closure)
closure
- the closure to call on the object.
|
Groovy JDK |