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 word) 10 { 11 this.parent = parent; 12 this.word = word; 13 } 14 15 public Tree getParent() 16 { return parent; } 17 18 public HashSet getChildren() 19 { 20 HashSet children = new HashSet(); 21 StringBuffer newWord = new StringBuffer (word); 22 for(Iterator i = getChildSuffixes().iterator(); i.hasNext();) 23 { 24 String suffix = (String ) 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 getChildSuffixes(); 33 34 protected abstract StringTree makeChild(String childWord); 35 36 public String toString() 37 { return quote(word); } 38 39 static String quote(String word) 40 { return '"' + word + '"'; } 41 42 private StringTree parent; 43 private String word; 44 } | Popular Tags |