Class CodePointBuilder


  • public final class CodePointBuilder
    extends Object
    A builder for a string of code points.
    Since:
    8.4.0
    • Constructor Summary

      Constructors 
      Constructor Description
      CodePointBuilder()
      Creates a new CodePointBuilder with an initial capacity of 0 and no code points.
      CodePointBuilder​(int initialCapacity)
      Creates a new CodePointBuilder with the specified initial capacity and a length of 0.
      CodePointBuilder​(int[] codePoints)
      Creates a new CodePointBuilder with the specified initial code points.
    • Constructor Detail

      • CodePointBuilder

        public CodePointBuilder()
        Creates a new CodePointBuilder with an initial capacity of 0 and no code points.
      • CodePointBuilder

        public CodePointBuilder​(int[] codePoints)
        Creates a new CodePointBuilder with the specified initial code points.
        Parameters:
        codePoints - The code points to initialize this builder with.
      • CodePointBuilder

        public CodePointBuilder​(int initialCapacity)
        Creates a new CodePointBuilder with the specified initial capacity and a length of 0.
        Parameters:
        initialCapacity - The initial capacity of the code points in this builder.
    • Method Detail

      • append

        public void append​(String value)
        Appends a string to this code point builder.
        Parameters:
        value - The string to append.
      • appendCodePoint

        public void appendCodePoint​(int codePoint)
        Appends a code point to this builder.
        Parameters:
        codePoint - The code point to append.
      • appendCodePoints

        public void appendCodePoints​(int[] newCodePoints)
        Appends an array of code points to this builder.
        Parameters:
        newCodePoints - The code points to append.
      • codePointAt

        public int codePointAt​(int index)
        Gets the code point at the specified index.
        Parameters:
        index - The index of the code point to get. Must be between 0 and - 1.
        Throws:
        IndexOutOfBoundsException - if the index is out of bounds.
      • lastCodePoint

        public int lastCodePoint()
        Gets the code point at the current position of this builder.
        Returns:
        The last code point in this builder.
        Throws:
        IndexOutOfBoundsException - if there are no code points in this builder.
      • length

        public int length()
        Gets the length of the code points in this builder.
        Returns:
        The number of code points in this builder.
      • rawCodePointsArray

        public int[] rawCodePointsArray()
        Provides direct access to the raw underlying array of code points. This method should be used with caution. Consider the array to be read-only, as modifying it directly may lead to unexpected behavior in this builder. The array may be longer than length(), only the first length() elements are meaningful.
        Returns:
        The raw array of code points in this builder.
      • setLength

        public void setLength​(int newLength)
        Sets the length of the code points in this builder. All code points between the current length and the new length are set to the code point 0.
        Parameters:
        newLength - The new length of the code points in this builder. Must not be negative.
        Throws:
        IndexOutOfBoundsException - if the new length is negative.
      • toString

        public String toString()
        Creates a string with the code points in this builder.
        Overrides:
        toString in class Object
        Returns:
        A string with the code points in this builder.