| 47 | * appropriate position in the trie. |
| 48 | */ |
| 49 | public void addWord(String word) { |
| 50 | if (word == null || word.isEmpty()) { |
| 51 | return; |
| 52 | } |
| 53 | |
| 54 | TrieNode child; |
| 55 | char firstChar = word.charAt(0); |
| 56 | |
| 57 | TrieNode t = getChild(firstChar); |
| 58 | |
| 59 | if (t == null) { |
| 60 | child = new TrieNode(firstChar); |
| 61 | children.add(child); |
| 62 | } else { |
| 63 | child = t; |
| 64 | } |
| 65 | |
| 66 | if (word.length() > 1) { |
| 67 | child.addWord(word.substring(1)); |
| 68 | } else { |
| 69 | child.setTerminates(true); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | /* Find a child node of this node that has the char argument as its |
| 74 | * data. Return null if no such child node is present in the trie. |