ewe.util
Class CharArray

java.lang.Object
  extended byewe.util.CharArray
All Implemented Interfaces:
Copyable, Encodable

public class CharArray
extends Object
implements Encodable, Copyable

A CharArray is a utility class that represents a number of text characters. It is generally used as a buffer for text storage.

Associated with the CharArray is a char [] value called "data" which holds the data characters (starting from index 0) and the "length" variable specifies how many of those characters are considered valid (which may be less than the actual length of the data variable).


Field Summary
 char[] data
          These are the data characters.
 int length
          This denotes the number of valid characters in the data array.
 
Constructor Summary
CharArray()
           
 
Method Summary
 void append(char[] src, int start, int length)
          Add characters to the end of the CharArray.
 void append(String src)
           
 void copyFrom(char[] data, int offset, int length)
          Set the data in the CharArray to be a copy of the data provided re-using the internal char array if possible.
 void copyFrom(String data)
          Set the data in the CharArray to be a copy of the data in the string, re-using the internal char array if possible.
 void copyFrom(SubString data)
          Set the data in the CharArray to be a copy of the data in the SubString, re-using the internal char array if possible.
 void ensureCapacity(int newCapacity)
          This will ensure that the size of the "data" character array is at least newCapacity.
 Object getCopy()
          Return a copy of this CharArray which has its own copy of the data.
 void insert(int where, char[] src, int start, int length)
          Insert characters into the CharArray.
 boolean makeSpace(int where, int numcharacters)
          This adds space to the CharArray at the specified index.
 String toString()
          Return a String representation of this object.
 void write(int where, char[] src, int start, int length)
          This writes into the data at the specific location.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode
 

Field Detail

data

public char[] data
These are the data characters.


length

public int length
This denotes the number of valid characters in the data array.

Constructor Detail

CharArray

public CharArray()
Method Detail

getCopy

public Object getCopy()
Return a copy of this CharArray which has its own copy of the data.

Specified by:
getCopy in interface Copyable

makeSpace

public boolean makeSpace(int where,
                         int numcharacters)
This adds space to the CharArray at the specified index. After this is done you can safely write into the data starting at index "where" for a length of numcharacters.


write

public void write(int where,
                  char[] src,
                  int start,
                  int length)
This writes into the data at the specific location. Make sure you have called makeSpace() before if necessary.


insert

public void insert(int where,
                   char[] src,
                   int start,
                   int length)
Insert characters into the CharArray.

Parameters:
where - The index in this CharArray where the data will go.
src - The source data characters.
start - The start index in the source data.
length - The number of characters to copy.

append

public void append(char[] src,
                   int start,
                   int length)
Add characters to the end of the CharArray.

Parameters:
src - The source data characters.
start - The start index in the source data.
length - The number of characters to copy.

append

public void append(String src)

ensureCapacity

public void ensureCapacity(int newCapacity)
This will ensure that the size of the "data" character array is at least newCapacity. If the size is already greater than or equal to newCapacity, then this will have no effect.

Parameters:
newCapacity - The minimum size of the data array.

toString

public String toString()
Description copied from class: Object
Return a String representation of this object.

Overrides:
toString in class Object
Returns:
a String representing this object.

copyFrom

public void copyFrom(String data)
Set the data in the CharArray to be a copy of the data in the string, re-using the internal char array if possible.


copyFrom

public void copyFrom(char[] data,
                     int offset,
                     int length)
Set the data in the CharArray to be a copy of the data provided re-using the internal char array if possible.


copyFrom

public void copyFrom(SubString data)
Set the data in the CharArray to be a copy of the data in the SubString, re-using the internal char array if possible.