FileDocCategorySizeDatePackage
CachingTokenFilter.javaAPI DocApache Lucene 2.2.01988Sat Jun 16 22:20:30 BST 2007org.apache.lucene.analysis

CachingTokenFilter

public class CachingTokenFilter extends TokenFilter
This class can be used if the Tokens of a TokenStream are intended to be consumed more than once. It caches all Tokens locally in a List. CachingTokenFilter implements the optional method {@link TokenStream#reset()}, which repositions the stream to the first Token.

Fields Summary
private List
cache
private int
index
Constructors Summary
public CachingTokenFilter(TokenStream input)

    super(input);
  
Methods Summary
private voidfillCache()

    Token token;
    while ( (token = input.next()) != null) {
      cache.add(token);
    }
  
public org.apache.lucene.analysis.Tokennext()

    if (cache == null) {
      // fill cache lazily
      cache = new LinkedList();
      fillCache();
    }
    
    if (index == cache.size()) {
      // the cache is exhausted, return null
      return null;
    }
    
    return (Token) cache.get(index++);
  
public voidreset()

    index = 0;