jodd.util
Class StringBand

java.lang.Object
  extended by jodd.util.StringBand

public class StringBand
extends java.lang.Object

StringBand is a faster alternative to StringBuilder. Instead of adding strings, they are stored in internal array. Only at the end of concatenation, when toString is invoked, strings are joined together.

To make StringBand even faster, predict the number of joined strings (and not the final string size)!


Constructor Summary
StringBand()
          Creates an empty StringBand.
StringBand(int initialCapacity)
          Creates an empty StringBand with provided capacity.
StringBand(java.lang.Object o)
           
StringBand(java.lang.String s)
          Creates StringBand with provided content.
 
Method Summary
 StringBand append(boolean b)
          Appends boolean value.
 StringBand append(byte b)
          Appends byte value.
 StringBand append(char c)
          Appends a character.
 StringBand append(double d)
          Appends double value.
 StringBand append(float f)
          Appends float value.
 StringBand append(int i)
          Appends int value.
 StringBand append(long l)
          Appends long value.
 StringBand append(java.lang.Object obj)
          Appends string representation of an object.
 StringBand append(short s)
          Appends short value.
 StringBand append(java.lang.String s)
          Appends a string.
protected  int calculateLength()
          Calculates string length.
 int capacity()
          Returns array capacity.
 char charAt(int pos)
          Returns char at given position.
protected  void expandCapacity()
          Expands internal string array by multiplying its size by 2.
 int index()
          Returns current index of string array.
 int length()
          Returns total string length.
 void setIndex(int newIndex)
          Specifies the new index.
 java.lang.String stringAt(int index)
          Returns string at given position.
 java.lang.String toString()
          Joins together all strings into one.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StringBand

public StringBand()
Creates an empty StringBand.


StringBand

public StringBand(int initialCapacity)
Creates an empty StringBand with provided capacity. Capacity refers to internal string array (i.e. number of joins) and not the total string size.


StringBand

public StringBand(java.lang.String s)
Creates StringBand with provided content.


StringBand

public StringBand(java.lang.Object o)
Method Detail

append

public StringBand append(boolean b)
Appends boolean value.


append

public StringBand append(double d)
Appends double value.


append

public StringBand append(float f)
Appends float value.


append

public StringBand append(int i)
Appends int value.


append

public StringBand append(long l)
Appends long value.


append

public StringBand append(short s)
Appends short value.


append

public StringBand append(char c)
Appends a character. This is not efficient as in StringBuilder, since new string is created.


append

public StringBand append(byte b)
Appends byte value.


append

public StringBand append(java.lang.Object obj)
Appends string representation of an object. If null, the 'null' string will be appended.


append

public StringBand append(java.lang.String s)
Appends a string.


capacity

public int capacity()
Returns array capacity.


length

public int length()
Returns total string length.


index

public int index()
Returns current index of string array.


setIndex

public void setIndex(int newIndex)
Specifies the new index.


charAt

public char charAt(int pos)
Returns char at given position. This method is not fast as it calculates the right string array element and the offset!


stringAt

public java.lang.String stringAt(int index)
Returns string at given position.


toString

public java.lang.String toString()
Joins together all strings into one.

Overrides:
toString in class java.lang.Object

expandCapacity

protected void expandCapacity()
Expands internal string array by multiplying its size by 2.


calculateLength

protected int calculateLength()
Calculates string length.



Copyright © 2003-2012 Jodd Team