Java Reference
In-Depth Information
public int getStepCount()
{
return getStepCount(new HashSet());
}
public abstract int getStepCount(Set visited);
The
ProcessComposite
class takes care in its implementation of the
getStepCount()
method not to visit a previously visited node:
public int getStepCount(Set visited)
{
visited.add(this);
int count = 0;
Iterator i = subprocesses.iterator();
while (i.hasNext())
{
ProcessComponent pc = (ProcessComponent) i.next();
if (!visited.contains(pc))
{
count += pc.getStepCount(visited);
}
}
return count;
}
The
ProcessStep
class implementation of
getStepCount()
is simple:
public int getStepCount(Set visited)
{
visited.add(this);
return 1;
}
The
com.oozinoz.process
package contains a
ShellProcess
class that has a
make()
method that returns the
make
object that Figure 5.8 depicts. (The code for this method
appears on page 320, although the point here is that the
make
process contains four steps.)
The
process
package also has a
TestProcess
class that provides automated tests of
various types of process graphs. For example, this class includes a method that tests that the
getStepCount()
operation correctly counts the number of steps in the cyclic
make
process:
public void testShell()
{
assertEquals(4, ShellProcess.make().getStepCount());
}
This test runs and passes within the
JUnit
testing framework. See www.junit.org for more
information about JUnit.