Lista circular Java
public class CircularList<T> { // Made by Bredo.
private List<T> list; // Create Raw list.
public CircularList() {
this.list = new ArrayList<>(); // Declare.
}
public boolean add(T t) {
return this.list.add(t); // Add to list.
}
public boolean remove(T t) {
return this.list.remove(t); // Remove from list.
}
public boolean contain(T t) {
return this.list.contains(t); // list contain object.
}
public T get(int index) {
if(size() <= 0) throw new NullPointerException(); // throw NullPointerException if list is empty.
if((index / size()) >= 1) index -= size() * (index / size()); // Check if index is higher than size, if so then minus
// until index is within size.
return list.get(index); // return object from list.
}
public int size() {
return list.size(); // list size.
}
public List<T> getRawList() {
return list; // Get raw list, if other methods is needed.
}
}
Bredo