import java.util.Random;

public abstract class CollectionTimer {
    public static final int[] DEFAULT_MUTATIONS = {10000, -10000};
    private Random elemGen = new Random();

    public CollectionTimer() {
        elemGen.setSeed(0);
    }
    public CollectionTimer(long elemGenSeed) {
        elemGen.setSeed(elemGenSeed);
    }

    public abstract void addElement(Integer elem);
    public abstract void removeElement();
    public abstract int getSize();
    public abstract boolean isEmpty();

    public void insert(int amount) {
        for (int a = 0; a <  amount; a++) {
            addElement(elemGen.nextInt());
        }
    }

    public boolean extract(int amount) {
        for (int a = 0; a <  amount; a++) {
            removeElement();
        }

        return true;
    }

    public long time() {
        long begin = System.currentTimeMillis();
        insert(DEFAULT_MUTATIONS[0]);
        extract(-DEFAULT_MUTATIONS[1]);
        return System.currentTimeMillis() - begin;
    }

    public long time(int[] mutations) {
        long begin = System.currentTimeMillis();

        for (int a : mutations) {
            if (a < 0) {
                extract(-a);
            } else {
                insert(a);
            }
        }

        return System.currentTimeMillis() - begin;
    }
}
