goldman.collection.positional
Class TrackedArray.Tracker

java.lang.Object
  extended by goldman.collection.AbstractCollection.AbstractLocator<E>
      extended by goldman.collection.positional.TrackedArray.Tracker
All Implemented Interfaces:
Locator<E>, PositionalCollectionLocator<E>, Cloneable, Iterator<E>
Enclosing class:
TrackedArray<E>

protected class TrackedArray.Tracker
extends AbstractCollection.AbstractLocator<E>
implements PositionalCollectionLocator<E>


Field Summary
protected  goldman.collection.positional.TrackedArray.Node<E> trackedNode
           
 
Fields inherited from class goldman.collection.AbstractCollection.AbstractLocator
versionNumber
 
Constructor Summary
protected TrackedArray.Tracker(goldman.collection.positional.TrackedArray.Node<E> toTrack)
           
 
Method Summary
 PositionalCollectionLocator<E> addAfter(E e)
          Adds to the collection after the tracker location If the tracker is between positions p-1, and p then the new element is inserted at position p.
 boolean advance()
          Moves the tracker to the next position
 boolean equals(Object tracker)
           
 E get()
          Returns the element associated with this locator.
 int getCurrentPosition()
          Returns the position within the collection for this locator.
 boolean hasNext()
           
 boolean inCollection()
          Returns true if and only if the locator is at an element of the collection.
 void remove()
          Removes the element at the tracker and updates the tracker to be between its current position and the one before it.
 boolean retreat()
          Moves the tracker to the previous position
 E set(E element)
           
 
Methods inherited from class goldman.collection.AbstractCollection.AbstractLocator
checkValidity, ignoreConcurrentModifications, ignorePriorConcurrentModifications, next, updateVersion
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface goldman.collection.Locator
ignoreConcurrentModifications, ignorePriorConcurrentModifications
 
Methods inherited from interface java.util.Iterator
next
 

Field Detail

trackedNode

protected goldman.collection.positional.TrackedArray.Node<E> trackedNode
Constructor Detail

TrackedArray.Tracker

protected TrackedArray.Tracker(goldman.collection.positional.TrackedArray.Node<E> toTrack)
Parameters:
toTrack - the node to track.
Throws:
IllegalArgumentException - the property TracksElement would be violated
Method Detail

inCollection

public boolean inCollection()
Description copied from interface: Locator
Returns true if and only if the locator is at an element of the collection.

Specified by:
inCollection in interface Locator<E>
Returns:
true if and only if the tracked element is currently in the collection

get

public E get()
Description copied from interface: Locator
Returns the element associated with this locator. When a tracker is used, the element associated with the locator might no longer be in the collection. If desired, the inCollection method can be used to determine if a tracked element is currently in the collection. If the locator is at FORE or AFT then a NoSuchElementException is thrown.

Specified by:
get in interface Locator<E>
Returns:
the tracked element
Throws:
NoSuchElementException - the tracker is not at an element in the collection.

set

public E set(E element)
Parameters:
element - the element to store at the current tracker location.
Returns:
the element that had been stored at the tracker location
Throws:
NoSuchElementException - the tracker is not at an element in the collection

getCurrentPosition

public int getCurrentPosition()
Description copied from interface: PositionalCollectionLocator
Returns the position within the collection for this locator.

Specified by:
getCurrentPosition in interface PositionalCollectionLocator<E>
Returns:
the position of the tracker.
Throws:
NoSuchElementException - the tracker is not at an element in the collection

advance

public boolean advance()
                throws ConcurrentModificationException
Moves the tracker to the next position

Specified by:
advance in interface Locator<E>
Returns:
true if and only if the tracker has not reached AFT
Throws:
AtBoundaryException - the tracker is at AFT, since there is no place to advance.
ConcurrentModificationException

retreat

public boolean retreat()
                throws ConcurrentModificationException
Moves the tracker to the previous position

Specified by:
retreat in interface Locator<E>
Returns:
true if and only if the tracker has not reached FORE.
Throws:
AtBoundaryException - the tracker is at FORE, since then there is no place to retreat.
ConcurrentModificationException

hasNext

public boolean hasNext()
                throws ConcurrentModificationException
Specified by:
hasNext in interface Iterator<E>
Returns:
true if there is some element after the current tracker position.
Throws:
ConcurrentModificationException

addAfter

public PositionalCollectionLocator<E> addAfter(E e)
Adds to the collection after the tracker location If the tracker is between positions p-1, and p then the new element is inserted at position p.

Specified by:
addAfter in interface PositionalCollectionLocator<E>
Parameters:
e - the element to be added
Returns:
a tracker for the new element
Throws:
AtBoundaryException - the tracker is at AFT

remove

public void remove()
Removes the element at the tracker and updates the tracker to be between its current position and the one before it.

Specified by:
remove in interface Iterator<E>
Throws:
NoSuchElementException - the tracker is not at a valid position in the collection

equals

public boolean equals(Object tracker)
Overrides:
equals in class Object
Parameters:
tracker - the tracker to be checked for equality
Returns:
true if the given tracker refers to the same element in this collection