Class LargeTextBuffer


  • public final class LargeTextBuffer
    extends java.lang.Object
    The segments (other than the last) have a fixed size of 65536 codepoints, which may use one byte per codepoint, two bytes per codepoint, or three bytes per codepoint, depending on the largest codepoint present in the segment.

    This is more efficient than a buffer backed by a contiguous array of characters in cases where the size is likely to grow very large, and where substring operations are rare. As used within the TinyTree, extraction of the string value of a node requires character copying only in the case where the value crosses segment boundaries.

    • Constructor Summary

      Constructors 
      Constructor Description
      LargeTextBuffer​(int initialSize)
      Create an empty LargeTextBuffer
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void appendUnicodeString​(UnicodeString chars)
      Append a string to the contents of the LargeTextBuffer
      void close()  
      int length()
      Get the number of characters in the LargeTextBuffer
      void setLength​(int newLength)
      Set the length.
      UnicodeString substring​(int start, int end)
      Returns a new character sequence that is a subsequence of this sequence.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LargeTextBuffer

        public LargeTextBuffer​(int initialSize)
        Create an empty LargeTextBuffer
        Parameters:
        initialSize - an estimate of the number of characters needed in the first segment
    • Method Detail

      • appendUnicodeString

        public void appendUnicodeString​(UnicodeString chars)
        Append a string to the contents of the LargeTextBuffer
        Parameters:
        chars - the string to be added
      • substring

        public UnicodeString substring​(int start,
                                       int end)
        Returns a new character sequence that is a subsequence of this sequence. The subsequence starts with the character at the specified index and ends with the character at index end - 1. The length of the returned sequence is end - start, so if start == end then an empty sequence is returned.
        Parameters:
        start - the start index, inclusive (codepoints, not bytes)
        end - the end index, exclusive (codepoints, not bytes)
        Returns:
        the specified subsequence
        Throws:
        java.lang.IndexOutOfBoundsException - if start or end are negative, if end is greater than length(), or if start is greater than end
      • close

        public void close()
      • length

        public int length()
        Get the number of characters in the LargeTextBuffer
        Returns:
        the number of characters present
      • setLength

        public void setLength​(int newLength)
        Set the length. If this exceeds the current length, this method is a no-op. If this is less than the current length, characters beyond the specified point are deleted.
        Parameters:
        newLength - the new length