org.moyoman.framework
Class DAG

java.lang.Object
  |
  +--org.moyoman.framework.DAG
All Implemented Interfaces:
Cloneable, Serializable

class DAG
extends Object
implements Cloneable, Serializable

A directed acyclic graph (DAG) is constructed leading from the module which implements the Board interface to the terminating module. Usually the terminating module implements the MoveGenerator interface, but it may be some other type of module since modules can get their own Scheduler object which contains its own DAG. For example, a module which implements the Joseki interface and calls getScheduler() would get a Scheduler object which contains a DAG object where the terminating module implements type Joseki.

The DAG can be traversed using the getFirst() and getNext() methods, while the state of each module is set using the clear() and setComplete() methods.

The DAG class does not do consistency checking on the module order, since this consistency checking is done by the ModuleCreator object before the DAG object is created.


Field Summary
private  ModuleName first
          The name of the Board module.
private  int modulesRemaining
          A count of the number of modules which have not yet completed running.
private  HashMap nodes
          Key is ModuleName, value is a DAGNode object.
private  ArrayList ready
          The modules which are ready to be started.
 
Constructor Summary
protected DAG(HashMap modules)
          Construct the DAG object.
 
Method Summary
protected  void clear()
          Set all the modules as not having been executed.
 Object clone()
          Override the Object.clone() method.
protected  ModuleName[] getAllModuleNames()
          Return all of the module names.
protected  ModuleName getFirst()
          Get the first module name.
protected  ModuleName[] getNext()
          Return the names of the modules to be run next.
protected  void setComplete(ModuleName name)
          Mark a module as completed.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nodes

private HashMap nodes
Key is ModuleName, value is a DAGNode object.


first

private ModuleName first
The name of the Board module.


ready

private ArrayList ready
The modules which are ready to be started. Each element is a ModuleName object.


modulesRemaining

private int modulesRemaining
A count of the number of modules which have not yet completed running.

Constructor Detail

DAG

protected DAG(HashMap modules)
       throws InternalErrorException
Construct the DAG object.

Parameters:
modules - a HashMap where the key is the ModuleName, and the value is the Module.
Throws:
InternalErrorException - Thrown if the operation fails for any reason.
Method Detail

clear

protected void clear()
Set all the modules as not having been executed. This is done before the start of a move.


getAllModuleNames

protected ModuleName[] getAllModuleNames()
Return all of the module names.

Returns:
The module names.

getFirst

protected ModuleName getFirst()
Get the first module name. This will have a module type of Board.

Returns:
The module name.

getNext

protected ModuleName[] getNext()
Return the names of the modules to be run next. Calls alternate between getNext() and setComplete(). Once setComplete() is called, the DAG is analyzed to determine what modules if any have all of their dependent modules complete. An array with the names of those modules is returned when this method is called.

Returns:
An array of the names of modules to be run next.

setComplete

protected void setComplete(ModuleName name)
Mark a module as completed. This method is called when a module has completed its work for the current move. The state of the DAG is updated so that getNext() can return the names of the modules which are ready to run.

Parameters:
name - The name of the module which is completed.

clone

public Object clone()
Override the Object.clone() method.

Overrides:
clone in class Object
Returns:
A DAG object which is a clone of this one.