You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2011/08/25 16:48:40 UTC

svn commit: r1161586 - in /lucene/dev/branches/branch_3x: ./ lucene/ lucene/backwards/ lucene/backwards/src/test-framework/ lucene/backwards/src/test/ lucene/contrib/highlighter/src/test/org/apache/lucene/search/highlight/ lucene/contrib/queryparser/sr...

Author: rmuir
Date: Thu Aug 25 14:48:39 2011
New Revision: 1161586

URL: http://svn.apache.org/viewvc?rev=1161586&view=rev
Log:
LUCENE-3397: backport r1161488

Modified:
    lucene/dev/branches/branch_3x/   (props changed)
    lucene/dev/branches/branch_3x/lucene/   (props changed)
    lucene/dev/branches/branch_3x/lucene/backwards/   (props changed)
    lucene/dev/branches/branch_3x/lucene/backwards/src/test/   (props changed)
    lucene/dev/branches/branch_3x/lucene/backwards/src/test-framework/   (props changed)
    lucene/dev/branches/branch_3x/lucene/contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java
    lucene/dev/branches/branch_3x/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/precedence/TestPrecedenceQueryParser.java
    lucene/dev/branches/branch_3x/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiAnalyzerQPHelper.java
    lucene/dev/branches/branch_3x/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.java
    lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestDocumentWriter.java
    lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java
    lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestPayloads.java
    lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestSameTokenSamePosition.java
    lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestTermVectorsReader.java
    lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestTermdocPerf.java
    lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/queryParser/TestMultiAnalyzer.java
    lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java
    lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestPositionIncrement.java
    lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/payloads/PayloadHelper.java
    lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadNearQuery.java
    lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadTermQuery.java
    lucene/dev/branches/branch_3x/solr/   (props changed)

