org.xins.logdoc
Class LogdocStringBuffer

java.lang.Object
  extended byorg.xins.logdoc.LogdocStringBuffer

public class LogdocStringBuffer
extends Object

Fast, unsynchronized string buffer implementation, specifically for Logdoc classes.

Since:
XINS 1.0.0
Version:
$Revision: 1.15 $ $Date: 2006/09/12 11:33:24 $
Author:
Ernst de Haan

Constructor Summary
LogdocStringBuffer(int capacity)
          Constructs a new LogdocStringBuffer object with the specified initial capacity.
LogdocStringBuffer(int capacity, String s)
          Constructs a new LogdocStringBuffer object with the specified initial capacity and content.
LogdocStringBuffer(String s)
          Constructs a new LogdocStringBuffer object with the specified initial content.
 
Method Summary
 void append(boolean b)
          Appends the specified boolean.
 void append(byte n)
          Appends the string representation of the specified byte.
 void append(char c)
          Appends the specified character.
 void append(char[] cbuf)
          Appends all characters in the specified character buffer.
 void append(char[] cbuf, int off, int len)
          Appends characters from the specified character buffer.
 void append(double n)
          Appends the string representation of the specified double.
 void append(float n)
          Appends the string representation of the specified float.
 void append(int n)
          Appends the string representation of the specified int.
 void append(long n)
          Appends the string representation of the specified long.
 void append(short n)
          Appends the string representation of the specified short.
 void append(String str)
          Appends all characters in the specified character string.
 void clear()
          Clears this string buffer.
 int getCapacity()
          Gets the capacity of this string buffer.
 int getLength()
          Gets the length of this string buffer.
 char setChar(int index, char newChar)
          Sets the character at the specified index.
 String toString()
          Converts the contents of this buffer to a String object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LogdocStringBuffer

public LogdocStringBuffer(int capacity)
                   throws IllegalArgumentException
Constructs a new LogdocStringBuffer object with the specified initial capacity.

Parameters:
capacity - the initial capacity, must be >= 0.
Throws:
IllegalArgumentException - if capacity < 0.

LogdocStringBuffer

public LogdocStringBuffer(String s)
                   throws IllegalArgumentException
Constructs a new LogdocStringBuffer object with the specified initial content. The capacity will be equal to the length of the specified string.

Parameters:
s - the initial content, cannot be null.
Throws:
IllegalArgumentException - if s == null.

LogdocStringBuffer

public LogdocStringBuffer(int capacity,
                          String s)
                   throws IllegalArgumentException
Constructs a new LogdocStringBuffer object with the specified initial capacity and content.

Parameters:
capacity - the initial capacity, must be >= s.String.length().
s - the initial content, cannot be null.
Throws:
IllegalArgumentException - if s == null || capacity < s.String.length().
Method Detail

append

public void append(boolean b)
Appends the specified boolean. If necessary, the capacity of this string buffer will be increased.

Parameters:
b - the boolean to append, if it is true then the string "true" will be appended, otherwise the string "false" will be appended..

append

public void append(char c)
Appends the specified character. If necessary, the capacity of this string buffer will be increased.

Parameters:
c - the character to append.

append

public void append(char[] cbuf)
            throws IllegalArgumentException
Appends all characters in the specified character buffer. If necessary, the capacity of this string buffer will be increased.

Parameters:
cbuf - the character array to copy characters from, not null.
Throws:
IllegalArgumentException - if cbuf == null.

append

public void append(char[] cbuf,
                   int off,
                   int len)
            throws IllegalArgumentException
Appends characters from the specified character buffer. If necessary, the capacity of this string buffer will be increased.

Parameters:
cbuf - the character array to copy characters from, not null.
off - the offset in cbuf, must be >= 0 and < cbuf.length.
len - the number of characters to copy, must be >= 0 and (off + len) must be <= cbuf.length.
Throws:
IllegalArgumentException - if cbuf == null || off < 0 || off >= cbuf.length || len < 0 || (off + len > cbuf.length).

append

public void append(String str)
            throws IllegalArgumentException
Appends all characters in the specified character string. If necessary, the capacity of this string buffer will be increased.

Parameters:
str - the character string to copy characters from, not null.
Throws:
IllegalArgumentException - if str == null.

append

public void append(byte n)
Appends the string representation of the specified byte. If necessary, the capacity of this string buffer will be increased.

Parameters:
n - the number of which the string representation should be added to this buffer.

append

public void append(short n)
Appends the string representation of the specified short. If necessary, the capacity of this string buffer will be increased.

Parameters:
n - the number of which the string representation should be added to this buffer.

append

public void append(int n)
Appends the string representation of the specified int. If necessary, the capacity of this string buffer will be increased.

Parameters:
n - the number of which the string representation should be added to this buffer.

append

public void append(long n)
Appends the string representation of the specified long. If necessary, the capacity of this string buffer will be increased.

Parameters:
n - the number of which the string representation should be added to this buffer.

append

public void append(float n)
Appends the string representation of the specified float. If necessary, the capacity of this string buffer will be increased.

Parameters:
n - the number of which the string representation should be added to this buffer.

append

public void append(double n)
Appends the string representation of the specified double. If necessary, the capacity of this string buffer will be increased.

Parameters:
n - the number of which the string representation should be added to this buffer.

getLength

public int getLength()
Gets the length of this string buffer. This is always <= the capacity.

Returns:
the number of characters in this buffer, always <= getCapacity().

getCapacity

public int getCapacity()
Gets the capacity of this string buffer. This is always >= the length.

Returns:
the number of characters that fits in this buffer without having to extend the internal data structure, always >= getLength().

setChar

public char setChar(int index,
                    char newChar)
             throws IndexOutOfBoundsException
Sets the character at the specified index.

Parameters:
index - the index at which to set the character, must be < getLength().
newChar - the new character value.
Returns:
the old character value.
Throws:
IndexOutOfBoundsException - if index < 0 || index >= getLength().

clear

public void clear()
Clears this string buffer. The capacity will remain untouched, though.


toString

public String toString()
Converts the contents of this buffer to a String object. A new String object is created each time this method is called.

Returns:
a newly constructed String that contains the same characters as this string buffer object, never null.


See http://www.xins.org/.