Java trie implementation