Class CompoundStringBuilder


  • public class CompoundStringBuilder
    extends java.lang.Object
    CompoundStringBuilder provides a mechanism for storing and retrieving a collection of variable length strings in a single StringBuilder.
    • Constructor Summary

      Constructors 
      Constructor Description
      CompoundStringBuilder()
      Constructs a CompoundStringBuilder with a default backing StringBuilder, and the default initial capacity.
      CompoundStringBuilder​(int capacity)
      Constructs a CompoundStringBuilder with a default backing StringBuilder, and the specified initial capacity.
      CompoundStringBuilder​(java.lang.StringBuilder stringBuilder, int capacity)
      Constructs a CompoundStringBuilder with the specified backing StringBuilder and initial capacity.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int append​(java.lang.CharSequence charSequence)
      Appends the contents of the specified substring to the end of this CompoundStringBuilder, incrementing the number of substrings by one.
      void clear()
      Clears this CompoundStringBuilder's backing StringBuilder and sets the number of substrings to zero.
      protected void expandCapacity​(int minCapacity)  
      int size()
      Returns the number of strings stored in this CompoundStringBuilder.
      java.lang.CharSequence subSequence​(int index)
      Returns the substring at the specified index as a CharSequence.
      java.lang.String substring​(int index)
      Returns the substring at the specified index as a String.
      int substringLength​(int index)
      Returns the length of the substring with the specified index.
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_INITIAL_CAPACITY

        protected static final int DEFAULT_INITIAL_CAPACITY
        See Also:
        Constant Field Values
      • buffer

        protected java.lang.StringBuilder buffer
      • count

        protected int count
      • capacity

        protected int capacity
      • offsets

        protected int[] offsets
      • lengths

        protected int[] lengths
    • Constructor Detail

      • CompoundStringBuilder

        public CompoundStringBuilder​(java.lang.StringBuilder stringBuilder,
                                     int capacity)
        Constructs a CompoundStringBuilder with the specified backing StringBuilder and initial capacity.
        Parameters:
        stringBuilder - the StringBuilder in which to store the string data.
        capacity - the compound buffer's initial capacity.
        Throws:
        java.lang.IllegalArgumentException - if the stringBuilder is null or if the capacity is less than 1.
      • CompoundStringBuilder

        public CompoundStringBuilder​(int capacity)
        Constructs a CompoundStringBuilder with a default backing StringBuilder, and the specified initial capacity.
        Parameters:
        capacity - the compound buffer's initial capacity.
        Throws:
        java.lang.IllegalArgumentException - if the capacity is less than 1.
      • CompoundStringBuilder

        public CompoundStringBuilder()
        Constructs a CompoundStringBuilder with a default backing StringBuilder, and the default initial capacity.
    • Method Detail

      • size

        public int size()
        Returns the number of strings stored in this CompoundStringBuilder.
        Returns:
        the number of strings in this CompoundStringBuilder.
      • substringLength

        public int substringLength​(int index)
        Returns the length of the substring with the specified index.
        Parameters:
        index - the index for the substring who's length is returned.
        Returns:
        the length of the specified substring.
        Throws:
        java.lang.IllegalArgumentException - if the index is out of range.
      • substring

        public java.lang.String substring​(int index)
        Returns the substring at the specified index as a String.
        Parameters:
        index - the index of the substring to return.
        Returns:
        the substring at the specified index.
        Throws:
        java.lang.IllegalArgumentException - if the index is out of range.
      • subSequence

        public java.lang.CharSequence subSequence​(int index)
        Returns the substring at the specified index as a CharSequence.
        Parameters:
        index - the index of the substring to return.
        Returns:
        the substring at the specified index.
        Throws:
        java.lang.IllegalArgumentException - if the index is out of range.
      • append

        public int append​(java.lang.CharSequence charSequence)
        Appends the contents of the specified substring to the end of this CompoundStringBuilder, incrementing the number of substrings by one. The backing buffer grows to accomodate the sub-buffer if it does not already have enough capacity to hold it.
        Parameters:
        charSequence - the substring to append.
        Returns:
        the substring's index.
        Throws:
        java.lang.IllegalArgumentException - if the charSequence is null.
      • clear

        public void clear()
        Clears this CompoundStringBuilder's backing StringBuilder and sets the number of substrings to zero. This does not free any memory associated with this CompoundStringBuilder.
      • expandCapacity

        protected void expandCapacity​(int minCapacity)