public class CharArray extends Object implements Encodable, Copyable
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).
Modifier and Type | Field and Description |
---|---|
char[] |
data
These are the data characters.
|
int |
length
This denotes the number of valid characters in the data array.
|
Constructor and Description |
---|
CharArray() |
CharArray(char[] data)
This will actually use the "data" char array as the data for the CharArray.
|
CharArray(String s) |
Modifier and Type | Method and Description |
---|---|
CharArray |
append(char c) |
CharArray |
append(char[] src,
int start,
int length)
Add characters to the end of the CharArray.
|
CharArray |
append(double value) |
CharArray |
append(int value) |
CharArray |
append(long value) |
CharArray |
append(String src) |
void |
append(StringBuffer source) |
void |
append(StringBuffer source,
int srcStart,
int srcEnd) |
void |
cached()
This is called when the CharArray is cached.
|
char |
charAt(int idx) |
CharArray |
clear()
Set the "length" field to zero and return this CharArray object.
|
boolean |
endsWith(char[] otherChars,
int otherStart,
int otherLength) |
boolean |
endsWith(String other) |
void |
ensureCapacity(int newCapacity)
This will ensure that the size of the "data" character array is at least
newCapacity.
|
boolean |
equals(Object other)
Returns if this object is considered equal to the other object.
|
Object |
getCopy()
Return a copy of this object.
|
int |
hashCode()
Returns a hashCode for the object.
|
int |
indexOf(char[] otherChars,
int otherStart,
int otherLength,
int start) |
int |
indexOf(int ch) |
int |
indexOf(int ch,
int start) |
int |
indexOf(String other) |
int |
indexOf(String other,
int start) |
CharArray |
insert(char c,
int where) |
CharArray |
insert(int where,
char[] src,
int start,
int length)
Insert characters into the CharArray.
|
void |
insert(StringBuffer source,
int where) |
void |
insert(StringBuffer source,
int where,
int srcStart,
int srcEnd) |
int |
lastIndexOf(char[] otherChars,
int otherStart,
int otherLength,
int start) |
int |
lastIndexOf(int ch) |
int |
lastIndexOf(int ch,
int start) |
int |
lastIndexOf(String other) |
int |
lastIndexOf(String other,
int start) |
int |
length()
A Convenience method.
|
boolean |
makeSpace(int where,
int numcharacters)
This adds space to the CharArray at the specified index.
|
int |
prepareReceive(int toReceive,
boolean append)
Make enough space to receive incoming data up to a maximum of toReceive characters.
|
void |
received(int received)
Call this after calling prepareReceive() and after having received some or zero data.
|
CharArray |
remove(int where,
int count) |
CharArray |
replace(char oldChar,
char newChar) |
CharArray |
replace(char oldChar,
char newChar,
int start,
int length) |
void |
setData(char[] data) |
void |
setLength(int len)
This sets the length of the valid data within the array and will either truncate or extend
the array as necessary.
|
boolean |
startsWith(char[] otherChars,
int otherStart,
int otherLength) |
boolean |
startsWith(String other) |
char[] |
toChars()
Return an array of chars the exact length of this CharArray containing
a copy of the chars in this CharArray.
|
protected void |
toNewLength(int newLength)
Moves the data into a new data array of the specified length - which
must be greater than or equal to the number of elements in the array.
|
String |
toString()
Return a String representation of this object.
|
void |
trim()
Remove excess storage so that the length of the data array matches the
number of elements in it.
|
static CharArray |
unNull(CharArray destination) |
void |
write(int where,
char[] src,
int start,
int length)
This writes into the data at the specific location.
|
public char[] data
public int length
public CharArray(String s)
public CharArray()
public CharArray(char[] data)
public int length()
public Object getCopy()
Copyable
public boolean makeSpace(int where, int numcharacters)
public void write(int where, char[] src, int start, int length)
public CharArray insert(int where, char[] src, int start, int length)
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.public CharArray remove(int where, int count)
public CharArray replace(char oldChar, char newChar, int start, int length)
oldChar
- newChar
- start
- length
- public CharArray replace(char oldChar, char newChar)
oldChar
- newChar
- public CharArray append(char[] src, int start, int length)
src
- The source data characters.start
- The start index in the source data.length
- The number of characters to copy.public CharArray insert(char c, int where)
public CharArray append(char c)
public void ensureCapacity(int newCapacity)
newCapacity
- The minimum size of the data array.public String toString()
Object
public void setData(char[] data)
public CharArray append(long value)
public CharArray append(int value)
public CharArray append(double value)
public char[] toChars()
protected void toNewLength(int newLength)
public char charAt(int idx)
public void trim()
public int prepareReceive(int toReceive, boolean append)
toReceive
- the maximum number of characters to receive.append
- if this is false the length is set to zero.public void received(int received)
received
- the number of characters actually received.public void setLength(int len)
public void append(StringBuffer source, int srcStart, int srcEnd)
public void insert(StringBuffer source, int where, int srcStart, int srcEnd)
public void append(StringBuffer source)
public void insert(StringBuffer source, int where)
public CharArray clear()
public int indexOf(int ch)
public int indexOf(int ch, int start)
public int lastIndexOf(int ch)
public int lastIndexOf(int ch, int start)
public boolean endsWith(String other)
public boolean endsWith(char[] otherChars, int otherStart, int otherLength)
public boolean startsWith(String other)
public boolean startsWith(char[] otherChars, int otherStart, int otherLength)
public int indexOf(String other)
public int indexOf(String other, int start)
public int indexOf(char[] otherChars, int otherStart, int otherLength, int start)
public int lastIndexOf(String other)
public int lastIndexOf(String other, int start)
public int lastIndexOf(char[] otherChars, int otherStart, int otherLength, int start)
public void cached()
public boolean equals(Object other)
Object
public int hashCode()
Object