Merge branch 'master' of feistymeow.org:feisty_meow
[feisty_meow.git] / kona / src / org / feistymeow / textual / SimpleDictionary.java
diff --git a/kona/src/org/feistymeow/textual/SimpleDictionary.java b/kona/src/org/feistymeow/textual/SimpleDictionary.java
new file mode 100644 (file)
index 0000000..9008ac9
--- /dev/null
@@ -0,0 +1,49 @@
+package org.feistymeow.textual;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class SimpleDictionary extends HashSet<String>
+// or alternatively, BinaryTree<String>
+// => what is BST implem for java! is it balanced?
+{
+
+       private static final long serialVersionUID = 1L;
+
+       public SimpleDictionary(Set<String> words)
+       {
+               addAll(words);
+               computeLongestWord();
+       }
+
+       public SimpleDictionary(String words[])
+       {
+               for (String word : words) {
+                       add(word);
+               }
+               computeLongestWord();
+       }
+
+       public int computeLongestWord()
+       {
+               previouslyComputedLongestWord = 1;
+
+               // hmmm: iterate on set to find longest.
+
+               // kludge implem placeholder.
+               previouslyComputedLongestWord = 100;
+               return previouslyComputedLongestWord;
+       }
+
+       public boolean lookup(String toFind)
+       {
+               return contains(toFind);
+       }
+
+       public int longestWord()
+       {
+               return previouslyComputedLongestWord;
+       }
+
+       int previouslyComputedLongestWord;
+}