package crypto.r35157;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;

public class RingBuffer {
    public RingBuffer(int capacity) {
        this.capacity = capacity;
        this.buffer = new ArrayDeque<>(capacity);
    }

    public void add(String command) {
        if (getSize() == capacity) {
            buffer.removeFirst();
        }
        buffer.addLast(command);
    }

    public List<String> getAll() {
        return new ArrayList<>(buffer);
    }

    public int getSize() {
        return buffer.size();
    }

    public int getCapacity() {
        return capacity;
    }

    private final int capacity;
    private final Deque<String> buffer;
}
