|
Groovy JDK |
Method Summary | |
---|---|
Object
|
asType(Class c)
Provides a method to perform custom 'dynamic' type conversion
to the given class using the By default, the following types are supported:
|
Pattern
|
bitwiseNegate()
Turns a String into a regular expression pattern |
String
|
center(Number numberOfChars, String padding)
Center a String and padd it with the characters appended around it |
String
|
center(Number numberOfChars)
Center a String and padd it with spaces appended around it |
boolean
|
contains(String text)
Provide an implementation of contains() like {@link Collection#contains(Object)} to make Strings more polymorphic This method is not required on JDK 1 |
int
|
count(String text)
Count the number of occurencies of a substring |
byte[]
|
decodeBase64()
Decode the String from Base64 into a byte array |
Object
|
eachLine(Closure closure)
Iterates through this String line by line to the given 1 or 2 arg closure the line count is passed as the second argument |
Object
|
eachLine(int firstLine, Closure closure)
Iterates through this String line by line to the given 1 or 2 arg closure the line count is passed as the second argument |
void
|
eachMatch(String regex, Closure closure)
Process each regex group matched substring of the given string parameter takes one argument, an array with all match groups is passed to it If the closure takes as many arguments as there are match groups, then each parameter will be one match group |
Process
|
execute()
Executes the given string as a command line process over the process mechanism in JDK 1 |
Process
|
execute(String[] envp, File dir)
Executes the command specified by the self with environments envp
under the working directory dir
For more control over the process mechanism in JDK 1
|
Process
|
execute(List envp, File dir)
Executes the command specified by the self with environments envp
under the working directory dir
For more control over the process mechanism in JDK 1
|
String
|
getAt(int index)
Support the subscript operator for String |
String
|
getAt(IntRange range)
Support the range subscript operator for String with IntRange |
String
|
getAt(EmptyRange range)
Support the range subscript operator for String with EmptyRange |
String
|
getAt(Range range)
Support the range subscript operator for String |
String
|
getAt(Collection indices)
Allows a List to be used as the indices to be used on a String |
char[]
|
getChars()
Converts the given String into an array of characters Alias for toCharArray |
boolean
|
isBigDecimal()
Determine if a String can be parsed into a BigDecimal |
boolean
|
isBigInteger()
Determine if a String can be parsed into a BigInteger |
boolean
|
isCase(Object switchValue)
'Case' implementation for a String, which uses String#equals(Object) in order to allow Strings to be used in switch statements For example: switch( str ) { case 'one' : // etc }Note that this returns true for the case where both the
'switch' and 'case' operand is null
|
boolean
|
isDouble()
Determine if a String can be parsed into a Double |
boolean
|
isFloat()
Determine if a String can be parsed into a Float |
boolean
|
isInteger()
Determine if a String can be parsed into an Integer |
boolean
|
isLong()
Determine if a String can be parsed into a Long |
boolean
|
isNumber()
Determine if a String can be parsed into a Number Synonym for 'isBigDecimal()' |
StringBuffer
|
leftShift(Object value)
Overloads the left shift operator to provide an easy way to append multiple objects as string representations to a String |
String
|
minus(Object target)
Remove a part of a String of target within self with '' and returns the result target is a regex Pattern, the first occurrence of that pattern will be removed (using regex matching), otherwise the first occurrence of target |
String
|
multiply(Number factor)
Repeat a String a certain number of times |
String
|
next()
This method is called by the ++ operator for the class String It increments the last character in the given string character in the string is Character will be appended consisting of the character Character |
String
|
padLeft(Number numberOfChars, String padding)
Pad a String with the characters appended to the left |
String
|
padLeft(Number numberOfChars)
Pad a String with the spaces appended to the left |
String
|
padRight(Number numberOfChars, String padding)
Pad a String with the characters appended to the right |
String
|
padRight(Number numberOfChars)
Pad a String with the spaces appended to the right |
String
|
plus(Object value)
Appends the String representation of the given operand to this string |
String
|
previous()
This method is called by the -- operator for the class String It decrements the last character in the given string character in the string is Character The empty string can't be decremented |
List
|
readLines()
Return the lines of a String as a List of Strings |
String
|
replaceAll(String regex, Closure closure)
Replaces all occurrencies of a captured group by the result of a closure on that text For examples, assert "FOOBAR-FOOBAR-" == "foobar-FooBar-" Here, it[0] is the global string of the matched group it[1] is the first string in the matched group it[2] is the second string in the matched group assert "FOO-FOO-" == "foobar-FooBar-" Here, x is the global string of the matched group y is the first string in the matched group z is the second string in the matched group |
String
|
reverse()
Creates a new string which is the reverse (backwards) of this string |
int
|
size()
Provide the standard Groovy size() method for String
|
String[]
|
split()
Convenience method to split a string (with whitespace as delimiter) Like tokenize, but returns an Array of Strings instead of a List |
Object
|
splitEachLine(String sep, Closure closure)
Iterates through the given String line by line, splitting each line using the given separator the given closure |
BigDecimal
|
toBigDecimal()
Parse a String into a BigDecimal |
BigInteger
|
toBigInteger()
Parse a String into a BigInteger |
Boolean
|
toBoolean()
Converts the given string into a Boolean object If the trimmed string is "true", "y" or "1" (ignoring case) then the result is true othewrwise it is false |
Character
|
toCharacter()
Converts the given string into a Character object using the first character in the string |
Double
|
toDouble()
Parse a String into a Double |
Float
|
toFloat()
Parse a String into a Float |
Integer
|
toInteger()
Parse a String into an Integer |
List
|
toList()
Converts the given String into a List of strings of one character |
Long
|
toLong()
Parse a String into a Long |
Short
|
toShort()
Parse a String into a Short |
URI
|
toURI()
Transforms a String representing a URI into a URI object |
URL
|
toURL()
Transforms a String representing a URL into a URL object |
List
|
tokenize(String token)
Tokenize a String based on the given string delimiter |
List
|
tokenize()
Tokenize a String (with a whitespace as the delimiter) |
Method Detail |
---|
public Object asType(Class c)
Provides a method to perform custom 'dynamic' type conversion
to the given class using the as
operator.
'123' as Double
By default, the following types are supported:
c
- the desired class.
public Pattern bitwiseNegate()
public String center(Number numberOfChars, String padding)
numberOfChars
- the total number of characters.
padding
- the charaters used for padding.
public String center(Number numberOfChars)
numberOfChars
- the total number of characters.
public boolean contains(String text)
text
- a String to look for.
public int count(String text)
text
- a substring.
public byte[] decodeBase64()
public Object eachLine(Closure closure)
closure
- a closure.
public Object eachLine(int firstLine, Closure closure)
firstLine
- the count of the first line.
closure
- a closure.
public void eachMatch(String regex, Closure closure)
regex
- a Regex string.
closure
- a closure with one parameter or as much parameters as groups.
public Process execute()
public Process execute(String[] envp, File dir)
self
with environments envp
under the working directory dir
.
For more control over the process mechanism in JDK 1.5 you can use java.lang.ProcessBuilder
.
envp
has
name=value,
null
the
- an array of Strings, each element of which
has environment variable settings in the format
name=value, or
null if the subprocess should inherit
the environment of the current process..
dir
null
the
- the working directory of the subprocess, or
null if the subprocess should inherit
the working directory of the current process..
public Process execute(List envp, File dir)
self
with environments envp
under the working directory dir
.
For more control over the process mechanism in JDK 1.5 you can use java.lang.ProcessBuilder
.
envp
has
name=value,
null
the
- a List of Strings, each member of which
has environment variable settings in the format
name=value, or
null if the subprocess should inherit
the environment of the current process..
dir
null
the
- the working directory of the subprocess, or
null if the subprocess should inherit
the working directory of the current process..
public String getAt(int index)
index
- the index of the Character to get.
public String getAt(IntRange range)
range
- an IntRange.
public String getAt(EmptyRange range)
range
- an EmptyRange.
public String getAt(Range range)
range
- a Range.
public String getAt(Collection indices)
indices
- a Collection of indices.
public char[] getChars()
public boolean isBigDecimal()
public boolean isBigInteger()
public boolean isCase(Object switchValue)
switch( str ) { case 'one' : // etc... }Note that this returns
true
for the case where both the
'switch' and 'case' operand is null
.
switchValue
- the switch value.
public boolean isDouble()
public boolean isFloat()
public boolean isInteger()
public boolean isLong()
public boolean isNumber()
public StringBuffer leftShift(Object value)
value
- an Obect.
public String minus(Object target)
target
- an object representing the part to remove.
public String multiply(Number factor)
factor
- the number of times the String should be repeated.
public String next()
public String padLeft(Number numberOfChars, String padding)
numberOfChars
- the total number of characters.
padding
- the charaters used for padding.
public String padLeft(Number numberOfChars)
numberOfChars
- the total number of characters.
public String padRight(Number numberOfChars, String padding)
numberOfChars
- the total number of characters.
padding
- the charaters used for padding.
public String padRight(Number numberOfChars)
numberOfChars
- the total number of characters.
public String plus(Object value)
value
- any Object.
public String previous()
public List readLines()
public String replaceAll(String regex, Closure closure)
For examples,
assert "FOOBAR-FOOBAR-" == "foobar-FooBar-".replaceAll("(([fF][oO]{2})[bB]ar)", { Object[] it -> it[0].toUpperCase() }) Here, it[0] is the global string of the matched group it[1] is the first string in the matched group it[2] is the second string in the matched group assert "FOO-FOO-" == "foobar-FooBar-".replaceAll("(([fF][oO]{2})[bB]ar)", { x, y, z -> z.toUpperCase() }) Here, x is the global string of the matched group y is the first string in the matched group z is the second string in the matched group
regex
- the capturing regex.
closure
- the closure to apply on each captured group.
public String reverse()
public int size()
size()
method for String
.
public String[] split()
public Object splitEachLine(String sep, Closure closure)
sep
- a String separator.
closure
- a closure.
public BigDecimal toBigDecimal()
public BigInteger toBigInteger()
public Boolean toBoolean()
public Character toCharacter()
public Double toDouble()
public Float toFloat()
public Integer toInteger()
public List toList()
public Long toLong()
public Short toShort()
public URI toURI()
public URL toURL()
public List tokenize(String token)
token
- the delimiter.
public List tokenize()
|
Groovy JDK |