KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.innig.macker.example.conventions;
2
3 import java.util.*;
4 import java.io.*;
5
6 public abstract class StringTree
7     implements Tree
8     {
9     public StringTree(StringTree parent, String JavaDoc word)
10         {
11         this.parent = parent;
12         this.word = word;
13         }
14     
15     public Tree getParent()
16         { return parent; }
17     
18     public HashSet/*<Tree>*/ getChildren()
19         {
20         HashSet children = new HashSet();
21         StringBuffer JavaDoc newWord = new StringBuffer JavaDoc(word);
22         for(Iterator i = getChildSuffixes().iterator(); i.hasNext();)
23             {
24             String JavaDoc suffix = (String JavaDoc) i.next();
25             newWord.setLength(word.length());
26             newWord.append(suffix);
27             children.add(makeChild(newWord.toString()));
28             }
29         return children;
30         }
31     
32     protected abstract Set/*<String>*/ getChildSuffixes();
33     
34     protected abstract StringTree makeChild(String JavaDoc childWord);
35         
36     public String JavaDoc toString()
37         { return quote(word); }
38     
39     static String JavaDoc quote(String JavaDoc word)
40         { return '"' + word + '"'; }
41     
42     private StringTree parent;
43     private String JavaDoc word;
44     }
Popular Tags