diff --git a/src/main/java/it/polimi/ingsw/gc14/LimitedList.java b/src/main/java/it/polimi/ingsw/gc14/LimitedList.java index ad351d0..5ac39ff 100644 --- a/src/main/java/it/polimi/ingsw/gc14/LimitedList.java +++ b/src/main/java/it/polimi/ingsw/gc14/LimitedList.java @@ -1,22 +1,42 @@ package it.polimi.ingsw.gc14; - import java.util.ArrayList; -//TODO Javadoc +/** + * An {@link ArrayList} with a configurable size limit and an associated action. + * When the number of elements reaches or exceeds the limit, the specified action is automatically triggered. + * + * @param the type of elements held in this list. + */ public class LimitedList extends ArrayList { - //TODO Javadoc + + /** + * The maximum number of elements allowed in the list before the action is triggered. + */ private int limit; - //TODO Javadoc + /** + * The action to execute when the list size reaches or exceeds the limit. + */ private Runnable action; - //TODO Javadoc + /** + * Creates a new {@code LimitedList} with the specified limit and action. + * + * @param limit the maximum number of elements before the action is triggered. + * @param action the action to execute when the limit is reached. + */ public LimitedList(int limit, Runnable action) { this.limit = limit; this.action = action; } - //TODO Javadoc + /** + * Adds the specified element to the list. + * If the list size reaches or exceeds the limit after the insertion, the configured action is triggered. + * + * @param element the element to add. + * @return {@code true} if the element was successfully added. + */ @Override public boolean add(T element) { boolean result = super.add(element); @@ -26,16 +46,30 @@ public class LimitedList extends ArrayList { return result; } - //TODO Javadoc + /** + * Sets a new size limit for this list. + * + * @param num the new limit. + */ public void setLimit(int num) { - this.limit=num; + this.limit = num; } - //TODO Javadoc - public int getLimit(){return limit;} + /** + * Returns the current size limit of this list. + * + * @return the current limit. + */ + public int getLimit() { + return limit; + } - //TODO Javadoc + /** + * Sets a new action to execute when the list size reaches or exceeds the limit. + * + * @param action the new action to set. + */ public void setAction(Runnable action) { - this.action=action; + this.action = action; } } \ No newline at end of file