Apache Lucene open-source search software
LUCENE-3842: refactor: don't make spooky State methods public
Michael McCandless93cc8141080b
diff --git a/lucene/core/src/java/org/apache/lucene/util/automaton/State.java b/lucene/core/src/java/org/apache/lucene/util/automaton/State.javaindex 73e8a927a22..b59876eebdb 100644--- a/lucene/core/src/java/org/apache/lucene/util/automaton/State.java+++ b/lucene/core/src/java/org/apache/lucene/util/automaton/State.java@@ -62,7 +62,7 @@ public class State implements Comparable<State> {/*** Resets transition set.*/- public final void resetTransitions() {+ final void resetTransitions() {transitionsArray = new Transition[0];numTransitions = 0;}@@ -169,7 +169,7 @@ public class State implements Comparable<State> {* {@code to} state. This is implemented by copying all* transitions from {@code to} to this state, and if {@code* to} is an accept state then set accept for this state. */- public void addEpsilon(State to) {+ void addEpsilon(State to) {if (to.accept) accept = true;for (Transition t : to.getTransitions())addTransition(t);diff --git a/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggester.java b/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggester.javaindex a5db5f0c913..c447bff21a2 100644--- a/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggester.java+++ b/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggester.java@@ -224,6 +224,15 @@ public class AnalyzingSuggester extends Lookup {return fst == null ? 0 : fst.sizeInBytes();}+ private void copyDestTransitions(State from, State to, List<Transition> transitions) {+ if (to.isAccept()) {+ from.setAccept(true);+ }+ for(Transition t : to.getTransitions()) {+ transitions.add(t);+ }+ }+// Replaces SEP with epsilon or remaps them if// we were asked to preserve them:private void replaceSep(Automaton a) {@@ -240,15 +249,10 @@ public class AnalyzingSuggester extends Lookup {if (t.getMin() == TokenStreamToAutomaton.POS_SEP) {if (preserveSep) {// Remap to SEP_LABEL:- t = new Transition(SEP_LABEL, t.getDest());+ newTransitions.add(new Transition(SEP_LABEL, t.getDest()));} else {- // NOTE: sort of weird because this will grow- // the transition array we are iterating over,- // but because we are going in reverse topo sort- // it will not add any SEP/HOLE transitions:- state.addEpsilon(t.getDest());+ copyDestTransitions(state, t.getDest(), newTransitions);a.setDeterministic(false);- t = null;}} else if (t.getMin() == TokenStreamToAutomaton.HOLE) {@@ -259,20 +263,12 @@ public class AnalyzingSuggester extends Lookup {// that's somehow a problem we can always map HOLE// to a dedicated byte (and escape it in the// input).-- // NOTE: sort of weird because this will grow- // the transition array we are iterating over,- // but because we are going in reverse topo sort- // it will not add any SEP/HOLE transitions:- state.addEpsilon(t.getDest());+ copyDestTransitions(state, t.getDest(), newTransitions);a.setDeterministic(false);- t = null;- }- if (t != null) {+ } else {newTransitions.add(t);}}- state.resetTransitions();state.setTransitions(newTransitions.toArray(new Transition[newTransitions.size()]));}}