Issue #10 make sure that State emits a specific match only once

This commit is contained in:
robert-bor 2014-08-27 08:42:46 +02:00
parent c96c57399a
commit 2b125d2689
2 changed files with 5 additions and 5 deletions

View File

@ -41,7 +41,7 @@ public class State {
private State failure = null;
/** whenever this state is reached, it will emit the matches keywords for future reference */
private List<String> emits = null;
private Set<String> emits = null;
public State() {
this(0);
@ -83,7 +83,7 @@ public class State {
public void addEmit(String keyword) {
if (this.emits == null) {
this.emits = new ArrayList<String>();
this.emits = new TreeSet<>();
}
this.emits.add(keyword);
}

View File

@ -48,8 +48,8 @@ public class TrieTest {
Collection<Emit> emits = trie.parseText("ushers");
assertEquals(3, emits.size()); // she @ 3, he @ 3, hers @ 5
Iterator<Emit> iterator = emits.iterator();
checkEmit(iterator.next(), 1, 3, "she");
checkEmit(iterator.next(), 2, 3, "he");
checkEmit(iterator.next(), 1, 3, "she");
checkEmit(iterator.next(), 2, 5, "hers");
}
@ -87,10 +87,10 @@ public class TrieTest {
checkEmit(iterator.next(), 0, 1, "he");
checkEmit(iterator.next(), 2, 3, "he");
checkEmit(iterator.next(), 4, 5, "he");
checkEmit(iterator.next(), 0, 7, "hehehehe");
checkEmit(iterator.next(), 6, 7, "he");
checkEmit(iterator.next(), 2, 9, "hehehehe");
checkEmit(iterator.next(), 0, 7, "hehehehe");
checkEmit(iterator.next(), 8, 9, "he");
checkEmit(iterator.next(), 2, 9, "hehehehe");
}
@Test