|
Groovy 1.8.7 | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.codehaus.groovy.runtime.DefaultGroovyMethodsSupport
org.codehaus.groovy.runtime.DefaultGroovyMethods
public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport
This class defines new groovy methods which appear on normal JDK
classes inside the Groovy environment. Static methods are used with the
first parameter being the destination class,
i.e. public static String reverse(String self)
provides a reverse()
method for String
.
NOTE: While this class contains many 'public' static methods, it is primarily regarded as an internal class (its internal package name suggests this also). We value backwards compatibility of these methods when used within Groovy but value less backwards compatibility at the Java method call level. I.e. future versions of Groovy may remove or move a method call in this file but would normally aim to keep the method available from within Groovy.
Field Summary | |
---|---|
static Class[] |
additionals
|
Method Summary | |
---|---|
static int
|
abs(Number number)
Truncate the value |
static long
|
abs(Long number)
Parse a String into an Integer |
static float
|
abs(Float number)
Parse a String into a Long |
static double
|
abs(Double number)
Parse a String into a Short |
static Socket
|
accept(ServerSocket serverSocket, Closure closure)
Converts the GString to a File, or delegates to the default asType(java.lang.Object, java.lang.Class) |
static Socket
|
accept(ServerSocket serverSocket, boolean runInANewThread, Closure closure)
|
static boolean
|
addAll(Collection self, Object[] items)
Modifies the collection by adding all of the elements in the specified array to the collection. |
static boolean
|
addAll(List self, int index, Object[] items)
|
static void
|
addShutdownHook(Object self, Closure closure)
Allows the usage of addShutdownHook without getting the runtime first. |
static Number
|
and(Number left, Number right)
|
static BitSet
|
and(BitSet left, BitSet right)
|
static Boolean
|
and(Boolean left, Boolean right)
Create an object input stream for this input stream. |
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 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 void
|
append(File file, Object text)
Invokes the closure for each descendant file in this directory. |
static void
|
append(File file, byte[] bytes)
|
static void
|
append(File self, InputStream stream)
|
static void
|
append(File file, Object text, String charset)
|
static boolean
|
asBoolean(Object object)
|
static boolean
|
asBoolean(Boolean bool)
|
static boolean
|
asBoolean(Matcher matcher)
|
static boolean
|
asBoolean(Collection collection)
|
static boolean
|
asBoolean(Map map)
|
static boolean
|
asBoolean(Iterator iterator)
|
static boolean
|
asBoolean(Enumeration enumeration)
|
static boolean
|
asBoolean(CharSequence string)
|
static boolean
|
asBoolean(Object[] array)
|
static boolean
|
asBoolean(byte[] array)
|
static boolean
|
asBoolean(short[] array)
|
static boolean
|
asBoolean(int[] array)
|
static boolean
|
asBoolean(long[] array)
|
static boolean
|
asBoolean(float[] array)
|
static boolean
|
asBoolean(double[] array)
|
static boolean
|
asBoolean(boolean[] array)
|
static boolean
|
asBoolean(char[] array)
|
static boolean
|
asBoolean(Character character)
|
static boolean
|
asBoolean(Number number)
|
static Map
|
asImmutable(Map self)
A convenience method for creating an immutable list |
static SortedMap
|
asImmutable(SortedMap self)
|
static List
|
asImmutable(List self)
|
static Set
|
asImmutable(Set self)
|
static SortedSet
|
asImmutable(SortedSet self)
A convenience method for creating a synchronized Map. |
static Collection
|
asImmutable(Collection self)
A convenience method for creating a synchronized SortedMap. |
static List
|
asList(Collection self)
Coerce an Boolean instance to a boolean value. |
static Map
|
asSynchronized(Map self)
|
static SortedMap
|
asSynchronized(SortedMap self)
|
static Collection
|
asSynchronized(Collection self)
|
static List
|
asSynchronized(List self)
|
static Set
|
asSynchronized(Set self)
|
static SortedSet
|
asSynchronized(SortedSet self)
|
static Object
|
asType(Collection col, Class clazz)
|
static Object
|
asType(Object[] ary, Class clazz)
Converts the given array to either a List, Set, or SortedSet. |
static Object
|
asType(Closure cl, 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(Map map, Class clazz)
Creates a new List with the identical contents to this list but in reverse order. |
static Object
|
asType(Number self, Class c)
Create a new ObjectOutputStream for this file and then pass it to the closure. |
static Object
|
asType(File f, Class c)
|
static Object
|
asType(GString self, Class c)
|
static Object
|
asType(String self, Class c)
Iterates over the elements of an iterable collection of items and returns the index of the last item that matches the condition specified in the closure. |
static Object
|
asType(CharSequence self, Class c)
Iterates over the elements of an iterable collection of items and returns the index values of the items that match the condition specified in the closure. |
static Object
|
asType(Object obj, Class type)
Sets the metaclass for a given class. |
static File
|
asWritable(File file)
|
static File
|
asWritable(File file, String encoding)
|
static Pattern
|
bitwiseNegate(String self)
|
static Pattern
|
bitwiseNegate(CharSequence self)
|
static BitSet
|
bitwiseNegate(BitSet self)
|
protected static Object
|
callClosureForLine(Closure closure, String line, int counter)
|
protected static Object
|
callClosureForMapEntry(Closure closure, Map.Entry entry)
|
protected static Object
|
callClosureForMapEntryAndCounter(Closure closure, Map.Entry entry, int counter)
|
static String
|
capitalize(String self)
Expands all tabs into spaces. |
static CharSequence
|
capitalize(CharSequence self)
Replaces sequences of whitespaces with tabs using tabStops of size 8. |
static String
|
center(String self, Number numberOfChars, String padding)
Pad a CharSequence to a minimum length specified by numberOfChars, appending the supplied padding CharSequence around the original as many times as needed keeping it centered. |
static CharSequence
|
center(CharSequence self, Number numberOfChars, CharSequence padding)
Pad a String to a minimum length specified by numberOfChars by adding the space character around it as many times as needed so that it remains centered. |
static String
|
center(String self, Number numberOfChars)
|
static CharSequence
|
center(CharSequence self, Number numberOfChars)
|
static List
|
collate(List self, int size)
|
static List
|
collate(List self, int size, int step)
|
static List
|
collate(List self, int size, boolean keepRemainder)
|
static List
|
collate(List self, int size, int step, boolean keepRemainder)
|
static List
|
collect(Object self, Closure transform)
Iterates through this aggregate Object transforming each item into a new value using the
|
static Collection
|
collect(Object self)
|
static Collection
|
collect(Object self, Collection collector, Closure transform)
|
static List
|
collect(Collection self, Closure transform)
|
static List
|
collect(Collection self)
|
static Collection
|
collect(Collection self, Collection collector, Closure transform)
|
static Collection
|
collect(Map self, Collection collector, Closure transform)
|
static List
|
collect(Map self, Closure transform)
|
static List
|
collectAll(Collection self, Closure transform)
Deprecated alias for collectNested |
static Collection
|
collectAll(Collection self, Collection collector, Closure transform)
|
static Map
|
collectEntries(Map self, Map collector, Closure transform)
|
static Map
|
collectEntries(Map self, Closure transform)
|
static Map
|
collectEntries(Collection self, Closure transform)
|
static Map
|
collectEntries(Collection self)
|
static Map
|
collectEntries(Collection self, Map collector, Closure transform)
|
static Map
|
collectEntries(Collection self, Map collector)
|
static Map
|
collectEntries(Object[] self, Map collector, Closure transform)
|
static Map
|
collectEntries(Object[] self, Map collector)
|
static Map
|
collectEntries(Object[] self, Closure transform)
|
static Map
|
collectEntries(Object[] self)
|
static List
|
collectMany(Collection self, Closure projection)
Projects each item from a source collection to a collection and concatenates (flattens) the resulting collections into a single list. |
static Collection
|
collectMany(Collection self, Collection collector, Closure projection)
|
static List
|
collectMany(Object[] self, Closure projection)
|
static List
|
collectMany(Iterator self, Closure projection)
|
static List
|
collectNested(Collection self, Closure transform)
Deprecated alias for collectNested |
static Collection
|
collectNested(Collection self, Collection collector, Closure transform)
|
static List
|
combinations(Collection self)
Adds GroovyCollections#combinations(Collection) as a method on collections. |
static int
|
compareTo(Character left, Number right)
|
static int
|
compareTo(Number left, Character right)
|
static int
|
compareTo(Character left, Character right)
|
static int
|
compareTo(Number left, Number right)
|
static boolean
|
contains(String self, String text)
Checks whether the array contains the given value. |
static boolean
|
contains(CharSequence self, CharSequence text)
Checks whether the array contains the given value. |
static boolean
|
contains(int[] self, Object value)
Checks whether the array contains the given value. |
static boolean
|
contains(long[] self, Object value)
Count the number of occurrences of a substring. |
static boolean
|
contains(short[] self, Object value)
|
static boolean
|
contains(char[] self, Object value)
|
static boolean
|
contains(boolean[] self, Object value)
|
static boolean
|
contains(double[] self, Object value)
|
static boolean
|
contains(float[] self, Object value)
This method is called by the -- operator for the class String. |
static boolean
|
contains(byte[] self, Object value)
|
static boolean
|
contains(Object[] self, Object value)
|
static boolean
|
containsAll(Collection self, Object[] items)
|
static Number
|
count(Iterator self, Object value)
|
static Number
|
count(Iterator self, Closure closure)
Counts the number of occurrences which satisfy the given closure from the items within this Iterator. |
static Number
|
count(Collection self, Object value)
Counts the number of occurrences of the given value inside this collection. |
static Number
|
count(Collection self, Closure closure)
|
static Number
|
count(Map self, Closure closure)
|
static Number
|
count(Object[] self, Object value)
Counts the number of occurrences of the given value inside this array. |
static Number
|
count(Object[] self, Closure closure)
|
static Number
|
count(int[] self, Object value)
|
static Number
|
count(long[] self, Object value)
|
static Number
|
count(short[] self, Object value)
|
static Number
|
count(char[] self, Object value)
|
static Number
|
count(boolean[] self, Object value)
|
static Number
|
count(double[] self, Object value)
|
static Number
|
count(float[] self, Object value)
|
static Number
|
count(byte[] self, Object value)
|
static int
|
count(String self, String text)
|
static int
|
count(CharSequence self, CharSequence text)
|
static Map
|
countBy(Collection self, Closure closure)
|
static Map
|
countBy(Object[] self, Closure closure)
|
static Map
|
countBy(Iterator self, Closure closure)
|
static Map
|
countBy(Map self, Closure closure)
Groups the current element according to the value |
protected static StringBufferWriter
|
createStringBufferWriter(StringBuffer self)
|
protected static StringWriter
|
createStringWriter(String self)
|
static boolean
|
deleteDir(File self)
Creates a new data output stream for this file. |
static String
|
denormalize(String self)
|
static CharSequence
|
denormalize(CharSequence self)
Reads the stream into a list, with one element for each line. |
static boolean
|
disjoint(Collection left, Collection right)
Compare the contents of this array to the contents of the given array. |
static Number
|
div(Character left, Number right)
Bitwise AND together two BitSets. |
static Number
|
div(Number left, Character right)
Bitwise XOR together two BitSets. |
static Number
|
div(Character left, Character right)
Bitwise NEGATE a BitSet. |
static void
|
downto(Number self, Number to, Closure closure)
Iterates from this number down to the given number, inclusive, decrementing by one each time. |
static void
|
downto(long self, Number to, Closure closure)
Iterates from this number down to the given number, inclusive, decrementing by one each time. |
static void
|
downto(Long self, Number to, Closure closure)
|
static void
|
downto(float self, Number to, Closure closure)
Iterates from this number down to the given number, inclusive, decrementing by one each time. |
static void
|
downto(Float self, Number to, Closure closure)
|
static void
|
downto(double self, Number to, Closure closure)
|
static void
|
downto(Double self, Number to, Closure closure)
|
static void
|
downto(BigInteger self, Number to, Closure closure)
|
static void
|
downto(BigDecimal self, Number to, Closure closure)
Get the absolute value |
static List
|
drop(List self, int num)
Drops the given number of elements from the head of this Iterable. |
static List
|
drop(Iterable self, int num)
Drops the given number of elements from the head of this array if they are available. |
static Object[]
|
drop(Object[] self, int num)
Drops the given number of key/value pairs from the head of this map if they are available. |
static Map
|
drop(Map self, int num)
Drops the given number of elements from the head of this iterator if they are available. |
static Iterator
|
drop(Iterator self, int num)
Drops the given number of chars from the head of this CharSequence if they are available. |
static CharSequence
|
drop(CharSequence self, int num)
|
static List
|
dropWhile(List self, Closure condition)
Returns a suffix of this Iterable where elements are dropped from the front while the given closure evaluates to true. |
static List
|
dropWhile(Iterable self, Closure condition)
|
static Map
|
dropWhile(Map self, Closure condition)
Create a suffix of the given array by dropping as many elements as possible from the front of the original array such that calling the given closure condition evaluates to true when passed each of the dropped elements. |
static Object[]
|
dropWhile(Object[] self, Closure condition)
Creates an Iterator that returns a suffix of the elements from an original Iterator. |
static Iterator
|
dropWhile(Iterator self, Closure condition)
|
static String
|
dump(Object self)
Generates a detailed dump string of an object showing its class, hashCode and fields. |
static Object
|
each(Object self, Closure closure)
Iterates through an aggregate type or data structure, passing each item to the given closure. |
static Map
|
each(Map self, Closure closure)
Allows a Map to be iterated through using a closure. |
static void
|
eachByte(File self, Closure closure)
|
static void
|
eachByte(File self, int bufferLen, Closure closure)
|
static void
|
eachByte(Byte[] self, Closure closure)
|
static void
|
eachByte(byte[] self, Closure closure)
|
static void
|
eachByte(InputStream is, Closure closure)
|
static void
|
eachByte(InputStream is, int bufferLen, Closure closure)
Filters the lines of a File and creates a Writable in return to stream the filtered lines. |
static void
|
eachByte(URL url, Closure closure)
Filter the lines from this File, and write them to the given writer based on the given closure predicate. |
static void
|
eachByte(URL url, int bufferLen, Closure closure)
Filter the lines from this File, and write them to the given writer based on the given closure predicate. |
static void
|
eachDir(File self, Closure closure)
|
static void
|
eachDirMatch(File self, Object nameFilter, Closure closure)
Create a buffered output stream for this file. |
static void
|
eachDirRecurse(File self, Closure closure)
Create a buffered reader for this file. |
static void
|
eachFile(File self, FileType fileType, Closure closure)
|
static void
|
eachFile(File self, Closure closure)
|
static void
|
eachFileMatch(File self, FileType fileType, Object nameFilter, Closure closure)
Create a buffered reader for this file, using the specified charset as the encoding. |
static void
|
eachFileMatch(File self, Object nameFilter, 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
|
eachFileRecurse(File self, FileType fileType, Closure closure)
|
static void
|
eachFileRecurse(File self, Closure closure)
Renames the file. |
static Object
|
eachLine(String self, Closure closure)
|
static Object
|
eachLine(CharSequence self, Closure closure)
|
static Object
|
eachLine(String self, int firstLine, Closure closure)
|
static Object
|
eachLine(CharSequence self, int firstLine, Closure closure)
|
static Object
|
eachLine(File self, Closure closure)
|
static Object
|
eachLine(File self, String charset, Closure closure)
|
static Object
|
eachLine(File self, int firstLine, Closure closure)
|
static Object
|
eachLine(File self, String charset, int firstLine, Closure closure)
Iterates through the given reader line by line. |
static Object
|
eachLine(InputStream stream, String charset, Closure closure)
Iterates through the given reader line by line. |
static Object
|
eachLine(InputStream stream, String charset, int firstLine, Closure closure)
|
static Object
|
eachLine(InputStream stream, Closure closure)
|
static Object
|
eachLine(InputStream stream, int firstLine, Closure closure)
|
static Object
|
eachLine(URL url, Closure closure)
|
static Object
|
eachLine(URL url, int firstLine, Closure closure)
|
static Object
|
eachLine(URL url, String charset, Closure closure)
|
static Object
|
eachLine(URL url, String charset, int firstLine, Closure closure)
|
static Object
|
eachLine(Reader self, Closure closure)
|
static Object
|
eachLine(Reader self, int firstLine, Closure closure)
Iterates through the input stream associated with this URL line by line, splitting each line using the given regex separator Pattern. |
static String
|
eachMatch(String self, String regex, Closure closure)
|
static String
|
eachMatch(CharSequence self, CharSequence regex, Closure closure)
|
static String
|
eachMatch(String self, Pattern pattern, Closure closure)
Converts a given object to a type. |
static String
|
eachMatch(CharSequence self, Pattern pattern, Closure closure)
|
static void
|
eachObject(File self, Closure closure)
|
static void
|
eachObject(ObjectInputStream ois, Closure closure)
|
static Iterator
|
eachPermutation(Collection self, Closure closure)
|
static Object
|
eachWithIndex(Object self, Closure closure)
|
static Map
|
eachWithIndex(Map self, Closure closure)
Allows a Map to be iterated through using a closure. |
static boolean
|
equals(int[] left, int[] right)
Determines if the contents of this array are equal to the contents of the given list, in the same order. |
static boolean
|
equals(Object[] left, List right)
|
static boolean
|
equals(List left, Object[] right)
|
static boolean
|
equals(List left, List right)
|
static boolean
|
equals(Set self, Set other)
|
static boolean
|
equals(Map self, Map other)
Create a Set composed of the elements of the first Set minus the elements of the given Collection. |
static boolean
|
every(Object self, Closure closure)
|
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 |
static Process
|
execute(String self)
|
static Process
|
execute(String self, String[] envp, File dir)
|
static Process
|
execute(String self, List envp, File dir)
|
static Process
|
execute(String[] commandArray)
|
static Process
|
execute(String[] commandArray, String[] envp, File dir)
Repeat a String a certain number of times. |
static Process
|
execute(String[] commandArray, List envp, File dir)
Repeat a CharSequence a certain number of times. |
static Process
|
execute(List commands)
Returns the string representation of the given array. |
static Process
|
execute(List commands, String[] envp, File dir)
Returns the string representation of the given array. |
static Process
|
execute(List commands, List envp, File dir)
Returns the string representation of the given array. |
static String
|
expand(String self)
Replaces sequences of whitespaces with tabs using tabStops of size 8. |
static CharSequence
|
expand(CharSequence self)
Replaces sequences of whitespaces with tabs. |
static String
|
expand(String self, int tabStop)
|
static CharSequence
|
expand(CharSequence self, int tabStop)
Replaces sequences of whitespaces with tabs. |
static String
|
expandLine(String self, int tabStop)
|
static CharSequence
|
expandLine(CharSequence self, int tabStop)
Replaces sequences of whitespaces with tabs within a line. |
static void
|
filterLine(Reader reader, Writer writer, Closure closure)
Filter lines from an input stream using a closure predicate. |
static Writable
|
filterLine(File self, Closure closure)
Uses a closure to filter lines from this InputStream and pass them to the given writer. |
static Writable
|
filterLine(File self, String charset, Closure closure)
|
static void
|
filterLine(File self, Writer writer, Closure closure)
Uses a closure to filter lines from this URL and pass them to the given writer. |
static void
|
filterLine(File self, Writer writer, String charset, Closure closure)
Uses a closure to filter lines from this URL and pass them to the given writer. |
static Writable
|
filterLine(Reader reader, Closure closure)
Reads the content of the file into a byte array. |
static Writable
|
filterLine(InputStream self, Closure predicate)
Passes the Socket's InputStream and OutputStream to the closure. |
static Writable
|
filterLine(InputStream self, String charset, Closure predicate)
|
static void
|
filterLine(InputStream self, Writer writer, Closure predicate)
|
static void
|
filterLine(InputStream self, Writer writer, String charset, Closure predicate)
|
static Writable
|
filterLine(URL self, Closure predicate)
|
static Writable
|
filterLine(URL self, String charset, Closure predicate)
Accepts a connection and passes the resulting Socket to the closure which runs in a new Thread. |
static void
|
filterLine(URL self, Writer writer, Closure predicate)
Accepts a connection and passes the resulting Socket to the closure which runs in a new Thread or the calling thread, as needed. |
static void
|
filterLine(URL self, Writer writer, String charset, Closure predicate)
|
static Object
|
find(Object self, Closure closure)
Finds the first value matching the closure condition |
static Object
|
find(Object self)
Treats the object as iterable, iterating through the values it represents and returns the first non-null result obtained from calling the closure, otherwise returns the defaultResult. |
static Object
|
find(Collection self, Closure closure)
|
static Object
|
find(Collection self)
|
static Map.Entry
|
find(Map self, Closure closure)
|
static String
|
find(String self, String regex)
Finds the first occurrence of a regular expression CharSequence within a CharSequence. |
static CharSequence
|
find(CharSequence self, CharSequence regex)
|
static String
|
find(String self, Pattern pattern)
Finds the first occurrence of a compiled regular expression Pattern within a CharSequence. |
static CharSequence
|
find(CharSequence self, Pattern pattern)
|
static String
|
find(String self, String regex, Closure closure)
Returns the result of calling a closure with the first occurrence of a regular expression found within a CharSequence. |
static CharSequence
|
find(CharSequence self, CharSequence regex, Closure closure)
|
static String
|
find(String self, Pattern pattern, Closure closure)
|
static CharSequence
|
find(CharSequence self, Pattern pattern, Closure closure)
Returns a (possibly empty) list of all occurrences of a regular expression (in String format) found within a String. |
static Collection
|
findAll(Collection self, Closure closure)
|
static Collection
|
findAll(Collection self)
Finds all items matching the closure condition. |
static Collection
|
findAll(Object self, Closure closure)
|
static Collection
|
findAll(Object self)
|
static Map
|
findAll(Map self, Closure closure)
|
static List
|
findAll(String self, String regex)
|
static List
|
findAll(CharSequence self, CharSequence regex)
|
static List
|
findAll(String self, Pattern pattern)
Returns a (possibly empty) list of all occurrences of a regular expression (in Pattern format) found within a CharSequence. |
static List
|
findAll(CharSequence self, Pattern pattern)
|
static List
|
findAll(String self, String regex, Closure closure)
Finds all occurrences of a capturing regular expression CharSequence within a CharSequence. |
static List
|
findAll(CharSequence self, CharSequence regex, Closure closure)
|
static List
|
findAll(String self, Pattern pattern, Closure closure)
Finds all occurrences of a compiled regular expression Pattern within a CharSequence. |
static List
|
findAll(CharSequence self, Pattern pattern, Closure closure)
|
static int
|
findIndexOf(Object self, Closure closure)
|
static int
|
findIndexOf(Object self, int startIndex, Closure closure)
|
static List
|
findIndexValues(Object self, Closure closure)
Convenience method to dynamically create a new instance of this class. |
static List
|
findIndexValues(Object self, Number startIndex, Closure closure)
Adds a "metaClass" property to all class objects so you can use the syntax
|
static int
|
findLastIndexOf(Object self, Closure closure)
|
static int
|
findLastIndexOf(Object self, int startIndex, Closure closure)
|
static Object
|
findResult(Object self, Object defaultResult, Closure closure)
|
static Object
|
findResult(Object self, Closure closure)
|
static Object
|
findResult(Collection self, Object defaultResult, Closure closure)
|
static Object
|
findResult(Collection self, Closure closure)
|
static Object
|
findResult(Map self, Object defaultResult, Closure closure)
|
static Object
|
findResult(Map self, Closure closure)
|
static Collection
|
findResults(Collection self, Closure filteringTransform)
|
static Collection
|
findResults(Map self, Closure filteringTransform)
|
static Object
|
first(List self)
|
static Object
|
first(Iterable self)
|
static Object
|
first(Object[] self)
Returns the first item from the Object array. |
static Collection
|
flatten(Collection self)
Flatten an array. |
static Collection
|
flatten(Object[] self)
Flatten an array. |
static Collection
|
flatten(boolean[] self)
Flatten an array. |
static Collection
|
flatten(byte[] self)
Flatten an array. |
static Collection
|
flatten(char[] self)
Flatten an array. |
static Collection
|
flatten(short[] self)
Flatten an array. |
static Collection
|
flatten(int[] self)
|
static Collection
|
flatten(long[] self)
|
static Collection
|
flatten(float[] self)
|
static Collection
|
flatten(double[] self)
|
static Collection
|
flatten(Collection self, Closure flattenUsing)
Overloads the left shift operator to provide an easy way to append objects to a Collection. |
static Object
|
get(Map map, Object key, Object defaultValue)
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 CharSequence
|
getAt(CharSequence text, int index)
|
static String
|
getAt(String text, int index)
|
static CharSequence
|
getAt(CharSequence text, Range range)
|
static CharSequence
|
getAt(CharSequence text, IntRange range)
Support the range subscript operator for CharSequence or StringBuffer with EmptyRange |
static CharSequence
|
getAt(CharSequence text, EmptyRange range)
|
static String
|
getAt(String text, IntRange range)
|
static String
|
getAt(String text, EmptyRange range)
|
static String
|
getAt(String text, Range range)
|
static Object
|
getAt(Matcher matcher, int idx)
Set the position of the given Matcher to the given index. |
static List
|
getAt(List self, Range range)
|
static List
|
getAt(List self, EmptyRange range)
|
static List
|
getAt(List self, Collection indices)
|
static List
|
getAt(Object[] self, Collection indices)
Select a List of characters from a CharSequence using a Collection to identify the indices to be selected. |
static CharSequence
|
getAt(CharSequence self, Collection indices)
Select a List of characters from a String using a Collection to identify the indices to be selected. |
static String
|
getAt(String self, Collection indices)
|
static List
|
getAt(Matcher self, Collection indices)
|
static List
|
getAt(Object[] array, Range range)
|
static List
|
getAt(Object[] array, IntRange range)
@param array an Array of Objects |
static List
|
getAt(Object[] array, EmptyRange range)
Allows conversion of arrays into a mutable List. |
static List
|
getAt(Object[] array, ObjectRange range)
Support the subscript operator for a List. |
static Object
|
getAt(List self, int idx)
|
static Object
|
getAt(Iterator self, int idx)
|
static Object
|
getAt(Map self, Object key)
Returns a new |
static List
|
getAt(Collection coll, String property)
|
static List
|
getAt(byte[] array, Range range)
|
static List
|
getAt(char[] array, Range range)
|
static List
|
getAt(short[] array, Range range)
|
static List
|
getAt(int[] array, Range range)
|
static List
|
getAt(long[] array, Range range)
|
static List
|
getAt(float[] array, Range range)
|
static List
|
getAt(double[] array, Range range)
|
static List
|
getAt(boolean[] array, Range range)
|
static List
|
getAt(byte[] array, IntRange range)
|
static List
|
getAt(char[] array, IntRange range)
|
static List
|
getAt(short[] array, IntRange range)
|
static List
|
getAt(int[] array, IntRange range)
|
static List
|
getAt(long[] array, IntRange range)
|
static List
|
getAt(float[] array, IntRange range)
|
static List
|
getAt(double[] array, IntRange range)
|
static List
|
getAt(boolean[] array, IntRange range)
|
static List
|
getAt(byte[] array, ObjectRange range)
|
static List
|
getAt(char[] array, ObjectRange range)
|
static List
|
getAt(short[] array, ObjectRange range)
|
static List
|
getAt(int[] array, ObjectRange range)
|
static List
|
getAt(long[] array, ObjectRange range)
|
static List
|
getAt(float[] array, ObjectRange range)
|
static List
|
getAt(double[] array, ObjectRange range)
|
static List
|
getAt(boolean[] array, ObjectRange range)
|
static List
|
getAt(byte[] array, Collection indices)
|
static List
|
getAt(char[] array, Collection indices)
|
static List
|
getAt(short[] array, Collection indices)
|
static List
|
getAt(int[] array, Collection indices)
|
static List
|
getAt(long[] array, Collection indices)
|
static List
|
getAt(float[] array, Collection indices)
|
static List
|
getAt(double[] array, Collection indices)
|
static List
|
getAt(boolean[] array, Collection indices)
|
static boolean
|
getAt(BitSet self, int index)
|
static BitSet
|
getAt(BitSet self, IntRange range)
|
static byte[]
|
getBytes(File file)
Write the text to the File. |
static byte[]
|
getBytes(URL url)
|
static byte[]
|
getBytes(InputStream is)
Write the text to the File, using the specified encoding. |
static char[]
|
getChars(String self)
Iterates over the elements of an iterable collection of items and returns the index of the first item that matches the condition specified in the closure. |
static char[]
|
getChars(CharSequence self)
|
static int
|
getCount(Matcher matcher)
Check whether a Matcher contains a group or not. |
static MetaClass
|
getMetaClass(Class c)
|
static MetaClass
|
getMetaClass(Object obj)
Attempts to create an Iterator for the given object by first converting it to a Collection. |
static MetaClass
|
getMetaClass(GroovyObject obj)
Attempts to create an Iterator for the given object by first converting it to a Collection. |
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 Map
|
getProperties(Object self)
Convenience method that calls getMetaPropertyValues(java.lang.Object)(self) and provides the data in form of simple key/value pairs, i.e. |
static ClassLoader
|
getRootLoader(ClassLoader self)
Obtains a MetaClass for an object either from the registry or in the case of a GroovyObject from the object itself. |
protected static List
|
getSubList(List self, List splice)
|
static String
|
getText(File file, String charset)
Read the content of this URL and returns it as a byte[]. |
static String
|
getText(File file)
|
static String
|
getText(URL url)
|
static String
|
getText(URL url, Map parameters)
Write the bytes from the byte array to the File. |
static String
|
getText(URL url, String charset)
Write the byte[] to the output stream. |
static String
|
getText(URL url, Map parameters, String charset)
Write the text and append a newline (using the platform's line-ending). |
static String
|
getText(InputStream is)
Write the text to the File. |
static String
|
getText(InputStream is, String charset)
|
static String
|
getText(Reader reader)
|
static String
|
getText(BufferedReader reader)
|
static Collection
|
grep(Object self, Object filter)
Iterates over the collection of items which this Object represents and returns each item that matches
the given filter - calling the |
static Collection
|
grep(Object self)
Iterates over the collection of items which this Object represents and returns each item that matches using the IDENTITY Closure as a filter - effectively returning all elements which satisfy Groovy truth. |
protected static void
|
groupAnswer(Map answer, Object element, Object value)
|
static Map
|
groupBy(Collection self, Closure closure)
|
static Map
|
groupBy(Collection self, Object... closures)
|
static Map
|
groupBy(Collection self, List closures)
Sorts all collection members into (sub)groups determined by the supplied mapping closures. |
static Map
|
groupBy(Map self, Closure closure)
|
static Map
|
groupBy(Map self, Object... closures)
|
static Map
|
groupBy(Map self, List closures)
Groups the members of a map into sub maps determined by the supplied mapping closures. |
static Map
|
groupEntriesBy(Map self, Closure closure)
|
static boolean
|
hasGroup(Matcher matcher)
|
static MetaProperty
|
hasProperty(Object self, String name)
|
static Object
|
head(List self)
Returns the items from the List excluding the first item. |
static Object
|
head(Object[] self)
|
static Object
|
identity(Object self, Closure closure)
Allows the closure to be called for the object reference self. |
static Boolean
|
implies(Boolean left, Boolean right)
|
static Object
|
inject(Collection self, Closure closure)
|
static Object
|
inject(Collection self, Object initialValue, Closure closure)
|
static Object
|
inject(Map self, Object initialValue, Closure closure)
|
static Object
|
inject(Iterator self, Object initialValue, Closure closure)
|
static Object
|
inject(Object self, Closure closure)
|
static Object
|
inject(Object self, Object initialValue, Closure closure)
Iterates through the given array as with inject(Object[],initialValue,closure), but using the first element of the array as the initialValue, and then iterating the remaining elements of the array. |
static Object
|
inject(Object[] self, Closure closure)
Iterates through the given array, passing in the initial value to the closure along with the first item. |
static Object
|
inject(Object[] self, Object initialValue, Closure closure)
|
static String
|
inspect(Object self)
Inspects returns the String that matches what would be typed into a terminal to create this object. |
static Number
|
intdiv(Character left, Number right)
Bitwise OR together two BitSets. |
static Number
|
intdiv(Number left, Character right)
Bitwise XOR together two Numbers. |
static Number
|
intdiv(Character left, Character right)
Performs a division modulus operation. |
static Number
|
intdiv(Number left, Number right)
|
static Collection
|
intersect(Collection left, Collection right)
Create a Map composed of the intersection of both maps. |
static Map
|
intersect(Map left, Map right)
Returns |
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
|
isAllWhitespace(String self)
|
static boolean
|
isAllWhitespace(CharSequence self)
|
static boolean
|
isBigDecimal(String self)
Determine if a CharSequence can be parsed as a Long. |
static boolean
|
isBigDecimal(CharSequence self)
|
static boolean
|
isBigInteger(String self)
|
static boolean
|
isBigInteger(CharSequence self)
|
static boolean
|
isCase(Object caseValue, Object switchValue)
Method for overloading the behavior of the 'case' method in switch statements. |
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 boolean
|
isCase(CharSequence caseValue, Object switchValue)
'Case' implementation for a CharSequence, which simply calls the equivalent method for String. |
static boolean
|
isCase(GString caseValue, Object switchValue)
|
static boolean
|
isCase(Class caseValue, Object switchValue)
|
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(Map caseValue, Object switchValue)
|
static boolean
|
isCase(Pattern caseValue, Object switchValue)
|
static boolean
|
isCase(Number caseValue, Number switchValue)
Special 'case' implementation for all numbers, which delegates to the
|
static boolean
|
isDigit(Character self)
Transform a Number into a BigDecimal |
static boolean
|
isDouble(String self)
Parse a CharSequence into a BigInteger |
static boolean
|
isDouble(CharSequence self)
|
static boolean
|
isFloat(String self)
Parse a CharSequence into a Double |
static boolean
|
isFloat(CharSequence self)
Determines if a character is a whitespace character. |
static boolean
|
isInteger(String self)
|
static boolean
|
isInteger(CharSequence self)
|
static boolean
|
isLetter(Character self)
|
static boolean
|
isLetterOrDigit(Character self)
|
static boolean
|
isLong(String self)
|
static boolean
|
isLong(CharSequence self)
Determines if a character is a letter or digit. |
static boolean
|
isLowerCase(Character self)
Transform a Number into a Double |
static boolean
|
isNumber(String self)
Determine if a CharSequence can be parsed as a Float. |
static boolean
|
isNumber(CharSequence self)
|
static boolean
|
isUpperCase(Character self)
Transform a Number into a Float |
static boolean
|
isWhitespace(Character self)
|
static Iterator
|
iterator(Object[] a)
Standard iterator for a input stream which iterates through the stream content in a byte-based fashion. |
static Iterator
|
iterator(Object o)
|
static Iterator
|
iterator(Enumeration enumeration)
|
static Iterator
|
iterator(Matcher matcher)
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(Reader self)
|
static Iterator
|
iterator(InputStream self)
|
static Iterator
|
iterator(DataInputStream self)
|
static Iterator
|
iterator(Iterator self)
|
static String
|
join(Iterator self, String separator)
Concatenates the |
static String
|
join(Collection self, String separator)
|
static String
|
join(Object[] self, String separator)
|
static Object
|
last(List self)
|
static Object
|
last(Iterable self)
Returns the last item from the array. |
static Object
|
last(Object[] self)
|
static Collection
|
leftShift(Collection self, Object value)
Overloads the left shift operator to provide an easy way to append Map.Entry values to a Map. |
static BlockingQueue
|
leftShift(BlockingQueue self, Object value)
Overloads the left shift operator to provide an easy way to append multiple objects as string representations to a String. |
static Map
|
leftShift(Map self, Map.Entry entry)
Overloads the left shift operator to provide an easy way to append multiple objects as string representations to a CharSequence. |
static Map
|
leftShift(Map self, Map other)
Overloads the left shift operator to provide syntactic sugar for appending to a StringBuilder. |
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 StringBuffer. |
static StringBuilder
|
leftShift(CharSequence self, Object value)
|
static StringBuilder
|
leftShift(StringBuilder self, Object value)
|
static StringBuffer
|
leftShift(StringBuffer self, Object value)
|
static Writer
|
leftShift(Writer self, Object value)
|
static Number
|
leftShift(Number self, Number operand)
|
static Writer
|
leftShift(OutputStream self, Object value)
|
static void
|
leftShift(ObjectOutputStream self, Object value)
|
static OutputStream
|
leftShift(OutputStream self, InputStream in)
|
static OutputStream
|
leftShift(OutputStream self, byte[] value)
Support the subscript operator with a range for a short array |
static File
|
leftShift(File file, Object text)
Invokes the closure for each 'child' file in this 'parent' folder/directory. |
static File
|
leftShift(File file, byte[] bytes)
|
static File
|
leftShift(File file, InputStream data)
Invokes the closure for each 'child' file in this 'parent' folder/directory. |
static Writer
|
leftShift(Socket self, Object value)
Converts the given String into a Set of unique strings of one character. |
static OutputStream
|
leftShift(Socket self, byte[] value)
Converts the given CharSequence into an array of characters. |
static boolean
|
matches(String self, Pattern pattern)
|
static boolean
|
matches(CharSequence self, Pattern pattern)
|
static Map.Entry
|
max(Map self, Closure closure)
|
static Object
|
max(Collection self)
|
static Object
|
max(Iterator self)
|
static Object
|
max(Object[] self)
|
static Object
|
max(Collection self, Closure closure)
|
static Object
|
max(Iterator self, Closure closure)
|
static Object
|
max(Object[] self, Closure closure)
Selects the maximum value found in the collection using the given comparator. |
static Object
|
max(Collection self, Comparator comparator)
Selects the maximum value found from the Iterator using the given comparator. |
static Object
|
max(Iterator self, Comparator comparator)
Selects the maximum value found from the Object array using the given comparator. |
static Object
|
max(Object[] self, Comparator comparator)
|
static MetaClass
|
metaClass(Class self, Closure closure)
|
static MetaClass
|
metaClass(Object self, Closure closure)
Creates an iterator which will traverse through the reader a line at a time. |
static Object
|
min(Collection self)
Adds min() method to Iterator objects. |
static Object
|
min(Iterator self)
|
static Object
|
min(Object[] self)
|
static Object
|
min(Collection self, Comparator comparator)
Selects the minimum value found from the Iterator using the given comparator. |
static Object
|
min(Iterator self, Comparator comparator)
Selects the minimum value found from the Object array using the given comparator. |
static Object
|
min(Object[] self, Comparator comparator)
|
static Object
|
min(Collection self, Closure closure)
|
static Map.Entry
|
min(Map self, Closure closure)
|
static Object
|
min(Iterator self, Closure closure)
|
static Object
|
min(Object[] self, Closure closure)
Adds max() method to Collection objects. |
static Set
|
minus(Set self, Collection removeMe)
Create a Set composed of the elements of the first Set minus the elements from the given Iterable. |
static Set
|
minus(Set self, Iterable removeMe)
Create an array composed of the elements of the first array minus the elements of the given Iterable. |
static Set
|
minus(Set self, Object removeMe)
|
static Object[]
|
minus(Object[] self, Iterable removeMe)
|
static Object[]
|
minus(Object[] self, Object[] removeMe)
|
static List
|
minus(List self, Collection removeMe)
|
static List
|
minus(List self, Iterable removeMe)
Create a List composed of the elements of the first list minus every occurrence of elements of the given Iterable. |
static List
|
minus(List self, Object removeMe)
|
static Object[]
|
minus(Object[] self, Object removeMe)
|
static Map
|
minus(Map self, Map removeMe)
Flatten an array. |
static String
|
minus(String self, Object target)
|
static CharSequence
|
minus(CharSequence self, Object target)
Checks whether the array contains the given value. |
static Number
|
minus(Character left, Number right)
Power of a Number to a certain exponent. |
static Number
|
minus(Number left, Character right)
|
static Number
|
minus(Character left, Character right)
|
static void
|
mixin(MetaClass self, List categoryClasses)
Extend object with category methods. |
static void
|
mixin(Class self, List categoryClasses)
Extend class globally with category methods. |
static void
|
mixin(Class self, Class categoryClass)
Extend class globally with category methods. |
static void
|
mixin(Class self, Class[] categoryClass)
Extend class globally with category methods. |
static void
|
mixin(MetaClass self, Class categoryClass)
Extend class globally with category methods. |
static void
|
mixin(MetaClass self, Class[] categoryClass)
Extend class globally with category methods. |
static Number
|
mod(Number left, Number right)
|
static List
|
multiply(Collection self, Number factor)
|
static String
|
multiply(String self, Number factor)
Returns the string representation of the given array. |
static CharSequence
|
multiply(CharSequence self, Number factor)
Returns the string representation of this map. |
static Number
|
multiply(Character left, Number right)
Power of a BigInteger to an integer certain exponent. |
static Number
|
multiply(Number left, Character right)
Power of an integer to an integer certain exponent. |
static Number
|
multiply(Character left, Character right)
|
static Number
|
multiply(BigDecimal left, Double right)
|
static Number
|
multiply(BigDecimal left, BigInteger right)
Divide a Character by a Number. |
static DataInputStream
|
newDataInputStream(File file)
|
static DataOutputStream
|
newDataOutputStream(File file)
|
static BufferedInputStream
|
newInputStream(File file)
Traverse through each byte of this Byte array. |
static BufferedInputStream
|
newInputStream(URL url)
Traverse through each the specified stream reading bytes into a buffer and calling the 2 parameter closure with this buffer and the number of bytes. |
static BufferedInputStream
|
newInputStream(URL url, Map parameters)
|
static Object
|
newInstance(Class c)
Sets/updates the metaclass for a given class to a closure. |
static Object
|
newInstance(Class c, Object[] args)
|
static ObjectInputStream
|
newObjectInputStream(File file)
|
static ObjectInputStream
|
newObjectInputStream(InputStream inputStream)
|
static ObjectInputStream
|
newObjectInputStream(InputStream inputStream, ClassLoader classLoader)
|
static ObjectInputStream
|
newObjectInputStream(File file, ClassLoader classLoader)
|
static ObjectOutputStream
|
newObjectOutputStream(File file)
|
static ObjectOutputStream
|
newObjectOutputStream(OutputStream outputStream)
|
static BufferedOutputStream
|
newOutputStream(File file)
|
static PrintWriter
|
newPrintWriter(File file)
|
static PrintWriter
|
newPrintWriter(File file, String charset)
Helper method to create a new Reader for a stream and then passes it into the closure. |
static PrintWriter
|
newPrintWriter(Writer writer)
|
static BufferedReader
|
newReader(File file)
Create a new DataInputStream for this file and passes it into the closure. |
static BufferedReader
|
newReader(File file, String charset)
|
static BufferedReader
|
newReader(InputStream self)
|
static BufferedReader
|
newReader(InputStream self, String charset)
|
static BufferedReader
|
newReader(URL url)
|
static BufferedReader
|
newReader(URL url, Map parameters)
Reads the InputStream from this URL, passing a byte[] and a number of bytes to the given closure. |
static BufferedReader
|
newReader(URL url, String charset)
Transforms each character from this reader by passing it to the given closure. |
static BufferedReader
|
newReader(URL url, Map parameters, String charset)
|
static BufferedWriter
|
newWriter(File file)
|
static BufferedWriter
|
newWriter(File file, boolean append)
|
static BufferedWriter
|
newWriter(File file, String charset, boolean append)
|
static BufferedWriter
|
newWriter(File file, String charset)
Allows this writer to be used within the closure, ensuring that it is flushed and closed before this method returns. |
static String
|
next(String self)
|
static CharSequence
|
next(CharSequence self)
Executes the command specified by the given |
static Character
|
next(Character self)
|
static Number
|
next(Number self)
|
static String
|
normalize(String self)
|
static CharSequence
|
normalize(CharSequence self)
Read the content of the File and returns it as a String. |
static int
|
numberAwareCompareTo(Comparable self, Comparable other)
Provides a method that compares two comparables using Groovy's default number aware comparator. |
static Number
|
or(Number left, Number right)
|
static BitSet
|
or(BitSet left, BitSet right)
|
static Boolean
|
or(Boolean left, Boolean right)
|
static String
|
padLeft(String self, Number numberOfChars, String padding)
Pad a CharSequence to a minimum length specified by numberOfChars, adding the supplied padding CharSequence as many times as needed to the left. |
static CharSequence
|
padLeft(CharSequence self, Number numberOfChars, CharSequence padding)
|
static String
|
padLeft(String self, Number numberOfChars)
Pad a CharSequence to a minimum length specified by numberOfChars by adding the space character to the left as many times as needed. |
static CharSequence
|
padLeft(CharSequence self, Number numberOfChars)
|
static String
|
padRight(String self, Number numberOfChars, String padding)
Pad a CharSequence to a minimum length specified by numberOfChars, adding the supplied padding CharSequence as many times as needed to the right. |
static CharSequence
|
padRight(CharSequence self, Number numberOfChars, CharSequence padding)
|
static String
|
padRight(String self, Number numberOfChars)
|
static CharSequence
|
padRight(CharSequence self, Number numberOfChars)
|
static Set
|
permutations(List self)
|
static Map
|
plus(Map left, Map right)
Support the subscript operator for Collection. |
static Object[]
|
plus(Object[] left, Object[] right)
|
static Object[]
|
plus(Object[] left, Object right)
|
static Object[]
|
plus(Object[] left, Collection right)
|
static Object[]
|
plus(Object[] left, Iterable right)
Create a Collection as a union of a Collection and an Iterable. |
static Collection
|
plus(Collection left, Collection right)
|
static Collection
|
plus(Collection left, Iterable right)
|
static List
|
plus(List self, int index, Object[] items)
Creates a new List by inserting all of the elements in the given additions List to the elements from the original List at the specified index. |
static List
|
plus(List self, int index, List additions)
Creates a new List by inserting all of the elements in the given Iterable to the elements from this List at the specified index. |
static List
|
plus(List self, int index, Iterable additions)
Synonym for toSpreadMap(java.util.Map). |
static Collection
|
plus(Collection left, Object right)
|
static Map
|
plus(Map self, Collection entries)
|
static String
|
plus(String left, Object value)
Checks whether the array contains the given value. |
static CharSequence
|
plus(CharSequence left, Object value)
Checks whether the array contains the given value. |
static String
|
plus(Number value, String right)
|
static String
|
plus(StringBuffer left, String value)
|
static Number
|
plus(Character left, Number right)
|
static Number
|
plus(Number left, Character right)
|
static Number
|
plus(Character left, Character right)
|
static Object
|
pop(List self)
Returns a new |
static Number
|
power(Number self, Number exponent)
|
static Number
|
power(BigDecimal self, Integer exponent)
Divide one Character by another. |
static Number
|
power(BigInteger self, Integer exponent)
Integer Divide a Number by a Character. |
static Number
|
power(Integer self, Integer exponent)
Integer Divide two Characters. |
static Number
|
power(Long self, Integer exponent)
Bitwise OR together two numbers. |
static String
|
previous(String self)
|
static CharSequence
|
previous(CharSequence self)
|
static Character
|
previous(Character self)
@todo maybe a double dispatch thing to handle new large numbers? |
static Number
|
previous(Number self)
|
protected static Object
|
primitiveArrayGet(Object self, int idx)
Convenience method to split a string (with whitespace as delimiter) Like tokenize, but returns an Array of Strings instead of a List |
protected static List
|
primitiveArrayGet(Object self, Range range)
|
protected static List
|
primitiveArrayGet(Object self, Collection indices)
|
protected static Object
|
primitiveArrayPut(Object self, int idx, Object newValue)
Convenience method to capitalize the first letter of a CharSequence. |
static void
|
print(Object self, Object value)
Print a value formatted Groovy style to self if it is a Writer, otherwise to the standard output stream. |
static void
|
print(PrintWriter self, Object value)
Print a value formatted Groovy style to the print writer. |
static void
|
print(PrintStream self, Object value)
Print a value formatted Groovy style to the print stream. |
static void
|
print(Closure 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[] values)
Printf to a console (Only works with JDK1.5 or later). |
static void
|
printf(Object self, String format, Object arg)
Prints a formatted string using the specified format string and arguments. |
static void
|
println(Object self)
Print a linebreak to the standard output stream. |
static void
|
println(Closure self)
Print a linebreak to the standard output stream. |
static void
|
println(Object self, Object value)
Print a value formatted Groovy style (followed by a newline) to self if it is a Writer, otherwise to the standard output stream. |
static void
|
println(PrintWriter self, Object value)
Print a value formatted Groovy style (followed by a newline) to the print writer. |
static void
|
println(PrintStream self, Object value)
Print a value formatted Groovy style (followed by a newline) to the print stream. |
static void
|
println(Closure 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 boolean
|
push(List self, Object value)
|
static Map
|
putAll(Map self, Collection entries)
|
static void
|
putAt(Object self, String property, Object newValue)
Allows the subscript operator to be used to set dynamically named property values. |
static void
|
putAt(List self, int idx, Object value)
Support the range subscript operator for StringBuffer. |
static void
|
putAt(StringBuffer self, IntRange range, Object value)
A helper method to allow lists to work with subscript operators. |
static void
|
putAt(StringBuffer self, EmptyRange range, Object value)
|
static void
|
putAt(List self, EmptyRange range, Object value)
|
static void
|
putAt(List self, EmptyRange range, Collection value)
List subscript assignment operator when given a range as the index and the assignment operand is a collection. |
static void
|
putAt(List self, IntRange range, Collection col)
List subscript assignment operator when given a range as the index. |
static void
|
putAt(List self, IntRange range, Object value)
|
static void
|
putAt(List self, List splice, List values)
A helper method to allow lists to work with subscript operators. |
static void
|
putAt(List self, List splice, Object value)
|
static Object
|
putAt(Map self, Object key, Object value)
|
static void
|
putAt(BitSet self, IntRange range, boolean value)
Support assigning a range of values with a single assignment statement. |
static void
|
putAt(BitSet self, int index, boolean value)
Converts this array to a List of the same size, with each element added to the list. |
static byte[]
|
readBytes(File file)
Converts this File to a Writable. |
static String
|
readLine(Reader self)
|
static List
|
readLines(String self)
|
static List
|
readLines(CharSequence self)
|
static List
|
readLines(File file)
Read the data from this URL and return it as a String. |
static List
|
readLines(File file, String charset)
Read the content of this InputStream and return it as a String. |
static List
|
readLines(InputStream stream)
|
static List
|
readLines(InputStream stream, String charset)
|
static List
|
readLines(URL self)
|
static List
|
readLines(URL self, String charset)
|
static List
|
readLines(Reader reader)
|
static boolean
|
removeAll(Collection self, Object[] items)
|
static boolean
|
removeAll(Collection self, Closure condition)
Modifies this collection by removing the elements that are matched according to the specified closure condition. |
static boolean
|
renameTo(File self, String newPathName)
Create a new InputStream for this file and passes it into the closure. |
static String
|
replaceAll(String self, Pattern pattern, String replacement)
Replaces all substrings of a CharSequence that match the given compiled regular expression with the given replacement. |
static CharSequence
|
replaceAll(CharSequence self, Pattern pattern, CharSequence replacement)
|
static String
|
replaceAll(String self, String regex, Closure closure)
Replaces all occurrences of a captured group by the result of a closure on that text. |
static CharSequence
|
replaceAll(CharSequence self, CharSequence regex, Closure closure)
|
static CharSequence
|
replaceAll(CharSequence self, CharSequence regex, CharSequence replacement)
|
static String
|
replaceAll(String self, Pattern pattern, Closure closure)
Replaces all occurrences of a captured group by the result of a closure call on that text. |
static String
|
replaceAll(CharSequence self, Pattern pattern, Closure closure)
|
static String
|
replaceFirst(String self, Pattern pattern, String replacement)
Replaces the first substring of a CharSequence that matches the given compiled regular expression with the given replacement. |
static CharSequence
|
replaceFirst(CharSequence self, Pattern pattern, CharSequence replacement)
|
static String
|
replaceFirst(String self, String regex, Closure closure)
|
static String
|
replaceFirst(CharSequence self, CharSequence regex, CharSequence replacement)
|
static String
|
replaceFirst(CharSequence self, CharSequence regex, Closure closure)
|
static String
|
replaceFirst(String self, Pattern pattern, Closure closure)
Replaces the first occurrence of a captured group by the result of a closure call on that text. |
static String
|
replaceFirst(CharSequence self, Pattern pattern, Closure closure)
|
static List
|
respondsTo(Object self, String name, Object[] argTypes)
|
static List
|
respondsTo(Object self, String name)
|
static boolean
|
retainAll(Collection self, Object[] items)
|
static boolean
|
retainAll(Collection self, Closure condition)
|
static String
|
reverse(String self)
Creates a new string which is the reverse (backwards) of this string |
static CharSequence
|
reverse(CharSequence self)
|
static List
|
reverse(List self)
Reverses the elements in a list. |
static List
|
reverse(List self, boolean mutate)
Reverse the items in an array. |
static Object[]
|
reverse(Object[] self)
Reverses the iterator. |
static Object[]
|
reverse(Object[] self, boolean mutate)
Create a List composed of the elements of this list, repeated a certain number of times. |
static Iterator
|
reverse(Iterator self)
Create a Collection composed of the intersection of both collections. |
static Map
|
reverseEach(Map self, Closure closure)
Allows a Map to be iterated through in reverse order using a closure. |
static List
|
reverseEach(List self, Closure closure)
Iterate over each element of the list in the reverse order. |
static Object[]
|
reverseEach(Object[] self, Closure closure)
|
static Number
|
rightShift(Number self, Number operand)
|
static Number
|
rightShiftUnsigned(Number self, Number operand)
|
static int
|
round(Float number)
Parse a String into a Float |
static float
|
round(Float number, int precision)
Parse a String into a Double |
static long
|
round(Double number)
|
static double
|
round(Double number, int precision)
Determine if a String can be parsed into a Long. |
static TimerTask
|
runAfter(Timer timer, int delay, Closure closure)
|
static void
|
setBytes(File file, byte[] bytes)
Append the text at the end of the File. |
static void
|
setBytes(OutputStream os, byte[] bytes)
|
static void
|
setIndex(Matcher matcher, int idx)
Find the number of Strings matched to the given Matcher. |
static void
|
setMetaClass(Class self, MetaClass metaClass)
Allows an Enumeration to behave like an Iterator. |
static void
|
setMetaClass(Object self, MetaClass metaClass)
|
static void
|
setText(File file, String text)
Append the text at the end of the File, using a specified encoding. |
static void
|
setText(File file, String text, String charset)
This method is used to throw useful exceptions when the eachFile* and eachDir closure methods are used incorrectly. |
static int
|
size(Iterator self)
Provide the standard Groovy |
static int
|
size(String text)
Provide the standard Groovy |
static int
|
size(CharSequence text)
|
static int
|
size(StringBuffer buffer)
|
static long
|
size(File self)
|
static long
|
size(Matcher self)
|
static int
|
size(Object[] self)
|
static int
|
size(boolean[] array)
|
static int
|
size(byte[] array)
|
static int
|
size(char[] array)
|
static int
|
size(short[] array)
|
static int
|
size(int[] array)
|
static int
|
size(long[] array)
Converts this array to a List of the same size, with each element added to the list. |
static int
|
size(float[] array)
Converts this array to a List of the same size, with each element added to the list. |
static int
|
size(double[] array)
|
static List
|
sort(Collection self)
|
static List
|
sort(Collection self, boolean mutate)
|
static Map
|
sort(Map self, Closure closure)
|
static Map
|
sort(Map self, Comparator comparator)
Modifies this array so that its elements are in sorted order. |
static Map
|
sort(Map self)
|
static Object[]
|
sort(Object[] self)
|
static Object[]
|
sort(Object[] self, boolean mutate)
Sorts the given iterator items into a sorted iterator using the comparator. |
static Iterator
|
sort(Iterator self)
|
static Iterator
|
sort(Iterator self, Comparator comparator)
|
static List
|
sort(Collection self, Comparator comparator)
|
static List
|
sort(Collection self, boolean mutate, Comparator comparator)
|
static Object[]
|
sort(Object[] self, Comparator comparator)
|
static Object[]
|
sort(Object[] self, boolean mutate, Comparator comparator)
|
static Iterator
|
sort(Iterator self, Closure closure)
|
static Object[]
|
sort(Object[] self, Closure closure)
|
static Object[]
|
sort(Object[] self, boolean mutate, Closure closure)
Sorts this Collection using the given Closure to determine the correct ordering. |
static List
|
sort(Collection self, Closure closure)
Sorts this Collection using the given Closure to determine the correct ordering. |
static List
|
sort(Collection self, boolean mutate, Closure closure)
Avoids doing unnecessary work when sorting an already sorted set (i.e. an identity function for an already sorted set). |
static SortedSet
|
sort(SortedSet self)
|
static SortedMap
|
sort(SortedMap self)
|
static Collection
|
split(Object self, Closure closure)
|
static Collection
|
split(Collection self, Closure closure)
|
static String[]
|
split(String self)
|
static CharSequence[]
|
split(CharSequence self)
Expands all tabs into spaces. |
static String[]
|
split(GString self)
Appends a String to the string representation of this number. |
static Object
|
splitEachLine(File self, String regex, Closure closure)
Iterates through the input stream associated with this URL line by line, splitting each line using the given regex separator. |
static Object
|
splitEachLine(File self, Pattern pattern, Closure closure)
|
static Object
|
splitEachLine(File self, String regex, String charset, Closure closure)
|
static Object
|
splitEachLine(File self, Pattern pattern, String charset, Closure closure)
|
static Object
|
splitEachLine(URL self, String regex, Closure closure)
|
static Object
|
splitEachLine(URL self, Pattern pattern, Closure closure)
Iterates through the given InputStream line by line using the specified encoding, splitting each line using the given separator. |
static Object
|
splitEachLine(URL self, String regex, String charset, Closure closure)
Iterates through the given InputStream line by line using the specified encoding, splitting each line using the given separator Pattern. |
static Object
|
splitEachLine(URL self, Pattern pattern, String charset, Closure closure)
Iterates through the given InputStream line by line, splitting each line using the given separator. |
static Object
|
splitEachLine(Reader self, String regex, Closure closure)
|
static Object
|
splitEachLine(Reader self, Pattern pattern, Closure closure)
Iterates through the given CharSequence line by line, splitting each line using the given separator. |
static Object
|
splitEachLine(InputStream stream, String regex, String charset, Closure closure)
Iterates through the given CharSequence line by line, splitting each line using the given separator Pattern. |
static Object
|
splitEachLine(InputStream stream, Pattern pattern, String charset, Closure closure)
|
static Object
|
splitEachLine(InputStream stream, String regex, Closure closure)
|
static Object
|
splitEachLine(InputStream stream, Pattern pattern, Closure closure)
|
static Object
|
splitEachLine(String self, String regex, Closure closure)
|
static Object
|
splitEachLine(CharSequence self, CharSequence regex, Closure closure)
|
static Object
|
splitEachLine(String self, Pattern pattern, Closure closure)
|
static Object
|
splitEachLine(CharSequence self, Pattern pattern, Closure closure)
Return a String with lines (separated by LF, CR/LF, or CR) terminated by the platform specific line separator. |
static SpreadMap
|
spread(Map self)
|
static String
|
sprintf(Object self, String format, Object[] values)
Sprintf to a string (Only works with JDK1.5 or later). |
static String
|
sprintf(Object self, String format, Object arg)
Returns a formatted string using the specified format string and arguments. |
static void
|
step(Number self, Number to, Number stepNumber, Closure closure)
Get the absolute value |
static String
|
stripIndent(String self)
|
static CharSequence
|
stripIndent(CharSequence self)
True if a String only contains whitespace characters. |
static String
|
stripIndent(String self, int numChars)
|
static CharSequence
|
stripIndent(CharSequence self, int numChars)
Transforms a String representing a URL into a URL object. |
static String
|
stripMargin(String self)
|
static CharSequence
|
stripMargin(CharSequence self)
|
static String
|
stripMargin(String self, String marginChar)
|
static String
|
stripMargin(CharSequence self, CharSequence marginChar)
|
static String
|
stripMargin(String self, char marginChar)
|
static CharSequence
|
stripMargin(CharSequence self, char marginChar)
|
static Map
|
subMap(Map map, Collection keys)
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 Set
|
subsequences(List self)
|
static Object
|
sum(Collection self)
Sums the items in an array. |
static Object
|
sum(Object[] self)
|
static Object
|
sum(Iterator self)
|
static Object
|
sum(Collection self, Object initialValue)
|
static Object
|
sum(Object[] self, Object initialValue)
|
static Object
|
sum(Iterator self, Object initialValue)
|
static Object
|
sum(Collection self, Closure closure)
Sums the result of apply a closure to each item of an array. |
static Object
|
sum(Object[] self, Closure closure)
Sums the result of apply a closure to each item returned from an iterator. |
static Object
|
sum(Iterator self, Closure closure)
Sums the result of applying a closure to each item of a collection to some initial value. |
static Object
|
sum(Collection self, Object initialValue, Closure closure)
Sums the result of applying a closure to each item of an array to some initial value. |
static Object
|
sum(Object[] self, Object initialValue, Closure closure)
Sums the result of applying a closure to each item of an Iterator to some initial value. |
static Object
|
sum(Iterator self, Object initialValue, Closure closure)
|
static List
|
tail(List self)
|
static Object[]
|
tail(Object[] self)
|
static List
|
take(List self, int num)
Returns the first |
static Object[]
|
take(Object[] self, int num)
Returns the first |
static List
|
take(Iterable self, int num)
Returns a new map containing the first |
static Map
|
take(Map self, int num)
|
static Iterator
|
take(Iterator self, int num)
|
static CharSequence
|
take(CharSequence self, int num)
|
static List
|
takeWhile(List self, Closure condition)
Returns a List containing the longest prefix of the elements from this Iterable where each element passed to the given closure evaluates to true. |
static List
|
takeWhile(Iterable self, Closure condition)
Returns the longest prefix of this Map where each entry (or key/value pair) when passed to the given closure evaluates to true. |
static Map
|
takeWhile(Map self, Closure condition)
Returns the longest prefix of this array where each element passed to the given closure evaluates to true. |
static Object[]
|
takeWhile(Object[] self, Closure condition)
|
static Iterator
|
takeWhile(Iterator self, Closure condition)
|
static CharSequence
|
takeWhile(CharSequence self, Closure closure)
@param array an Array of Objects |
static void
|
times(Number self, Closure closure)
Iterates from this number up to the given number, inclusive, incrementing by one each time. |
static String
|
toArrayString(Object[] self)
Compare a Character and a Number. |
static BigDecimal
|
toBigDecimal(String self)
|
static BigDecimal
|
toBigDecimal(CharSequence self)
|
static BigDecimal
|
toBigDecimal(Number self)
Exclusive disjunction of two boolean operators |
static BigInteger
|
toBigInteger(String self)
|
static BigInteger
|
toBigInteger(CharSequence self)
|
static BigInteger
|
toBigInteger(Number self)
Create an object input stream for this file. |
static Boolean
|
toBoolean(String self)
|
static Boolean
|
toBoolean(Boolean self)
|
static Character
|
toCharacter(String self)
Expands all tabs into spaces with tabStops of size 8. |
static Double
|
toDouble(String self)
|
static Double
|
toDouble(CharSequence self)
|
static Double
|
toDouble(Number self)
Logical implication of two boolean operators |
static Float
|
toFloat(String self)
|
static Float
|
toFloat(CharSequence self)
|
static Float
|
toFloat(Number self)
Logical disjunction of two boolean operators |
static Integer
|
toInteger(String self)
Determine if a String can be parsed into a Double. |
static Integer
|
toInteger(CharSequence self)
|
static Integer
|
toInteger(Number self)
|
static List
|
toList(Collection self)
|
static List
|
toList(Iterator self)
|
static List
|
toList(Iterable self)
|
static List
|
toList(Enumeration self)
|
static List
|
toList(Object[] array)
|
static List
|
toList(byte[] array)
|
static List
|
toList(boolean[] array)
|
static List
|
toList(char[] array)
|
static List
|
toList(short[] array)
|
static List
|
toList(int[] array)
|
static List
|
toList(long[] array)
|
static List
|
toList(float[] array)
|
static List
|
toList(double[] array)
|
static List
|
toList(String self)
|
static List
|
toList(CharSequence self)
|
static String
|
toListString(Collection self)
|
static String
|
toListString(Collection self, int maxSize)
|
static Long
|
toLong(String self)
|
static Long
|
toLong(CharSequence self)
|
static Long
|
toLong(Number self)
|
static char
|
toLowerCase(Character self)
Transform this Number into a BigInteger. |
static String
|
toMapString(Map self)
|
static String
|
toMapString(Map self, int maxSize)
|
static Set
|
toSet(byte[] array)
|
static Set
|
toSet(boolean[] array)
Convert an iterator to a Set. |
static Set
|
toSet(char[] array)
Convert an enumeration to a Set. |
static Set
|
toSet(short[] array)
|
static Set
|
toSet(int[] array)
|
static Set
|
toSet(long[] array)
|
static Set
|
toSet(float[] array)
|
static Set
|
toSet(double[] array)
|
static Set
|
toSet(Collection self)
|
static Set
|
toSet(Iterator self)
|
static Set
|
toSet(Enumeration self)
|
static Set
|
toSet(String self)
|
static Set
|
toSet(CharSequence self)
|
static Short
|
toShort(String self)
|
static Short
|
toShort(CharSequence self)
|
static SpreadMap
|
toSpreadMap(Map self)
Creates a spreadable map from this list. |
static SpreadMap
|
toSpreadMap(Object[] self)
|
static SpreadMap
|
toSpreadMap(List self)
|
static String
|
toString(boolean[] self)
|
static String
|
toString(byte[] self)
|
static String
|
toString(char[] self)
Returns the string representation of the given list. |
static String
|
toString(short[] self)
|
static String
|
toString(int[] self)
|
static String
|
toString(long[] self)
|
static String
|
toString(float[] self)
|
static String
|
toString(double[] self)
|
static String
|
toString(AbstractMap self)
|
static String
|
toString(AbstractCollection self)
|
static String
|
toString(Object[] self)
|
static String
|
toString(Object value)
|
static URI
|
toURI(String self)
|
static URI
|
toURI(CharSequence self)
|
static URL
|
toURL(String self)
|
static URL
|
toURL(CharSequence self)
|
static char
|
toUpperCase(Character self)
|
static List
|
tokenize(String self, String token)
Appends a String to this StringBuffer. |
static List
|
tokenize(CharSequence self, CharSequence token)
Remove a part of a String. |
static List
|
tokenize(String self, Character token)
|
static List
|
tokenize(CharSequence self, Character token)
|
static List
|
tokenize(String self)
|
static List
|
tokenize(CharSequence self)
|
static String
|
tr(String self, String sourceSet, String replacementSet)
Translates a string by replacing characters from the sourceSet with characters from replacementSet. |
static CharSequence
|
tr(CharSequence self, CharSequence sourceSet, CharSequence replacementSet)
Tells whether or not a CharSequence matches the given compiled regular expression Pattern. |
static void
|
transformChar(Reader self, Writer writer, 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
|
transformLine(Reader reader, Writer writer, Closure closure)
|
static List
|
transpose(List self)
|
static void
|
traverse(File self, Map options, Closure closure)
Invokes the closure for each descendant file in this directory. |
static void
|
traverse(File self, Closure closure)
Invokes the closure for each file whose name (file.name) matches the given nameFilter in the given directory - calling the isCase(java.lang.Object, java.lang.Object) method to determine if a match occurs. |
static void
|
traverse(File self, Map options)
Invokes the closure for each subdirectory whose name (dir.name) matches the given nameFilter in the given directory - calling the isCase(java.lang.Object, java.lang.Object) method to determine if a match occurs. |
static float
|
trunc(Float number, int precision)
|
static float
|
trunc(Float number)
|
static double
|
trunc(Double number)
|
static double
|
trunc(Double number, int precision)
|
static Number
|
unaryMinus(Number left)
|
static String
|
unexpand(String self)
|
static CharSequence
|
unexpand(CharSequence self)
|
static String
|
unexpand(String self, int tabStop)
|
static CharSequence
|
unexpand(CharSequence self, int tabStop)
Tokenize a CharSequence based on the given character delimiter. |
static String
|
unexpandLine(String self, int tabStop)
|
static CharSequence
|
unexpandLine(CharSequence self, int tabStop)
Appends the String representation of the given operand to this string. |
static Iterator
|
unique(Iterator self)
|
static Collection
|
unique(Collection self)
|
static Collection
|
unique(Collection self, boolean mutate)
|
static Iterator
|
unique(Iterator self, Closure closure)
|
static Collection
|
unique(Collection self, Closure closure)
|
static Collection
|
unique(Collection self, boolean mutate, Closure closure)
|
static Iterator
|
unique(Iterator self, Comparator comparator)
Returns an iterator equivalent to this iterator with all duplicated items removed by using the supplied comparator. |
static Collection
|
unique(Collection self, Comparator comparator)
|
static Collection
|
unique(Collection self, boolean mutate, Comparator comparator)
|
static void
|
upto(Number self, Number to, Closure closure)
Iterates from this number up to the given number, inclusive, incrementing by one each time. |
static void
|
upto(long self, Number to, Closure closure)
Iterates from this number up to the given number, inclusive, incrementing by one each time. |
static void
|
upto(Long 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(double self, Number to, Closure closure)
|
static void
|
upto(Double self, Number to, Closure closure)
|
static void
|
upto(BigInteger self, Number to, Closure closure)
Iterates from this number down to the given number, inclusive, decrementing by one each time. |
static void
|
upto(BigDecimal self, Number to, Closure closure)
Iterates from this number down to the given number, inclusive, decrementing by one each time. |
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)
Allows you to use a list of categories, specifying the list as varargs. |
static Object
|
with(Object self, Closure closure)
Allows the closure to be called for the object reference self. |
static Object
|
withDataInputStream(File file, Closure closure)
|
static Object
|
withDataOutputStream(File file, Closure closure)
Create a new PrintWriter for this file. |
static Map
|
withDefault(Map self, Closure init)
|
static List
|
withDefault(List self, Closure init)
|
static List
|
withEagerDefault(List self, Closure init)
Sorts the Collection. |
static Object
|
withInputStream(File file, Closure closure)
Create a new BufferedWriter which will append to this file. |
static Object
|
withInputStream(URL url, Closure closure)
Create a new BufferedWriter for this file in append mode. |
static List
|
withLazyDefault(List self, Closure init)
|
static Object
|
withObjectInputStream(File file, Closure closure)
Iterates through this file line by line. |
static Object
|
withObjectInputStream(File file, ClassLoader classLoader, Closure closure)
|
static Object
|
withObjectInputStream(InputStream inputStream, Closure closure)
|
static Object
|
withObjectInputStream(InputStream inputStream, ClassLoader classLoader, Closure closure)
|
static Object
|
withObjectOutputStream(File file, Closure closure)
|
static Object
|
withObjectOutputStream(OutputStream outputStream, Closure closure)
Create a new ObjectInputStream for this file and pass it to the closure. |
static Object
|
withObjectStreams(Socket socket, Closure closure)
Converts the given String into a List of strings of one character. |
static Object
|
withOutputStream(File file, Closure closure)
|
static Object
|
withPrintWriter(File file, Closure closure)
|
static Object
|
withPrintWriter(File file, String charset, Closure closure)
|
static Object
|
withPrintWriter(Writer writer, Closure closure)
|
static Object
|
withReader(File file, Closure closure)
|
static Object
|
withReader(File file, String charset, Closure closure)
Write a Byte Order Mark at the beginning of the file |
static Object
|
withReader(Reader reader, Closure closure)
Creates a buffered input stream for this file. |
static Object
|
withReader(URL url, Closure closure)
Creates a buffered input stream for this URL. |
static Object
|
withReader(URL url, String charset, Closure closure)
|
static Object
|
withReader(InputStream in, Closure closure)
|
static Object
|
withReader(InputStream in, String charset, Closure closure)
Creates a buffered reader for this URL using the given encoding. |
static Object
|
withStream(InputStream stream, Closure closure)
|
static Object
|
withStream(OutputStream os, Closure closure)
|
static Object
|
withStreams(Socket socket, Closure closure)
Converts this File to a Writable or delegates to default asType(java.lang.Object, java.lang.Class). |
static Object
|
withWriter(File file, Closure closure)
Allows this reader to be used within the closure, ensuring that it is closed before this method returns. |
static Object
|
withWriter(File file, String charset, Closure closure)
Allows this input stream to be used within the closure, ensuring that it is flushed and closed before this method returns. |
static Object
|
withWriter(Writer writer, Closure closure)
|
static Object
|
withWriter(OutputStream stream, Closure closure)
Creates a buffered reader for this URL using the given encoding. |
static Object
|
withWriter(OutputStream stream, String charset, Closure closure)
Create a data input stream for this file |
static Object
|
withWriterAppend(File file, String charset, Closure closure)
|
static Object
|
withWriterAppend(File file, Closure closure)
|
static void
|
write(Writer self, Writable writable)
|
static void
|
write(File file, String text)
Append binary data to the file. |
static void
|
write(File file, String text, String charset)
|
static void
|
writeLine(BufferedWriter writer, String line)
|
static BitSet
|
xor(BitSet left, BitSet right)
Iterates from this number up to the given number, inclusive, incrementing by one each time. |
static Number
|
xor(Number left, Number right)
Iterates from this number up to the given number, inclusive, incrementing by one each time. |
static Boolean
|
xor(Boolean left, Boolean right)
|
Methods inherited from class Object | |
---|---|
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll |
Field Detail |
---|
public static final Class[] additionals
Method Detail |
---|
public static int abs(Number number)
number
- a Double
public static long abs(Long number)
self
- a String
public static float abs(Float number)
self
- a String
public static double abs(Double number)
self
- a String
public static Socket accept(ServerSocket serverSocket, Closure closure)
self
- a GStringc
- the desired class
public static Socket accept(ServerSocket serverSocket, boolean runInANewThread, Closure closure)
public static boolean addAll(Collection self, Object[] items)
plus
or the '+' operator if wanting to produce a new collection
containing additional items but while leaving the original collection unchanged.
self
- a Collection to be modifieditems
- array containing elements to be added to this collection
public static boolean addAll(List self, int index, Object[] items)
public static void addShutdownHook(Object self, Closure closure)
self
- the object the method is called on (ignored)closure
- the shutdown hook action
public static Number and(Number left, Number right)
public static BitSet and(BitSet left, BitSet right)
public static Boolean and(Boolean left, Boolean right)
inputStream
- an input stream
public static boolean any(Object self, Closure closure)
self
- the object over which we iterateclosure
- the closure predicate used for matching
public static boolean any(Map self, Closure closure)
assert [2:3, 4:5, 5:10].any { key, value -> key * 2 == value } assert ![2:3, 4:5, 5:10].any { entry -> entry.key == entry.value * 2 }
self
- the map over which we iterateclosure
- the 1 or 2 arg closure predicate used for matching
public static boolean any(Object self)
self
- the object over which we iterate
public static void append(File file, Object text)
self
- a file objectfileType
- if normal files or directories or both should be processedclosure
- the closure to invoke on each file
public static void append(File file, byte[] bytes)
public static void append(File self, InputStream stream)
public static void append(File file, Object text, String charset)
public static boolean asBoolean(Object object)
public static boolean asBoolean(Boolean bool)
public static boolean asBoolean(Matcher matcher)
public static boolean asBoolean(Collection collection)
public static boolean asBoolean(Map map)
public static boolean asBoolean(Iterator iterator)
public static boolean asBoolean(Enumeration enumeration)
public static boolean asBoolean(CharSequence string)
public static boolean asBoolean(Object[] array)
public static boolean asBoolean(byte[] array)
public static boolean asBoolean(short[] array)
public static boolean asBoolean(int[] array)
public static boolean asBoolean(long[] array)
public static boolean asBoolean(float[] array)
public static boolean asBoolean(double[] array)
public static boolean asBoolean(boolean[] array)
public static boolean asBoolean(char[] array)
public static boolean asBoolean(Character character)
public static boolean asBoolean(Number number)
public static Map asImmutable(Map self)
self
- a List
public static SortedMap asImmutable(SortedMap self)
public static List asImmutable(List self)
public static Set asImmutable(Set self)
public static SortedSet asImmutable(SortedSet self)
self
- a Map
public static Collection asImmutable(Collection self)
self
- a SortedMap
public static List asList(Collection self)
bool
- the Boolean
public static Map asSynchronized(Map self)
public static SortedMap asSynchronized(SortedMap self)
public static Collection asSynchronized(Collection self)
public static List asSynchronized(List self)
public static Set asSynchronized(Set self)
public static SortedSet asSynchronized(SortedSet self)
try { public static Object asType(Collection col, Class clazz)
} catch (GroovyRuntimeException cause) { public static Object asType(Object[] ary, Class clazz)
ary
- an arrayclazz
- the desired class
try { public static Object asType(Closure cl, Class clazz)
map
- this mapclazz
- the target type
/** public static Object asType(Map map, Class clazz)
def list = ["a", 4, false] assert list.reverse() == [false, 4, "a"] assert list == ["a", 4, false]
self
- a List
* returns. public static Object asType(Number self, Class c)
file
- a Fileclosure
- a closure
* @param self a CharSequence public static Object asType(File f, Class c)
break; public static Object asType(GString self, Class c)
} public static Object asType(String self, Class c)
self
- the iteration object over which to iterateclosure
- the filter to perform a match on the collection
public static Object asType(CharSequence self, Class c)
self
- the iteration object over which to iterateclosure
- the filter to perform a match on the collection
} public static Object asType(Object obj, Class type)
self
- the class whose metaclass we wish to setmetaClass
- the new MetaClass
public static File asWritable(File file)
public static File asWritable(File file, String encoding)
public static Pattern bitwiseNegate(String self)
public static Pattern bitwiseNegate(CharSequence self)
public static BitSet bitwiseNegate(BitSet self)
protected static Object callClosureForLine(Closure closure, String line, int counter)
protected static Object callClosureForMapEntry(Closure closure, Map.Entry entry)
protected static Object callClosureForMapEntryAndCounter(Closure closure, Map.Entry entry, int counter)
public static String capitalize(String self)
self
- A line to expandtabStop
- The number of spaces a tab represents
public static CharSequence capitalize(CharSequence self)
self
- A String to unexpand
public static String center(String self, Number numberOfChars, String padding)
self
- a CharSequence objectnumberOfChars
- the total minimum number of characters of the resulting CharSequencepadding
- the characters used for padding
public static CharSequence center(CharSequence self, Number numberOfChars, CharSequence padding)
['A', 'BB', 'CCC', 'DDDD'].each{ println '|' + it.center(6) + '|' }will produce output like:
| A | | BB | | CCC | | DDDD |
self
- a String objectnumberOfChars
- the total minimum number of characters of the resulting string
public static String center(String self, Number numberOfChars)
public static CharSequence center(CharSequence self, Number numberOfChars)
public static List collate(List self, int size)
public static List collate(List self, int size, int step)
public static List collate(List self, int size, boolean keepRemainder)
public static List collate(List self, int size, int step, boolean keepRemainder)
public static List collect(Object self, Closure transform)
transform
closure, returning a list of transformed values.
Example:
def list = [1, 'a', 1.23, true ] def types = list.collect { it.class } assert types == [Integer, String, BigDecimal, Boolean]
self
- an aggregate Object with an Iterator returning its itemstransform
- the closure used to transform each item of the aggregate object
public static Collection collect(Object self)
public static Collection collect(Object self, Collection collector, Closure transform)
public static List collect(Collection self, Closure transform)
public static List collect(Collection self)
public static Collection collect(Collection self, Collection collector, Closure transform)
public static Collection collect(Map self, Collection collector, Closure transform)
public static List collect(Map self, Closure transform)
public static List collectAll(Collection self, Closure transform)
public static Collection collectAll(Collection self, Collection collector, Closure transform)
public static Map collectEntries(Map self, Map collector, Closure transform)
public static Map collectEntries(Map self, Closure transform)
public static Map collectEntries(Collection self, Closure transform)
public static Map collectEntries(Collection self)
public static Map collectEntries(Collection self, Map collector, Closure transform)
public static Map collectEntries(Collection self, Map collector)
public static Map collectEntries(Object[] self, Map collector, Closure transform)
public static Map collectEntries(Object[] self, Map collector)
public static Map collectEntries(Object[] self, Closure transform)
public static Map collectEntries(Object[] self)
public static List collectMany(Collection self, Closure projection)
def nums = 1..10 def squaresAndCubesOfEvens = nums.collectMany{ it % 2 ? [] : [it**2, it**3] } assert squaresAndCubesOfEvens == [4, 8, 16, 64, 36, 216, 64, 512, 100, 1000] def animals = ['CAT', 'DOG', 'ELEPHANT'] as Set def smallAnimals = animals.collectMany{ it.size() > 3 ? [] : [it.toLowerCase()] } assert smallAnimals == ['cat', 'dog'] def orig = nums as Set def origPlusIncrements = orig.collectMany{ [it, it+1] } assert origPlusIncrements.size() == orig.size() * 2 assert origPlusIncrements.unique().size() == orig.size() + 1
self
- a collectionprojection
- a projecting Closure returning a collection of items
public static Collection collectMany(Collection self, Collection collector, Closure projection)
public static List collectMany(Object[] self, Closure projection)
public static List collectMany(Iterator self, Closure projection)
public static List collectNested(Collection self, Closure transform)
public static Collection collectNested(Collection self, Collection collector, Closure transform)
public static List combinations(Collection self)
Example usage:
assert [['a', 'b'],[1, 2, 3]].combinations() == [['a', 1], ['b', 1], ['a', 2], ['b', 2], ['a', 3], ['b', 3]]
self
- a Collection of lists
public static int compareTo(Character left, Number right)
public static int compareTo(Number left, Character right)
public static int compareTo(Character left, Character right)
public static int compareTo(Number left, Number right)
public static boolean contains(String self, String text)
self
- the array we are searchingvalue
- the value being searched for
public static boolean contains(CharSequence self, CharSequence text)
self
- the array we are searchingvalue
- the value being searched for
public static boolean contains(int[] self, Object value)
self
- the array we are searchingvalue
- the value being searched for
public static boolean contains(long[] self, Object value)
self
- a Stringtext
- a substring
public static boolean contains(short[] self, Object value)
public static boolean contains(char[] self, Object value)
public static boolean contains(boolean[] self, Object value)
public static boolean contains(double[] self, Object value)
public static boolean contains(float[] self, Object value)
self
- a String
public static boolean contains(byte[] self, Object value)
public static boolean contains(Object[] self, Object value)
public static boolean containsAll(Collection self, Object[] items)
public static Number count(Iterator self, Object value)
public static Number count(Iterator self, Closure closure)
Example usage:
assert [2,4,2,1,3,5,2,4,3].toSet().iterator().count{ it % 2 == 0 } == 2
self
- the Iterator from which we count the number of matching occurrencesclosure
- a closure condition
public static Number count(Collection self, Object value)
compareTo(value) == 0
or equals(value)
).
Example usage:
assert [2,4,2,1,3,5,2,4,3].count(4) == 2
self
- the collection within which we count the number of occurrencesvalue
- the value being searched for
public static Number count(Collection self, Closure closure)
public static Number count(Map self, Closure closure)
public static Number count(Object[] self, Object value)
compareTo(value) == 0
or equals(value)
).
self
- the array within which we count the number of occurrencesvalue
- the value being searched for
public static Number count(Object[] self, Closure closure)
public static Number count(int[] self, Object value)
public static Number count(long[] self, Object value)
public static Number count(short[] self, Object value)
public static Number count(char[] self, Object value)
public static Number count(boolean[] self, Object value)
public static Number count(double[] self, Object value)
public static Number count(float[] self, Object value)
public static Number count(byte[] self, Object value)
public static int count(String self, String text)
public static int count(CharSequence self, CharSequence text)
public static Map countBy(Collection self, Closure closure)
public static Map countBy(Object[] self, Closure closure)
public static Map countBy(Iterator self, Closure closure)
public static Map countBy(Map self, Closure closure)
answer
- the map containing the resultselement
- the element to be placedvalue
- the value according to which the element will be placed
protected static StringBufferWriter createStringBufferWriter(StringBuffer self)
protected static StringWriter createStringWriter(String self)
public static boolean deleteDir(File self)
file
- a file object
public static String denormalize(String self)
public static CharSequence denormalize(CharSequence self)
stream
- a stream
public static boolean disjoint(Collection left, Collection right)
left
- an int arrayright
- the array being compared
public static Number div(Character left, Number right)
left
- a BitSetright
- another BitSet to bitwise AND
public static Number div(Number left, Character right)
left
- a BitSetright
- another BitSet to bitwise AND
public static Number div(Character left, Character right)
self
- a BitSet
public static void downto(Number self, Number to, Closure closure)
self
- a doubleto
- the end numberclosure
- the code to execute for each number
public static void downto(long self, Number to, Closure closure)
self
- a BigIntegerto
- the end numberclosure
- the code to execute for each number
public static void downto(Long self, Number to, Closure closure)
public static void downto(float self, Number to, Closure closure)
10.5.downto(0) { println it }Prints numbers 10.5, 9.5 ... to 0.5.
self
- a BigDecimalto
- the end numberclosure
- the code to execute for each number
public static void downto(Float self, Number to, Closure closure)
public static void downto(double self, Number to, Closure closure)
public static void downto(Double self, Number to, Closure closure)
public static void downto(BigInteger self, Number to, Closure closure)
public static void downto(BigDecimal self, Number to, Closure closure)
number
- a Number
public static List drop(List self, int num)
class AbcIterable implements Iterable{ Iterator iterator() { "abc".iterator() } } def abc = new AbcIterable() assert abc.drop(0) == ['a', 'b', 'c'] assert abc.drop(1) == ['b', 'c'] assert abc.drop(3) == [] assert abc.drop(5) == []
self
- the original Iterablenum
- the number of elements to drop from this Iterablenum
elements,
or an empty list if it has less then num
elements.
public static List drop(Iterable self, int num)
String[] strings = [ 'a', 'b', 'c' ] assert strings.drop( 0 ) == [ 'a', 'b', 'c' ] as String[] assert strings.drop( 2 ) == [ 'c' ] as String[] assert strings.drop( 5 ) == [] as String[]
self
- the original arraynum
- the number of elements to drop from this arraynum
ones, or else the empty array, if this
array has less than num
elements.
public static Object[] drop(Object[] self, int num)
def strings = [ 'a':10, 'b':20, 'c':30 ] assert strings.drop( 0 ) == [ 'a':10, 'b':20, 'c':30 ] assert strings.drop( 2 ) == [ 'c':30 ] assert strings.drop( 5 ) == [:]If the map instance does not have ordered keys, then this function could drop a random
num
entries. Groovy by default uses LinkedHashMap, so this shouldn't be an issue in the main.
self
- the original mapnum
- the number of elements to drop from this mapnum
ones, or else the empty map, if this map has
less than num
elements.
public static Map drop(Map self, int num)
num
elements.
def iteratorCompare( Iterator a, List b ) { a.collect { it } == b } def iter = [ 1, 2, 3, 4, 5 ].listIterator() assert iteratorCompare( iter.drop( 0 ), [ 1, 2, 3, 4, 5 ] ) iter = [ 1, 2, 3, 4, 5 ].listIterator() assert iteratorCompare( iter.drop( 2 ), [ 3, 4, 5 ] ) iter = [ 1, 2, 3, 4, 5 ].listIterator() assert iteratorCompare( iter.drop( 5 ), [] )
self
- the original iteratornum
- the number of elements to drop from this iteratornum
elements if they exist.
public static Iterator drop(Iterator self, int num)
def text = "Groovy" assert text.drop( 0 ) == 'Groovy' assert text.drop( 2 ) == 'oovy' assert text.drop( 7 ) == ''
self
- the original CharSequencenum
- the number of characters to drop from this iteratornum
ones,
or else an empty String, if this CharSequence has less than num
characters.
public static CharSequence drop(CharSequence self, int num)
public static List dropWhile(List self, Closure condition)
class AbcIterable implements Iterable{ Iterator iterator() { "abc".iterator() } } def abc = new AbcIterable() assert abc.dropWhile{ it < 'b' } == ['b', 'c'] assert abc.dropWhile{ it <= 'b' } == ['c']
self
- an Iterablecondition
- the closure that must evaluate to true to continue dropping elements
public static List dropWhile(Iterable self, Closure condition)
public static Map dropWhile(Map self, Closure condition)
def nums = [ 1, 3, 2 ] as Integer[] assert nums.dropWhile{ it <= 3 } == [ ] as Integer[] assert nums.dropWhile{ it < 3 } == [ 3, 2 ] as Integer[] assert nums.dropWhile{ it != 2 } == [ 2 ] as Integer[] assert nums.dropWhile{ it == 0 } == [ 1, 3, 2 ] as Integer[]
self
- the original arraycondition
- the closure that must evaluate to true to
continue dropping elements
public static Object[] dropWhile(Object[] self, Closure condition)
def a = 0 def iter = [ hasNext:{ a < 10 }, next:{ a++ } ] as Iterator assert [].iterator().dropWhile{ it < 3 }.toList() == [] assert [1, 2, 3, 4, 5].iterator().dropWhile{ it < 3 }.toList() == [ 3, 4, 5 ] assert iter.dropWhile{ it < 5 }.toList() == [ 5, 6, 7, 8, 9 ]
self
- the Iteratorcondition
- the closure that must evaluate to true to continue dropping elements
public static Iterator dropWhile(Iterator self, Closure condition)
public static String dump(Object self)
self
- an object
public static Object each(Object self, Closure closure)
self
- the object over which we iterateclosure
- the closure applied on each element found
public static Map each(Map self, Closure closure)
def result = "" [a:1, b:3].each { key, value -> result += "$key$value" } assert result == "a1b3"
def result = "" [a:1, b:3].each { entry -> result += entry } assert result == "a=1b=3"In general, the order in which the map contents are processed cannot be guaranteed. In practise, specialized forms of Map, e.g. a TreeMap will have its contents processed according to the natural ordering of the map.
self
- the map over which we iterateclosure
- the 1 or 2 arg closure applied on each entry of the map
public static void eachByte(File self, Closure closure)
public static void eachByte(File self, int bufferLen, Closure closure)
public static void eachByte(Byte[] self, Closure closure)
public static void eachByte(byte[] self, Closure closure)
public static void eachByte(InputStream is, Closure closure)
public static void eachByte(InputStream is, int bufferLen, Closure closure)
self
is not readableself
- a Fileclosure
- a closure which returns a boolean indicating to filter
the line or not
public static void eachByte(URL url, Closure closure)
self
is not readableself
- a Filewriter
- a writer destination to write filtered lines toclosure
- a closure which takes each line as a parameter and returns
true
if the line should be written to this writer.
public static void eachByte(URL url, int bufferLen, Closure closure)
self
- a Filewriter
- a writer destination to write filtered lines tocharset
- opens the file with a specified charsetclosure
- a closure which takes each line as a parameter and returns
true
if the line should be written to this writer.
public static void eachDir(File self, Closure closure)
public static void eachDirMatch(File self, Object nameFilter, Closure closure)
file
- a file object
public static void eachDirRecurse(File self, Closure closure)
file
- a File
public static void eachFile(File self, FileType fileType, Closure closure)
public static void eachFile(File self, Closure closure)
public static void eachFileMatch(File self, FileType fileType, Object nameFilter, Closure closure)
file
- a Filecharset
- the charset for this File
public static void eachFileMatch(File self, Object nameFilter, Closure closure)
file
- a file objectclosure
- a closure
public static void eachFileRecurse(File self, FileType fileType, Closure closure)
public static void eachFileRecurse(File self, Closure closure)
self
- a FilenewPathName
- The new pathname for the named filetrue
if and only if the renaming succeeded;
false
otherwise
public static Object eachLine(String self, Closure closure)
public static Object eachLine(CharSequence self, Closure closure)
public static Object eachLine(String self, int firstLine, Closure closure)
public static Object eachLine(CharSequence self, int firstLine, Closure closure)
public static Object eachLine(File self, Closure closure)
public static Object eachLine(File self, String charset, Closure closure)
public static Object eachLine(File self, int firstLine, Closure closure)
public static Object eachLine(File self, String charset, int firstLine, Closure closure)
self
- a Reader, closed after the method returnsclosure
- a closure (arg 1 is line, optional arg 2 is line number starting at line 1)
public static Object eachLine(InputStream stream, String charset, Closure closure)
self
- a Reader, closed after the method returnsfirstLine
- the line number value used for the first line (default is 1, set to 0 to start counting from 0)closure
- a closure which will be passed each line (or for 2 arg closures the line and line count)
public static Object eachLine(InputStream stream, String charset, int firstLine, Closure closure)
public static Object eachLine(InputStream stream, Closure closure)
public static Object eachLine(InputStream stream, int firstLine, Closure closure)
public static Object eachLine(URL url, Closure closure)
public static Object eachLine(URL url, int firstLine, Closure closure)
public static Object eachLine(URL url, String charset, Closure closure)
public static Object eachLine(URL url, String charset, int firstLine, Closure closure)
public static Object eachLine(Reader self, Closure closure)
public static Object eachLine(Reader self, int firstLine, Closure closure)
self
- a URL to open and readpattern
- the regular expression Pattern for the delimiterclosure
- a closure
public static String eachMatch(String self, String regex, Closure closure)
public static String eachMatch(CharSequence self, CharSequence regex, Closure closure)
public static String eachMatch(String self, Pattern pattern, Closure closure)
obj
- the object to converttype
- the goal type
public static String eachMatch(CharSequence self, Pattern pattern, Closure closure)
public static void eachObject(File self, Closure closure)
public static void eachObject(ObjectInputStream ois, Closure closure)
public static Iterator eachPermutation(Collection self, Closure closure)
public static Object eachWithIndex(Object self, Closure closure)
public static Map eachWithIndex(Map self, Closure closure)
def result = "" [a:1, b:3].eachWithIndex { key, value, index -> result += "$index($key$value)" } assert result == "0(a1)1(b3)"
def result = "" [a:1, b:3].eachWithIndex { entry, index -> result += "$index($entry)" } assert result == "0(a=1)1(b=3)"
self
- the map over which we iterateclosure
- a 2 or 3 arg Closure to operate on each item
public static boolean equals(int[] left, int[] right)
false
if either collection is null
.
left
- an arrayright
- the List being compared
public static boolean equals(Object[] left, List right)
public static boolean equals(List left, Object[] right)
public static boolean equals(List left, List right)
public static boolean equals(Set self, Set other)
public static boolean equals(Map self, Map other)
self
- a Set objectremoveMe
- the items to remove from the Set
public static boolean every(Object self, Closure closure)
public static boolean every(Map self, Closure closure)
def map = [a:1, b:2.0, c:2L] assert !map.every { key, value -> value instanceof Integer } assert map.every { entry -> entry.value instanceof Number }
self
- the map over which we iterateclosure
- the 1 or 2 arg Closure predicate used for matching
public static boolean every(Object self)
true
according to the Groovy Truth.
Equivalent to self.every({element -> element})
self
- the object over which we iterate
public static Process execute(String self)
public static Process execute(String self, String[] envp, File dir)
public static Process execute(String self, List envp, File dir)
public static Process execute(String[] commandArray)
public static Process execute(String[] commandArray, String[] envp, File dir)
self
- a String to be repeatedfactor
- the number of times the String should be repeated
public static Process execute(String[] commandArray, List envp, File dir)
self
- a CharSequence to be repeatedfactor
- the number of times the CharSequence should be repeated
public static Process execute(List commands)
self
- an array
public static Process execute(List commands, String[] envp, File dir)
self
- an array
public static Process execute(List commands, List envp, File dir)
self
- an array
public static String expand(String self)
self
- A CharSequence to unexpand
public static CharSequence expand(CharSequence self)
self
- A String to unexpandtabStop
- The number of spaces a tab represents
public static String expand(String self, int tabStop)
public static CharSequence expand(CharSequence self, int tabStop)
self
- A CharSequence to unexpandtabStop
- The number of spaces a tab represents
public static String expandLine(String self, int tabStop)
public static CharSequence expandLine(CharSequence self, int tabStop)
self
- A line to unexpandtabStop
- The number of spaces a tab represents
public static void filterLine(Reader reader, Writer writer, Closure closure)
true
if the line should be passed to the writer.self
- an input streamcharset
- opens the stream with a specified charsetpredicate
- a closure which returns boolean and takes a line
public static Writable filterLine(File self, Closure closure)
true
if the line should be passed to the
writer.self
- the InputStreamwriter
- a writer to write output tocharset
- opens the stream with a specified charsetpredicate
- a closure which returns true if a line should be accepted
public static Writable filterLine(File self, String charset, Closure closure)
public static void filterLine(File self, Writer writer, Closure closure)
true
if the line should be passed to the
writer.self
- the URLwriter
- a writer to write output topredicate
- a closure which returns true if a line should be accepted
public static void filterLine(File self, Writer writer, String charset, Closure closure)
true
if the line should be passed to the
writer.self
- the URLwriter
- a writer to write output tocharset
- opens the URL with a specified charsetpredicate
- a closure which returns true if a line should be accepted
public static Writable filterLine(Reader reader, Closure closure)
file
- a File
public static Writable filterLine(InputStream self, Closure predicate)
socket
- a Socketclosure
- a Closure
public static Writable filterLine(InputStream self, String charset, Closure predicate)
public static void filterLine(InputStream self, Writer writer, Closure predicate)
public static void filterLine(InputStream self, Writer writer, String charset, Closure predicate)
public static Writable filterLine(URL self, Closure predicate)
public static Writable filterLine(URL self, String charset, Closure predicate)
serverSocket
- a ServerSocketclosure
- a Closure
public static void filterLine(URL self, Writer writer, Closure predicate)
serverSocket
- a ServerSocketrunInANewThread
- This flag should be true, if the closure should be invoked in a new thread, else false.closure
- a Closure
public static void filterLine(URL self, Writer writer, String charset, Closure predicate)
public static Object find(Object self, Closure closure)
self
- an Object with an iterator returning its valuesclosure
- a closure condition
public static Object find(Object self)
self
- an Object with an iterator returning its valuesdefaultResult
- an Object that should be returned if all closure results are nullclosure
- a closure that returns a non-null value when processing should stop
public static Object find(Collection self, Closure closure)
public static Object find(Collection self)
public static Map.Entry find(Map self, Closure closure)
public static String find(String self, String regex)
self
- a CharSequenceregex
- the capturing regex
public static CharSequence find(CharSequence self, CharSequence regex)
public static String find(String self, Pattern pattern)
self
- a CharSequencepattern
- the compiled regex Pattern
public static CharSequence find(CharSequence self, Pattern pattern)
public static String find(String self, String regex, Closure closure)
self
- a CharSequenceregex
- the capturing regex CharSequenceclosure
- the closure that will be passed the full match, plus each of the capturing groups
public static CharSequence find(CharSequence self, CharSequence regex, Closure closure)
public static String find(String self, Pattern pattern, Closure closure)
public static CharSequence find(CharSequence self, Pattern pattern, Closure closure)
For example, if the regex doesn't match, it returns an empty list:
assert [] == "foo".findAll(/(\w*) Fish/)
Any regular expression matches are returned in a list, and all regex capture groupings are ignored, only the full match is returned:
def expected = ["One Fish", "Two Fish", "Red Fish", "Blue Fish"] assert expected == "One Fish, Two Fish, Red Fish, Blue Fish".findAll(/(\w*) Fish/)If you need to work with capture groups, then use the closure version of this method or use Groovy's matcher operators or use eachMatch.
self
- a Stringregex
- the capturing regex String
public static Collection findAll(Collection self, Closure closure)
public static Collection findAll(Collection self)
self
- an Object with an Iterator returning its valuesclosure
- a closure condition
public static Collection findAll(Object self, Closure closure)
public static Collection findAll(Object self)
public static Map findAll(Map self, Closure closure)
public static List findAll(String self, String regex)
public static List findAll(CharSequence self, CharSequence regex)
public static List findAll(String self, Pattern pattern)
self
- a CharSequencepattern
- the compiled regex Pattern
public static List findAll(CharSequence self, Pattern pattern)
public static List findAll(String self, String regex, Closure closure)
self
- a CharSequenceregex
- the capturing regex CharSequenceclosure
- will be passed the full match plus each of the capturing groups
public static List findAll(CharSequence self, CharSequence regex, Closure closure)
public static List findAll(String self, Pattern pattern, Closure closure)
self
- a CharSequencepattern
- the compiled regex Patternclosure
- will be passed the full match plus each of the capturing groups
public static List findAll(CharSequence self, Pattern pattern, Closure closure)
public static int findIndexOf(Object self, Closure closure)
public static int findIndexOf(Object self, int startIndex, Closure closure)
public static List findIndexValues(Object self, Closure closure)
c
- a class
public static List findIndexValues(Object self, Number startIndex, Closure closure)
String.metaClass.myMethod = { println "foo" }
c
- The java.lang.Class instance
public static int findLastIndexOf(Object self, Closure closure)
public static int findLastIndexOf(Object self, int startIndex, Closure closure)
public static Object findResult(Object self, Object defaultResult, Closure closure)
public static Object findResult(Object self, Closure closure)
public static Object findResult(Collection self, Object defaultResult, Closure closure)
public static Object findResult(Collection self, Closure closure)
public static Object findResult(Map self, Object defaultResult, Closure closure)
public static Object findResult(Map self, Closure closure)
public static Collection findResults(Collection self, Closure filteringTransform)
public static Collection findResults(Map self, Closure filteringTransform)
public static Object first(List self)
public static Object first(Iterable self)
public static Object first(Object[] self)
def array = [3, 4, 2].toArray() assert array.head() == 3
self
- an Object array
public static Collection flatten(Collection self)
self
- a byte Array to flatten
public static Collection flatten(Object[] self)
self
- a short Array to flatten
public static Collection flatten(boolean[] self)
self
- an int Array to flatten
public static Collection flatten(byte[] self)
self
- a long Array to flatten
public static Collection flatten(char[] self)
self
- a float Array to flatten
public static Collection flatten(short[] self)
self
- a double Array to flatten
public static Collection flatten(int[] self)
public static Collection flatten(long[] self)
public static Collection flatten(float[] self)
public static Collection flatten(double[] self)
public static Collection flatten(Collection self, Closure flattenUsing)
def list = [1,2] list << 3 assert list == [1,2,3]
self
- a Collectionvalue
- an Object to be added to the collection.
public static Object get(Map map, Object key, Object defaultValue)
array
- an Array of Objectsrange
- a Range
public static Object getAt(Object self, String property)
bean[somePropertyNameExpression]
. The normal property notation
of groovy is neater and more concise but only works with compile-time known
property names.
self
- the object to act uponproperty
- the property name of interest
public static CharSequence getAt(CharSequence text, int index)
public static String getAt(String text, int index)
public static CharSequence getAt(CharSequence text, Range range)
public static CharSequence getAt(CharSequence text, IntRange range)
text
- a CharSequencerange
- an EmptyRange
public static CharSequence getAt(CharSequence text, EmptyRange range)
public static String getAt(String text, IntRange range)
public static String getAt(String text, EmptyRange range)
public static String getAt(String text, Range range)
public static Object getAt(Matcher matcher, int idx)
matcher
- a Matcheridx
- the index number
public static List getAt(List self, Range range)
public static List getAt(List self, EmptyRange range)
public static List getAt(List self, Collection indices)
public static List getAt(Object[] self, Collection indices)
self
- a CharSequenceindices
- a Collection of indices
public static CharSequence getAt(CharSequence self, Collection indices)
self
- a Stringindices
- a Collection of indices
public static String getAt(String self, Collection indices)
public static List getAt(Matcher self, Collection indices)
public static List getAt(Object[] array, Range range)
public static List getAt(Object[] array, IntRange range)
array
- an Array of Objectsrange
- an ObjectRange
public static List getAt(Object[] array, EmptyRange range)
array
- an Array of Objects
public static List getAt(Object[] array, ObjectRange range)
def list = [2, "a", 5.3] assert list[1] == "a"
self
- a Listidx
- an index
public static Object getAt(List self, int idx)
public static Object getAt(Iterator self, int idx)
public static Object getAt(Map self, Object key)
Map
containing all entries from left
and right
,
giving precedence to right
. Any keys appearing in both Maps
will appear in the resultant map with values from the right
operand. If the left
map is one of TreeMap, LinkedHashMap, Hashtable
or Properties, the returned Map will preserve that type, otherwise a HashMap will
be returned.
Roughly equivalent to Map m = new HashMap(); m.putAll(left); m.putAll(right); return m;
but with some additional logic to preserve the left
Map type for common cases as
described above.
assert [a:10, b:20] + [a:5, c:7] == [a:5, b:20, c:7]
left
- a Mapright
- a Map
public static List getAt(Collection coll, String property)
*/ public static List getAt(byte[] array, Range range)
*/ public static List getAt(char[] array, Range range)
*/ public static List getAt(short[] array, Range range)
*/ public static List getAt(int[] array, Range range)
*/ public static List getAt(long[] array, Range range)
*/ public static List getAt(float[] array, Range range)
*/ public static List getAt(double[] array, Range range)
*/ public static List getAt(boolean[] array, Range range)
*/ public static List getAt(byte[] array, IntRange range)
*/ public static List getAt(char[] array, IntRange range)
*/ public static List getAt(short[] array, IntRange range)
*/ public static List getAt(int[] array, IntRange range)
*/ public static List getAt(long[] array, IntRange range)
*/ public static List getAt(float[] array, IntRange range)
*/ public static List getAt(double[] array, IntRange range)
*/ public static List getAt(boolean[] array, IntRange range)
*/ public static List getAt(byte[] array, ObjectRange range)
*/ public static List getAt(char[] array, ObjectRange range)
*/ public static List getAt(short[] array, ObjectRange range)
*/ public static List getAt(int[] array, ObjectRange range)
*/ public static List getAt(long[] array, ObjectRange range)
*/ public static List getAt(float[] array, ObjectRange range)
*/ public static List getAt(double[] array, ObjectRange range)
*/ public static List getAt(boolean[] array, ObjectRange range)
*/ public static List getAt(byte[] array, Collection indices)
*/ public static List getAt(char[] array, Collection indices)
*/ public static List getAt(short[] array, Collection indices)
*/ public static List getAt(int[] array, Collection indices)
* @since 1.5.0 public static List getAt(long[] array, Collection indices)
* @see groovy.lang.IntRange public static List getAt(float[] array, Collection indices)
if (range.isReverse()) { public static List getAt(double[] array, Collection indices)
return (Boolean) primitiveArrayPut(array, idx, newValue); // public static List getAt(boolean[] array, Collection indices)
public static boolean getAt(BitSet self, int index)
public static BitSet getAt(BitSet self, IntRange range)
public static byte[] getBytes(File file)
file
- a Filetext
- the text to write to the File
public static byte[] getBytes(URL url)
public static byte[] getBytes(InputStream is)
file
- a Filetext
- the text to write to the Filecharset
- the charset used
public static char[] getChars(String self)
self
- the iteration object over which to iterateclosure
- the filter to perform a match on the collection
public static char[] getChars(CharSequence self)
public static int getCount(Matcher matcher)
matcher
- a Matchertrue
if matcher contains at least one group.
public static MetaClass getMetaClass(Class c)
public static MetaClass getMetaClass(Object obj)
a
- an array
public static MetaClass getMetaClass(GroovyObject obj)
o
- an object
public static List getMetaPropertyValues(Object self)
self
- the receiver object
public static Map getProperties(Object self)
self
- the receiver object
public static ClassLoader getRootLoader(ClassLoader self)
obj
- The object in question
protected static List getSubList(List self, List splice)
public static String getText(File file, String charset)
url
- URL to read content from
public static String getText(File file)
public static String getText(URL url)
public static String getText(URL url, Map parameters)
file
- the file to write tobytes
- the byte[] to write to the file
public static String getText(URL url, String charset)
os
- an output streambytes
- the byte[] to write to the output stream
public static String getText(URL url, Map parameters, String charset)
writer
- a BufferedWriterline
- the line to write
public static String getText(InputStream is)
file
- a Filetext
- the text to write to the File
public static String getText(InputStream is, String charset)
public static String getText(Reader reader)
public static String getText(BufferedReader reader)
public static Collection grep(Object self, Object filter)
isCase(java.lang.Object, java.lang.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', 3, 4.5] assert list.grep( ~/a+/ ) == ['a', 'aa'] assert list.grep( ~/../ ) == ['aa', 'bc'] assert list.grep( Number ) == [ 3, 4.5 ] assert list.grep{ it.toString().size() == 1 } == [ 'a', 'b', 3 ]
self
- the object over which we iteratefilter
- the filter to perform on the object (using the isCase(java.lang.Object, java.lang.Object) method)
public static Collection grep(Object self)
def items = [1, 2, 0, false, true, '', 'foo', [], [4, 5], null] assert items.grep() == [1, 2, true, 'foo', [4, 5]]
self
- the object over which we iterate
protected static void groupAnswer(Map answer, Object element, Object value)
public static Map groupBy(Collection self, Closure closure)
public static Map groupBy(Collection self, Object... closures)
public static Map groupBy(Collection self, List closures)
Example usage:
def result = [1,2,3,4,5,6].groupBy([{ it % 2 }, { it < 4 }]) assert result == [1:[(true):[1, 3], (false):[5]], 0:[(true):[2], (false):[4, 6]]]Another example:
def sql = groovy.sql.Sql.newInstance(/* ... */) def data = sql.rows("SELECT * FROM a_table").groupBy([{ it.column1 }, { it.column2 }, { it.column3 }]) if (data.val1.val2.val3) { // there exists a record where: // a_table.column1 == val1 // a_table.column2 == val2, and // a_table.column3 == val3 } else { // there is no such record }If an empty list of closures is supplied the IDENTITY Closure will be used.
self
- a collection to groupclosures
- a list of closures, each mapping entries on keys
public static Map groupBy(Map self, Closure closure)
public static Map groupBy(Map self, Object... closures)
public static Map groupBy(Map self, List closures)
If the self
map is one of TreeMap, Hashtable, or Properties,
the returned Map will preserve that type, otherwise a LinkedHashMap will
be returned.
def result = [a:1,b:2,c:3,d:4,e:5,f:6].groupBy([{ it.value % 2 }, { it.key.next() }]) assert result == [1:[b:[a:1], d:[c:3], f:[e:5]], 0:[c:[b:2], e:[d:4], g:[f:6]]]If an empty list of closures is supplied the IDENTITY Closure will be used.
self
- a map to groupclosures
- a list of closures that map entries on keys
public static Map groupEntriesBy(Map self, Closure closure)
public static boolean hasGroup(Matcher matcher)
public static MetaProperty hasProperty(Object self, String name)
public static Object head(List self)
def list = [3, 4, 2] assert list.tail() == [4, 2] assert list == [3, 4, 2]
self
- a List
public static Object head(Object[] self)
public static Object identity(Object self, Closure closure)
self
- the object to have a closure act uponclosure
- the closure to call on the object
public static Boolean implies(Boolean left, Boolean right)
public static Object inject(Collection self, Closure closure)
public static Object inject(Collection self, Object initialValue, Closure closure)
public static Object inject(Map self, Object initialValue, Closure closure)
public static Object inject(Iterator self, Object initialValue, Closure closure)
public static Object inject(Object self, Closure closure)
public static Object inject(Object self, Object initialValue, Closure closure)
self
- an Object[]closure
- a closure
public static Object inject(Object[] self, Closure closure)
self
- an Object[]initialValue
- some initial valueclosure
- a closure
public static Object inject(Object[] self, Object initialValue, Closure closure)
public static String inspect(Object self)
self
- any Object
public static Number intdiv(Character left, Number right)
left
- a BitSetright
- another BitSet to bitwise AND
public static Number intdiv(Number left, Character right)
left
- a Numberright
- another Number to bitwse XOR
public static Number intdiv(Character left, Character right)
left
- a Numberright
- another Number to mod
public static Number intdiv(Number left, Number right)
public static Collection intersect(Collection left, Collection right)
assert [4:4,5:5] == [1:1,2:2,3:3,4:4,5:5].intersect([4:4,5:5,6:6,7:7,8:8])
assert [1: 1, 2: 2, 3: 3, 4: 4].intersect( [1: 1.0, 2: 2, 5: 5] ) == [1:1, 2:2]
left
- a mapright
- a map
public static Map intersect(Map left, Map right)
true
if the intersection of two collections is empty.
assert [1,2,3].disjoint([3,4,5]) == false
assert [1,2].disjoint([3,4]) == true
left
- a Collectionright
- a Collectiontrue
if the intersection of two collections
is empty, false
otherwise.
public static Object invokeMethod(Object object, String method, Object arguments)
object
- any Objectmethod
- the name of the method to callarguments
- the arguments to use
public static boolean is(Object self, Object other)
def same = this.is(that)
self
- an objectother
- an object to compare identity with
public static boolean isAllWhitespace(String self)
public static boolean isAllWhitespace(CharSequence self)
Strip numChar leading characters from every line in a String.
assert 'DEF\n456' == '''ABCDEF\n123456'''.stripIndent(3)
self
- The String to strip the characters fromnumChars
- The number of characters to strip
public static boolean isBigDecimal(String self)
self
- a CharSequence
public static boolean isBigDecimal(CharSequence self)
public static boolean isBigInteger(String self)
public static boolean isBigInteger(CharSequence self)
public static boolean isCase(Object caseValue, Object switchValue)
switch( a ) { case b: //some code }"some code" is called when
b.isCase( a )
returns
true
.
caseValue
- the case valueswitchValue
- the switch value
public static boolean isCase(String caseValue, Object switchValue)
switch( str ) { case 'one' : // etc... }Note that this returns
true
for the case where both the
'switch' and 'case' operand is null
.
caseValue
- the case valueswitchValue
- the switch value
public static boolean isCase(CharSequence caseValue, Object switchValue)
caseValue
- the case valueswitchValue
- the switch value
public static boolean isCase(GString caseValue, Object switchValue)
public static boolean isCase(Class caseValue, Object switchValue)
public static boolean isCase(Collection caseValue, Object switchValue)
switch( 3 ) { case [1,3,5]: assert true break default: assert false }
caseValue
- the case valueswitchValue
- the switch value
public static boolean isCase(Map caseValue, Object switchValue)
public static boolean isCase(Pattern caseValue, Object switchValue)
public static boolean isCase(Number caseValue, Number switchValue)
compareTo()
method for comparing numbers of different
types.
caseValue
- the case valueswitchValue
- the switch value
public static boolean isDigit(Character self)
self
- a Number
public static boolean isDouble(String self)
self
- a CharSequence
public static boolean isDouble(CharSequence self)
public static boolean isFloat(String self)
self
- a CharSequence
public static boolean isFloat(CharSequence self)
self
- a Character
public static boolean isInteger(String self)
public static boolean isInteger(CharSequence self)
public static boolean isLetter(Character self)
public static boolean isLetterOrDigit(Character self)
public static boolean isLong(String self)
public static boolean isLong(CharSequence self)
self
- a Character
public static boolean isLowerCase(Character self)
self
- a Number
public static boolean isNumber(String self)
self
- a CharSequence
public static boolean isNumber(CharSequence self)
public static boolean isUpperCase(Character self)
self
- a Number
public static boolean isWhitespace(Character self)
public static Iterator iterator(Object[] a)
self
- an InputStream object
public static Iterator iterator(Object o)
public static Iterator iterator(Enumeration enumeration)
public static Iterator iterator(Matcher matcher)
self
- an iterator object
public static Iterator iterator(Reader self)
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
self
- The object to inspectname
- The name of the method of interest
public static Iterator iterator(InputStream self)
public static Iterator iterator(DataInputStream self)
public static Iterator iterator(Iterator self)
public static String join(Iterator self, String separator)
toString()
representation of each
item in this collection, with the given String as a separator between
each item.
assert "1, 2, 3" == [1,2,3].join(", ")
self
- a Collection of objectsseparator
- a String separator
public static String join(Collection self, String separator)
public static String join(Object[] self, String separator)
public static Object last(List self)
public static Object last(Iterable self)
def array = [3, 4, 2].toArray() assert array.last() == 2
self
- an array
public static Object last(Object[] self)
public static Collection leftShift(Collection self, Object value)
self
- a Mapentry
- a Map.Entry to be added to the Map.
public static BlockingQueue leftShift(BlockingQueue self, Object value)
self
- a Stringvalue
- an Object
public static Map leftShift(Map self, Map.Entry entry)
self
- a CharSequencevalue
- an Object
public static Map leftShift(Map self, Map other)
self
- a StringBuildervalue
- an Object
public static StringBuffer leftShift(String self, Object value)
self
- a StringBuffervalue
- a value to append
public static StringBuilder leftShift(CharSequence self, Object value)
public static StringBuilder leftShift(StringBuilder self, Object value)
public static StringBuffer leftShift(StringBuffer self, Object value)
public static Writer leftShift(Writer self, Object value)
public static Number leftShift(Number self, Number operand)
public static Writer leftShift(OutputStream self, Object value)
public static void leftShift(ObjectOutputStream self, Object value)
public static OutputStream leftShift(OutputStream self, InputStream in)
public static OutputStream leftShift(OutputStream self, byte[] value)
array
- a short arrayrange
- a range indicating the indices for the items to retrieve
public static File leftShift(File file, Object text)
self
- a file objectfileType
- if normal files or directories or both should be processedclosure
- the closure to invoke
public static File leftShift(File file, byte[] bytes)
public static File leftShift(File file, InputStream data)
self
- a File (that happens to be a folder/directory)closure
- a closure (first parameter is the 'child' file)
public static Writer leftShift(Socket self, Object value)
Example usage:
assert 'groovy'.toSet() == ['v', 'g', 'r', 'o', 'y'] as Set assert "abc".toSet().iterator()[0] instanceof String
self
- a String
public static OutputStream leftShift(Socket self, byte[] value)
self
- a CharSequence
public static boolean matches(String self, Pattern pattern)
public static boolean matches(CharSequence self, Pattern pattern)
public static Map.Entry max(Map self, Closure closure)
public static Object max(Collection self)
public static Object max(Iterator self)
public static Object max(Object[] self)
public static Object max(Collection self, Closure closure)
public static Object max(Iterator self, Closure closure)
public static Object max(Object[] self, Closure closure)
assert "hello" == ["hello","hi","hey"].max( { a, b -> a.length() <=> b.length() } as Comparator )
self
- a Collectioncomparator
- a Comparator
public static Object max(Collection self, Comparator comparator)
self
- an Iteratorcomparator
- a Comparator
public static Object max(Iterator self, Comparator comparator)
self
- an Object arraycomparator
- a Comparator
public static Object max(Object[] self, Comparator comparator)
public static MetaClass metaClass(Class self, Closure closure)
public static MetaClass metaClass(Object self, Closure closure)
self
- a Reader object
public static Object min(Collection self)
self
- an Iterator
public static Object min(Iterator self)
public static Object min(Object[] self)
public static Object min(Collection self, Comparator comparator)
self
- an Iteratorcomparator
- a Comparator
public static Object min(Iterator self, Comparator comparator)
self
- an Object arraycomparator
- a Comparator
public static Object min(Object[] self, Comparator comparator)
public static Object min(Collection self, Closure closure)
public static Map.Entry min(Map self, Closure closure)
public static Object min(Iterator self, Closure closure)
public static Object min(Object[] self, Closure closure)
assert 5 == [2,3,1,5,4].max()
self
- a Collection
public static Set minus(Set self, Collection removeMe)
self
- a Set objectremoveMe
- the items to remove from the Set
public static Set minus(Set self, Iterable removeMe)
self
- an object arrayremoveMe
- a Collection of elements to remove
public static Set minus(Set self, Object removeMe)
public static Object[] minus(Object[] self, Iterable removeMe)
} public static Object[] minus(Object[] self, Object[] removeMe)
public static List minus(List self, Collection removeMe)
public static List minus(List self, Iterable removeMe)
class AbcIterable implements Iterable{ Iterator iterator() { "abc".iterator() } } assert "backtrack".toList() - new AbcIterable() == ["k", "t", "r", "k"]
self
- a ListremoveMe
- an Iterable of elements to remove
public static List minus(List self, Object removeMe)
* @since 1.6.0 public static Object[] minus(Object[] self, Object removeMe)
public static Map minus(Map self, Map removeMe)
self
- a boolean Array to flatten
public static String minus(String self, Object target)
public static CharSequence minus(CharSequence self, Object target)
self
- the array we are searchingvalue
- the value being searched for
public static Number minus(Character left, Number right)
self
- a Numberexponent
- a Number exponent
public static Number minus(Number left, Character right)
public static Number minus(Character left, Character right)
public static void mixin(MetaClass self, List categoryClasses)
self
- any ClasscategoryClasses
- a category classes to use
public static void mixin(Class self, List categoryClasses)
self
- any ClasscategoryClasses
- a category classes to use
public static void mixin(Class self, Class categoryClass)
self
- any ClasscategoryClass
- a category class to use
public static void mixin(Class self, Class[] categoryClass)
self
- any ClasscategoryClass
- a category class to use
public static void mixin(MetaClass self, Class categoryClass)
self
- any ClasscategoryClass
- a category class to use
public static void mixin(MetaClass self, Class[] categoryClass)
self
- any ClasscategoryClass
- a category class to use
public static Number mod(Number left, Number right)
public static List multiply(Collection self, Number factor)
public static String multiply(String self, Number factor)
self
- an array
public static CharSequence multiply(CharSequence self, Number factor)
[one:1, two:2, three:3]
.
self
- a Map
public static Number multiply(Character left, Number right)
self
- a BigIntegerexponent
- an Integer exponent
public static Number multiply(Number left, Character right)
self
- an Integerexponent
- an Integer exponent
public static Number multiply(Character left, Character right)
public static Number multiply(BigDecimal left, Double right)
public static Number multiply(BigDecimal left, BigInteger right)
left
- a Characterright
- a Number
public static DataInputStream newDataInputStream(File file)
public static DataOutputStream newDataOutputStream(File file)
public static BufferedInputStream newInputStream(File file)
self
- a Byte arrayclosure
- a closure
public static BufferedInputStream newInputStream(URL url)
is
- stream to iterate over, closed after the method call.bufferLen
- the length of the buffer to use.closure
- a 2 parameter closure which is passed the byte[] and a number of bytes successfully read.
public static BufferedInputStream newInputStream(URL url, Map parameters)
return metaClass; public static Object newInstance(Class c)
self
- the class whose metaclass we wish to updateclosure
- the closure representing the new metaclass
} public static Object newInstance(Class c, Object[] args)
public static ObjectInputStream newObjectInputStream(File file)
public static ObjectInputStream newObjectInputStream(InputStream inputStream)
public static ObjectInputStream newObjectInputStream(InputStream inputStream, ClassLoader classLoader)
public static ObjectInputStream newObjectInputStream(File file, ClassLoader classLoader)
public static ObjectOutputStream newObjectOutputStream(File file)
public static ObjectOutputStream newObjectOutputStream(OutputStream outputStream)
public static BufferedOutputStream newOutputStream(File file)
public static PrintWriter newPrintWriter(File file)
public static PrintWriter newPrintWriter(File file, String charset)
in
- a streamclosure
- the closure to invoke with the InputStream
public static PrintWriter newPrintWriter(Writer writer)
public static BufferedReader newReader(File file)
file
- a Fileclosure
- a closure
public static BufferedReader newReader(File file, String charset)
public static BufferedReader newReader(InputStream self)
public static BufferedReader newReader(InputStream self, String charset)
public static BufferedReader newReader(URL url)
public static BufferedReader newReader(URL url, Map parameters)
url
- url to iterate overbufferLen
- the length of the buffer to use.closure
- a 2 parameter closure which is passed the byte[] and a number of bytes successfully read.
public static BufferedReader newReader(URL url, String charset)
self
- a Reader objectwriter
- a Writer to receive the transformed charactersclosure
- a closure that performs the required transformation
public static BufferedReader newReader(URL url, Map parameters, String charset)
public static BufferedWriter newWriter(File file)
public static BufferedWriter newWriter(File file, boolean append)
public static BufferedWriter newWriter(File file, String charset, boolean append)
public static BufferedWriter newWriter(File file, String charset)
writer
- the writer which is used and then closedclosure
- the closure that the writer is passed into
public static String next(String self)
public static CharSequence next(CharSequence self)
String
array.
The first item in the array is the command; the others are the parameters.
For more control over Process construction you can use
java.lang.ProcessBuilder
(JDK 1.5+).
commandArray
- an array of String
containing the command name and
parameters as separate items in the array.
public static Character next(Character self)
public static Number next(Number self)
public static String normalize(String self)
public static CharSequence normalize(CharSequence self)
file
- the file whose content we want to read
public static int numberAwareCompareTo(Comparable self, Comparable other)
self
- a Comparableother
- another Comparable
public static Number or(Number left, Number right)
public static BitSet or(BitSet left, BitSet right)
public static Boolean or(Boolean left, Boolean right)
public static String padLeft(String self, Number numberOfChars, String padding)
self
- a CharSequence objectnumberOfChars
- the total minimum number of characters of the resulting CharSequencepadding
- the characters used for padding
public static CharSequence padLeft(CharSequence self, Number numberOfChars, CharSequence padding)
public static String padLeft(String self, Number numberOfChars)
self
- a CharSequence objectnumberOfChars
- the total minimum number of characters of the resulting CharSequence
public static CharSequence padLeft(CharSequence self, Number numberOfChars)
public static String padRight(String self, Number numberOfChars, String padding)
self
- a CharSequence objectnumberOfChars
- the total minimum number of characters of the resulting CharSequencepadding
- the characters used for padding
public static CharSequence padRight(CharSequence self, Number numberOfChars, CharSequence padding)
public static String padRight(String self, Number numberOfChars)
public static CharSequence padRight(CharSequence self, Number numberOfChars)
public static Set permutations(List self)
public static Map plus(Map left, Map right)
assert [String, Long, Integer] == ["a",5L,2]["class"]
coll
- a Collectionproperty
- a String
*/ public static Object[] plus(Object[] left, Object[] right)
* @param left the array public static Object[] plus(Object[] left, Object right)
* @param right the right Collection public static Object[] plus(Object[] left, Collection right)
public staticCollection plus(Collection left, Iterable right) { public static Object[] plus(Object[] left, Iterable right)
left
- the left Collectionright
- the right Iterable
public static Collection plus(Collection left, Collection right)
public static Collection plus(Collection left, Iterable right)
public static List plus(List self, int index, Object[] items)
def items = [1, 2, 3] def newItems = items.plus(2, 'a'..'c') assert newItems == [1, 2, 'a', 'b', 'c', 3] assert items == [1, 2, 3]See also
addAll
for similar functionality with modify semantics, i.e. which performs
the changes on the original list itself.
self
- an original Listadditions
- a List containing elements to be merged with elements from the original Listindex
- index at which to insert the first element from the given additions List
public static List plus(List self, int index, List additions)
self
- an original listadditions
- an Iterable containing elements to be merged with the elements from the original Listindex
- index at which to insert the first element from the given additions Iterable
public static List plus(List self, int index, Iterable additions)
self
- a map
public static Collection plus(Collection left, Object right)
public static Map plus(Map self, Collection entries)
public static String plus(String left, Object value)
self
- the array we are searchingvalue
- the value being searched for
public static CharSequence plus(CharSequence left, Object value)
self
- the array we are searchingvalue
- the value being searched for
public static String plus(Number value, String right)
public static String plus(StringBuffer left, String value)
public static Number plus(Character left, Number right)
public static Number plus(Number left, Character right)
public static Number plus(Character left, Character right)
public static Object pop(List self)
Map
containing all entries from self
and entries
,
giving precedence to entries
. Any keys appearing in both Maps
will appear in the resultant map with values from the entries
operand. If self
map is one of TreeMap, LinkedHashMap, Hashtable
or Properties, the returned Map will preserve that type, otherwise a HashMap will
be returned.
self
- a Mapentries
- a Collection of Map.Entry items to be added to the Map.
public static Number power(Number self, Number exponent)
public static Number power(BigDecimal self, Integer exponent)
left
- a Characterright
- another Character
public static Number power(BigInteger self, Integer exponent)
left
- a Numberright
- a Character
public static Number power(Integer self, Integer exponent)
left
- a Characterright
- another Character
public static Number power(Long self, Integer exponent)
left
- a Numberright
- another Number to bitwise OR
public static String previous(String self)
public static CharSequence previous(CharSequence self)
public static Character previous(Character self)
public static Number previous(Number self)
protected static Object primitiveArrayGet(Object self, int idx)
self
- the string to split
protected static List primitiveArrayGet(Object self, Range range)
protected static List primitiveArrayGet(Object self, Collection indices)
protected static Object primitiveArrayPut(Object self, int idx, Object newValue)
self
- The CharSequence to capitalize
public static void print(Object self, Object value)
self
- any Objectvalue
- the value to print
public static void print(PrintWriter self, Object value)
self
- a PrintWritervalue
- the value to print
public static void print(PrintStream self, Object value)
self
- a PrintStreamvalue
- the value to print
public static void print(Closure self, Object value)
self
- a generated closurevalue
- the value to print
public static void print(Object self, PrintWriter out)
self
- any Objectout
- the PrintWriter used for printing
public static void printf(Object self, String format, Object[] values)
self
- any Objectformat
- a format stringvalues
- values referenced by the format specifiers in the format string.
public static void printf(Object self, String format, Object arg)
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[] ) }
self
- any Objectformat
- A format stringarg
- 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 static void println(Object self)
self
- any Object
public static void println(Closure self)
self
- a closure
public static void println(Object self, Object value)
self
- any Objectvalue
- the value to print
public static void println(PrintWriter self, Object value)
self
- a PrintWritervalue
- the value to print
public static void println(PrintStream self, Object value)
self
- any Objectvalue
- the value to print
public static void println(Closure self, Object value)
self
- a closurevalue
- the value to print
public static void println(Object self, PrintWriter out)
self
- any Objectout
- the PrintWriter used for printing
public static boolean push(List self, Object value)
public static Map putAll(Map self, Collection entries)
public static void putAt(Object self, String property, Object newValue)
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.
self
- the object to act uponproperty
- the name of the property to setnewValue
- the value to set
public static void putAt(List self, int idx, Object value)
self
- a StringBufferrange
- a Rangevalue
- the object that's toString() will be inserted
public static void putAt(StringBuffer self, IntRange range, Object value)
def list = ["a", true] list[1..<1] = 5 assert list == ["a", 5, true]
self
- a Listrange
- the (in this case empty) subset of the list to setvalue
- the values to put at the given sublist or a Collection of values
public static void putAt(StringBuffer self, EmptyRange range, Object value)
public static void putAt(List self, EmptyRange range, Object value)
public static void putAt(List self, EmptyRange range, Collection value)
def myList = [4, 3, 5, 1, 2, 8, 10] myList[3..5] = ["a", true] assert myList == [4, 3, 5, "a", true, 10]Items in the given range are replaced with items from the collection.
self
- a Listrange
- the subset of the list to setcol
- the collection of values to put at the given sublist
public static void putAt(List self, IntRange range, Collection col)
def myList = [4, 3, 5, 1, 2, 8, 10] myList[3..5] = "b" assert myList == [4, 3, 5, "b", 10]Items in the given range are replaced with the operand. The
value
operand is
always treated as a single value.
self
- a Listrange
- the subset of the list to setvalue
- the value to put at the given sublist
public static void putAt(List self, IntRange range, Object value)
public static void putAt(List self, List splice, List values)
def list = ["a", true, 42, 9.4] list[1, 3] = 5 assert list == ["a", 5, 42, 5]
self
- a Listsplice
- the subset of the list to setvalue
- the value to put at the given sublist
public static void putAt(List self, List splice, Object value)
public static Object putAt(Map self, Object key, Object value)
public static void putAt(BitSet self, IntRange range, boolean value)
self
- a BitSetrange
- the range of values to setvalue
- value
public static void putAt(BitSet self, int index, boolean value)
array
- a byte array
public static byte[] readBytes(File file)
file
- a File
public static String readLine(Reader self)
public static List readLines(String self)
public static List readLines(CharSequence self)
public static List readLines(File file)
url
- URL to read content fromparameters
- connection parameterscharset
- opens the stream with a specified charset
public static List readLines(File file, String charset)
is
- an input stream
public static List readLines(InputStream stream)
public static List readLines(InputStream stream, String charset)
public static List readLines(URL self)
public static List readLines(URL self, String charset)
public static List readLines(Reader reader)
public static boolean removeAll(Collection self, Object[] items)
public static boolean removeAll(Collection self, Closure condition)
findAll
and grep
when wanting to produce a new list
containing items which don't match some criteria while leaving the original collection unchanged.
self
- a Collection to be modifiedcondition
- a closure condition
public static boolean renameTo(File self, String newPathName)
file
- a Fileclosure
- a closure
public static String replaceAll(String self, Pattern pattern, String replacement)
self
- the CharSequence that is to be matchedpattern
- the regex Pattern to which the CharSequence of interest is to be matchedreplacement
- the CharSequence to be substituted for the first match
public static CharSequence replaceAll(CharSequence self, Pattern pattern, CharSequence replacement)
public static String replaceAll(String self, String regex, Closure closure)
self
- a CharSequenceregex
- the capturing regexclosure
- the closure to apply on each captured group
public static CharSequence replaceAll(CharSequence self, CharSequence regex, Closure closure)
public static CharSequence replaceAll(CharSequence self, CharSequence regex, CharSequence replacement)
public static String replaceAll(String self, Pattern pattern, Closure closure)
self
- a CharSequencepattern
- the capturing regex Patternclosure
- the closure to apply on each captured group
public static String replaceAll(CharSequence self, Pattern pattern, Closure closure)
public static String replaceFirst(String self, Pattern pattern, String replacement)
self
- the CharSequence that is to be matchedpattern
- the regex Pattern to which the CharSequence of interest is to be matchedreplacement
- the CharSequence to be substituted for the first match
public static CharSequence replaceFirst(CharSequence self, Pattern pattern, CharSequence replacement)
public static String replaceFirst(String self, String regex, Closure closure)
public static String replaceFirst(CharSequence self, CharSequence regex, CharSequence replacement)
public static String replaceFirst(CharSequence self, CharSequence regex, Closure closure)
public static String replaceFirst(String self, Pattern pattern, Closure closure)
self
- a CharSequencepattern
- the capturing regex Patternclosure
- the closure to apply on the first captured group
public static String replaceFirst(CharSequence self, Pattern pattern, Closure closure)
public static List respondsTo(Object self, String name, Object[] argTypes)
public static List respondsTo(Object self, String name)
public static boolean retainAll(Collection self, Object[] items)
public static boolean retainAll(Collection self, Closure condition)
public static String reverse(String self)
self
- a String
public static CharSequence reverse(CharSequence self)
public static List reverse(List self)
def list = ["a", 4, false] assert list.reverse(false) == [false, 4, "a"] assert list == ["a", 4, false] assert list.reverse(true) == [false, 4, "a"] assert list == [false, 4, "a"]
self
- a Listmutate
- true if the list itself should be reversed in place and returned, false if a new list should be created
public static List reverse(List self, boolean mutate)
self
- an arraymutate
- true if the array itself should be reversed in place and returned, false if a new array should be created
/** public static Object[] reverse(Object[] self)
self
- an Iterator
for (int i = 0; i < size; i++) { public static Object[] reverse(Object[] self, boolean mutate)
assert [1,2,3,1,2,3] == [1,2,3] * 2
self
- a Collectionfactor
- the number of times to append
public static Iterator reverse(Iterator self)
assert [4,5] == [1,2,3,4,5].intersect([4,5,6,7,8])
left
- a Collectionright
- a Collection
public static Map reverseEach(Map self, Closure closure)
self
- the map over which we iterateclosure
- the 1 or 2 arg closure applied on each entry of the map
public static List reverseEach(List self, Closure closure)
def result = [] [1,2,3].reverseEach { result << it } assert result == [3,2,1]
self
- a Listclosure
- a closure to which each item is passed.
public static Object[] reverseEach(Object[] self, Closure closure)
public static Number rightShift(Number self, Number operand)
public static Number rightShiftUnsigned(Number self, Number operand)
public static int round(Float number)
self
- a String
public static float round(Float number, int precision)
self
- a String
public static long round(Double number)
public static double round(Double number, int precision)
self
- a String
public static TimerTask runAfter(Timer timer, int delay, Closure closure)
public static void setBytes(File file, byte[] bytes)
file
- a Filetext
- the text to append at the end of the File
public static void setBytes(OutputStream os, byte[] bytes)
public static void setIndex(Matcher matcher, int idx)
matcher
- a Matcher
public static void setMetaClass(Class self, MetaClass metaClass)
enumeration
- an Enumeration object
public static void setMetaClass(Object self, MetaClass metaClass)
public static void setText(File file, String text)
file
- a Filetext
- the text to append at the end of the Filecharset
- the charset used
public static void setText(File file, String text, String charset)
dir
- The directory to check
public static int size(Iterator self)
size()
method for String
.
text
- a String
public static int size(String text)
size()
method for CharSequence
.
text
- a CharSequence
public static int size(CharSequence text)
public static int size(StringBuffer buffer)
public static long size(File self)
public static long size(Matcher self)
public static int size(Object[] self)
public static int size(boolean[] array)
public static int size(byte[] array)
public static int size(char[] array)
public static int size(short[] array)
public static int size(int[] array)
public static int size(long[] array)
array
- a float array
public static int size(float[] array)
array
- a double array
public static int size(double[] array)
public static List sort(Collection self)
public static List sort(Collection self, boolean mutate)
public static Map sort(Map self, Closure closure)
public static Map sort(Map self, Comparator comparator)
self
- the array to be sorted
public static Map sort(Map self)
public static Object[] sort(Object[] self)
public static Object[] sort(Object[] self, boolean mutate)
self
- the Iterator to be sortedcomparator
- a Comparator used for comparing items
public static Iterator sort(Iterator self)
public static Iterator sort(Iterator self, Comparator comparator)
public static List sort(Collection self, Comparator comparator)
public static List sort(Collection self, boolean mutate, Comparator comparator)
public static Object[] sort(Object[] self, Comparator comparator)
public static Object[] sort(Object[] self, boolean mutate, Comparator comparator)
public static Iterator sort(Iterator self, Closure closure)
} public static Object[] sort(Object[] self, Closure closure)
/** public static Object[] sort(Object[] self, boolean mutate, Closure closure)
assert ["hi","hey","hello"] == ["hello","hi","hey"].sort { it.length() }
assert ["hi","hey","hello"] == ["hello","hi","hey"].sort { a, b -> a.length() <=> b.length() }
self
- a Collection to be sortedclosure
- a 1 or 2 arg Closure used to determine the correct ordering
public static List sort(Collection self, Closure closure)
assert ["hi","hey","hello"] == ["hello","hi","hey"].sort { it.length() }
assert ["hi","hey","hello"] == ["hello","hi","hey"].sort { a, b -> a.length() <=> b.length() }
def orig = ["hello","hi","Hey"] def sorted = orig.sort(false) { it.toUpperCase() } assert orig == ["hello","hi","Hey"] assert sorted == ["hello","Hey","hi"]
self
- a Collection to be sortedmutate
- false will always cause a new list to be created, true will mutate lists in placeclosure
- a 1 or 2 arg Closure used to determine the correct ordering
public static List sort(Collection self, boolean mutate, Closure closure)
self
- an already sorted set
public static SortedSet sort(SortedSet self)
public static SortedMap sort(SortedMap self)
public static Collection split(Object self, Closure closure)
public static Collection split(Collection self, Closure closure)
public static String[] split(String self)
public static CharSequence[] split(CharSequence self)
self
- A line to expandtabStop
- The number of spaces a tab represents
public static String[] split(GString self)
value
- a Numberright
- a String
public static Object splitEachLine(File self, String regex, Closure closure)
self
- a URL to open and readregex
- the delimiting regular expressioncharset
- opens the file with a specified charsetclosure
- a closure
public static Object splitEachLine(File self, Pattern pattern, Closure closure)
public static Object splitEachLine(File self, String regex, String charset, Closure closure)
public static Object splitEachLine(File self, Pattern pattern, String charset, Closure closure)
public static Object splitEachLine(URL self, String regex, Closure closure)
public static Object splitEachLine(URL self, Pattern pattern, Closure closure)
stream
- an InputStreamregex
- the delimiting regular expressioncharset
- opens the stream with a specified charsetclosure
- a closure
public static Object splitEachLine(URL self, String regex, String charset, Closure closure)
stream
- an InputStreampattern
- the regular expression Pattern for the delimitercharset
- opens the stream with a specified charsetclosure
- a closure
public static Object splitEachLine(URL self, Pattern pattern, String charset, Closure closure)
stream
- an InputStreamregex
- the delimiting regular expressionclosure
- a closure
public static Object splitEachLine(Reader self, String regex, Closure closure)
public static Object splitEachLine(Reader self, Pattern pattern, Closure closure)
self
- a CharSequenceregex
- the delimiting regular expressionclosure
- a closure
public static Object splitEachLine(InputStream stream, String regex, String charset, Closure closure)
self
- a CharSequencepattern
- the regular expression Pattern for the delimiterclosure
- a closure
public static Object splitEachLine(InputStream stream, Pattern pattern, String charset, Closure closure)
public static Object splitEachLine(InputStream stream, String regex, Closure closure)
public static Object splitEachLine(InputStream stream, Pattern pattern, Closure closure)
public static Object splitEachLine(String self, String regex, Closure closure)
public static Object splitEachLine(CharSequence self, CharSequence regex, Closure closure)
public static Object splitEachLine(String self, Pattern pattern, Closure closure)
public static Object splitEachLine(CharSequence self, Pattern pattern, Closure closure)
self
- a String object
public static SpreadMap spread(Map self)
public static String sprintf(Object self, String format, Object[] values)
self
- any Objectformat
- a format stringvalues
- values referenced by the format specifiers in the format string.
public static String sprintf(Object self, String format, Object arg)
self
- any Objectformat
- A format stringarg
- 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 static void step(Number self, Number to, Number stepNumber, Closure closure)
number
- a Double
public static String stripIndent(String self)
public static CharSequence stripIndent(CharSequence self)
self
- The String to check the characters in
public static String stripIndent(String self, int numChars)
public static CharSequence stripIndent(CharSequence self, int numChars)
self
- the String representing a URL
public static String stripMargin(String self)
Strip leading whitespace/control characters followed by '|' from every line in a CharSequence.
self
- The CharSequence to strip the margin from
public static CharSequence stripMargin(CharSequence self)
public static String stripMargin(String self, String marginChar)
public static String stripMargin(CharSequence self, CharSequence marginChar)
public static String stripMargin(String self, char marginChar)
public static CharSequence stripMargin(CharSequence self, char marginChar)
public static Map subMap(Map map, Collection keys)
def map=[:] map.get("a", []) << 5 assert map == [a:[5]]
map
- a Mapkey
- the key to lookup the value ofdefaultValue
- the value to return and add to the map for this key if
there is no entry for the given key
public static Set subsequences(List self)
public static Object sum(Collection self)
self
- The array of values to add together
public static Object sum(Object[] self)
public static Object sum(Iterator self)
public static Object sum(Collection self, Object initialValue)
public static Object sum(Object[] self, Object initialValue)
public static Object sum(Iterator self, Object initialValue)
public static Object sum(Collection self, Closure closure)
array.sum(closure)
is equivalent to:
array.collect(closure).sum()
.
self
- An arrayclosure
- a single parameter closure that returns a numeric value.
public static Object sum(Object[] self, Closure closure)
iter.sum(closure)
is equivalent to:
iter.collect(closure).sum()
. The iterator will become
exhausted of elements after determining the sum value.
self
- An Iteratorclosure
- a single parameter closure that returns a numeric value.
public static Object sum(Iterator self, Closure closure)
coll.sum(initVal, closure)
is equivalent to:
coll.collect(closure).sum(initVal)
.
assert 50+4+6+10+12 == [2,3,5,6].sum(50) { it * 2 }
self
- a Collectionclosure
- a single parameter closure that returns a numeric value.initialValue
- the closure results will be summed to this initial value
public static Object sum(Collection self, Object initialValue, Closure closure)
array.sum(initVal, closure)
is equivalent to:
array.collect(closure).sum(initVal)
.
self
- an arrayclosure
- a single parameter closure that returns a numeric value.initialValue
- the closure results will be summed to this initial value
public static Object sum(Object[] self, Object initialValue, Closure closure)
iter.sum(initVal, closure)
is equivalent to:
iter.collect(closure).sum(initVal)
. The iterator will become
exhausted of elements after determining the sum value.
self
- an Iteratorclosure
- a single parameter closure that returns a numeric value.initialValue
- the closure results will be summed to this initial value
public static Object sum(Iterator self, Object initialValue, Closure closure)
public static List tail(List self)
public static Object[] tail(Object[] self)
public static List take(List self, int num)
num
elements from the head of this array.
String[] strings = [ 'a', 'b', 'c' ] assert strings.take( 0 ) == [] as String[] assert strings.take( 2 ) == [ 'a', 'b' ] as String[] assert strings.take( 5 ) == [ 'a', 'b', 'c' ] as String[]
self
- the original arraynum
- the number of elements to take from this arraynum
elements of this array,
or else the whole array if it has less then num
elements.
public static Object[] take(Object[] self, int num)
num
elements from the head of this Iterable.
class AbcIterable implements Iterable{ Iterator iterator() { "abc".iterator() } } def abc = new AbcIterable() assert abc.take(0) == [] assert abc.take(1) == ['a'] assert abc.take(3) == ['a', 'b', 'c'] assert abc.take(5) == ['a', 'b', 'c']
self
- the original Iterablenum
- the number of elements to take from this Iterablenum
elements from this Iterable,
or else all the elements from the Iterable if it has less then num
elements.
public static List take(Iterable self, int num)
num
elements from the head of this map.
If the map instance does not have ordered keys, then this function could return a random num
entries. Groovy by default uses LinkedHashMap, so this shouldn't be an issue in the main.
def strings = [ 'a':10, 'b':20, 'c':30 ] assert strings.take( 0 ) == [:] assert strings.take( 2 ) == [ 'a':10, 'b':20 ] assert strings.take( 5 ) == [ 'a':10, 'b':20, 'c':30 ]
self
- the original mapnum
- the number of elements to take from this mapnum
elements of this map,
or else the whole map if it has less then num
elements.
public static Map take(Map self, int num)
*public static Iterator take(Iterator self, int num)
public static CharSequence take(CharSequence self, int num)
public static List takeWhile(List self, Closure condition)
class AbcIterable implements Iterable{ Iterator iterator() { "abc".iterator() } } def abc = new AbcIterable() assert abc.takeWhile{ it < 'b' } == ['a'] assert abc.takeWhile{ it <= 'b' } == ['a', 'b']
self
- an Iterablecondition
- the closure that must evaluate to true to
continue taking elements
public static List takeWhile(Iterable self, Closure condition)
def shopping = [milk:1, bread:2, chocolate:3] assert shopping.takeWhile{ it.key.size() < 6 } == [milk:1, bread:2] assert shopping.takeWhile{ it.value % 2 } == [milk:1] assert shopping.takeWhile{ k, v -> k.size() + v <= 7 } == [milk:1, bread:2]If the map instance does not have ordered keys, then this function could appear to take random entries. Groovy by default uses LinkedHashMap, so this shouldn't be an issue in the main.
self
- a Mapcondition
- a 1 (or 2) arg Closure that must evaluate to true for the
entry (or key and value) to continue taking elements
public static Map takeWhile(Map self, Closure condition)
def nums = [ 1, 3, 2 ] as Integer[] assert nums.takeWhile{ it < 1 } == [] as Integer[] assert nums.takeWhile{ it < 3 } == [ 1 ] as Integer[] assert nums.takeWhile{ it < 4 } == [ 1, 3, 2 ] as Integer[]
self
- the original arraycondition
- the closure that must evaluate to true to
continue taking elements
public static Object[] takeWhile(Object[] self, Closure condition)
public static Iterator takeWhile(Iterator self, Closure condition)
public static CharSequence takeWhile(CharSequence self, Closure closure)
array
- an Array of Objectsrange
- an IntRange
public static void times(Number self, Closure closure)
self
- a doubleto
- the end numberclosure
- the code to execute for each number
public static String toArrayString(Object[] self)
left
- a Characterright
- a Number
public static BigDecimal toBigDecimal(String self)
public static BigDecimal toBigDecimal(CharSequence self)
public static BigDecimal toBigDecimal(Number self)
left
- left operatorright
- right operator
public static BigInteger toBigInteger(String self)
public static BigInteger toBigInteger(CharSequence self)
public static BigInteger toBigInteger(Number self)
file
- a file
public static Boolean toBoolean(String self)
public static Boolean toBoolean(Boolean self)
public static Character toCharacter(String self)
self
- A CharSequence to expand
public static Double toDouble(String self)
public static Double toDouble(CharSequence self)
public static Double toDouble(Number self)
left
- left operatorright
- right operator
public static Float toFloat(String self)
public static Float toFloat(CharSequence self)
public static Float toFloat(Number self)
left
- left operatorright
- right operator
public static Integer toInteger(String self)
self
- a String
public static Integer toInteger(CharSequence self)
public static Integer toInteger(Number self)
public static List toList(Collection self)
public static List toList(Iterator self)
public static List toList(Iterable self)
public static List toList(Enumeration self)
public static List toList(Object[] array)
* @return a set containing the unique contents of this array. public static List toList(byte[] array)
* @return a set containing the unique contents of this array. public static List toList(boolean[] array)
* @return a set containing the unique contents of this array. public static List toList(char[] array)
* @return a set containing the unique contents of this array. public static List toList(short[] array)
* @return a set containing the unique contents of this array. public static List toList(int[] array)
* @return a set containing the unique contents of this array. public static List toList(long[] array)
* @return a set containing the unique contents of this array. public static List toList(float[] array)
*public static List toList(double[] array)
public static List toList(String self)
public static List toList(CharSequence self)
public static String toListString(Collection self)
public static String toListString(Collection self, int maxSize)
public static Long toLong(String self)
public static Long toLong(CharSequence self)
public static Long toLong(Number self)
public static char toLowerCase(Character self)
self
- a Number
public static String toMapString(Map self)
public static String toMapString(Map self, int maxSize)
return answer; public static Set toSet(byte[] array)
while (self.hasNext()) { public static Set toSet(boolean[] array)
self
- an iterator
public staticSet toSet(Enumeration self) { public static Set toSet(char[] array)
self
- an enumeration
* @return the returned value from the array public static Set toSet(short[] array)
* @since 1.5.0 public static Set toSet(int[] array)
* value in the collection argument is assumed to be a valid array index. public static Set toSet(long[] array)
} else if (value instanceof List) { public static Set toSet(float[] array)
* @param self an object public static Set toSet(double[] array)
public static Set toSet(Collection self)
public static Set toSet(Iterator self)
public static Set toSet(Enumeration self)
public static Set toSet(String self)
public static Set toSet(CharSequence self)
public static Short toShort(String self)
public static Short toShort(CharSequence self)
public static SpreadMap toSpreadMap(Map self)
self
- a list
public static SpreadMap toSpreadMap(Object[] self)
public static SpreadMap toSpreadMap(List self)
public static String toString(boolean[] self)
public static String toString(byte[] self)
public static String toString(char[] self)
[1, 2, a]
.
self
- a Collection
public static String toString(short[] self)
public static String toString(int[] self)
public static String toString(long[] self)
public static String toString(float[] self)
public static String toString(double[] self)
public static String toString(AbstractMap self)
public static String toString(AbstractCollection self)
public static String toString(Object[] self)
public static String toString(Object value)
public static URI toURI(String self)
public static URI toURI(CharSequence self)
public static URL toURL(String self)
public static URL toURL(CharSequence self)
public static char toUpperCase(Character self)
public static List tokenize(String self, String token)
left
- a StringBuffervalue
- a String
public static List tokenize(CharSequence self, CharSequence token)
self
- a Stringtarget
- an object representing the part to remove
public static List tokenize(String self, Character token)
public static List tokenize(CharSequence self, Character token)
* Provide an implementation of contains() like public static List tokenize(String self)
public static List tokenize(CharSequence self)
public static String tr(String self, String sourceSet, String replacementSet)
self
- the CharSequence that is to be translatedsourceSet
- the set of characters to translate fromreplacementSet
- the set of replacement characters
public static CharSequence tr(CharSequence self, CharSequence sourceSet, CharSequence replacementSet)
self
- the CharSequence that is to be matchedpattern
- the regex Pattern to which the string of interest is to be matched
public static void transformChar(Reader self, Writer writer, Closure closure)
true
if the line should be passed to the writer.
reader
- this readerclosure
- a closure used for filtering
public static void transformLine(Reader reader, Writer writer, Closure closure)
public static List transpose(List self)
public static void traverse(File self, Map options, Closure closure)
self
- a Fileclosure
- a closure
public static void traverse(File self, Closure closure)
self
- a filenameFilter
- the nameFilter to perform on the name of the file (using the isCase(java.lang.Object, java.lang.Object) method)closure
- the closure to invoke
public static void traverse(File self, Map options)
self
- a filenameFilter
- the nameFilter to perform on the name of the directory (using the isCase(java.lang.Object, java.lang.Object) method)closure
- the closure to invoke
public static float trunc(Float number, int precision)
public static float trunc(Float number)
public static double trunc(Double number)
public static double trunc(Double number, int precision)
public static Number unaryMinus(Number left)
public static String unexpand(String self)
public static CharSequence unexpand(CharSequence self)
public static String unexpand(String self, int tabStop)
public static CharSequence unexpand(CharSequence self, int tabStop)
self
- a CharSequencetoken
- the delimiter
public static String unexpandLine(String self, int tabStop)
public static CharSequence unexpandLine(CharSequence self, int tabStop)
left
- a Stringvalue
- any Object
public static Iterator unique(Iterator self)
public static Collection unique(Collection self)
public static Collection unique(Collection self, boolean mutate)
public static Iterator unique(Iterator self, Closure closure)
public static Collection unique(Collection self, Closure closure)
public static Collection unique(Collection self, boolean mutate, Closure closure)
public static Iterator unique(Iterator self, Comparator comparator)
self
- an Iteratorcomparator
- a Comparator
public static Collection unique(Collection self, Comparator comparator)
public static Collection unique(Collection self, boolean mutate, Comparator comparator)
public static void upto(Number self, Number to, Closure closure)
self
- a Doubleto
- the end numberclosure
- the code to execute for each number
public static void upto(long self, Number to, Closure closure)
0.upto( 10 ) { println it }Prints numbers 0 to 10
self
- a BigIntegerto
- the end numberclosure
- the code to execute for each number
public static void upto(Long self, Number to, Closure closure)
public static void upto(float self, Number to, Closure closure)
public static void upto(Float self, Number to, Closure closure)
public static void upto(double self, Number to, Closure closure)
public static void upto(Double self, Number to, Closure closure)
public static void upto(BigInteger self, Number to, Closure closure)
self
- a Longto
- the end numberclosure
- the code to execute for each number
public static void upto(BigDecimal self, Number to, Closure closure)
self
- a floatto
- the end numberclosure
- the code to execute for each number
public static Object use(Object self, Class categoryClass, Closure closure)
self
- any ObjectcategoryClass
- a category class to useclosure
- the closure to invoke with the category in place
public static Object use(Object self, List categoryClassList, Closure closure)
self
- any ObjectcategoryClassList
- a list of category classesclosure
- the closure to invoke with the categories in place
public static Object use(Object self, Object[] array)
use(CategoryClass1, CategoryClass2) { ... }
This method saves having to wrap the the category
classes in a list.
self
- any Objectarray
- a list of category classes and a Closure
public static Object with(Object self, Closure closure)
def b = new StringBuilder().with { append('foo') append('bar') return it } assert b.toString() == 'foobar'This is commonly used to simplify object creation, such as this example:
def p = new Person().with { firstName = 'John' lastName = 'Doe' return it }
self
- the object to have a closure act uponclosure
- the closure to call on the object
public static Object withDataInputStream(File file, Closure closure)
public static Object withDataOutputStream(File file, Closure closure)
file
- a File
public static Map withDefault(Map self, Closure init)
public static List withDefault(List self, Closure init)
public static List withEagerDefault(List self, Closure init)
assert [1,2,3] == [3,1,2].sort()
self
- the collection to be sorted
public static Object withInputStream(File file, Closure closure)
file
- a Filecharset
- the charset usedclosure
- a closure
public static Object withInputStream(URL url, Closure closure)
file
- a Fileclosure
- a closure
public static List withLazyDefault(List self, Closure init)
public static Object withObjectInputStream(File file, Closure closure)
self
- a Fileclosure
- a closure (arg 1 is line, optional arg 2 is line number starting at line 1)
public static Object withObjectInputStream(File file, ClassLoader classLoader, Closure closure)
public static Object withObjectInputStream(InputStream inputStream, Closure closure)
public static Object withObjectInputStream(InputStream inputStream, ClassLoader classLoader, Closure closure)
public static Object withObjectOutputStream(File file, Closure closure)
public static Object withObjectOutputStream(OutputStream outputStream, Closure closure)
inputStream
- an input streamclosure
- a closure
public static Object withObjectStreams(Socket socket, Closure closure)
self
- a String
public static Object withOutputStream(File file, Closure closure)
public static Object withPrintWriter(File file, Closure closure)
public static Object withPrintWriter(File file, String charset, Closure closure)
public static Object withPrintWriter(Writer writer, Closure closure)
public static Object withReader(File file, Closure closure)
public static Object withReader(File file, String charset, Closure closure)
stream
- the FileOutputStream to write the BOM tobigEndian
- true if UTF 16 Big Endian or false if Low Endian
public static Object withReader(Reader reader, Closure closure)
file
- a File
public static Object withReader(URL url, Closure closure)
url
- a URL
public static Object withReader(URL url, String charset, Closure closure)
public static Object withReader(InputStream in, Closure closure)
public static Object withReader(InputStream in, String charset, Closure closure)
url
- a URLcharset
- opens the stream with a specified charset
public static Object withStream(InputStream stream, Closure closure)
public static Object withStream(OutputStream os, Closure closure)
public static Object withStreams(Socket socket, Closure closure)
f
- a Filec
- the desired class
public static Object withWriter(File file, Closure closure)
reader
- the reader which is used and then closedclosure
- the closure that the writer is passed into
public static Object withWriter(File file, String charset, Closure closure)
stream
- the stream which is used and then closedclosure
- the closure that the stream is passed into
public static Object withWriter(Writer writer, Closure closure)
public static Object withWriter(OutputStream stream, Closure closure)
url
- a URLparameters
- connection parameterscharset
- opens the stream with a specified charset
public static Object withWriter(OutputStream stream, String charset, Closure closure)
file
- a File
public static Object withWriterAppend(File file, String charset, Closure closure)
public static Object withWriterAppend(File file, Closure closure)
public static void write(Writer self, Writable writable)
public static void write(File file, String text)
self
- a Filestream
- stream to read data from.
public static void write(File file, String text, String charset)
public static void writeLine(BufferedWriter writer, String line)
public static BitSet xor(BitSet left, BitSet right)
self
- a longto
- the end numberclosure
- the code to execute for each number
public static Number xor(Number left, Number right)
self
- a floatto
- the end numberclosure
- the code to execute for each number
public static Boolean xor(Boolean left, Boolean right)
Copyright © 2003-2012 The Codehaus. All rights reserved.