public class DynamicFloatArray { private int length; private int currentIndex; private int currentArrayIndex; private float[] currentArray; private ArrayList arrays; public DynamicFloatArray() { this(16); } public DynamicFloatArray(int baseCapacity) { this.arrays = new ArrayList(); this.arrays.add(new float[baseCapacity]); this.reset(); } public synchronized DynamicFloatArray adds(float value) { return this.add(value); } public DynamicFloatArray add(float value) { this.length++; this.currentIndex++; if (this.currentIndex >= this.currentArray.length) { this.currentIndex = 0; this.currentArrayIndex++; if (this.currentArrayIndex < this.arrays.size()) { this.currentArray = this.arrays.get(this.currentArrayIndex); } else { int newCapacity = this.currentArray.length + (this.currentArray.length >> 1); this.currentArray = new float[newCapacity]; this.arrays.add(this.currentArray); } } this.currentArray[this.currentIndex] = value; return this; } public final DynamicFloatArray reset() { this.length = 0; this.currentIndex = -1; this.currentArrayIndex = 0; this.currentArray = this.arrays.get(0); return this; } public DynamicFloatArray clear() { this.reset(); this.arrays.clear(); this.arrays.add(this.currentArray); return this; } public FloatBuffer toFloatBuffer() { return this.toFloatBuffer(null); } public FloatBuffer toFloatBuffer(FloatBuffer result) { if (result == null || result.remaining() < this.length) { result = BufferUtils.createFloatBuffer(this.length); } int currIdx = 0; int currArrIdx = 0; float[] currArr; while (currArrIdx < this.currentArrayIndex) { currArr = this.arrays.get(currArrIdx); result.put(currArr); currIdx += currArr.length; currArrIdx++; } currArr = this.arrays.get(currArrIdx); int remaining = this.length - currIdx; result.put(currArr, 0, remaining); return result; } public int getLength() { return this.length; } }