Class GStringImpl
- All Implemented Interfaces:
Buildable
,GroovyObject
,Writable
,Serializable
,CharSequence
,Comparable
- See Also:
-
Field Summary
Fields inherited from class groovy.lang.GString
EMPTY, EMPTY_OBJECT_ARRAY, EMPTY_STRING_ARRAY
-
Constructor Summary
ModifierConstructorDescriptionGStringImpl
(Object[] values, String[] strings) Create a new GString with values and strings.protected
GStringImpl
(Object[] values, String[] strings, boolean cacheable, String cachedStringLiteral, boolean frozen) Create a new GString with values and strings. -
Method Summary
Modifier and TypeMethodDescriptionvoid
build
(GroovyObject builder) protected int
int
codePointAt
(int index) int
codePointBefore
(int index) int
codePointCount
(int beginIndex, int endIndex) int
int
boolean
boolean
boolean
boolean
boolean
equalsIgnoreCase
(String anotherString) freeze()
byte[]
void
getChars
(int srcBegin, int srcEnd, char[] dst, int dstBegin) String[]
Get the strings of this GString.Object[]
int
indexOf
(int ch) int
indexOf
(int ch, int fromIndex) int
int
intern()
boolean
isEmpty()
int
lastIndexOf
(int ch) int
lastIndexOf
(int ch, int fromIndex) int
lastIndexOf
(String str) int
lastIndexOf
(String str, int fromIndex) boolean
int
offsetByCodePoints
(int index, int codePointOffset) boolean
regionMatches
(boolean ignoreCase, int toffset, String other, int ooffset, int len) boolean
regionMatches
(int toffset, String other, int ooffset, int len) replace
(char oldChar, char newChar) replace
(CharSequence target, CharSequence replacement) replaceAll
(String regex, String replacement) replaceFirst
(String regex, String replacement) String[]
String[]
boolean
startsWith
(String prefix) boolean
startsWith
(String prefix, int toffset) substring
(int beginIndex) substring
(int beginIndex, int endIndex) char[]
toLowerCase
(Locale locale) toString()
toUpperCase
(Locale locale) trim()
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 Details
-
GStringImpl
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 Details
-
plus
-
writeTo
Description copied from interface:Writable
Writes 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 it 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:
writeTo
in interfaceWritable
- Overrides:
writeTo
in 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
-
calcInitialCapacity
protected int calcInitialCapacity()- Overrides:
calcInitialCapacity
in classGString
-
freeze
- Returns:
- returns an equivalent optimised but less mutable version of this GString
-
getStrings
Get the strings of this GString.This method 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:
getStrings
in classGString
-
getValues
-
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
-
contentEquals
-
contentEquals
-
equalsIgnoreCase
-
compareTo
-
compareToIgnoreCase
-
regionMatches
-
regionMatches
-
startsWith
-
startsWith
-
endsWith
-
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
-
indexOf
-
lastIndexOf
-
lastIndexOf
-
substring
-
substring
-
concat
-
replace
-
matches
-
contains
-
replaceFirst
-
replaceAll
-
replace
-
split
-
split
-
toLowerCase
-
toLowerCase
-
toUpperCase
-
toUpperCase
-
toCharArray
public char[] toCharArray() -
intern
-
toString
- Specified by:
toString
in interfaceCharSequence
- Overrides:
toString
in classGString
-