Modified: lucene/dev/branches/branch_3x/lucene/contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java?rev=1161586&r1=1161585&r2=1161586&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java (original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java Thu Aug 25 14:48:39 2011
@@ -1823,18 +1823,18 @@ final class SynonymAnalyzer extends Anal
  *
  */
 final class SynonymTokenizer extends TokenStream {
-  private TokenStream realStream;
+  private final TokenStream realStream;
   private Token currentRealToken = null;
-  private Map<String,String> synonyms;
-  StringTokenizer st = null;
-  private CharTermAttribute realTermAtt;
-  private PositionIncrementAttribute realPosIncrAtt;
-  private OffsetAttribute realOffsetAtt;
-  private CharTermAttribute termAtt;
-  private PositionIncrementAttribute posIncrAtt;
-  private OffsetAttribute offsetAtt;
+  private final Map<String, String> synonyms;
+  private StringTokenizer st = null;
+  private final CharTermAttribute realTermAtt;
+  private final PositionIncrementAttribute realPosIncrAtt;
+  private final OffsetAttribute realOffsetAtt;
+  private final CharTermAttribute termAtt;
+  private final PositionIncrementAttribute posIncrAtt;
+  private final OffsetAttribute offsetAtt;
 
-  public SynonymTokenizer(TokenStream realStream, Map<String,String> synonyms) {
+  public SynonymTokenizer(TokenStream realStream, Map<String, String> synonyms) {
     this.realStream = realStream;
     this.synonyms = synonyms;
     realTermAtt = realStream.addAttribute(CharTermAttribute.class);
@@ -1886,6 +1886,13 @@ final class SynonymTokenizer extends Tok
     
   }
 
+  @Override
+  public void reset() throws IOException {
+    super.reset();
+    this.currentRealToken = null;
+    this.st = null;
+  }
+
   static abstract class TestHighlightRunner {
     static final int QUERY = 0;
     static final int QUERY_TERM = 1;

Modified: lucene/dev/branches/branch_3x/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/precedence/TestPrecedenceQueryParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/precedence/TestPrecedenceQueryParser.java?rev=1161586&r1=1161585&r2=1161586&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/precedence/TestPrecedenceQueryParser.java (original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/precedence/TestPrecedenceQueryParser.java Thu Aug 25 14:48:39 2011
@@ -81,13 +81,14 @@ public class TestPrecedenceQueryParser e
       super(in);
     }
 
-    boolean inPhrase = false;
+    private boolean inPhrase = false;
 
-    int savedStart = 0, savedEnd = 0;
+    private int savedStart = 0;
+    private int savedEnd = 0;
 
-    CharTermAttribute termAtt = addAttribute(CharTermAttribute.class);
+    private final CharTermAttribute termAtt = addAttribute(CharTermAttribute.class);
 
-    OffsetAttribute offsetAtt = addAttribute(OffsetAttribute.class);
+    private final OffsetAttribute offsetAtt = addAttribute(OffsetAttribute.class);
 
     @Override
     public boolean incrementToken() throws IOException {
@@ -109,6 +110,14 @@ public class TestPrecedenceQueryParser e
             return true;
       return false;
     }
+
+    @Override
+    public void reset() throws IOException {
+      super.reset();
+      this.inPhrase = false;
+      this.savedStart = 0;
+      this.savedEnd = 0;
+    }
   }
 
   public static final class QPTestAnalyzer extends Analyzer {

Modified: lucene/dev/branches/branch_3x/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiAnalyzerQPHelper.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiAnalyzerQPHelper.java?rev=1161586&r1=1161585&r2=1161586&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiAnalyzerQPHelper.java (original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiAnalyzerQPHelper.java Thu Aug 25 14:48:39 2011
@@ -17,6 +17,7 @@ package org.apache.lucene.queryParser.st
  * limitations under the License.
  */
 
+import java.io.IOException;
 import java.io.Reader;
 
 import org.apache.lucene.analysis.Analyzer;
@@ -186,7 +187,7 @@ public class TestMultiAnalyzerQPHelper e
         return true;
       } else {
         boolean next = input.incrementToken();
-        if (next == false) {
+        if (!next) {
           return false;
         }
         prevType = typeAtt.type();
@@ -205,6 +206,13 @@ public class TestMultiAnalyzerQPHelper e
       }
     }
 
+    @Override
+    public void reset() throws IOException {
+      super.reset();
+      this.prevType = null;
+      this.prevStartOffset = 0;
+      this.prevEndOffset = 0;
+    }
   }
 
   /**

Modified: lucene/dev/branches/branch_3x/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.java?rev=1161586&r1=1161585&r2=1161586&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.java (original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.java Thu Aug 25 14:48:39 2011
@@ -40,6 +40,7 @@ import org.apache.lucene.analysis.StopAn
 import org.apache.lucene.analysis.StopFilter;
 import org.apache.lucene.analysis.TokenFilter;
 import org.apache.lucene.analysis.TokenStream;
+import org.apache.lucene.analysis.Tokenizer;
 import org.apache.lucene.analysis.WhitespaceAnalyzer;
 import org.apache.lucene.analysis.standard.StandardAnalyzer;
 import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
@@ -101,8 +102,9 @@ public class TestQPHelper extends Lucene
       super(in);
     }
 
-    boolean inPhrase = false;
-    int savedStart = 0, savedEnd = 0;
+    private boolean inPhrase = false;
+    private int savedStart = 0;
+    private int savedEnd = 0;
 
     @Override
     public boolean incrementToken() throws IOException {
@@ -126,6 +128,14 @@ public class TestQPHelper extends Lucene
         }
       return false;
     }
+
+    @Override
+    public void reset() throws IOException {
+      super.reset();
+      this.inPhrase = false;
+      this.savedStart = 0;
+      this.savedEnd = 0;
+    }
   }
 
   public static final class QPTestAnalyzer extends Analyzer {
@@ -1203,10 +1213,11 @@ public class TestQPHelper extends Lucene
     super.tearDown();
   }
 
-  private class CannedTokenStream extends TokenStream {
+  private class CannedTokenStream extends Tokenizer {
     private int upto = 0;
-    final PositionIncrementAttribute posIncr = addAttribute(PositionIncrementAttribute.class);
-    final CharTermAttribute term = addAttribute(CharTermAttribute.class);
+    private final PositionIncrementAttribute posIncr = addAttribute(PositionIncrementAttribute.class);
+    private final CharTermAttribute term = addAttribute(CharTermAttribute.class);
+    
     @Override
     public boolean incrementToken() {
       clearAttributes();
@@ -1229,6 +1240,12 @@ public class TestQPHelper extends Lucene
       upto++;
       return true;
     }
+
+    @Override
+    public void reset() throws IOException {
+      super.reset();
+      this.upto = 0;
+    }
   }
 
   private class CannedAnalyzer extends Analyzer {

Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestDocumentWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestDocumentWriter.java?rev=1161586&r1=1161585&r2=1161586&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestDocumentWriter.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestDocumentWriter.java Thu Aug 25 14:48:39 2011
@@ -146,7 +146,7 @@ public class TestDocumentWriter extends 
       @Override
       public TokenStream tokenStream(String fieldName, Reader reader) {
         return new TokenFilter(new WhitespaceTokenizer(TEST_VERSION_CURRENT, reader)) {
-          boolean first=true;
+          boolean first = true;
           AttributeSource.State state;
 
           @Override
@@ -177,9 +177,16 @@ public class TestDocumentWriter extends 
 
           }
 
-          CharTermAttribute termAtt = addAttribute(CharTermAttribute.class);
-          PayloadAttribute payloadAtt = addAttribute(PayloadAttribute.class);
-          PositionIncrementAttribute posIncrAtt = addAttribute(PositionIncrementAttribute.class);          
+          @Override
+          public void reset() throws IOException {
+            super.reset();
+            first = true;
+            state = null;
+          }
+
+          final CharTermAttribute termAtt = addAttribute(CharTermAttribute.class);
+          final PayloadAttribute payloadAtt = addAttribute(PayloadAttribute.class);
+          final PositionIncrementAttribute posIncrAtt = addAttribute(PositionIncrementAttribute.class);
         };
       }
     };

Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java?rev=1161586&r1=1161585&r2=1161586&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java Thu Aug 25 14:48:39 2011
@@ -159,46 +159,6 @@ public class TestIndexWriter extends Luc
       }
     }
 
-    static final class StringSplitAnalyzer extends Analyzer {
-      @Override
-      public TokenStream tokenStream(String fieldName, Reader reader) {
-        return new StringSplitTokenizer(reader);
-      }
-    }
-
-    private static class StringSplitTokenizer extends Tokenizer {
-      private final String[] tokens;
-      private int upto = 0;
-      private final CharTermAttribute termAtt = addAttribute(CharTermAttribute.class);
-
-      public StringSplitTokenizer(Reader r) {
-        try {
-          final StringBuilder b = new StringBuilder();
-          final char[] buffer = new char[1024];
-          int n;
-          while((n = r.read(buffer)) != -1) {
-            b.append(buffer, 0, n);
-          }
-          tokens = b.toString().split(" ");
-        } catch (IOException ioe) {
-          throw new RuntimeException(ioe);
-        }
-      }
-
-      @Override
-      public final boolean incrementToken() throws IOException {
-        clearAttributes();      
-        if (upto < tokens.length) {
-          termAtt.setEmpty();
-          termAtt.append(tokens[upto]);
-          upto++;
-          return true;
-        } else {
-          return false;
-        }
-      }
-    }
-
     /**
      * Make sure we skip wicked long terms.
     */
@@ -1891,6 +1851,52 @@ public class TestIndexWriter extends Luc
     dir.close();
   }
 
+  static final class StringSplitAnalyzer extends Analyzer {
+    @Override
+    public TokenStream tokenStream(String fieldName, Reader reader) {
+      return new StringSplitTokenizer(reader);
+    }
+  }
+
+  private static class StringSplitTokenizer extends Tokenizer {
+    private String[] tokens;
+    private int upto;
+    private final CharTermAttribute termAtt = addAttribute(CharTermAttribute.class);
+
+    public StringSplitTokenizer(Reader r) {
+      try {
+        reset(r);
+      } catch (IOException e) {
+        throw new RuntimeException(e);
+      }
+    }
+
+    @Override
+    public final boolean incrementToken() throws IOException {
+      clearAttributes();      
+      if (upto < tokens.length) {
+        termAtt.setEmpty();
+        termAtt.append(tokens[upto]);
+        upto++;
+        return true;
+      } else {
+        return false;
+      }
+    }
+
+    @Override
+    public void reset(Reader input) throws IOException {
+       this.upto = 0;
+       final StringBuilder b = new StringBuilder();
+       final char[] buffer = new char[1024];
+       int n;
+       while ((n = input.read(buffer)) != -1) {
+         b.append(buffer, 0, n);
+       }
+       this.tokens = b.toString().split(" ");
+    }
+  }
+
   // LUCENE-3183
   public void testEmptyFieldNameTIIOne() throws IOException {
     Directory dir = newDirectory();

Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestPayloads.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestPayloads.java?rev=1161586&r1=1161585&r2=1161586&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestPayloads.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestPayloads.java Thu Aug 25 14:48:39 2011
@@ -440,7 +440,7 @@ public class TestPayloads extends Lucene
         private byte[] data;
         private int length;
         private int offset;
-        Payload payload = new Payload();
+        private int startOffset;
         PayloadAttribute payloadAtt;
         
         public PayloadFilter(TokenStream in, byte[] data, int offset, int length) {
@@ -448,6 +448,7 @@ public class TestPayloads extends Lucene
             this.data = data;
             this.length = length;
             this.offset = offset;
+            this.startOffset = offset;
             payloadAtt = addAttribute(PayloadAttribute.class);
         }
         
@@ -467,6 +468,12 @@ public class TestPayloads extends Lucene
             
             return hasNext;
         }
+
+      @Override
+      public void reset() throws IOException {
+        super.reset();
+        this.offset = startOffset;
+      }
     }
     
     public void testThreadSafety() throws Exception {

Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestSameTokenSamePosition.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestSameTokenSamePosition.java?rev=1161586&r1=1161585&r2=1161586&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestSameTokenSamePosition.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestSameTokenSamePosition.java Thu Aug 25 14:48:39 2011
@@ -21,7 +21,9 @@ import java.io.IOException;
 import java.io.Reader;
 
 import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.ReusableAnalyzerBase;
 import org.apache.lucene.analysis.TokenStream;
+import org.apache.lucene.analysis.Tokenizer;
 import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
 import org.apache.lucene.analysis.tokenattributes.OffsetAttribute;
 import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;
@@ -35,7 +37,6 @@ public class TestSameTokenSamePosition e
   /**
    * Attempt to reproduce an assertion error that happens
    * only with the trunk version around April 2011.
-   * @param args
    */
   public void test() throws Exception {
     Directory dir = newDirectory();
@@ -72,16 +73,16 @@ final class BugReproAnalyzer extends Ana
   }
 }
 
-final class BugReproAnalyzerTokenizer extends TokenStream {
+final class BugReproAnalyzerTokenizer extends Tokenizer {
   private final CharTermAttribute termAtt = addAttribute(CharTermAttribute.class);
   private final OffsetAttribute offsetAtt = addAttribute(OffsetAttribute.class);
   private final PositionIncrementAttribute posIncAtt = addAttribute(PositionIncrementAttribute.class);
-  int tokenCount = 4;
-  int nextTokenIndex = 0;
-  String terms[] = new String[]{"six", "six", "drunken", "drunken"};
-  int starts[] = new int[]{0, 0, 4, 4};
-  int ends[] = new int[]{3, 3, 11, 11};
-  int incs[] = new int[]{1, 0, 1, 0};
+  private final int tokenCount = 4;
+  private int nextTokenIndex = 0;
+  private final String terms[] = new String[]{"six", "six", "drunken", "drunken"};
+  private final int starts[] = new int[]{0, 0, 4, 4};
+  private final int ends[] = new int[]{3, 3, 11, 11};
+  private final int incs[] = new int[]{1, 0, 1, 0};
 
   @Override
   public boolean incrementToken() throws IOException {
@@ -95,4 +96,10 @@ final class BugReproAnalyzerTokenizer ex
       return false;
     }
   }
+
+  @Override
+  public void reset() throws IOException {
+    super.reset();
+    this.nextTokenIndex = 0;
+  }
 }

Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestTermVectorsReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestTermVectorsReader.java?rev=1161586&r1=1161585&r2=1161586&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestTermVectorsReader.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestTermVectorsReader.java Thu Aug 25 14:48:39 2011
@@ -24,8 +24,7 @@ import java.util.Iterator;
 import java.util.Map;
 import java.util.SortedSet;
 
-import org.apache.lucene.analysis.Analyzer;
-import org.apache.lucene.analysis.TokenStream;
+import org.apache.lucene.analysis.*;
 import org.apache.lucene.analysis.tokenattributes.OffsetAttribute;
 import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;
 import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
@@ -123,11 +122,11 @@ public class TestTermVectorsReader exten
   }
 
   private class MyTokenStream extends TokenStream {
-    int tokenUpto;
+    private int tokenUpto;
     
-    CharTermAttribute termAtt;
-    PositionIncrementAttribute posIncrAtt;
-    OffsetAttribute offsetAtt;
+    private final CharTermAttribute termAtt;
+    private final PositionIncrementAttribute posIncrAtt;
+    private final OffsetAttribute offsetAtt;
     
     public MyTokenStream() {
       termAtt = addAttribute(CharTermAttribute.class);
@@ -152,6 +151,12 @@ public class TestTermVectorsReader exten
         return true;
       }
     }
