org.apache.xml.utils
Class FastStringBuffer

java.lang.Object
  |
  +--org.apache.xml.utils.FastStringBuffer

public class FastStringBuffer
extends java.lang.Object

Bare-bones, unsafe, fast string buffer. No thread-safety, no parameter range checking, exposed fields. Note that in typical applications, thread-safety of a StringBuffer is a somewhat dubious concept in any case.


Field Summary
 int m_blocksize
          Field m_blocksize establishes the allocation granularity -- the initial size of m_map[] and the minimum increment by which it grows when necessary.
 int m_firstFree
          Field m_firstFree is an index into m_map[], pointing to the first character in the array which is not part of the FastStringBuffer's current content.
 char[] m_map
          Field m_map[] is a character array holding the string buffer's contents.
 int m_mapSize
          Field m_mapSize is a cached copy of m_map.length -- or, transiently, the new length that m_map will grow to.
 
Constructor Summary
FastStringBuffer()
          Construct a IntVector, using the default block size.
FastStringBuffer(int blocksize)
          Construct a IntVector, using the given block size.
 
Method Summary
 void append(char value)
          Append a single character onto the FastStringBuffer, growing the storage if necessary.
 void append(char[] chars, int start, int length)
          Append part of the contents of a Character Array onto the FastStringBuffer, growing the storage if necessary.
 void append(FastStringBuffer value)
          Append the contents of another FastStringBuffer onto this FastStringBuffer, growing the storage if necessary.
 void append(java.lang.String value)
          Append the contents of a String onto the FastStringBuffer, growing the storage if necessary.
 void append(java.lang.StringBuffer value)
          Append the contents of a StringBuffer onto the FastStringBuffer, growing the storage if necessary.
 int length()
          Get the length of the list.
 void reset()
          Discard the content of the FastStringBuffer.
 void setLength(int l)
          Directly set how much of the FastStringBuffer's storage is to be considered part of its content.
 int size()
          Get the length of the list.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_blocksize

public int m_blocksize
Field m_blocksize establishes the allocation granularity -- the initial size of m_map[] and the minimum increment by which it grows when necessary.

m_map

public char[] m_map
Field m_map[] is a character array holding the string buffer's contents. Note that this array will be reallocated when necessary in order to allow the buffer to grow, so references to this object may become (indedetectably) invalid after any edit is made to the FastStringBuffer. DO NOT retain such references! (Note that this imposes a multithreading hazard; its the user's responsibility to manage access to FastStringBuffer to prevent the problem from arising.)

m_firstFree

public int m_firstFree
Field m_firstFree is an index into m_map[], pointing to the first character in the array which is not part of the FastStringBuffer's current content. Since m_map[] is zero-based, m_firstFree is also equal to the length of that content.

m_mapSize

public int m_mapSize
Field m_mapSize is a cached copy of m_map.length -- or, transiently, the new length that m_map will grow to.
Constructor Detail

FastStringBuffer

public FastStringBuffer()
Construct a IntVector, using the default block size.

FastStringBuffer

public FastStringBuffer(int blocksize)
Construct a IntVector, using the given block size.
Parameters:
blocksize - Desired value for m_blocksize, establishes both the initial storage allocation and the minimum growth increment.
Method Detail

size

public final int size()
Get the length of the list. Synonym for length().
Returns:
the number of characters in the FastStringBuffer's content.

length

public final int length()
Get the length of the list. Synonym for size().
Returns:
the number of characters in the FastStringBuffer's content.

reset

public final void reset()
Discard the content of the FastStringBuffer. Does _not_ release any of the storage space.

setLength

public final void setLength(int l)
Directly set how much of the FastStringBuffer's storage is to be considered part of its content. This is a fast but hazardous operation. It is not protected against negative values, or values greater than the amount of storage currently available... and even if additional storage does exist, its contents are unpredictable. The only safe use for setLength() is to truncate the FastStringBuffer to a shorter string.
Parameters:
l - New length. If l<0 or l>=m_mapSize, this operation will not report an error but future operations will almost certainly fail.

toString

public final java.lang.String toString()
Returns:
the contents of the FastStringBuffer as a standard Java string
Overrides:
toString in class java.lang.Object

append

public final void append(char value)
Append a single character onto the FastStringBuffer, growing the storage if necessary.

NOTE THAT after calling append(), previously obtained references to m_map[] may no longer be valid.

Parameters:
value - character to be appended.

append

public final void append(java.lang.String value)
Append the contents of a String onto the FastStringBuffer, growing the storage if necessary.

NOTE THAT after calling append(), previously obtained references to m_map[] may no longer be valid.

Parameters:
value - String whose contents are to be appended.

append

public final void append(java.lang.StringBuffer value)
Append the contents of a StringBuffer onto the FastStringBuffer, growing the storage if necessary.

NOTE THAT after calling append(), previously obtained references to m_map[] may no longer be valid.

Parameters:
value - StringBuffer whose contents are to be appended.

append

public final void append(char[] chars,
                         int start,
                         int length)
Append part of the contents of a Character Array onto the FastStringBuffer, growing the storage if necessary.

NOTE THAT after calling append(), previously obtained references to m_map[] may no longer be valid.

Parameters:
chars - character array from which data is to be copied
start - offset in chars of first character to be copied, zero-based.
length - number of characters to be copied

append

public final void append(FastStringBuffer value)
Append the contents of another FastStringBuffer onto this FastStringBuffer, growing the storage if necessary.

NOTE THAT after calling append(), previously obtained references to m_map[] may no longer be valid.

Parameters:
value - FastStringBuffer whose contents are to be appended.


Copyright � 2000 Apache XML Project. All Rights Reserved.