01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
package horstmann.ch10_visitor;

public class PrintVisitor implements FileSystemVisitor
{
  public void visitFileNode(FileNode node)
  {
    for (int i = 0; i < level; i++) System.out.print(" ");
    System.out.println(node.getFile().getName());
  }

  public void visitDirectoryNode(DirectoryNode node)
  {
    for (int i = 0; i < level; i++) System.out.print(" ");
    System.out.println(node.getDirectory().getName());
    level++;
    for (FileSystemNode c : node.getChildren())
      c.accept(this);
    level--;
  }

  private int level = 0;
}