~slub.team/goobi-indexserver/3.x

« back to all changes in this revision

Viewing changes to lucene/src/test-framework/java/org/apache/lucene/search/CachingWrapperFilterHelper.java

  • Committer: Sebastian Meyer
  • Date: 2012-08-03 09:12:40 UTC
  • Revision ID: sebastian.meyer@slub-dresden.de-20120803091240-x6861b0vabq1xror
Remove Lucene and Solr source code and add patches instead
Fix Bug #985487: Auto-suggestion for the search interface

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package org.apache.lucene.search;
2
 
 
3
 
/**
4
 
 * Licensed to the Apache Software Foundation (ASF) under one or more
5
 
 * contributor license agreements.  See the NOTICE file distributed with
6
 
 * this work for additional information regarding copyright ownership.
7
 
 * The ASF licenses this file to You under the Apache License, Version 2.0
8
 
 * (the "License"); you may not use this file except in compliance with
9
 
 * the License.  You may obtain a copy of the License at
10
 
 *
11
 
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 
 *
13
 
 * Unless required by applicable law or agreed to in writing, software
14
 
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 
 * See the License for the specific language governing permissions and
17
 
 * limitations under the License.
18
 
 */
19
 
 
20
 
import java.io.IOException;
21
 
 
22
 
import junit.framework.Assert;
23
 
import org.apache.lucene.index.IndexReader;
24
 
 
25
 
/**
26
 
 * A unit test helper class to test when the filter is getting cached and when it is not.
27
 
 */
28
 
public class CachingWrapperFilterHelper extends CachingWrapperFilter {
29
 
  
30
 
  private boolean shouldHaveCache = false;
31
 
 
32
 
  /**
33
 
   * @param filter Filter to cache results of
34
 
   */
35
 
  public CachingWrapperFilterHelper(Filter filter) {
36
 
    super(filter);
37
 
  }
38
 
  
39
 
  public void setShouldHaveCache(boolean shouldHaveCache) {
40
 
    this.shouldHaveCache = shouldHaveCache;
41
 
  }
42
 
  
43
 
  @Override
44
 
  public synchronized DocIdSet getDocIdSet(IndexReader reader) throws IOException {
45
 
 
46
 
    final int saveMissCount = missCount;
47
 
    DocIdSet docIdSet = super.getDocIdSet(reader);
48
 
 
49
 
    if (shouldHaveCache) {
50
 
      Assert.assertEquals("Cache should have data ", saveMissCount, missCount);
51
 
    } else {
52
 
      Assert.assertTrue("Cache should be null " + docIdSet, missCount > saveMissCount);
53
 
    }
54
 
 
55
 
    return docIdSet;
56
 
  }
57
 
 
58
 
  @Override
59
 
  public String toString() {
60
 
    return "CachingWrapperFilterHelper("+filter+")";
61
 
  }
62
 
 
63
 
  @Override
64
 
  public boolean equals(Object o) {
65
 
    if (!(o instanceof CachingWrapperFilterHelper)) return false;
66
 
    return this.filter.equals(o);
67
 
  }
68
 
  
69
 
  @Override
70
 
  public int hashCode() {
71
 
    return this.filter.hashCode() ^ 0x5525aacb;
72
 
  }
73
 
}