SSF.Util.Plot
Class SelfExpandingIntArray

java.lang.Object
  |
  +--java.util.AbstractCollection
        |
        +--java.util.AbstractList
              |
              +--java.util.ArrayList
                    |
                    +--SSF.Util.Plot.SelfExpandingIntArray
All Implemented Interfaces:
java.lang.Cloneable, java.util.Collection, java.util.List, java.util.RandomAccess, java.io.Serializable

public class SelfExpandingIntArray
extends java.util.ArrayList

Class to implement an "automatically extending Integer array" by extending the Vector class. Overloads the set(...) method of the Vector class to check whether or not the index is within the current bounds of the array. If it's outside, the size of the array is increased to fit in this new element. Also implements a new convenience method "update(...)" for a "read-modify-write" operation on a element in the array.

NOTE: The methods supplied in this class are the only ones supported for self-expanding arrays. Using other methods in the superclasses may have "undefined" results - generally resulting in an "index out of bounds" exception.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
SelfExpandingIntArray()
           
 
Method Summary
 int getVal(int index)
          Returns the element at the specified position in the array.
 void set(int index, int element)
          Sets the specified element (by index) to "element", and automatically increases the size of the array if necessary.
 void update(int index, int increment)
          Update element at index by increment (+/-)
 void updateMax(int index, int newVal)
          Update element by setting it to max(previous, new)
 
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, removeRange, set, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, remove, removeAll, retainAll, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, remove, removeAll, retainAll, subList
 

Constructor Detail

SelfExpandingIntArray

public SelfExpandingIntArray()
Method Detail

set

public void set(int index,
                int element)
Sets the specified element (by index) to "element", and automatically increases the size of the array if necessary.


getVal

public int getVal(int index)
Returns the element at the specified position in the array. If this element has not been set, the value 0 will be returned but the element will not be created in the array.


update

public void update(int index,
                   int increment)
Update element at index by increment (+/-)


updateMax

public void updateMax(int index,
                      int newVal)
Update element by setting it to max(previous, new)