View Javadoc

1   // BSD License (http://www.galagosearch.org/license)
2   
3   package org.galagosearch.core.util;
4   
5   /***
6    *
7    * @author trevor
8    */
9   public class FloatArray {
10      float[] _array;
11      int _position;
12  
13      public FloatArray(int capacity) {
14          _array = new float[capacity];
15          _position = 0;
16      }
17  
18      public FloatArray() {
19          this(16);
20      }
21  
22      public void add(float value) {
23          if(_position == _array.length) {
24              // grow array if we're out of space
25              _array = _copyArray(_array.length * 2);
26          }
27  
28          _array[_position] = value;
29          _position += 1;
30      }
31  
32      public float[] getBuffer() {
33          return _array;
34      }
35  
36      public int getPosition() {
37          return _position;
38      }
39  
40      private float[] _copyArray(int newSize) {
41          float[] result = new float[newSize];
42          System.arraycopy(_array, 0, result, 0, _position);
43          return result;
44      }
45  
46      public float[] toArray() {
47          return _copyArray(_position);
48      }
49  }