KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > innig > macker > example > conventions > FileTree


1 package net.innig.macker.example.conventions;
2
3 import java.util.*;
4 import java.io.*;
5
6 public class FileTree
7     implements Tree
8     {
9     public FileTree(File file)
10         { this.file = file; }
11     
12     public Tree getParent()
13         {
14         File parentFile = file.getParentFile();
15         return (parentFile == null) ? null : new FileTree(parentFile);
16         }
17     
18     public HashSet getChildren()
19         {
20         HashSet children = new HashSet();
21         File[] childFiles = file.listFiles();
22         if(childFiles != null)
23             for(int f = 0; f < childFiles.length; f++)
24                 children.add(new FileTree(childFiles[f]));
25         return children;
26         }
27     
28     public String JavaDoc toString()
29         { return StringTree.quote(file.getPath()); }
30     
31     private File file;
32     }
Popular Tags