|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.mindprod.fastcat.FastCat
public class FastCat
Stripped down, fast replacement for StringBuilder and StringWriter to build concatenated Strings.
For concatenating individual characters, StringBuilder will probably be faster. It has an overhead of 4 bytes per piece appended, which would be 50% if the Strings were only 2-bytes long. This algorithm works best with fairly long pieces. The main advantage is it is much easier to get a precise estimate of how much space you will need.
Field Summary | |
---|---|
static java.lang.String |
EMBEDDED_COPYRIGHT
undisplayed copyright notice |
Constructor Summary | |
---|---|
FastCat()
no-arg constructor, defaults to 20 pieces as the estimate. |
|
FastCat(int estNumberOfPieces)
constructor |
Method Summary | |
---|---|
FastCat |
append(char c)
append char |
FastCat |
append(int i)
append int |
FastCat |
append(java.lang.Object... oo)
append arbitrary number of Objects |
FastCat |
append(java.lang.Object o)
append Object |
FastCat |
append(java.lang.String... ss)
append arbitrary number of strings |
FastCat |
append(java.lang.String s)
append String |
void |
clear()
empty the concatenated String being created |
int |
length()
current buffer length. |
static void |
main(java.lang.String[] args)
test harness |
int |
room()
how many unused slots are available for pieces? Not same as total number of chars that could append. |
int |
size()
how many slots (used or unused) are available for pieces? Not same as total number of chars that could append. |
java.lang.String |
toString()
Get the concatenation of all the strings appended so far |
int |
used()
how many used slot containing pieces? Not same as total number of chars appended. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String EMBEDDED_COPYRIGHT
Constructor Detail |
---|
public FastCat()
public FastCat(int estNumberOfPieces)
estNumberOfPieces
- estimated number of chunks you will concatenate.
If the estimate is low, you will get ArrayIndexOutOfBoundsExceptions.Method Detail |
---|
public FastCat append(java.lang.String s)
s
- String to append
public FastCat append(java.lang.String... ss)
ss
- comma-separated list of Strings to append
public FastCat append(int i)
i
- int to append.
public FastCat append(char c)
c
- char to append.
If you use this method extensively, you will probably get better performance from StringBuilder.
public FastCat append(java.lang.Object o)
o
- Object to append. toString is called to acquire a String to concatenate.
public FastCat append(java.lang.Object... oo)
oo
- comma-separated list of Objects to to append. toString is called to acquire a String to concatenate.
public void clear()
public int length()
used()
public int room()
public int size()
length()
public java.lang.String toString()
toString
in class java.lang.Object
public int used()
public static void main(java.lang.String[] args)
args
- not used.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |