~ubuntu-branches/ubuntu/karmic/lucene2/karmic

« back to all changes in this revision

Viewing changes to src/test/org/apache/lucene/analysis/TestAnalyzers.java

  • Committer: Bazaar Package Importer
  • Author(s): Onkar Shinde
  • Date: 2008-11-22 05:22:42 UTC
  • mfrom: (1.1.4 upstream) (2.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20081122052242-iwzhyxjja1qlk2eq
Tags: 2.4.0+ds1-2ubuntu1
* Merge from debian unstable. (LP: #300540)
* Remaining Ubuntu changes:
  - debian/patches
    * 00list - Remove Debian's patch 81_prevent-network-access.dpatch. Not
      needed anymore.
  - debian/control
     * Modify Maintainer value to match the DebianMaintainerField
       specification.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 * limitations under the License.
18
18
 */
19
19
 
20
 
import java.io.*;
 
20
import java.io.IOException;
 
21
import java.io.StringReader;
 
22
import java.util.LinkedList;
21
23
import java.util.List;
22
 
import java.util.LinkedList;
23
24
 
 
25
import org.apache.lucene.analysis.standard.StandardTokenizer;
 
26
import org.apache.lucene.index.Payload;
24
27
import org.apache.lucene.util.LuceneTestCase;
25
 
import org.apache.lucene.index.Payload;
26
 
import org.apache.lucene.analysis.standard.StandardTokenizer;
27
28
 
28
29
public class TestAnalyzers extends LuceneTestCase {
29
30
 
35
36
                               String input, 
36
37
                               String[] output) throws Exception {
37
38
    TokenStream ts = a.tokenStream("dummy", new StringReader(input));
 
39
    final Token reusableToken  = new Token();
38
40
    for (int i=0; i<output.length; i++) {
39
 
      Token t = ts.next();
40
 
      assertNotNull(t);
41
 
      assertEquals(t.termText(), output[i]);
 
41
      Token nextToken = ts.next(reusableToken);
 
42
      assertNotNull(nextToken);
 
43
      assertEquals(nextToken.term(), output[i]);
42
44
    }
43
 
    assertNull(ts.next());
 
45
    assertNull(ts.next(reusableToken));
44
46
    ts.close();
45
47
  }
46
48
 
93
95
  }
94
96
 
95
97
  void verifyPayload(TokenStream ts) throws IOException {
96
 
    Token t = new Token();
 
98
    final Token reusableToken = new Token();
97
99
    for(byte b=1;;b++) {
98
 
      t.clear();
99
 
      t = ts.next(t);
100
 
      if (t==null) break;
101
 
      // System.out.println("id="+System.identityHashCode(t) + " " + t);
102
 
      // System.out.println("payload=" + (int)t.getPayload().toByteArray()[0]);
103
 
      assertEquals(b, t.getPayload().toByteArray()[0]);
 
100
      reusableToken.clear();
 
101
      Token nextToken = ts.next(reusableToken);
 
102
      if (nextToken==null) break;
 
103
      // System.out.println("id="+System.identityHashCode(nextToken) + " " + t);
 
104
      // System.out.println("payload=" + (int)nextToken.getPayload().toByteArray()[0]);
 
105
      assertEquals(b, nextToken.getPayload().toByteArray()[0]);
104
106
    }
105
107
  }
106
108
 
141
143
    super(input);
142
144
  }
143
145
 
144
 
  public Token next() throws IOException {
 
146
  public Token next(final Token reusableToken) throws IOException {
145
147
    if (lst == null) {
146
148
      lst = new LinkedList();
147
 
      for(;;) {
148
 
        Token t = input.next();
149
 
        if (t==null) break;
150
 
        lst.add(t);
 
149
      for(Token nextToken = input.next(reusableToken); nextToken != null; nextToken = input.next(reusableToken)) {
 
150
        lst.add(nextToken.clone());
151
151
      }
152
152
    }
153
153
    return lst.size()==0 ? null : (Token)lst.remove(0);
162
162
  byte[] data = new byte[1];
163
163
  Payload p = new Payload(data,0,1);
164
164
 
165
 
  public Token next(Token target) throws IOException {
166
 
    target = input.next(target);
167
 
    if (target==null) return null;
168
 
    target.setPayload(p);  // reuse the payload / byte[]
 
165
  public Token next(final Token reusableToken) throws IOException {
 
166
    assert reusableToken != null;
 
167
    Token nextToken = input.next(reusableToken);
 
168
    if (nextToken==null) return null;
 
169
    nextToken.setPayload(p);  // reuse the payload / byte[]
169
170
    data[0]++;
170
 
    return target;
 
171
    return nextToken;
171
172
  }
172
173
}
 
 
b'\\ No newline at end of file'