Package gov.nasa.worldwind.util
Class CompoundStringBuilder
- java.lang.Object
-
- gov.nasa.worldwind.util.CompoundStringBuilder
-
public class CompoundStringBuilder extends java.lang.Object
CompoundStringBuilder provides a mechanism for storing and retrieving a collection of variable length strings in a singleStringBuilder
.
-
-
Constructor Summary
Constructors Constructor Description 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(java.lang.StringBuilder stringBuilder, int capacity)
Constructs a CompoundStringBuilder with the specified backing StringBuilder and initial capacity.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
append(java.lang.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.java.lang.CharSequence
subSequence(int index)
Returns the substring at the specified index as aCharSequence
.java.lang.String
substring(int index)
Returns the substring at the specified index as aString
.int
substringLength(int index)
Returns the length of the substring with the specified index.
-
-
-
Field Detail
-
DEFAULT_INITIAL_CAPACITY
protected static final int DEFAULT_INITIAL_CAPACITY
- See Also:
- Constant Field Values
-
buffer
protected java.lang.StringBuilder buffer
-
count
protected int count
-
capacity
protected int capacity
-
offsets
protected int[] offsets
-
lengths
protected int[] lengths
-
-
Constructor Detail
-
CompoundStringBuilder
public CompoundStringBuilder(java.lang.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:
java.lang.IllegalArgumentException
- if the stringBuilder is null or if the capacity is less than 1.
-
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:
java.lang.IllegalArgumentException
- if the capacity is less than 1.
-
CompoundStringBuilder
public CompoundStringBuilder()
Constructs a CompoundStringBuilder with a default backing StringBuilder, and the default initial capacity.
-
-
Method Detail
-
size
public int size()
Returns the number of strings stored in this CompoundStringBuilder.- Returns:
- the number of strings in this CompoundStringBuilder.
-
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:
java.lang.IllegalArgumentException
- if the index is out of range.
-
substring
public java.lang.String substring(int index)
Returns the substring at the specified index as aString
.- Parameters:
index
- the index of the substring to return.- Returns:
- the substring at the specified index.
- Throws:
java.lang.IllegalArgumentException
- if the index is out of range.
-
subSequence
public java.lang.CharSequence subSequence(int index)
Returns the substring at the specified index as aCharSequence
.- Parameters:
index
- the index of the substring to return.- Returns:
- the substring at the specified index.
- Throws:
java.lang.IllegalArgumentException
- if the index is out of range.
-
append
public int append(java.lang.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:
java.lang.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)
-
-