add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / src / java / org / apache / lucene / document / SetBasedFieldSelector.java
1 package org.apache.lucene.document;
2
3 import java.util.Set;
4 /**
5  * Copyright 2004 The Apache Software Foundation
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * 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 /**
21  * Declare what fields to load normally and what fields to load lazily
22  *
23  **/
24 public class SetBasedFieldSelector implements FieldSelector {
25   
26   private Set<String> fieldsToLoad;
27   private Set<String> lazyFieldsToLoad;
28   
29   /**
30    * Pass in the Set of {@link Field} names to load and the Set of {@link Field} names to load lazily.  If both are null, the
31    * Document will not have any {@link Field} on it.  
32    * @param fieldsToLoad A Set of {@link String} field names to load.  May be empty, but not null
33    * @param lazyFieldsToLoad A Set of {@link String} field names to load lazily.  May be empty, but not null  
34    */
35   public SetBasedFieldSelector(Set<String> fieldsToLoad, Set<String> lazyFieldsToLoad) {
36     this.fieldsToLoad = fieldsToLoad;
37     this.lazyFieldsToLoad = lazyFieldsToLoad;
38   }
39
40   /**
41    * Indicate whether to load the field with the given name or not. If the {@link Field#name()} is not in either of the 
42    * initializing Sets, then {@link org.apache.lucene.document.FieldSelectorResult#NO_LOAD} is returned.  If a Field name
43    * is in both <code>fieldsToLoad</code> and <code>lazyFieldsToLoad</code>, lazy has precedence.
44    * 
45    * @param fieldName The {@link Field} name to check
46    * @return The {@link FieldSelectorResult}
47    */
48   public FieldSelectorResult accept(String fieldName) {
49     FieldSelectorResult result = FieldSelectorResult.NO_LOAD;
50     if (fieldsToLoad.contains(fieldName) == true){
51       result = FieldSelectorResult.LOAD;
52     }
53     if (lazyFieldsToLoad.contains(fieldName) == true){
54       result = FieldSelectorResult.LAZY_LOAD;
55     }                                           
56     return result;
57   }
58 }