Class CharArrayBuffer

java.lang.Object
org.aspectj.org.eclipse.jdt.internal.core.util.CharArrayBuffer

public class CharArrayBuffer extends Object
The CharArrayBuffer is intended as a lightweight partial implementation of the StringBuffer class, but using char[]'s instead of Strings.

The CharArrayBuffer maintains a list of char[]'s which don't get appended until the user asks for them. The following code illustrates how to use the class. CharArrayBuffer buffer = new CharArrayBuffer(myCharArray); buffer.append(moreBytes, 0, someLength); myCharArray = buffer.getContents();

NOTE: This class is not Thread safe!

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected char[][]
    This is the buffer of char arrays which must be appended together during the getContents method.
    static int
    The default buffer size.
    protected int
    The end of the buffer
    protected int[][]
    A buffer of ranges which is maintained along with the buffer.
    protected int
    The current size of the buffer.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a CharArrayBuffer with the default buffer size (10).
    CharArrayBuffer​(char[] first)
    Creates a CharArrayBuffer with the default buffer size, and sets the first element in the buffer to be the given char[].
    CharArrayBuffer​(char[] first, int size)
    Creates a CharArrayBuffer with the given buffer size, and sets the first element in the buffer to be the given char array.
    CharArrayBuffer​(int size)
    Creates a CharArrayBuffer with the given buffer size.
  • Method Summary

    Modifier and Type
    Method
    Description
    append​(char c)
    Appends the given char.
    append​(char[] src)
    Appends the entire given char array.
    append​(char[] src, int start, int length)
    Appends a sub array of the given array to the buffer.
    append​(String src)
    Appends the given String to the buffer.
    char[]
    Returns the entire contents of the buffer as one char[] or null if nothing has been put in the buffer.
    Returns the contents of the buffer as a String, or an empty string if the buffer is empty.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • buffer

      protected char[][] buffer
      This is the buffer of char arrays which must be appended together during the getContents method.
    • DEFAULT_BUFFER_SIZE

      public static final int DEFAULT_BUFFER_SIZE
      The default buffer size.
      See Also:
      Constant Field Values
    • end

      protected int end
      The end of the buffer
    • size

      protected int size
      The current size of the buffer.
    • ranges

      protected int[][] ranges
      A buffer of ranges which is maintained along with the buffer. Ranges are of the form {start, length}. Enables append(char[] array, int start, int end).
  • Constructor Details

    • CharArrayBuffer

      public CharArrayBuffer()
      Creates a CharArrayBuffer with the default buffer size (10).
    • CharArrayBuffer

      public CharArrayBuffer(char[] first)
      Creates a CharArrayBuffer with the default buffer size, and sets the first element in the buffer to be the given char[].
      Parameters:
      first - - the first element to be placed in the buffer, ignored if null
    • CharArrayBuffer

      public CharArrayBuffer(char[] first, int size)
      Creates a CharArrayBuffer with the given buffer size, and sets the first element in the buffer to be the given char array.
      Parameters:
      first - - the first element of the buffer, ignored if null.
      size - - the buffer size, if less than 1, set to the DEFAULT_BUFFER_SIZE.
    • CharArrayBuffer

      public CharArrayBuffer(int size)
      Creates a CharArrayBuffer with the given buffer size.
      Parameters:
      size - - the size of the buffer.
  • Method Details

    • append

      public CharArrayBuffer append(char[] src)
      Appends the entire given char array. Given for convenience.
      Parameters:
      src - - a char array which is appended to the end of the buffer.
    • append

      public CharArrayBuffer append(char[] src, int start, int length)
      Appends a sub array of the given array to the buffer.
      Parameters:
      src - - the next array of characters to be appended to the buffer, ignored if null
      start - - the start index in the src array.
      length - - the number of characters from start to be appended
      Throws:
      ArrayIndexOutOfBoundsException - - if arguments specify an array index out of bounds.
    • append

      public CharArrayBuffer append(char c)
      Appends the given char. Given for convenience.
      Parameters:
      c - - a char which is appended to the end of the buffer.
    • append

      public CharArrayBuffer append(String src)
      Appends the given String to the buffer. Given for convenience, use #append(char[]) if possible
      Parameters:
      src - - a char array which is appended to the end of the buffer.
    • getContents

      public char[] getContents()
      Returns the entire contents of the buffer as one char[] or null if nothing has been put in the buffer.
    • toString

      public String toString()
      Returns the contents of the buffer as a String, or an empty string if the buffer is empty.
      Overrides:
      toString in class Object