add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / facet / src / java / org / apache / lucene / facet / enhancements / params / DefaultEnhancementsIndexingParams.java
1 package org.apache.lucene.facet.enhancements.params;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import org.apache.lucene.facet.enhancements.CategoryEnhancement;
7 import org.apache.lucene.facet.index.attributes.CategoryProperty;
8 import org.apache.lucene.facet.index.params.CategoryListParams;
9 import org.apache.lucene.facet.index.params.PerDimensionIndexingParams;
10
11 /**
12  * Licensed to the Apache Software Foundation (ASF) under one or more
13  * contributor license agreements.  See the NOTICE file distributed with
14  * this work for additional information regarding copyright ownership.
15  * The ASF licenses this file to You under the Apache License, Version 2.0
16  * (the "License"); you may not use this file except in compliance with
17  * the License.  You may obtain a copy of the License at
18  *
19  *     http://www.apache.org/licenses/LICENSE-2.0
20  *
21  * Unless required by applicable law or agreed to in writing, software
22  * distributed under the License is distributed on an "AS IS" BASIS,
23  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24  * See the License for the specific language governing permissions and
25  * limitations under the License.
26  */
27
28 /**
29  * Default implementation of {@link EnhancementsIndexingParams} 
30  * 
31  * @lucene.experimental
32  */
33 public class DefaultEnhancementsIndexingParams extends
34     PerDimensionIndexingParams implements EnhancementsIndexingParams {
35
36   private List<CategoryEnhancement> enhancedCategories;
37
38   /**
39    * Construct with a certain {@link CategoryEnhancement enhancement}
40    * @throws IllegalArgumentException if no enhancements are provided
41    */
42   public DefaultEnhancementsIndexingParams(CategoryEnhancement... enhancements) {
43     super();
44     validateparams(enhancements);
45     addCategoryEnhancements(enhancements);
46   }
47
48   private void validateparams(CategoryEnhancement... enhancements) {
49     if (enhancements==null || enhancements.length<1) {
50       throw new IllegalArgumentException("at least one enhancement is required");
51     }
52   }
53
54   /**
55    * Construct with certain {@link CategoryEnhancement enhancements}
56    * and {@link CategoryListParams}
57    * @throws IllegalArgumentException if no enhancements are provided
58    */
59   public DefaultEnhancementsIndexingParams(
60       CategoryListParams categoryListParams,
61       CategoryEnhancement... enhancements) {
62     super(categoryListParams);
63     validateparams(enhancements);
64     addCategoryEnhancements(enhancements);
65   }
66
67   public void addCategoryEnhancements(CategoryEnhancement... enhancements) {
68     if (enhancedCategories == null) {
69       enhancedCategories = new ArrayList<CategoryEnhancement>();
70     }
71     for (CategoryEnhancement categoryEnhancement : enhancements) {
72       enhancedCategories.add(categoryEnhancement);
73     }
74   }
75
76   public List<CategoryEnhancement> getCategoryEnhancements() {
77     if (enhancedCategories == null || enhancedCategories.isEmpty()) {
78       return null;
79     }
80     return enhancedCategories;
81   }
82
83   public List<Class<? extends CategoryProperty>> getRetainableProperties() {
84     if (enhancedCategories == null) {
85       return null;
86     }
87     List<Class<? extends CategoryProperty>> retainableProperties = new ArrayList<Class<? extends CategoryProperty>>();
88     for (CategoryEnhancement enhancement : enhancedCategories) {
89       if (enhancement.getRetainableProperty() != null) {
90         retainableProperties.add(enhancement.getRetainableProperty());
91       }
92     }
93     if (retainableProperties.isEmpty()) {
94       return null;
95     }
96     return retainableProperties;
97   }
98 }