|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.waveset.util.StringAppender
StringAppender is built for 'append' speed and scalability it uses block based storage to reduce the number and amount of allocations.
Field Summary | |
static int |
DEFAULT_BLOCKSIZE
|
static int |
DEFAULT_CAPACITY
|
Constructor Summary | |
StringAppender()
Constructs a string buffer with no characters in it and an initial capacity of 1024 characters. |
|
StringAppender(char[] str)
Constructs a string buffer so that it represents the same sequence of characters as the string argument; in other words, the initial contents of the string buffer is a copy of the argument string. |
|
StringAppender(int capacity)
Constructs a string buffer with no characters in it and an initial capacity specified by the length argument. |
|
StringAppender(int capacity,
int blocksize)
Constructs a string buffer with no characters in it and an initial capacity specified by the length argument. |
|
StringAppender(java.lang.String str)
Constructs a string buffer so that it represents the same sequence of characters as the string argument; in other words, the initial contents of the string buffer is a copy of the argument string. |
Method Summary | |
StringAppender |
append(boolean b)
Appends the string representation of the boolean argument
to the string buffer. |
StringAppender |
append(char c)
Appends the string representation of the char argument to
this string buffer. |
StringAppender |
append(char[] src)
Appends the string representation of the char array
argument to this string buffer. |
StringAppender |
append(char[] str,
int offset,
int len)
Appends the string representation of a subarray of the char
array argument to this string buffer. |
StringAppender |
append(double d)
Appends the string representation of the double argument
to this string buffer. |
StringAppender |
append(float f)
Appends the string representation of the float argument to
this string buffer. |
StringAppender |
append(int i)
Appends the string representation of the int argument to
this string buffer. |
StringAppender |
append(long l)
Appends the string representation of the long argument to
this string buffer. |
StringAppender |
append(java.lang.Object obj)
Appends the string representation of the Object argument
to this string buffer. |
StringAppender |
append(java.lang.String src)
Appends the string to this string buffer. |
int |
blocksize()
Returns the current size of the blocks in the buffer. |
int |
capacity()
Returns the current capacity of the String buffer. |
char |
charAt(int index)
|
void |
ensureCapacity(int mincap)
Ensures that the capacity of the buffer is at least equal to the specified minimum. |
void |
getChars(int srcBegin,
int srcEnd,
char[] dst,
int dstBegin)
Characters are copied from this string buffer into the destination character array dst . |
int |
length()
|
void |
setCharAt(int index,
char ch)
The character at the specified index of this string buffer is set to ch . |
void |
setLength(int len)
|
java.lang.CharSequence |
subSequence(int start,
int end)
|
java.lang.String |
substring(int start)
Returns a new String that contains a subsequence of
characters currently contained in this OptimizedStringBuffer
.The substring begins at the specified index and extends to the end of
the OptimizedStringBuffer . |
java.lang.String |
substring(int start,
int end)
Returns a new String that contains a subsequence of
characters currently contained in this OptimizedStringBuffer . |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int DEFAULT_CAPACITY
public static final int DEFAULT_BLOCKSIZE
Constructor Detail |
public StringAppender()
public StringAppender(int capacity)
length
argument.
java.lang.NegativeArraySizeException
- if the length
argument is less than 0
.public StringAppender(int capacity, int blocksize)
length
argument.
capacity
- the initial capacity.blocksize
- the allocation size of each block
java.lang.NegativeArraySizeException
- if the length
argument is less than 0
.public StringAppender(java.lang.String str)
1024
plus the length of
the string argument.
str
- the initial contents of the buffer.public StringAppender(char[] str)
1024
plus the length of
the string argument.
str
- the initial contents of the buffer.Method Detail |
public int capacity()
public int blocksize()
public void ensureCapacity(int mincap)
minimumCapacity
argument.
2
.
mincap
argument is nonpositive, this method takes
no action and simply returns. TODO: manually inline the code for faster
performance.
public void setLength(int len)
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
dst
. The first character to be copied is
at index srcBegin
; the last character to be copied is at
index srcEnd-1
. The total number of characters to be
copied is srcEnd-srcBegin
. The characters are copied into
the subarray of dst
starting at index
dstBegin
and ending at index:
dstbegin + (srcEnd - srcBegin) - 1
srcBegin
- start copying at this offset in the string buffer.srcEnd
- stop copying at this offset in the string buffer.dst
- the array to copy the data into.dstBegin
- offset into dst
.
java.lang.NullPointerException
- if dst
is
null
.
java.lang.IndexOutOfBoundsException
- if any of the following is true:
srcBegin
is negative
dstBegin
is negative
srcBegin
argument is greater than the
srcEnd
argument.
srcEnd
is greater than
this.length()
, the current length of this
string buffer.
dstBegin+srcEnd-srcBegin
is greater than
dst.length
public void setCharAt(int index, char ch)
ch
. The string buffer is altered to represent a new
character sequence that is identical to the old character sequence,
except that it contains the character ch
at position
index
.
The offset argument must be greater than or equal to 0
,
and less than the length of this string buffer.
index
- the index of the character to modify.ch
- the new character.
java.lang.IndexOutOfBoundsException
- if index
is negative
or greater than or equal to length()
.java.lang.StringAppender#length()
public StringAppender append(java.lang.Object obj)
Object
argument
to this string buffer.
The argument is converted to a string as if by the method
String.valueOf
, and the characters of that string are
then appended to this string buffer.
obj
- an Object
.
OptimizedStringBuffer
object.String.valueOf(java.lang.Object)
,
java.lang.StringAppender#append(java.lang.String)
public StringAppender append(java.lang.String src)
The characters of the String
argument are appended, in
order, to the contents of this string buffer, increasing the length of
this string buffer by the length of the argument. If str
is null
, then the four characters "null"
are appended to this string buffer.
Let n be the length of the old character sequence, the one
contained in the string buffer just prior to execution of the
append
method. Then the character at index k in
the new character sequence is equal to the character at index k
in the old character sequence, if k is less than n ;
otherwise, it is equal to the character at index k-n in the
argument str
.
OptimizedStringBuffer
.public StringAppender append(char[] src)
char
array
argument to this string buffer.
The characters of the array argument are appended, in order, to the contents of this string buffer. The length of this string buffer increases by the length of the argument.
The overall effect is exactly as if the argument were converted to a
string by the method String.valueOf(char[])
and the characters of
that string were then appended
to this
OptimizedStringBuffer
object.
OptimizedStringBuffer
object.public StringAppender append(char[] str, int offset, int len)
char
array argument to this string buffer.
Characters of the character array str
, starting at index
offset
, are appended, in order, to the contents of this
string buffer. The length of this string buffer increases by the value of
len
.
The overall effect is exactly as if the arguments were converted to a
string by the method String.valueOf(char[],int,int)
and the
characters of that string were then appended
to
this OptimizedStringBuffer
object.
str
- the characters to be appended.offset
- the index of the first character to append.len
- the number of characters to append.
OptimizedStringBuffer
object.public StringAppender append(boolean b)
boolean
argument
to the string buffer.
The argument is converted to a string as if by the method
String.valueOf
, and the characters of that string are
then appended to this string buffer.
b
- a boolean
.
OptimizedStringBuffer
.String.valueOf(boolean)
,
java.lang.StringAppender#append(java.lang.String)
public StringAppender append(char c)
char
argument to
this string buffer.
The argument is appended to the contents of this string buffer. The
length of this string buffer increases by 1
.
The overall effect is exactly as if the argument were converted to a
string by the method String.valueOf(char)
and the character in
that string were then appended
to this
OptimizedStringBuffer
object.
c
- a char
.
OptimizedStringBuffer
object.public StringAppender append(int i)
int
argument to
this string buffer.
The argument is converted to a string as if by the method
String.valueOf
, and the characters of that string are
then appended to this string buffer.
i
- an int
.
OptimizedStringBuffer
object.String.valueOf(int)
,
java.lang.StringAppender#append(java.lang.String)
public StringAppender append(long l)
long
argument to
this string buffer.
The argument is converted to a string as if by the method
String.valueOf
, and the characters of that string are
then appended to this string buffer.
l
- a long
.
OptimizedStringBuffer
object.String.valueOf(long)
,
java.lang.StringAppender#append(java.lang.String)
public StringAppender append(float f)
float
argument to
this string buffer.
The argument is converted to a string as if by the method
String.valueOf
, and the characters of that string are
then appended to this string buffer.
f
- a float
.
OptimizedStringBuffer
object.String.valueOf(float)
,
java.lang.StringAppender#append(java.lang.String)
public StringAppender append(double d)
double
argument
to this string buffer.
The argument is converted to a string as if by the method
String.valueOf
, and the characters of that string are
then appended to this string buffer.
d
- a double
.
OptimizedStringBuffer
object.String.valueOf(double)
,
java.lang.StringAppender#append(java.lang.String)
public java.lang.String substring(int start)
String
that contains a subsequence of
characters currently contained in this OptimizedStringBuffer
.The substring begins at the specified index and extends to the end of
the OptimizedStringBuffer
.
start
- The beginning index, inclusive.
java.lang.StringIndexOutOfBoundsException
- if start
is
less than zero, or greater than the length of this
OptimizedStringBuffer
.public java.lang.String substring(int start, int end)
String
that contains a subsequence of
characters currently contained in this OptimizedStringBuffer
.
The substring begins at the specified start
and extends to
the character at index end - 1
. An exception is thrown if
start
- The beginning index, inclusive.end
- The ending index, exclusive.
java.lang.StringIndexOutOfBoundsException
- if start
or
end
are negative or greater than
length()
, or start
is greater
than end
.public int length()
length
in interface java.lang.CharSequence
public char charAt(int index)
charAt
in interface java.lang.CharSequence
public java.lang.CharSequence subSequence(int start, int end)
subSequence
in interface java.lang.CharSequence
public java.lang.String toString()
toString
in interface java.lang.CharSequence
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |