edu.rice.cs.drjava.model.definitions.reducedmodel
Class ModelList<T>

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

 class ModelList<T>
extends Object

A doubly-linked list class with header and trailer nodes. Allows multiple iterators to make modifications to the same list without failing unlike the iterators for java.util.*List.

Version:
$Id: ModelList.java 5175 2010-01-20 08:46:32Z mgricken $

Nested Class Summary
(package private)  class ModelList.ModelIterator
          The iterator class for ModelList.
private static class ModelList.Node<T>
          The Node class for ModelLists.
 
Field Summary
private  ModelList.Node<T> _head
           
private  int _length
          length of this list; supports constant time length lookup
private  Set<ModelList.ModelIterator> _listeners
          a set of objects that can trigger and listen for updates to the list
private  ModelList.Node<T> _tail
           
 
Constructor Summary
ModelList()
          Constructor.
 
Method Summary
private  void addListener(ModelList.ModelIterator that)
           
 ModelList.ModelIterator getIterator()
          Create a new iterator for this list and register it as one of the listeners which are notified when the list is updated.
private  ModelList.Node<T> insert(ModelList.Node<T> point, T item)
          Insert a node immediately before the specified point.
 void insertFront(T item)
           
 boolean isEmpty()
          Returns true if the list is empty.
 int length()
           
 int listenerCount()
           
private  void remove(ModelList.Node<T> point)
          Remove a node from the list.
private  void removeListener(ModelList.ModelIterator that)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_head

private ModelList.Node<T> _head

_tail

private ModelList.Node<T> _tail

_length

private int _length
length of this list; supports constant time length lookup


_listeners

private Set<ModelList.ModelIterator> _listeners
a set of objects that can trigger and listen for updates to the list

Constructor Detail

ModelList

ModelList()
Constructor. Initializes the head and tail nodes, as well as the listener table and the length variable.

Method Detail

insertFront

public void insertFront(T item)

insert

private ModelList.Node<T> insert(ModelList.Node<T> point,
                                 T item)
Insert a node immediately before the specified point. Returns the inserted node. Assumes point is not head.


remove

private void remove(ModelList.Node<T> point)
Remove a node from the list. Assumes point is not head or tail.


addListener

private void addListener(ModelList.ModelIterator that)

removeListener

private void removeListener(ModelList.ModelIterator that)

listenerCount

public int listenerCount()

isEmpty

public boolean isEmpty()
Returns true if the list is empty.


length

public int length()

getIterator

public ModelList.ModelIterator getIterator()
Create a new iterator for this list and register it as one of the listeners which are notified when the list is updated.