polyglot.util
Class WorkList

java.lang.Object
  extended by polyglot.util.WorkList

public class WorkList
extends java.lang.Object

This class represents a set of calculations to be performed, some of which have already been completed. It optionally stores the results of those calculations. Requires: every 'calculation' object has a working hashcode and toString method.


Field Summary
static java.lang.Object NOT_CALCULATED
           
 
Constructor Summary
WorkList()
          Creates a new, empty worklist.
 
Method Summary
 void addWork(java.util.Collection c)
          Adds every member of the collection to the worklist, if it has not already been calculted.
 void addWork(java.lang.Object o)
          Adds the calculation represented by to the worklist, if it has not already been calculated.
 boolean finished()
          Returns true iff there is no more work to do.
 void finishWork(java.lang.Object work)
          Announces that we have finished the calculation represented by .
 void finishWork(java.lang.Object work, java.lang.Object result)
          Announces that we have finished the calculation represented by , getting the result .
 java.util.Map getMap()
          Returns an immutable view of a map from calculation objects to their results.
 java.lang.Object getWork()
          Returns the first element with no known result.
 boolean isFinished(java.lang.Object work)
          Returns true iff has been completed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NOT_CALCULATED

public static final java.lang.Object NOT_CALCULATED
Constructor Detail

WorkList

public WorkList()
Creates a new, empty worklist.

Method Detail

addWork

public void addWork(java.lang.Object o)
Adds the calculation represented by to the worklist, if it has not already been calculated.


addWork

public void addWork(java.util.Collection c)
Adds every member of the collection to the worklist, if it has not already been calculted.


finished

public boolean finished()
Returns true iff there is no more work to do.


getWork

public java.lang.Object getWork()
Returns the first element with no known result. Throws NoSuchElementException if no such element exists.


finishWork

public void finishWork(java.lang.Object work,
                       java.lang.Object result)
Announces that we have finished the calculation represented by , getting the result . Removes from the pending list, and sets its result to


finishWork

public void finishWork(java.lang.Object work)
Announces that we have finished the calculation represented by .


isFinished

public boolean isFinished(java.lang.Object work)
Returns true iff has been completed.


getMap

public java.util.Map getMap()
Returns an immutable view of a map from calculation objects to their results. Non-computed values map to NOT_CALCULATED