FileDocCategorySizeDatePackage
CachingWrapperFilterHelper.javaAPI DocApache Lucene 2.2.02354Sat Jun 16 22:20:28 BST 2007org.apache.lucene.search

CachingWrapperFilterHelper

public class CachingWrapperFilterHelper extends CachingWrapperFilter
A unit test helper class to test when the filter is getting cached and when it is not.

Fields Summary
private boolean
shouldHaveCache
Constructors Summary
public CachingWrapperFilterHelper(Filter filter)

param
filter Filter to cache results of


            
     
    super(filter);
  
Methods Summary
public java.util.BitSetbits(org.apache.lucene.index.IndexReader reader)

    if (cache == null) {
      cache = new WeakHashMap();
    }
    
    synchronized (cache) {  // check cache
      BitSet cached = (BitSet) cache.get(reader);
      if (shouldHaveCache) {
        TestCase.assertNotNull("Cache should have data ", cached);
      } else {
        TestCase.assertNull("Cache should be null " + cached , cached);
      }
      if (cached != null) {
        return cached;
      }
    }

    final BitSet bits = filter.bits(reader);

    synchronized (cache) {  // update cache
      cache.put(reader, bits);
    }

    return bits;
  
public booleanequals(java.lang.Object o)

    if (!(o instanceof CachingWrapperFilterHelper)) return false;
    return this.filter.equals((CachingWrapperFilterHelper)o);
  
public voidsetShouldHaveCache(boolean shouldHaveCache)

    this.shouldHaveCache = shouldHaveCache;
  
public java.lang.StringtoString()

    return "CachingWrapperFilterHelper("+filter+")";