pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / contrib / facet / src / java / org / apache / lucene / facet / search / cache / CategoryListCache.java
1 package org.apache.lucene.facet.search.cache;
2
3 import java.io.IOException;
4 import java.util.HashMap;
5
6 import org.apache.lucene.index.IndexReader;
7
8 import org.apache.lucene.facet.index.params.CategoryListParams;
9 import org.apache.lucene.facet.index.params.FacetIndexingParams;
10 import org.apache.lucene.facet.taxonomy.TaxonomyReader;
11
12 /**
13  * Licensed to the Apache Software Foundation (ASF) under one or more
14  * contributor license agreements.  See the NOTICE file distributed with
15  * this work for additional information regarding copyright ownership.
16  * The ASF licenses this file to You under the Apache License, Version 2.0
17  * (the "License"); you may not use this file except in compliance with
18  * the License.  You may obtain a copy of the License at
19  *
20  *     http://www.apache.org/licenses/LICENSE-2.0
21  *
22  * Unless required by applicable law or agreed to in writing, software
23  * distributed under the License is distributed on an "AS IS" BASIS,
24  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25  * See the License for the specific language governing permissions and
26  * limitations under the License.
27  */
28
29 /**
30  * Cache for {@link CategoryListData}, per {@link CategoryListParams}. 
31  * 
32  * @lucene.experimental
33  */
34 public class CategoryListCache {
35
36   private HashMap<CategoryListParams, CategoryListData> 
37     cldMap = new HashMap<CategoryListParams,CategoryListData>();
38
39   /**
40    * Fetch the cached {@link CategoryListData} for a given {@link CategoryListParams}.
41    */
42   public CategoryListData get(CategoryListParams clp) {
43     return cldMap.get(clp);
44   }
45   
46   /**
47    * Register a pre-computed {@link CategoryListData}.
48    */
49   public void register(CategoryListParams clp, CategoryListData clData) {
50     cldMap.put(clp,clData);
51   }
52   
53   /**
54    * Load and register {@link CategoryListData}.
55    */
56   public void loadAndRegister(CategoryListParams clp, 
57       IndexReader reader, TaxonomyReader taxo, FacetIndexingParams iparams) throws IOException {
58     CategoryListData clData = new CategoryListData(reader, taxo, iparams, clp);
59     register(clp,clData);
60   }
61 }