GStringImpl (Groovy 5.0.6)
Description: declaration: package: org.codehaus.groovy.runtime, class: GStringImpl

Package org.codehaus.groovy.runtime

# 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.
  `protected`
  `GStringImpl(Object[] values, String[] strings, boolean cacheable, String cachedStringLiteral, boolean frozen)`
  Create a new GString with values and strings.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `build(GroovyObject builder)`
  `protected int`
  `calcInitialCapacity()`
  `int`
  `codePointAt(int index)`
  `int`
  `codePointBefore(int index)`
  `int`
  `codePointCount(int beginIndex, int endIndex)`
  `int`
  `compareTo(String anotherString)`
  `int`
  `compareToIgnoreCase(String str)`
  `String`
  `concat(String str)`
  `boolean`
  `contains(CharSequence s)`
  `boolean`
  `contentEquals(CharSequence cs)`
  `boolean`
  `contentEquals(StringBuffer sb)`
  `boolean`
  `endsWith(String suffix)`
  `boolean`
  `equalsIgnoreCase(String anotherString)`
  `GString`
  `freeze()`
  `byte[]`
  `getBytes(Charset charset)`
  `void`
  `getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)`
  `String[]`
  `getStrings()`
  Get the strings of this GString.
  `Object[]`
  `getValues()`
  `int`
  `indexOf(int ch)`
  `int`
  `indexOf(int ch, int fromIndex)`
  `int`
  `indexOf(String str)`
  `int`
  `indexOf(String str, int fromIndex)`
  `String`
  `intern()`
  `boolean`
  `isBlank()`
  Returns `true` if the string is empty or contains only white space codepoints, otherwise `false`.
  `boolean`
  `isEmpty()`
  `int`
  `lastIndexOf(int ch)`
  `int`
  `lastIndexOf(int ch, int fromIndex)`
  `int`
  `lastIndexOf(String str)`
  `int`
  `lastIndexOf(String str, int fromIndex)`
  `Stream<String>`
  `lines()`
  Returns a stream of lines extracted from this string, separated by line terminators.
  `boolean`
  `matches(String regex)`
  `int`
  `offsetByCodePoints(int index, int codePointOffset)`
  `GString`
  `plus(GString that)`
  `boolean`
  `regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len)`
  `boolean`
  `regionMatches(int toffset, String other, int ooffset, int len)`
  `String`
  `repeat(int count)`
  Returns a string whose value is the concatenation of this string repeated `count` times.
  `String`
  `replace(char oldChar, char newChar)`
  `String`
  `replace(CharSequence target, CharSequence replacement)`
  `String`
  `replaceAll(String regex, String replacement)`
  `String`
  `replaceFirst(String regex, String replacement)`
  `String[]`
  `split(String regex)`
  `String[]`
  `split(String regex, int limit)`
  `boolean`
  `startsWith(String prefix)`
  `boolean`
  `startsWith(String prefix, int toffset)`
  `String`
  `strip()`
  Returns a string whose value is this string, with all leading and trailing white space removed.
  `String`
  `stripLeading()`
  Returns a string whose value is this string, with all leading white space removed.
  `String`
  `stripTrailing()`
  Returns a string whose value is this string, with all trailing white space removed.
  `String`
  `substring(int beginIndex)`
  `String`
  `substring(int beginIndex, int endIndex)`
  `char[]`
  `toCharArray()`
  `String`
  `toLowerCase()`
  `String`
  `toLowerCase(Locale locale)`
  `String`
  `toString()`
  `String`
  `toUpperCase()`
  `String`
  `toUpperCase(Locale locale)`
  `String`
  `trim()`
  `Writer`
  `writeTo(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 Details

  - ### 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 parts
      `strings` - 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 parts
      `strings` - the string parts
      `frozen` - creates a GStringImpl which is not subject to mutation and hence more amenable to caching

- ## Method Details

  - ### plus

    public GString plus(GString that)
    Overrides:
      `plus` in class `GString`

  - ### writeTo

    public Writer writeTo(Writer out) throws IOException
    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 interface `Writable`
    Overrides:
      `writeTo` in class `GString`
    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)
    Specified by:
      `build` in interface `Buildable`
    Overrides:
      `build` in class `GString`

  - ### calcInitialCapacity

    protected int calcInitialCapacity()
    Overrides:
      `calcInitialCapacity` in class `GString`

  - ### 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 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 class `GString`

  - ### getValues

    public Object[] getValues()
    Overrides:
      `getValues` in class `GString`

  - ### trim

    public String trim()

  - ### isEmpty

    public boolean isEmpty()

  - ### lines

    public Stream<String> lines()
    Returns a stream of lines extracted from this string, separated by line terminators.

    A line terminator is one of the following: a line feed character `"\n"` (U+000A), a carriage return character `"\r"` (U+000D), or a carriage return followed immediately by a line feed `"\r\n"` (U+000D U+000A).

    A line is either a sequence of zero or more characters followed by a line terminator, or it is a sequence of one or more characters followed by the end of the string. A line does not include the line terminator.

    The stream returned by this method contains the lines from this string in the order in which they occur.

    Returns:
      the stream of lines extracted from this string
    Since:
      5.0.0
    "Implementation Note:"
      This method provides better performance than split("\R") by supplying elements lazily and by faster search of new line terminators.

  - ### isBlank

    public boolean isBlank()
    Returns `true` if the string is empty or contains only white space codepoints, otherwise `false`.
    Returns:
      `true` if the string is empty or contains only white space codepoints, otherwise `false`
    Since:
      5.0.0
    See Also:
      - `Character.isWhitespace(int)`

  - ### repeat

    public String repeat(int count)
    Returns a string whose value is the concatenation of this string repeated `count` times.

    If this string is empty or count is zero then the empty string is returned.

    Parameters:
      `count` - number of times to repeat
    Returns:
      A string composed of this string repeated `count` times or the empty string if this string is empty or count is zero
    Throws:
      `IllegalArgumentException` - if the `count` is negative.
    Since:
      5.0.0

  - ### stripLeading

    public String stripLeading()
    Returns a string whose value is this string, with all leading white space removed.

    If this `String` object represents an empty string, or if all code points in this string are white space, then an empty string is returned.

    Otherwise, returns a substring of this string beginning with the first code point that is not a white space up to and including the last code point of this string.

    This method may be used to trim white space from the beginning of a string.

    Returns:
      a string whose value is this string, with all leading white space removed
    Since:
      5.0.0
    See Also:
      - `Character.isWhitespace(int)`

  - ### stripTrailing

    public String stripTrailing()
    Returns a string whose value is this string, with all trailing white space removed.

    If this `String` object represents an empty string, or if all characters in this string are white space, then an empty string is returned.

    Otherwise, returns a substring of this string beginning with the first code point of this string up to and including the last code point that is not a white space.

    This method may be used to trim white space from the end of a string.

    Returns:
      a string whose value is this string, with all trailing white space removed
    Since:
      5.0.0
    See Also:
      - `Character.isWhitespace(int)`

  - ### strip

    public String strip()
    Returns a string whose value is this string, with all leading and trailing white space removed.

    If this `String` object represents an empty string, or if all code points in this string are white space, then an empty string is returned.

    Otherwise, returns a substring of this string beginning with the first code point that is not a white space up to and including the last code point that is not a white space.

    This method may be used to strip white space from the beginning and end of a string.

    Returns:
      a string whose value is this string, with all leading and trailing white space removed
    Since:
      5.0.0
    See Also:
      - `Character.isWhitespace(int)`

  - ### 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)

  - ### concat

    public String concat(String str)

  - ### replace

    public String replace(char oldChar, char newChar)

  - ### matches

    public boolean matches(String regex)

  - ### contains

    public boolean contains(CharSequence s)

  - ### replaceFirst

    public String replaceFirst(String regex, String replacement)

  - ### replaceAll

    public String replaceAll(String regex, String replacement)

  - ### replace

    public String replace(CharSequence target, CharSequence replacement)

  - ### split

    public String[] split(String regex, int limit)

  - ### split

    public String[] split(String regex)

  - ### toLowerCase

    public String toLowerCase(Locale locale)

  - ### toLowerCase

    public String toLowerCase()

  - ### toUpperCase

    public String toUpperCase(Locale locale)

  - ### toUpperCase

    public String toUpperCase()

  - ### toCharArray

    public char[] toCharArray()

  - ### intern

    public String intern()

  - ### toString

    public String toString()
    Specified by:
      `toString` in interface `CharSequence`
    Overrides:
      `toString` in class `GString`