package net.kevxu.senselib;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;

/**
 * Data container which stores last n data, n is defined by poolSize. It uses
 * the concept of circular array, but the underlining data container uses
 * ArrayList due to the need of support generic. This data container is NOT
 * thread-safe, use with ABSOLUTE caution.
 * 
 * @author Kaiwen Xu
 * 
 * @param <T>
 *            Type of data to be stored.
 */
public class FloatDataPool {

	private int mPoolSize;

	private float[] mPool;
	private int mStartPos;
	private int mEndPos;
	private int mSize;

	public FloatDataPool(int poolSize) {
		mPoolSize = poolSize;
		mPool = new float[poolSize];
		mStartPos = 0;
		mEndPos = 0;
		mSize = 0;
	}

	public int size() {
		return mSize;
	}

	public int getPoolSize() {
		return mPoolSize;
	}

	public void append(float value) {
		if (mSize < mPoolSize) {
			mPool[mEndPos] = value;
			mEndPos = (mEndPos + 1) % mPoolSize;
			mSize++;
		} else {
			mStartPos = (mStartPos + 1) % mPoolSize;
			mPool[mEndPos] = value;
			mEndPos = (mEndPos + 1) % mPoolSize;
		}
	}

	public float get(int i) {
		if (i < mSize) {
			return mPool[(mStartPos + i) % mPoolSize];
		} else {
			throw new IndexOutOfBoundsException("i is larger than DataPool size.");
		}
	}

	public float[] getList(int n) {
		if (n > mSize) {
			throw new IndexOutOfBoundsException("n is larger than DataPool size.");
		}

		float[] fd = new float[n];
		for (int i = 0; i < n; i++) {
			fd[i] = get(i);
		}

		return fd;
	}

	public float getFromBack(int i) {
		return get(mSize - 1 - i);
	}

	public float[] getListFromBack(int n) {
		if (n > mSize) {
			throw new IndexOutOfBoundsException("n is larger than DataPool size.");
		}

		float[] pd = new float[n];
		for (int i = 0; i < n; i++) {
			pd[i] = getFromBack(i);
		}

		return pd;
	}

	@Override
	public String toString() {
		return Arrays.toString(mPool);
	}

}
@@ -48,450 +48,11 @@
 rray
-List;%0Aimport java.util.Arrays;%0Aimport java.util.List;%0Aimport java.util.Random;%0A%0A/**%0A * Data container which stores last n data, n is defined by poolSize. It uses%0A * the concept of circular array, but the underlining data container uses%0A * ArrayList due to the need of support generic. This data container is NOT%0A * thread-safe, use with ABSOLUTE caution.%0A * %0A * @author Kaiwen Xu%0A * %0A * @param %3CT%3E%0A *            Type of data to be stored.%0A */
+s;%0A
 %0Apub

Remove JavaDocs from FloatDataPool.