goldman.collection.positional
Class DynamicCircularArray<E>

java.lang.Object
  extended by goldman.collection.AbstractCollection<E>
      extended by goldman.collection.positional.AbstractPositionalCollection<E>
          extended by goldman.collection.positional.Array<E>
              extended by goldman.collection.positional.CircularArray<E>
                  extended by goldman.collection.positional.DynamicCircularArray<E>
All Implemented Interfaces:
Collection<E>, PositionalCollection<E>, Iterable<E>
Direct Known Subclasses:
TrackedArray

public class DynamicCircularArray<E>
extends CircularArray<E>
implements PositionalCollection<E>

This array-based data structure allows element 0 of the positional collection to be in any slot of the underlying array, with the range of underlying indices wrapping around as needed, and also performs automatic resizing. It is best if the size of the collection is not known a priori and if some insertions and/or deletions tend to occur near the front portion of the collection. As with DynamicArray, the application program can provide an initial size in the constructor and use ensureCapacity and trimToSize to optimize performance. This is an untracked implementation.


Nested Class Summary
 
Nested classes/interfaces inherited from class goldman.collection.positional.Array
Array.BasicMarker, Array.Marker
 
Nested classes/interfaces inherited from class goldman.collection.AbstractCollection
AbstractCollection.AbstractLocator<T extends E>, AbstractCollection.VisitingIterator
 
Field Summary
 
Fields inherited from class goldman.collection.positional.CircularArray
start
 
Fields inherited from class goldman.collection.AbstractCollection
comp, DEFAULT_CAPACITY, FORE, NOT_FOUND, size, version
 
Constructor Summary
DynamicCircularArray()
           
DynamicCircularArray(int capacity)
           
DynamicCircularArray(int capacity, Comparator<? super E> equivalenceTester)
           
 
Method Summary
protected  PositionalCollectionLocator<E> addImpl(int p, Object value)
          Inserts object value at position p and increments the position number for the elements that were at positions p, ..., size-1.
 void ensureCapacity(int capacity)
          Increases the capacity of the underlying array if needed
 void removeRange(int fromPos, int toPos)
          Requires 0 ≤ fromPostoPos < size.
protected  void resizeArray(int desiredCapacity)
          Changes the capacity of the underlying array to desiredCapacity while maintaining the same positional collection.
 
Methods inherited from class goldman.collection.positional.CircularArray
closeGap, createGap, getIndex, getPosition, moveElementsTo, nextIndex, prevIndex, setToNull, shiftLeft, shiftRight
 
Methods inherited from class goldman.collection.positional.Array
add, add, bucketsort, bucketsortImpl, clear, contains, findPosition, get, getCapacity, getLocator, heapsort, heapsort, insertionsort, insertionsort, iterator, iteratorAt, iteratorAtEnd, mergesort, mergesort, positionOf, quicksort, quicksort, radixsort, radixsortImpl, read, remove, remove, removeFirst, removeLast, repositionElementByRank, repositionElementByRank, set, swap, traverseForVisitor, treesort, treesort, trimToSize
 
Methods inherited from class goldman.collection.positional.AbstractPositionalCollection
addFirst, addLast, toString
 
Methods inherited from class goldman.collection.AbstractCollection
accept, addAll, checkRep, compare, equivalent, getComparator, getElementAtRank, getElementAtRank, getEquivalentElement, getSize, isEmpty, retainAll, toArray, toArray, writeElements
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface goldman.collection.positional.PositionalCollection
add, addFirst, addLast, bucketsort, get, heapsort, heapsort, insertionsort, insertionsort, iterator, iteratorAtEnd, mergesort, mergesort, positionOf, quicksort, quicksort, radixsort, remove, removeFirst, removeLast, repositionElementByRank, repositionElementByRank, set, swap, treesort, treesort
 
Methods inherited from interface goldman.collection.Collection
accept, add, addAll, checkRep, clear, contains, getCapacity, getComparator, getEquivalentElement, getLocator, getSize, isEmpty, remove, retainAll, toArray, toArray, toString, trimToSize
 

Constructor Detail

DynamicCircularArray

public DynamicCircularArray(int capacity,
                            Comparator<? super E> equivalenceTester)

DynamicCircularArray

public DynamicCircularArray()

DynamicCircularArray

public DynamicCircularArray(int capacity)
Method Detail

resizeArray

protected void resizeArray(int desiredCapacity)
Description copied from class: Array
Changes the capacity of the underlying array to desiredCapacity while maintaining the same positional collection.

Parameters:
desiredCapacity - the desired capacity of the underlying array

ensureCapacity

public void ensureCapacity(int capacity)
Description copied from class: Array
Increases the capacity of the underlying array if needed

Specified by:
ensureCapacity in interface Collection<E>
Overrides:
ensureCapacity in class Array<E>
Parameters:
capacity - the desired capacity

addImpl

protected PositionalCollectionLocator<E> addImpl(int p,
                                                 Object value)
Description copied from class: Array
Inserts object value at position p and increments the position number for the elements that were at positions p, ..., size-1.

Parameters:
p - a valid user position
value - the object to insert
Returns:
null for an untracked implementations

removeRange

public void removeRange(int fromPos,
                        int toPos)
Description copied from class: Array
Requires 0 ≤ fromPostoPos < size. It removes the elements at positions fromPos, ..., toPos, inclusive, from the collection and decrements the positions of the elements at positions toPos+1 to size-1 by toPos-fromPos+1 (the number of elements being removed).

Specified by:
removeRange in interface PositionalCollection<E>
Overrides:
removeRange in class Array<E>
Parameters:
fromPos - a valid position
toPos - a valid position