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

java.lang.Object
  |
  +--edu.rice.cs.drjava.model.definitions.reducedmodel.ModelList.Iterator
Direct Known Subclasses:
TokenList.Iterator
Enclosing class:
ModelList

class ModelList.Iterator
extends Object

Iterators for model list. The iterators are intimately coupled with the ModelList to which they belong. They are the only public interface for manipulating ModelList. The iterators are also fail-safe with regards to manipulation of the same list, although probably not thread-safe.


Field Summary
private  ModelList.Node _point
           
private  int _pos
           
 
Constructor Summary
ModelList.Iterator()
          Constructor.
ModelList.Iterator(ModelList.Iterator iter)
          Copy constructor.
 
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.Iterator iter)
          Delete all nodes between the current position of this and the current position of the given iterator.
 ModelList.Iterator copy()
           
 Object current()
          Return the item associated with the current node.
 void dispose()
          Disposes of an iterator by removing it from the list's set of listeners.
 boolean eq(Object thing)
          an equals test
 void insert(Object item)
          Insert an item before the current item.
 void next()
          Move to the next node.
 Object nextItem()
          Return the item associated with the node after the current node.
private  void notifyOfCollapse(int leftPos, int rightPos, ModelList.Node rightPoint)
          When an iterator collapses part of the list, it notifies other iterators in the set of listeners so they can stay updated.
private  void notifyOfInsert(int pos)
          When an iterator inserts an item, it notifies other iterators in the set of listeners so they can stay updated.
private  void notifyOfRemove(int pos, ModelList.Node point)
          When an iterator removes an item, it notifies other iterators in the set of listeners so they can stay updated.
 void prev()
          Move to the previous node.
 Object prevItem()
          Return the item associated with the node before the current node.
 void remove()
          Remove the current item from the list.
 void setTo(ModelList.Iterator it)
          Force this iterator to take the values of the given iterator.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

_point

private ModelList.Node _point

_pos

private int _pos
Constructor Detail

ModelList.Iterator

public ModelList.Iterator()
Constructor. Initializes an iterator to point to its list's head.

ModelList.Iterator

public ModelList.Iterator(ModelList.Iterator iter)
Copy constructor. Creates a new iterator with the same values as the progenitor. Adds it to the list's set of listeners.
Method Detail

copy

public ModelList.Iterator copy()

eq

public boolean eq(Object thing)
an equals test

setTo

public void setTo(ModelList.Iterator it)
Force this iterator to take the values of the given iterator.

dispose

public void dispose()
Disposes of an iterator by removing it from the list's set of listeners. When an iterator is no longer necessary, it should be disposed of. Otherwise, there will be memory leaks because the listener set of the list provides a root reference for the duration of the list's existence. What this means is that unless an iterator is disposed of, it will continue to exist even after garbage collection as long as the list itself is not garbage collected.

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 Object current()
Return the item associated with the current node.

prevItem

public Object prevItem()
Return the item associated with the node before the current node.

nextItem

public Object nextItem()
Return the item associated with the node after the current node.

insert

public void insert(Object item)
Insert an item before the current item. If at the containing list's 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()
Remove 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()
Move to the previous node. Throws exception atStart().

next

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

collapse

public void collapse(ModelList.Iterator 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 D oes not remove points iterators point to.

notifyOfInsert

private void notifyOfInsert(int pos)
When an iterator inserts an item, it notifies other iterators in the set of listeners so they can stay updated.

notifyOfRemove

private void notifyOfRemove(int pos,
                            ModelList.Node point)
When an iterator removes an item, it notifies other iterators in the set of listeners so they can stay updated.

notifyOfCollapse

private void notifyOfCollapse(int leftPos,
                              int rightPos,
                              ModelList.Node rightPoint)
When an iterator collapses part of the list, it notifies other iterators in the set of listeners so they can stay updated.