add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / facet / src / java / org / apache / lucene / facet / search / FacetArrays.java
1 package org.apache.lucene.facet.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 /**
21  * Provider of arrays used for facet operations such as counting.
22  * 
23  * @lucene.experimental
24  */
25 public class FacetArrays {
26
27   private int[] intArray;
28   private float[] floatArray;
29   private IntArrayAllocator intArrayAllocator;
30   private FloatArrayAllocator floatArrayAllocator;
31   private int arraysLength;
32
33   /**
34    * Create a FacetArrays with certain array allocators.
35    * @param intArrayAllocator allocator for int arrays.
36    * @param floatArrayAllocator allocator for float arrays.
37    */
38   public FacetArrays(IntArrayAllocator intArrayAllocator,
39                       FloatArrayAllocator floatArrayAllocator) {
40     this.intArrayAllocator = intArrayAllocator;
41     this.floatArrayAllocator = floatArrayAllocator;
42   }
43
44   /**
45    * Notify allocators that they can free arrays allocated 
46    * on behalf of this FacetArrays object. 
47    */
48   public void free() {
49     if (intArrayAllocator!=null) {
50       intArrayAllocator.free(intArray);
51       // Should give up handle to the array now
52       // that it is freed.
53       intArray = null;
54     }
55     if (floatArrayAllocator!=null) {
56       floatArrayAllocator.free(floatArray);
57       // Should give up handle to the array now
58       // that it is freed.
59       floatArray = null;
60     }
61     arraysLength = 0;
62   }
63
64   /**
65    * Obtain an int array, e.g. for facet counting. 
66    */
67   public int[] getIntArray() {
68     if (intArray == null) {
69       intArray = intArrayAllocator.allocate();
70       arraysLength = intArray.length;
71     }
72     return intArray;
73   }
74
75   /** Obtain a float array, e.g. for evaluating facet association values. */
76   public float[] getFloatArray() {
77     if (floatArray == null) {
78       floatArray = floatArrayAllocator.allocate();
79       arraysLength = floatArray.length;
80     }
81     return floatArray;
82   }
83
84   /**
85    * Return the arrays length
86    */
87   public int getArraysLength() {
88     return arraysLength;
89   }
90
91 }