+
+    @Override
+    public void reset() throws IOException {
+      super.reset();
+      this.tokenUpto = 0;
+    }
   }
 
   private class MyAnalyzer extends Analyzer {

Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestTermdocPerf.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestTermdocPerf.java?rev=1161586&r1=1161585&r2=1161586&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestTermdocPerf.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestTermdocPerf.java Thu Aug 25 14:48:39 2011
@@ -22,7 +22,9 @@ import java.io.Reader;
 import java.util.Random;
 
 import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.ReusableAnalyzerBase;
 import org.apache.lucene.analysis.TokenStream;
+import org.apache.lucene.analysis.Tokenizer;
 import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
@@ -30,13 +32,20 @@ import org.apache.lucene.index.IndexWrit
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.LuceneTestCase;
 
-class RepeatingTokenStream extends TokenStream {
-  public int num;
+class RepeatingTokenStream extends Tokenizer {
+  
+  private final Random random;
+  private final float percentDocs;
+  private final int maxTF;
+  private int num;
   CharTermAttribute termAtt;
   String value;
 
-   public RepeatingTokenStream(String val) {
+   public RepeatingTokenStream(String val, Random random, float percentDocs, int maxTF) {
      this.value = val;
+     this.random = random;
+     this.percentDocs = percentDocs;
+     this.maxTF = maxTF;
      this.termAtt = addAttribute(CharTermAttribute.class);
    }
 
@@ -50,19 +59,27 @@ class RepeatingTokenStream extends Token
      }
      return false;
    }
+
+  @Override
+  public void reset() throws IOException {
+    super.reset();
+    if (random.nextFloat() < percentDocs) {
+      num = random.nextInt(maxTF) + 1;
+    } else {
+      num = 0;
+    }
+  }
 }
 
 
 public class TestTermdocPerf extends LuceneTestCase {
 
   void addDocs(final Random random, Directory dir, final int ndocs, String field, final String val, final int maxTF, final float percentDocs) throws IOException {
-    final RepeatingTokenStream ts = new RepeatingTokenStream(val);
+    final RepeatingTokenStream ts = new RepeatingTokenStream(val, random, percentDocs, maxTF);
 
     Analyzer analyzer = new Analyzer() {
       @Override
       public TokenStream tokenStream(String fieldName, Reader reader) {
-        if (random.nextFloat() < percentDocs) ts.num = random.nextInt(maxTF)+1;
-        else ts.num=0;
         return ts;
       }
     };

Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/queryParser/TestMultiAnalyzer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/queryParser/TestMultiAnalyzer.java?rev=1161586&r1=1161585&r2=1161586&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/queryParser/TestMultiAnalyzer.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/queryParser/TestMultiAnalyzer.java Thu Aug 25 14:48:39 2011
@@ -17,9 +17,11 @@ package org.apache.lucene.queryParser;
  * limitations under the License.
  */
 
+import java.io.IOException;
 import java.io.Reader;
 
 import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.BaseTokenStreamTestCase;
 import org.apache.lucene.analysis.LowerCaseFilter;
 import org.apache.lucene.analysis.TokenFilter;
 import org.apache.lucene.analysis.TokenStream;
@@ -29,7 +31,6 @@ import org.apache.lucene.analysis.tokena
 import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
 import org.apache.lucene.analysis.tokenattributes.TypeAttribute;
 import org.apache.lucene.search.Query;
-import org.apache.lucene.analysis.BaseTokenStreamTestCase;
 import org.apache.lucene.util.Version;
 
 /**
@@ -148,10 +149,10 @@ public class TestMultiAnalyzer extends B
     private int prevStartOffset;
     private int prevEndOffset;
     
-    CharTermAttribute termAtt;
-    PositionIncrementAttribute posIncrAtt;
-    OffsetAttribute offsetAtt;
-    TypeAttribute typeAtt;
+    private final CharTermAttribute termAtt;
+    private final PositionIncrementAttribute posIncrAtt;
+    private final OffsetAttribute offsetAtt;
+    private final TypeAttribute typeAtt;
     
     public TestFilter(TokenStream in) {
       super(in);
@@ -172,7 +173,7 @@ public class TestMultiAnalyzer extends B
         return true;
       } else {
         boolean next = input.incrementToken();
-        if (next == false) {
+        if (!next) {
           return false;
         }
         prevType = typeAtt.type();
@@ -190,6 +191,13 @@ public class TestMultiAnalyzer extends B
         }
       }
     }
+
+    public void reset() throws IOException {
+      super.reset();
+      this.prevType = null;
+      this.prevStartOffset = 0;
+      this.prevEndOffset = 0;
+    }
   }
 
   /**

Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java?rev=1161586&r1=1161585&r2=1161586&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java Thu Aug 25 14:48:39 2011
@@ -381,6 +381,13 @@ public class TestMultiPhraseQuery extend
         return false;
       }
     }
+
+    @Override
+    public void reset() throws IOException {
+      super.reset();
+      this.upto = 0;
+      this.lastPos = 0;
+    }
   }
 
   public void testZeroPosIncr() throws IOException {

Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestPositionIncrement.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestPositionIncrement.java?rev=1161586&r1=1161585&r2=1161586&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestPositionIncrement.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestPositionIncrement.java Thu Aug 25 14:48:39 2011
@@ -17,6 +17,7 @@ package org.apache.lucene.search;
  * limitations under the License.
  */
 
+import java.io.IOException;
 import java.io.Reader;
 import java.io.IOException;
 import java.io.StringReader;
@@ -82,6 +83,12 @@ public class TestPositionIncrement exten
             i++;
             return true;
           }
+
+          @Override
+          public void reset() throws IOException {
+            super.reset();
+            this.i = 0;
+          }
         };
       }
     };

Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/payloads/PayloadHelper.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/payloads/PayloadHelper.java?rev=1161586&r1=1161585&r2=1161586&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/payloads/PayloadHelper.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/payloads/PayloadHelper.java Thu Aug 25 14:48:39 2011
@@ -57,7 +57,6 @@ public class PayloadHelper {
   public final class PayloadAnalyzer extends Analyzer {
 
 
-
     @Override
     public TokenStream tokenStream(String fieldName, Reader reader) {
       TokenStream result = new LowerCaseTokenizer(TEST_VERSION_CURRENT, reader);
@@ -67,9 +66,9 @@ public class PayloadHelper {
   }
 
   public final class PayloadFilter extends TokenFilter {
-    String fieldName;
-    int numSeen = 0;
-    PayloadAttribute payloadAtt;
+    private final String fieldName;
+    private int numSeen = 0;
+    private final PayloadAttribute payloadAtt;
     
     public PayloadFilter(TokenStream input, String fieldName) {
       super(input);
@@ -81,18 +80,13 @@ public class PayloadHelper {
     public boolean incrementToken() throws IOException {
       
       if (input.incrementToken()) {
-        if (fieldName.equals(FIELD))
-        {
+        if (fieldName.equals(FIELD)) {
           payloadAtt.setPayload(new Payload(payloadField));
-        }
-        else if (fieldName.equals(MULTI_FIELD))
-        {
-          if (numSeen  % 2 == 0)
-          {
+        } else if (fieldName.equals(MULTI_FIELD)) {
+          if (numSeen  % 2 == 0) {
             payloadAtt.setPayload(new Payload(payloadMultiField1));
           }
-          else
-          {
+          else {
             payloadAtt.setPayload(new Payload(payloadMultiField2));
           }
           numSeen++;
@@ -101,6 +95,12 @@ public class PayloadHelper {
       }
       return false;
     }
+
+    @Override
+    public void reset() throws IOException {
+      super.reset();
+      this.numSeen = 0;
+    }
   }
 
   /**

Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadNearQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadNearQuery.java?rev=1161586&r1=1161585&r2=1161586&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadNearQuery.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadNearQuery.java Thu Aug 25 14:48:39 2011
@@ -67,9 +67,9 @@ public class TestPayloadNearQuery extend
   }
 
   private static class PayloadFilter extends TokenFilter {
-    String fieldName;
-    int numSeen = 0;
-    protected PayloadAttribute payAtt;
+    private final String fieldName;
+    private int numSeen = 0;
+    private final PayloadAttribute payAtt;
 
     public PayloadFilter(TokenStream input, String fieldName) {
       super(input);
@@ -80,7 +80,7 @@ public class TestPayloadNearQuery extend
     @Override
     public boolean incrementToken() throws IOException {
       boolean result = false;
-      if (input.incrementToken() == true){
+      if (input.incrementToken()) {
         if (numSeen % 2 == 0) {
           payAtt.setPayload(new Payload(payload2));
         } else {
@@ -91,6 +91,12 @@ public class TestPayloadNearQuery extend
       }
       return result;
     }
+
+    @Override
+    public void reset() throws IOException {
+      super.reset();
+      this.numSeen = 0;
+    }
   }
   
   private PayloadNearQuery newPhraseQuery (String fieldName, String phrase, boolean inOrder, PayloadFunction function ) {

Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadTermQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadTermQuery.java?rev=1161586&r1=1161585&r2=1161586&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadTermQuery.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadTermQuery.java Thu Aug 25 14:48:39 2011
@@ -72,10 +72,10 @@ public class TestPayloadTermQuery extend
   }
 
   private class PayloadFilter extends TokenFilter {
-    String fieldName;
-    int numSeen = 0;
+    private final String fieldName;
+    private int numSeen = 0;
     
-    PayloadAttribute payloadAtt;    
+    private final PayloadAttribute payloadAtt;
     
     public PayloadFilter(TokenStream input, String fieldName) {
       super(input);
@@ -102,6 +102,12 @@ public class TestPayloadTermQuery extend
         return false;
       }
     }
+
+    @Override
+    public void reset() throws IOException {
+      super.reset();
+      this.numSeen = 0;
+    }
   }
 
   @Override