You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2012/09/29 02:16:23 UTC

svn commit: r1391704 - in /lucene/dev/branches/branch_4x: ./ lucene/ lucene/core/ lucene/core/src/java/org/apache/lucene/util/automaton/State.java lucene/suggest/ lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggester.java

Author: mikemccand
Date: Sat Sep 29 00:16:22 2012
New Revision: 1391704

URL: http://svn.apache.org/viewvc?rev=1391704&view=rev
Log:
LUCENE-3842: refactor: don't make spooky State methods public

Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/lucene/   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/automaton/State.java
    lucene/dev/branches/branch_4x/lucene/suggest/   (props changed)
    lucene/dev/branches/branch_4x/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggester.java

Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/automaton/State.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/automaton/State.java?rev=1391704&r1=1391703&r2=1391704&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/automaton/State.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/automaton/State.java Sat Sep 29 00:16:22 2012
@@ -62,7 +62,7 @@ public class State implements Comparable
   /**
    * 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
    *  {@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);

Modified: lucene/dev/branches/branch_4x/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggester.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggester.java?rev=1391704&r1=1391703&r2=1391704&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggester.java (original)
+++ lucene/dev/branches/branch_4x/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggester.java Sat Sep 29 00:16:22 2012
@@ -224,6 +224,15 @@ public class AnalyzingSuggester extends 
     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 
         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 
           // 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()]));
     }
   }