KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.innig.macker.example.conventions;
2
3 import java.util.*;
4
5 public class DepthFirstDump
6     {
7     public static void dump(Tree tree, int levels, int maxChildren, String JavaDoc prefix)
8         {
9         if(levels == 0)
10             {
11             System.out.println(prefix + tree + " ...");
12             return;
13             }
14         
15         System.out.println(prefix + tree);
16         prefix = prefix + " ";
17         int childCount = 0;
18         for(Iterator childIter = tree.getChildren().iterator(); childIter.hasNext(); )
19             {
20             childCount++;
21             if(childCount > maxChildren)
22                 {
23                 System.out.println(prefix + "...");
24                 break;
25                 }
26             
27             Tree child = (Tree) childIter.next();
28             dump(child, levels-1, maxChildren, prefix);
29             }
30         }
31     
32     private DepthFirstDump() { }
33     }
Popular Tags