goldman.collection.priority
Class BinaryHeap.BinaryHeapLocator

java.lang.Object
  extended by goldman.collection.AbstractCollection.AbstractLocator<E>
      extended by goldman.collection.priority.BinaryHeap.BinaryHeapLocator
All Implemented Interfaces:
Locator<E>, PriorityQueueLocator<E>, Cloneable, Iterator<E>
Enclosing class:
BinaryHeap<E>

public class BinaryHeap.BinaryHeapLocator
extends AbstractCollection.AbstractLocator<E>
implements PriorityQueueLocator<E>


Field Summary
 
Fields inherited from class goldman.collection.AbstractCollection.AbstractLocator
versionNumber
 
Constructor Summary
protected BinaryHeap.BinaryHeapLocator(PositionalCollectionLocator<E> loc)
           
 
Method Summary
 boolean advance()
          Moves the locator to the next element in the iteration order (or {\texttt AFT} if it is currently at the last element).
 void decreasePriority(E element)
          Replaces the tracked element by element
REQUIRES: the given parameter is less than e, or that e is the parameter being passed and its value has been mutated to have a lower priority than it had previously.
 E get()
          Returns the element associated with this locator.
 boolean hasNext()
           
 boolean inCollection()
          Returns true if and only if the locator is at an element of the collection.
 void increasePriority(E element)
          Replaces the tracked element by element
REQUIRES: the given parameter is greater than e, or that e is the parameter being passed and its value has been mutated to have a higher priority than it had previously.
 void remove()
          Removes the element at the locator position, and updates the locator to be at the element in the iteration order that preceded the one removed.
 boolean retreat()
          Moves the locator to the previous element in the iteration order (or FORE if it is currently at the first element).
 void update(E element)
          Replaces the element associated with this priority queue locator by the given element.
 
Methods inherited from class goldman.collection.AbstractCollection.AbstractLocator
checkValidity, ignoreConcurrentModifications, ignorePriorConcurrentModifications, next, updateVersion
 
Methods inherited from class java.lang.Object
clone, equals, 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
 

Constructor Detail

BinaryHeap.BinaryHeapLocator

protected BinaryHeap.BinaryHeapLocator(PositionalCollectionLocator<E> loc)
Parameters:
loc - a reference to the node to place the locator.
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 element at the locator is 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 element at the locator position
Throws:
NoSuchElementException - locator is not at an element in the collection.

advance

public boolean advance()
Moves the locator to the next element in the iteration order (or {\texttt AFT} if it is currently at the last element).

Specified by:
advance in interface Locator<E>
Returns:
true if and only if after the update, the locator is at an element of the collection.
Throws:
AtBoundaryException - the locator is at AFT since there is no place to advance.

retreat

public boolean retreat()
Moves the locator to the previous element in the iteration order (or FORE if it is currently at the first element).

Specified by:
retreat in interface Locator<E>
Returns:
true if and only if after the update, the locator is at an element of the collection.
Throws:
AtBoundaryException - the locator is at FORE since then there is no place to retreat.

hasNext

public boolean hasNext()
Specified by:
hasNext in interface Iterator<E>
Returns:
true if and only if advancing it would leave the locator at an element in the collection

update

public void update(E element)
Description copied from interface: PriorityQueueLocator
Replaces the element associated with this priority queue locator by the given element. This method requires that the parameter is not the same object as e. This is necessary because the method compares the old and the new values to decide whether the priority must be decreased or increased. Therefore, it would be an error to mutate the element referenced by the locator and then call update.

Specified by:
update in interface PriorityQueueLocator<E>
Parameters:
element - the new element to replace the one at the locator position

increasePriority

public void increasePriority(E element)
Replaces the tracked element by element
REQUIRES: the given parameter is greater than e, or that e is the parameter being passed and its value has been mutated to have a higher priority than it had previously.

Specified by:
increasePriority in interface PriorityQueueLocator<E>

decreasePriority

public void decreasePriority(E element)
Replaces the tracked element by element
REQUIRES: the given parameter is less than e, or that e is the parameter being passed and its value has been mutated to have a lower priority than it had previously.

Specified by:
decreasePriority in interface PriorityQueueLocator<E>

remove

public void remove()
Removes the element at the locator position, and updates the locator to be at the element in the iteration order that preceded the one removed.

Specified by:
remove in interface Iterator<E>
Throws:
NoSuchElementException - called on a locator at FORE or AFT