NASA World Wind

gov.nasa.worldwind.util
Class CompoundStringBuilder

java.lang.Object
  extended by gov.nasa.worldwind.util.CompoundStringBuilder

public class CompoundStringBuilder
extends Object

CompoundStringBuilder provides a mechanism for storing and retrieving a collection of variable length strings in a single StringBuilder.


Field Summary
protected  StringBuilder buffer
           
protected  int capacity
           
protected  int count
           
protected static int DEFAULT_INITIAL_CAPACITY
           
protected  int[] lengths
           
protected  int[] offsets
           
 
Constructor Summary
CompoundStringBuilder()
          Constructs a CompoundStringBuilder with a default backing StringBuilder, and the default initial capacity.
CompoundStringBuilder(int capacity)
          Constructs a CompoundStringBuilder with a default backing StringBuilder, and the specified initial capacity.
CompoundStringBuilder(StringBuilder stringBuilder, int capacity)
          Constructs a CompoundStringBuilder with the specified backing StringBuilder and initial capacity.
 
Method Summary
 int append(CharSequence charSequence)
          Appends the contents of the specified substring to the end of this CompoundStringBuilder, incrementing the number of substrings by one.
 void clear()
          Clears this CompoundStringBuilder's backing StringBuilder and sets the number of substrings to zero.
protected  void expandCapacity(int minCapacity)
           
 int size()
          Returns the number of strings stored in this CompoundStringBuilder.
 CharSequence subSequence(int index)
          Returns the substring at the specified index as a CharSequence.
 String substring(int index)
          Returns the substring at the specified index as a String.
 int substringLength(int index)
          Returns the length of the substring with the specified index.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

buffer

protected StringBuilder buffer

capacity

protected int capacity

count

protected int count

DEFAULT_INITIAL_CAPACITY

protected static final int DEFAULT_INITIAL_CAPACITY
See Also:
Constant Field Values

lengths

protected int[] lengths

offsets

protected int[] offsets
Constructor Detail

CompoundStringBuilder

public CompoundStringBuilder()
Constructs a CompoundStringBuilder with a default backing StringBuilder, and the default initial capacity.


CompoundStringBuilder

public CompoundStringBuilder(int capacity)
Constructs a CompoundStringBuilder with a default backing StringBuilder, and the specified initial capacity.

Parameters:
capacity - the compound buffer's initial capacity.
Throws:
IllegalArgumentException - if the capacity is less than 1.

CompoundStringBuilder

public CompoundStringBuilder(StringBuilder stringBuilder,
                             int capacity)
Constructs a CompoundStringBuilder with the specified backing StringBuilder and initial capacity.

Parameters:
stringBuilder - the StringBuilder in which to store the string data.
capacity - the compound buffer's initial capacity.
Throws:
IllegalArgumentException - if the stringBuilder is null or if the capacity is less than 1.
Method Detail

append

public int append(CharSequence charSequence)
Appends the contents of the specified substring to the end of this CompoundStringBuilder, incrementing the number of substrings by one. The backing buffer grows to accomodate the sub-buffer if it does not already have enough capacity to hold it.

Parameters:
charSequence - the substring to append.
Returns:
the substring's index.
Throws:
IllegalArgumentException - if the charSequence is null.

clear

public void clear()
Clears this CompoundStringBuilder's backing StringBuilder and sets the number of substrings to zero. This does not free any memory associated with this CompoundStringBuilder.


expandCapacity

protected void expandCapacity(int minCapacity)

size

public int size()
Returns the number of strings stored in this CompoundStringBuilder.

Returns:
the number of strings in this CompoundStringBuilder.

subSequence

public CharSequence subSequence(int index)
Returns the substring at the specified index as a CharSequence.

Parameters:
index - the index of the substring to return.
Returns:
the substring at the specified index.
Throws:
IllegalArgumentException - if the index is out of range.

substring

public String substring(int index)
Returns the substring at the specified index as a String.

Parameters:
index - the index of the substring to return.
Returns:
the substring at the specified index.
Throws:
IllegalArgumentException - if the index is out of range.

substringLength

public int substringLength(int index)
Returns the length of the substring with the specified index.

Parameters:
index - the index for the substring who's length is returned.
Returns:
the length of the specified substring.
Throws:
IllegalArgumentException - if the index is out of range.

NASA World Wind