mirror of
https://github.com/apache/lucene.git
synced 2025-03-09 01:59:27 +00:00
LUCENE-6033: CachingTokenFilter now uses ArrayList not LinkedList, and has new isCached() method
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1638794 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e698180451
commit
a38cb51906
@ -302,6 +302,9 @@ Optimizations
|
||||
* LUCENE-6040: Speed up EliasFanoDocIdSet through broadword bit selection.
|
||||
(Paul Elschot)
|
||||
|
||||
* LUCENE-6033: CachingTokenFilter now uses ArrayList not LinkedList, and has new
|
||||
isCached() method. (David Smiley)
|
||||
|
||||
Build
|
||||
|
||||
* LUCENE-5909: Smoke tester now has better command line parsing and
|
||||
|
@ -18,8 +18,8 @@ package org.apache.lucene.analysis;
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.lucene.util.AttributeSource;
|
||||
@ -27,7 +27,8 @@ import org.apache.lucene.util.AttributeSource;
|
||||
/**
|
||||
* This class can be used if the token attributes of a TokenStream
|
||||
* are intended to be consumed more than once. It caches
|
||||
* all token attribute states locally in a List.
|
||||
* all token attribute states locally in a List when the first call to
|
||||
* {@link #incrementToken()} is called.
|
||||
*
|
||||
* <P>CachingTokenFilter implements the optional method
|
||||
* {@link TokenStream#reset()}, which repositions the
|
||||
@ -51,7 +52,7 @@ public final class CachingTokenFilter extends TokenFilter {
|
||||
public final boolean incrementToken() throws IOException {
|
||||
if (cache == null) {
|
||||
// fill cache lazily
|
||||
cache = new LinkedList<>();
|
||||
cache = new ArrayList<>(64);
|
||||
fillCache();
|
||||
iterator = cache.iterator();
|
||||
}
|
||||
@ -81,13 +82,13 @@ public final class CachingTokenFilter extends TokenFilter {
|
||||
*/
|
||||
@Override
|
||||
public void reset() {
|
||||
if(cache != null) {
|
||||
if (cache != null) {
|
||||
iterator = cache.iterator();
|
||||
}
|
||||
}
|
||||
|
||||
private void fillCache() throws IOException {
|
||||
while(input.incrementToken()) {
|
||||
while (input.incrementToken()) {
|
||||
cache.add(captureState());
|
||||
}
|
||||
// capture final state
|
||||
@ -95,4 +96,9 @@ public final class CachingTokenFilter extends TokenFilter {
|
||||
finalState = captureState();
|
||||
}
|
||||
|
||||
/** If the underlying token stream was consumed and cached. */
|
||||
public boolean isCached() {
|
||||
return cache != null;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user