📜  循环列表java代码示例

📅  最后修改于: 2022-03-11 14:52:15.408000             🧑  作者: Mango

代码示例1
public class CircularList { // Made by Bredo.
    private List 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 getRawList() {
        return list; // Get raw list, if other methods is needed.
    }
}