001package horstmann.ch10_visitor;
002
003public class PrintVisitor implements FileSystemVisitor
004{
005        public void visitFileNode(FileNode node)
006        {
007                for (int i = 0; i < level; i++) System.out.print(" ");
008                System.out.println(node.getFile().getName());
009        }
010
011        public void visitDirectoryNode(DirectoryNode node)
012        {
013                for (int i = 0; i < level; i++) System.out.print(" ");
014                System.out.println(node.getDirectory().getName());
015                level++;
016                for (FileSystemNode c : node.getChildren())
017                        c.accept(this);
018                level--;
019        }
020
021        private int level = 0;
022}