com.sosnoski.util.array
Class StringArray

java.lang.Object
  |
  +--com.sosnoski.util.GrowableBase
        |
        +--com.sosnoski.util.array.ArrayBase
              |
              +--com.sosnoski.util.array.StringArray

public class StringArray
extends ArrayBase

Growable 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. See the base classes for other details of the implementation.

Version:
1.1
Author:
Dennis M. Sosnoski

Field Summary
protected  java.lang.String[] m_baseArray
          The underlying array used for storing the data.
 
Fields inherited from class com.sosnoski.util.array.ArrayBase
m_countPresent
 
Fields inherited from class com.sosnoski.util.GrowableBase
DEFAULT_SIZE, m_countLimit, m_maximumGrowth
 
Constructor Summary
StringArray()
          Default constructor.
StringArray(int size)
          Constructor with initial size specified.
StringArray(int size, int growth)
          Constructor with full specification.
StringArray(StringArray base)
          Copy (clone) constructor.
 
Method Summary
 void add(int index, java.lang.String value)
          Add a value at a specified index in the array.
 int add(java.lang.String value)
          Add a value to the array, appending it after the current values.
 java.lang.Object clone()
          Duplicates the object with the generic call.
 java.lang.String get(int index)
          Retrieve the value present at an index position in the array.
protected  java.lang.Object getArray()
          Get the backing array.
 java.util.Iterator iterator()
          Return an iterator for the Strings in this array.
 void set(int index, java.lang.String value)
          Set the value at an index position in the array.
protected  void setArray(java.lang.Object array)
          Set the backing array.
 java.lang.String[] toArray()
          Constructs and returns a simple array containing the same data as held in this growable array.
 java.lang.String[] toArray(int offset, int length)
          Constructs and returns a simple array containing the same data as held in a portion of this growable array.
 
Methods inherited from class com.sosnoski.util.array.ArrayBase
buildArray, clear, getAddIndex, getArray, makeInsertSpace, remove, remove, setSize, size
 
Methods inherited from class com.sosnoski.util.GrowableBase
discardValues, ensureCapacity, growArray, resizeCopy
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_baseArray

protected java.lang.String[] m_baseArray
The underlying array used for storing the data.
Constructor Detail

StringArray

public StringArray(int size,
                   int growth)
Constructor with full specification.
Parameters:
size - number of String values initially allowed in array
growth - maximum size increment for growing array

StringArray

public StringArray(int size)
Constructor with initial size specified.
Parameters:
size - number of chars to size array for initially

StringArray

public StringArray()
Default constructor.

StringArray

public StringArray(StringArray base)
Copy (clone) constructor.
Parameters:
base - instance being copied
Method Detail

getArray

protected final java.lang.Object getArray()
Get the backing array. This method is used by the type-agnostic base class code to access the array used for type-specific storage.
Overrides:
getArray in class GrowableBase
Returns:
backing array object

setArray

protected final void setArray(java.lang.Object array)
Set the backing array. This method is used by the type-agnostic base class code to set the array used for type-specific storage.
Overrides:
setArray in class GrowableBase
Parameters:
backing - array object

add

public final int add(java.lang.String value)
Add a value to the array, appending it after the current values.
Parameters:
value - value to be added
Returns:
index number of added element

add

public void add(int index,
                java.lang.String value)
Add a value at a specified index in the array.
Parameters:
index - index position at which to insert element
value - value to be inserted into array

get

public final java.lang.String get(int index)
Retrieve the value present at an index position in the array.
Parameters:
index - index position for value to be retrieved
Returns:
value from position in the array

set

public final void set(int index,
                      java.lang.String value)
Set the value at an index position in the array. Note that this method can only be used for modifying an existing value in the array, not for appending to the end of the array.
Parameters:
index - index position to be set
value - value to be set
See Also:
add(java.lang.String)

iterator

public final java.util.Iterator iterator()
Return an iterator for the Strings in this array. The iterator returns all values in order, but is not "live". Values added to the array during iteration will not be returned by the iteration, and any other changes to the array while the iteration is in progress will give indeterminant results.
Returns:
iterator for values in array

toArray

public java.lang.String[] toArray()
Constructs and returns a simple array containing the same data as held in this growable array.
Returns:
array containing a copy of the data

toArray

public java.lang.String[] toArray(int offset,
                                  int length)
Constructs and returns a simple array containing the same data as held in a portion of this growable array.
Parameters:
offset - start offset in array
length - number of characters to use
Returns:
array containing a copy of the data

clone

public java.lang.Object clone()
Duplicates the object with the generic call.
Overrides:
clone in class java.lang.Object
Returns:
a copy of the object


Company Web Site

XML Benchmark Home