jfreerails.util
Class ArrayBase

java.lang.Object
  extended by jfreerails.util.GrowableBase
      extended by jfreerails.util.ArrayBase
Direct Known Subclasses:
IntArray

public abstract class ArrayBase
extends GrowableBase

Base class for type-specific growable array classes with any type of values (including primitive types). This class builds on the basic structure provided by GrowableBase, specializing it for usage as a growable array. See the base class description for details of the implementation.

Growable arrays based on this class are unsynchronized in order to provide the best possible performance for typical usage scenarios, so explicit synchronization must be implemented by the subclass or the application in cases where they are to be modified in a multithreaded environment.

Subclasses need to implement the abstract methods defined by the base class for working with the data array, as well as the actual data access methods (at least the basic add(), get(), set(), and toArray() methods).

Version:
1.0
Author:
Dennis M. Sosnoski

Field Summary
protected  int countPresent
          The number of values currently present in the array.
 
Fields inherited from class jfreerails.util.GrowableBase
countLimit, DEFAULT_SIZE, maximumGrowth
 
Constructor Summary
ArrayBase(ArrayBase base)
          Copy (clone) constructor.
ArrayBase(int size, java.lang.Class type)
          Constructor with partial specification.
ArrayBase(int size, int growth, java.lang.Class type)
          Constructor with full specification.
 
Method Summary
protected  java.lang.Object buildArray(java.lang.Class type, int offset, int length)
          Constructs and returns a simple array containing the same data as held in a portion of this growable array.
 void clear()
          Set the array to the empty state.
protected  int getAddIndex()
          Gets the array offset for appending a value to those in the array.
protected static java.lang.Object getArray(ArrayBase other)
          Get the array for another instance of this class.
protected  void makeInsertSpace(int index)
          Makes room to insert a value at a specified index in the array.
 void remove(int index)
          Remove a value from the array.
 void remove(int from, int to)
          Remove a range of value from the array.
 void setSize(int count)
          Sets the number of values currently present in the array.
 int size()
          Get the number of values currently present in the array.
 
Methods inherited from class jfreerails.util.GrowableBase
discardValues, ensureCapacity, getArray, growArray, resizeCopy, setArray
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

countPresent

protected int countPresent
The number of values currently present in the array.

Constructor Detail

ArrayBase

public ArrayBase(int size,
                 int growth,
                 java.lang.Class type)
Constructor with full specification.

Parameters:
size - number of elements initially allowed in array
growth - maximum size increment for growing array
type - array element type

ArrayBase

public ArrayBase(int size,
                 java.lang.Class type)
Constructor with partial specification.

Parameters:
size - number of elements initially allowed in array
type - array element type

ArrayBase

public ArrayBase(ArrayBase base)
Copy (clone) constructor.

Parameters:
base - instance being copied
Method Detail

getArray

protected static java.lang.Object getArray(ArrayBase other)
Get the array for another instance of this class. This is a convenience method to allow subclasses access to the backing array of other subclasses.

Parameters:
other - subclass instance to get array from
Returns:
backing array object

getAddIndex

protected final int getAddIndex()
Gets the array offset for appending a value to those in the array. If the underlying array is full, it is grown by the appropriate size increment so that the index value returned is always valid for the array in use by the time of the return.

Returns:
index position for added element

makeInsertSpace

protected void makeInsertSpace(int index)
Makes room to insert a value at a specified index in the array.

Parameters:
index - index position at which to insert element

remove

public void remove(int from,
                   int to)
Remove a range of value from the array. The index positions for values above the range removed are decreased by the number of values removed.

Parameters:
from - index number of first value to be removed
to - index number past last value to be removed

remove

public void remove(int index)
Remove a value from the array. All values above the index removed are moved down one index position.

Parameters:
index - index number of value to be removed

size

public final int size()
Get the number of values currently present in the array.

Returns:
count of values present

setSize

public void setSize(int count)
Sets the number of values currently present in the array. If the new size is greater than the current size, the added values are initialized to the default values. If the new size is less than the current size, all values dropped from the array are discarded.

Parameters:
count - number of values to be set

clear

public final void clear()
Set the array to the empty state.


buildArray

protected java.lang.Object buildArray(java.lang.Class type,
                                      int offset,
                                      int length)
Constructs and returns a simple array containing the same data as held in a portion of this growable array. This override of the base class method checks that the portion specified actually has data present before constructing the returned array.

Overrides:
buildArray in class GrowableBase
Parameters:
type - element type for constructed array
offset - start offset in array
length - number of characters to use
Returns:
array containing a copy of the data