edu.rice.cs.drjava.model.definitions.reducedmodel
Class ModelList.ModelIterator

java.lang.Object
  extended by edu.rice.cs.drjava.model.definitions.reducedmodel.ModelList.ModelIterator
Direct Known Subclasses:
TokenList.Iterator
Enclosing class:
ModelList<T>

 class ModelList.ModelIterator
extends Object

The iterator class for ModelList. Package private instead of private so that it can be extended. The methods of this class constitute the only public interface for traversing and modifying ModelList objects (other than insertFront). These iterators support concurrent modification from within the same thread. They are NOT thread safe.


Field Summary
private  ModelList.Node<T> _point
           
private  int _pos
           
 
Constructor Summary
ModelList.ModelIterator()
          Standard constructor that creates an iterator pointing to the list head (_head) and adds it the listeners.
ModelList.ModelIterator(ModelList.ModelIterator iter)
          Copy constructor that creates a copy of an existing iterator and adds it to the listeners.
 
Method Summary
 boolean atEnd()
          Return true if we're pointing at the tail.
 boolean atFirstItem()
          Return true if we're pointing at the node after the head.
 boolean atLastItem()
          Return true if we're pointing at the node before the tail.
 boolean atStart()
          Return true if we're pointing at the head.
 void collapse(ModelList.ModelIterator iter)
          Delete all nodes between the current position of this and the current position of the given iterator.
 ModelList.ModelIterator copy()
           
 T current()
          Return the item associated with the current node.
 void dispose()
          Disposes of an iterator by removing it from the listeners.
 boolean eq(ModelList.ModelIterator that)
          Tests "that" for equality with "this".
 void insert(T item)
          Inserts an item before the current item.
 void next()
          Moves to the next node.
 T nextItem()
          Returns the item associated with the node after the current node.
private  void notifyOfCollapse(int leftPos, int rightPos, ModelList.Node<T> rightPoint)
          Notifies the iterators in _listeners that a range of nodes has been collapsed.
private  void notifyOfInsert(int pos)
          Notifies the iterators in _listeners that a node has been inserted.
private  void notifyOfRemove(int pos, ModelList.Node<T> point)
          Notifies the iterators in _listeners that a node has been removed.
 int pos()
           
 void prev()
          Moves to the previous node.
 T prevItem()
          Returns the item associated with the node before the current node.
 void remove()
          Removes the current item from the list.
 void setTo(ModelList.ModelIterator that)
          Force "this" iterator to take the values of "that".
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_point

private ModelList.Node<T> _point

_pos

private int _pos
Constructor Detail

ModelList.ModelIterator

public ModelList.ModelIterator()
Standard constructor that creates an iterator pointing to the list head (_head) and adds it the listeners.


ModelList.ModelIterator

public ModelList.ModelIterator(ModelList.ModelIterator iter)
Copy constructor that creates a copy of an existing iterator and adds it to the listeners.

Method Detail

copy

public ModelList.ModelIterator copy()

eq

public boolean eq(ModelList.ModelIterator that)
Tests "that" for equality with "this".


setTo

public void setTo(ModelList.ModelIterator that)
Force "this" iterator to take the values of "that".


dispose

public void dispose()
Disposes of an iterator by removing it from the listeners. If an iterator becomes unreachable, it is automatically reclaimed as part of system garbage collection. The manual use of dispose() reduces the cost of notifying the listeners because it reduces the size of the listener set.


atStart

public boolean atStart()
Return true if we're pointing at the head.


atEnd

public boolean atEnd()
Return true if we're pointing at the tail.


atFirstItem

public boolean atFirstItem()
Return true if we're pointing at the node after the head.


atLastItem

public boolean atLastItem()
Return true if we're pointing at the node before the tail.


current

public T current()
Return the item associated with the current node.


prevItem

public T prevItem()
Returns the item associated with the node before the current node.


nextItem

public T nextItem()
Returns the item associated with the node after the current node.


pos

public int pos()

insert

public void insert(T item)
Inserts an item before the current item. If current is head, we need to move to the next node to perform the insert properly. Otherwise, we'll get a null pointer exception because the function will try to insert the new item before the head. Ends pointing to inserted item.


remove

public void remove()
Removes the current item from the list. Ends pointing to the node following the removed node. Throws exception if performed atStart() or atEnd().


prev

public void prev()
Moves to the previous node. Throws exception atStart().


next

public void next()
Moves to the next node. Throws exception atEnd().


collapse

public void collapse(ModelList.ModelIterator iter)
Delete all nodes between the current position of this and the current position of the given iterator. 1) Two iterators pointing to same node: do nothing 2) Iterator 2 is before iterator 1: remove between iterator 2 and iterator 1 3) Iterator 1 is before iterator 2: remove between iterator 1 and iterator 2 Does not remove points iterators point to.


notifyOfInsert

private void notifyOfInsert(int pos)
Notifies the iterators in _listeners that a node has been inserted.


notifyOfRemove

private void notifyOfRemove(int pos,
                            ModelList.Node<T> point)
Notifies the iterators in _listeners that a node has been removed.


notifyOfCollapse

private void notifyOfCollapse(int leftPos,
                              int rightPos,
                              ModelList.Node<T> rightPoint)
Notifies the iterators in _listeners that a range of nodes has been collapsed.