All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.khelekore.prtree.Circle Maven / Gradle / Ivy

There is a newer version: 1.11
Show newest version
package org.khelekore.prtree;

import java.util.ArrayList;
import java.util.List;

/** A simple circular data structure.
 *
 * @param  the element type
 */
class Circle {
    private final List data;
    private int currentPos;

    public Circle (int size) {
	data = new ArrayList<> (size);
    }

    public void add (T t) {
	data.add (t);
    }

    public T get (int pos) {
	pos %= data.size ();
	return data.get (pos);
    }

    public int getNumElements () {
	return data.size ();
    }

    public void reset () {
	currentPos = 0;
    }

    public T getNext () {
	T ret = data.get (currentPos++);
	currentPos %= data.size ();
	return ret;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy