Class GStringImpl
- java.lang.Object
-
- groovy.lang.GroovyObjectSupport
-
- groovy.lang.GString
-
- org.codehaus.groovy.runtime.GStringImpl
-
- All Implemented Interfaces:
Buildable,GroovyObject,Writable,Serializable,CharSequence,Comparable
public class GStringImpl extends GString
Default implementation of a GString used by the compiler. A GString consists of a list of values and strings which can be combined to create a new String.- See Also:
GString, Serialized Form
-
-
Field Summary
-
Fields inherited from class groovy.lang.GString
EMPTY, EMPTY_OBJECT_ARRAY, EMPTY_STRING_ARRAY
-
-
Constructor Summary
Constructors Modifier Constructor Description GStringImpl(Object[] values, String[] strings)Create a new GString with values and strings.protectedGStringImpl(Object[] values, String[] strings, boolean cacheable, String cachedStringLiteral, boolean frozen)Create a new GString with values and strings.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbuild(GroovyObject builder)protected intcalcInitialCapacity()intcodePointAt(int index)intcodePointBefore(int index)intcodePointCount(int beginIndex, int endIndex)intcompareTo(String anotherString)intcompareToIgnoreCase(String str)Stringconcat(String str)booleancontains(CharSequence s)booleancontentEquals(CharSequence cs)booleancontentEquals(StringBuffer sb)booleanendsWith(String suffix)booleanequalsIgnoreCase(String anotherString)GStringfreeze()byte[]getBytes(Charset charset)voidgetChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)String[]getStrings()Get the strings of this GString.Object[]getValues()intindexOf(int ch)intindexOf(int ch, int fromIndex)intindexOf(String str)intindexOf(String str, int fromIndex)Stringintern()booleanisEmpty()intlastIndexOf(int ch)intlastIndexOf(int ch, int fromIndex)intlastIndexOf(String str)intlastIndexOf(String str, int fromIndex)booleanmatches(String regex)intoffsetByCodePoints(int index, int codePointOffset)GStringplus(GString that)booleanregionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len)booleanregionMatches(int toffset, String other, int ooffset, int len)Stringreplace(char oldChar, char newChar)Stringreplace(CharSequence target, CharSequence replacement)StringreplaceAll(String regex, String replacement)StringreplaceFirst(String regex, String replacement)String[]split(String regex)String[]split(String regex, int limit)booleanstartsWith(String prefix)booleanstartsWith(String prefix, int toffset)Stringsubstring(int beginIndex)Stringsubstring(int beginIndex, int endIndex)char[]toCharArray()StringtoLowerCase()StringtoLowerCase(Locale locale)StringtoString()StringtoUpperCase()StringtoUpperCase(Locale locale)Stringtrim()WriterwriteTo(Writer out)Writes this object to the given writer.-
Methods inherited from class groovy.lang.GString
charAt, compareTo, equals, equals, getBytes, getBytes, getValue, getValueCount, hashCode, invokeMethod, length, negate, plus, subSequence
-
Methods inherited from class groovy.lang.GroovyObjectSupport
getMetaClass, setMetaClass
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.CharSequence
chars, codePoints
-
Methods inherited from interface groovy.lang.GroovyObject
getProperty, setProperty
-
-
-
-
Constructor Detail
-
GStringImpl
public GStringImpl(Object[] values, String[] strings)
Create a new GString with values and strings.Each value is prefixed by a string, after the last value an additional String might be used, hence the following constraint is expected to hold:
strings.length == values.length || strings.length == values.length + 1.NOTE: The lengths are not checked but using arrays with lengths which violate the above constraint could result in unpredictable behaviour.
- Parameters:
values- the value partsstrings- the string parts
-
GStringImpl
protected GStringImpl(Object[] values, String[] strings, boolean cacheable, String cachedStringLiteral, boolean frozen)
Create a new GString with values and strings.Each value is prefixed by a string, after the last value an additional String might be used, hence the following constraint is expected to hold:
strings.length == values.length || strings.length == values.length + 1.NOTE: The lengths are not checked but using arrays with lengths which violate the above constraint could result in unpredictable behaviour.
- Parameters:
values- the value partsstrings- the string partsfrozen- creates a GStringImpl which is not subject to mutation and hence more amenable to caching
-
-
Method Detail
-
writeTo
public Writer writeTo(Writer out) throws IOException
Description 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.)
- Specified by:
writeToin interfaceWritable- Overrides:
writeToin classGString- Parameters:
out- the Writer to which this Writable should output its data.- Returns:
- the Writer that was passed
- Throws:
IOException- if an error occurred while outputting data to the writer
-
build
public void build(GroovyObject builder)
-
calcInitialCapacity
protected int calcInitialCapacity()
- Overrides:
calcInitialCapacityin classGString
-
freeze
public GString freeze()
- Returns:
- returns an equivalent optimised but less mutable version of this GString
-
getStrings
public String[] getStrings()
Get the strings of this GString.This methods returns the same array as used in the constructor. Changing the values will result in changes of the GString. It is generally not recommended to do so.
- Specified by:
getStringsin classGString
-
trim
public String trim()
-
isEmpty
public boolean isEmpty()
-
codePointAt
public int codePointAt(int index)
-
codePointBefore
public int codePointBefore(int index)
-
codePointCount
public int codePointCount(int beginIndex, int endIndex)
-
offsetByCodePoints
public int offsetByCodePoints(int index, int codePointOffset)
-
getChars
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
-
getBytes
public byte[] getBytes(Charset charset)
-
contentEquals
public boolean contentEquals(StringBuffer sb)
-
contentEquals
public boolean contentEquals(CharSequence cs)
-
equalsIgnoreCase
public boolean equalsIgnoreCase(String anotherString)
-
compareTo
public int compareTo(String anotherString)
-
compareToIgnoreCase
public int compareToIgnoreCase(String str)
-
regionMatches
public boolean regionMatches(int toffset, String other, int ooffset, int len)
-
regionMatches
public boolean regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len)
-
startsWith
public boolean startsWith(String prefix, int toffset)
-
startsWith
public boolean startsWith(String prefix)
-
endsWith
public boolean endsWith(String suffix)
-
indexOf
public int indexOf(int ch)
-
indexOf
public int indexOf(int ch, int fromIndex)
-
lastIndexOf
public int lastIndexOf(int ch)
-
lastIndexOf
public int lastIndexOf(int ch, int fromIndex)
-
indexOf
public int indexOf(String str)
-
indexOf
public int indexOf(String str, int fromIndex)
-
lastIndexOf
public int lastIndexOf(String str)
-
lastIndexOf
public int lastIndexOf(String str, int fromIndex)
-
substring
public String substring(int beginIndex)
-
substring
public String substring(int beginIndex, int endIndex)
-
replace
public String replace(char oldChar, char newChar)
-
matches
public boolean matches(String regex)
-
contains
public boolean contains(CharSequence s)
-
replace
public String replace(CharSequence target, CharSequence replacement)
-
toLowerCase
public String toLowerCase()
-
toUpperCase
public String toUpperCase()
-
toCharArray
public char[] toCharArray()
-
intern
public String intern()
-
toString
public String toString()
- Specified by:
toStringin interfaceCharSequence- Overrides:
toStringin classGString
-
-