ptolemy.graph.sched
Class Schedule.FiringIterator

java.lang.Object
  extended by ptolemy.graph.sched.Schedule.FiringIterator
All Implemented Interfaces:
java.util.Iterator
Enclosing class:
Schedule

private class Schedule.FiringIterator
extends java.lang.Object
implements java.util.Iterator

An adapter class for iterating over the firings of this schedule. An exception is thrown if the schedule structure changes while this iterator is active. The iterator walks the schedule tree as the hasNext() and next() methods are invoked, using a small number of state variables.


Field Summary
private  boolean _advance
           
private  int _currentDepth
           
private  ScheduleElement _currentNode
           
private  int[] _horizontalNodePosition
           
private  int[] _iterationCounts
           
private  boolean _lastHasNext
           
private  long _startingVersion
           
 
Constructor Summary
Schedule.FiringIterator(Schedule schedule)
          Construct a ScheduleIterator.
 
Method Summary
private  Schedule _backTrack(ScheduleElement firingNode)
          Start at the specified node in the schedule tree and move up the tree (towards the root node) until we find a node the has children we have not iterated through yet or children that we have not iterated through enough times (not reached the maximum iteration count).
private  ScheduleElement _findLeafNode(Schedule node)
          Start at the specified node and move down the tree (away from the root node) until we find the next Firing in the iteration order.
 boolean hasNext()
          Return true if the iteration has more elements.
 java.lang.Object next()
          Return the next object in the iteration.
 void remove()
          Throw an exception, since removal is not allowed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_advance

private boolean _advance

_currentNode

private ScheduleElement _currentNode

_lastHasNext

private boolean _lastHasNext

_currentDepth

private int _currentDepth

_startingVersion

private long _startingVersion

_iterationCounts

private int[] _iterationCounts

_horizontalNodePosition

private int[] _horizontalNodePosition
Constructor Detail

Schedule.FiringIterator

public Schedule.FiringIterator(Schedule schedule)
Construct a ScheduleIterator.

Method Detail

hasNext

public boolean hasNext()
Return true if the iteration has more elements.

Specified by:
hasNext in interface java.util.Iterator
Returns:
True if the iterator has more elements.
Throws:
java.util.ConcurrentModificationException - If the schedule data structure has changed since this iterator was created.
InternalErrorException - If the schedule contains any leaf nodes that are not an instance of Firing.

next

public java.lang.Object next()
                      throws java.util.NoSuchElementException
Return the next object in the iteration.

Specified by:
next in interface java.util.Iterator
Returns:
The next object in the iteration.
Throws:
InvalidStateException - If the schedule data structure has changed since this iterator was created.
java.util.NoSuchElementException

remove

public void remove()
Throw an exception, since removal is not allowed. It really doesn't make sense to remove a firing from the firing sequence anyway, since there is not a 1-1 correspondence between the firing in a firing iterator and a firing in the schedule.

Specified by:
remove in interface java.util.Iterator

_backTrack

private Schedule _backTrack(ScheduleElement firingNode)
Start at the specified node in the schedule tree and move up the tree (towards the root node) until we find a node the has children we have not iterated through yet or children that we have not iterated through enough times (not reached the maximum iteration count).

Parameters:
firingNode - The starting node to backtrack from.

_findLeafNode

private ScheduleElement _findLeafNode(Schedule node)
Start at the specified node and move down the tree (away from the root node) until we find the next Firing in the iteration order. Through a runtime exception if we encounter a leaf node that is not an instance of Firing.

Parameters:
node - The schedule node to start from.