Java Reference
In-Depth Information
Figure 29.3. The
FindVisitor
class effectively adds a
find()
operation to the
MachineComponent
hierarchy.
The
visit()
methods do not return an object, so the
FindVisitor
class records the status
of a search in its
sought
instance variable:
package com.oozinoz.dublin;
import com.oozinoz.machine.*;
import java.util.*;
public class FindVisitor implements MachineVisitor
{
private MachineComponent sought;
private int soughtId;
public MachineComponent find(
MachineComponent mc, int id)
{
sought = null;
soughtId = id;
mc.accept(this);
return sought;
}