01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package horstmann.ch10_visitor;
import java.io.File;

public class DirectoryNode implements FileSystemNode
{
  public DirectoryNode(File directory)
  {
    this.directory = directory;
  }

  public void accept(FileSystemVisitor v)
  {
    v.visitDirectoryNode(this);
  }

  public File getDirectory() { return directory; }

  public FileSystemNode[] getChildren()
  {
    File[] files = directory.listFiles();
    FileSystemNode[] children = new FileSystemNode[files.length];
    for (int i = 0; i < files.length; i++)
    {
      File f = files[i];
      if (f.isDirectory())
        children[i] = new DirectoryNode(f);
      else
        children[i] = new FileNode(f);
    }
    return children;
  }

  private File directory;
}