add builder method for setting word transitions

This commit is contained in:
Douglas Lovell 2015-10-28 14:10:53 -06:00
parent a646f233a5
commit 4be3e115b6

View File

@ -223,6 +223,8 @@ public class Trie {
private final Trie trie = new Trie(trieConfig); private final Trie trie = new Trie(trieConfig);
private boolean hasAddedKeyword = false;
private TrieBuilder() {} private TrieBuilder() {}
public TrieBuilder caseInsensitive() { public TrieBuilder caseInsensitive() {
@ -240,8 +242,18 @@ public class Trie {
return this; return this;
} }
public TrieBuilder wordTransitions() {
if (hasAddedKeyword) {
throw new IllegalStateException(
"Unable to switch to word transitions after keywords added");
}
this.trieConfig.setWordTransitions(true);
return this;
}
public TrieBuilder addKeyword(String keyword) { public TrieBuilder addKeyword(String keyword) {
trie.addKeyword(keyword); trie.addKeyword(keyword);
hasAddedKeyword = true;
return this; return this;
} }