package it.polimi.ingsw.gc14;

import java.util.ArrayList;

public class LimitedList<T> extends ArrayList<T> {
    private int limit;
    private Runnable action;

    public LimitedList(int limit, Runnable action) {
        this.limit = limit;
        this.action = action;
    }

    @Override
    public boolean add(T element) {
        boolean result = super.add(element);
        if (size() >= limit) {
            action.run();
        }
        return result;
    }

    public void setLimit(int num) {
        this.limit=num;
    }

    public int getLimit(){return limit;}

    public void setAction(Runnable action) {
        this.action=action;
    }
}