public class GrowableStringArray
extends java.lang.Object
String
array with type specific access methods. This
implementation is unsynchronized in order to provide the best possible
performance for typical usage scenarios, so explicit synchronization must
be implemented by a wrapper class or directly by the application in cases
where instances are modified in a multithreaded environment.Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_SIZE
Default initial array size.
|
private java.lang.String[] |
m_baseArray
The underlying array used for storing the data.
|
private int |
m_countLimit
Size of the current array.
|
private int |
m_countPresent
The number of values currently present in the array.
|
private int |
m_maximumGrowth
Maximum size increment for growing array.
|
Constructor and Description |
---|
GrowableStringArray()
Default constructor.
|
GrowableStringArray(GrowableStringArray base)
Copy (clone) constructor.
|
GrowableStringArray(int size)
Constructor with initial size specified.
|
GrowableStringArray(int size,
int growth)
Constructor with full specification.
|
Modifier and Type | Method and Description |
---|---|
void |
add(java.lang.String value)
Add a value at the end of the array.
|
void |
addAll(java.lang.String[] values)
Add an array of values at the end of the array.
|
void |
clear()
Set the array to the empty state.
|
java.lang.Object |
clone()
Duplicates the object with the generic call.
|
private void |
discardValues(int from,
int to)
Discards values for a range of indices in the array.
|
void |
ensureCapacity(int min)
Ensure that the array has the capacity for at least the specified
number of values.
|
java.lang.String |
get(int index)
Get a value from the array.
|
private int |
getAddIndex()
Gets the array offset for appending a value to those in the array.
|
private void |
growArray(int required)
Increase the size of the array to at least a specified size.
|
boolean |
isEmpty()
Check if array is empty.
|
void |
remove(int count)
Remove some number of values from the end of the array.
|
private void |
resizeCopy(java.lang.Object base,
java.lang.Object grown)
Copy data after array resize.
|
void |
set(int index,
java.lang.String value)
Overwrite an existing value in the array.
|
int |
size()
Get the number of values currently present in the array.
|
java.lang.String[] |
toArray()
Constructs and returns a simple array containing the same data as held
in this array.
|
public static final int DEFAULT_SIZE
private int m_countLimit
private int m_countPresent
private int m_maximumGrowth
private java.lang.String[] m_baseArray
public GrowableStringArray(int size, int growth)
size
- number of String
values initially allowed in
arraygrowth
- maximum size increment for growing arraypublic GrowableStringArray(int size)
size
- number of String
values initially allowed in
arraypublic GrowableStringArray()
public GrowableStringArray(GrowableStringArray base)
base
- instance being copiedprivate void resizeCopy(java.lang.Object base, java.lang.Object grown)
base
- original array containing datagrown
- resized array for dataprivate void discardValues(int from, int to)
from
- index of first value to be discardedto
- index past last value to be discardedprivate void growArray(int required)
required
- new minimum size requiredpublic final void ensureCapacity(int min)
min
- minimum capacity to be guaranteedpublic void set(int index, java.lang.String value)
index
- position of value to be overwrittenvalue
- value to be addedpublic void add(java.lang.String value)
value
- value to be addedpublic void addAll(java.lang.String[] values)
values
- values to be addedpublic void remove(int count)
count
- number of values to be removedjava.lang.ArrayIndexOutOfBoundsException
- on attempt to remove more than
the count presentpublic java.lang.String get(int index)
index
- index of value to be returnedjava.lang.ArrayIndexOutOfBoundsException
- on attempt to access outside
valid rangepublic java.lang.String[] toArray()
public java.lang.Object clone()
clone
in class java.lang.Object
private int getAddIndex()
public int size()
public boolean isEmpty()
true
if array empty, false
if notpublic void clear()