Class GStringImpl

    • 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 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 Detail

      • 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 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:
        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
      • 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:
        getStrings in class GString