Apache Lucene open-source search software
LUCENE-6033: CachingTokenFilter now uses ArrayList not LinkedList, and has new isCached() method
David Wayne Smileya38cb51906aa
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 60a8b8c594c..91efb29abe5 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -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 anddiff --git a/lucene/core/src/java/org/apache/lucene/analysis/CachingTokenFilter.java b/lucene/core/src/java/org/apache/lucene/analysis/CachingTokenFilter.javaindex aef4a70feb9..006d6dff119 100644--- a/lucene/core/src/java/org/apache/lucene/analysis/CachingTokenFilter.java+++ b/lucene/core/src/java/org/apache/lucene/analysis/CachingTokenFilter.java@@ -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 {*/@Overridepublic 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;+ }+}