ported trie.go to Java