1 package org.apache.lucene.search; 2 3 18 19 import org.apache.lucene.index.IndexReader; 20 import java.util.BitSet ; 21 import java.util.WeakHashMap ; 22 import java.util.Map ; 23 import java.io.IOException ; 24 25 31 public class CachingWrapperFilter extends Filter { 32 private Filter filter; 33 34 38 private transient Map cache; 39 40 43 public CachingWrapperFilter(Filter filter) { 44 this.filter = filter; 45 } 46 47 public BitSet bits(IndexReader reader) throws IOException { 48 if (cache == null) { 49 cache = new WeakHashMap (); 50 } 51 52 synchronized (cache) { BitSet cached = (BitSet ) cache.get(reader); 54 if (cached != null) { 55 return cached; 56 } 57 } 58 59 final BitSet bits = filter.bits(reader); 60 61 synchronized (cache) { cache.put(reader, bits); 63 } 64 65 return bits; 66 } 67 68 public String toString() { 69 return "CachingWrapperFilter("+filter+")"; 70 } 71 72 public boolean equals(Object o) { 73 if (!(o instanceof CachingWrapperFilter)) return false; 74 return this.filter.equals(((CachingWrapperFilter)o).filter); 75 } 76 77 public int hashCode() { 78 return filter.hashCode() ^ 0x1117BF25; 79 } 80 } 81 | Popular Tags |