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

com.github.jy2.logs.console.collections.LimitedList Maven / Gradle / Ivy

There is a newer version: 0.0.39
Show newest version
package com.github.jy2.logs.console.collections;

public class LimitedList {

	private T[] array;
	private int pos = -1;
	private int size = 0;

	@SuppressWarnings("unchecked")
	public LimitedList(int size) {
		this.array = (T[]) new Object[size];
	}

	public void add(T item) {
		pos = (pos + 1) % array.length;
		array[pos] = item;
		if (size < array.length) {
			size++;
		}
	}

	public T get(int i) {
		return array[Math.floorMod((pos - i), array.length)];
	}

	public int size() {
		return size;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy