Package groovy.lang
Class GString
java.lang.Object
groovy.lang.GroovyObjectSupport
groovy.lang.GString
- All Implemented Interfaces:
- Buildable,- GroovyObject,- Writable,- java.io.Serializable,- java.lang.CharSequence,- java.lang.Comparable
- Direct Known Subclasses:
- GStringImpl
public abstract class GString extends GroovyObjectSupport implements java.lang.Comparable, java.lang.CharSequence, Writable, Buildable, java.io.Serializable
Represents a String which contains embedded values such as "hello there
 ${user} how are you?" which can be evaluated lazily. Advanced users can
 iterate over the text and values to perform special processing, such as for
 performing SQL operations, the values can be substituted for ? and the
 actual value objects can be bound to a JDBC statement.
 
James Strachan: The lovely name of this class was suggested by Jules Gosnell and was such a good idea, I couldn't resist :)
- See Also:
- Serialized Form
- 
Field SummaryFields Modifier and Type Field Description static GStringEMPTYA GString containing a single empty String and no values.static java.lang.Object[]EMPTY_OBJECT_ARRAYstatic java.lang.String[]EMPTY_STRING_ARRAY
- 
Constructor Summary
- 
Method SummaryModifier and Type Method Description voidbuild(GroovyObject builder)charcharAt(int index)intcompareTo(java.lang.Object that)booleanequals(GString that)booleanequals(java.lang.Object that)byte[]getBytes()byte[]getBytes(java.lang.String charset)abstract java.lang.String[]getStrings()java.lang.ObjectgetValue(int idx)intgetValueCount()java.lang.Object[]getValues()inthashCode()java.lang.ObjectinvokeMethod(java.lang.String name, java.lang.Object args)Overloaded to implement duck typing for Strings so that any method that can't be evaluated on this object will be forwarded to the toString() object instead.intlength()java.util.regex.Patternnegate()Turns a String into a regular expression patternGStringplus(GString that)GStringplus(java.lang.String that)java.lang.CharSequencesubSequence(int start, int end)java.lang.StringtoString()java.io.WriterwriteTo(java.io.Writer out)Writes this object to the given writer.Methods inherited from class groovy.lang.GroovyObjectSupportgetMetaClass, setMetaClassMethods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.CharSequencechars, codePoints, isEmptyMethods inherited from interface groovy.lang.GroovyObjectgetProperty, setProperty
- 
Field Details- 
EMPTY_STRING_ARRAYpublic static final java.lang.String[] EMPTY_STRING_ARRAY
- 
EMPTY_OBJECT_ARRAYpublic static final java.lang.Object[] EMPTY_OBJECT_ARRAY
- 
EMPTYA GString containing a single empty String and no values.
 
- 
- 
Constructor Details- 
GStringpublic GString(java.lang.Object values)
- 
GStringpublic GString(java.lang.Object[] values)
 
- 
- 
Method Details- 
getStringspublic abstract java.lang.String[] getStrings()
- 
invokeMethodpublic java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args)Overloaded to implement duck typing for Strings so that any method that can't be evaluated on this object will be forwarded to the toString() object instead.- Specified by:
- invokeMethodin interface- GroovyObject
- Parameters:
- name- the name of the method to call
- args- the arguments to use for the method call
- Returns:
- the result of invoking the method
 
- 
getValuespublic java.lang.Object[] getValues()
- 
plus
- 
plus
- 
getValueCountpublic int getValueCount()
- 
getValuepublic java.lang.Object getValue(int idx)
- 
toStringpublic java.lang.String toString()- Specified by:
- toStringin interface- java.lang.CharSequence
- Overrides:
- toStringin class- java.lang.Object
 
- 
writeTopublic java.io.Writer writeTo(java.io.Writer out) throws java.io.IOExceptionDescription copied from interface:WritableWrites this object to the given writer.This is used to defer content creation until the point when it is streamed to the output destination. Oftentimes, content will be defined but not necessarily created (as is may be the case with a Closure definition.) In that case, the output is then 'deferred' to the point when it is serialized to the writer. This class may be used whenever an object should be responsible for creating its own textual representation, but creating the entire output as a single String would be inefficient (such as outputting a multi-gigabyte XML document.) 
- 
build
- 
hashCodepublic int hashCode()- Overrides:
- hashCodein class- java.lang.Object
 
- 
equalspublic boolean equals(java.lang.Object that)- Overrides:
- equalsin class- java.lang.Object
 
- 
equals
- 
compareTopublic int compareTo(java.lang.Object that)- Specified by:
- compareToin interface- java.lang.Comparable
 
- 
charAtpublic char charAt(int index)- Specified by:
- charAtin interface- java.lang.CharSequence
 
- 
lengthpublic int length()- Specified by:
- lengthin interface- java.lang.CharSequence
 
- 
subSequencepublic java.lang.CharSequence subSequence(int start, int end)- Specified by:
- subSequencein interface- java.lang.CharSequence
 
- 
negatepublic java.util.regex.Pattern negate()Turns a String into a regular expression pattern- Returns:
- the regular expression pattern
 
- 
getBytespublic byte[] getBytes()
- 
getBytespublic byte[] getBytes(java.lang.String charset) throws java.io.UnsupportedEncodingException- Throws:
- java.io.UnsupportedEncodingException
 
 
-