Add: JavaDOC to LimitedList
This commit is contained in:
@@ -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 <T> the type of elements held in this list.
|
||||
*/
|
||||
public class LimitedList<T> extends ArrayList<T> {
|
||||
//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,15 +46,29 @@ public class LimitedList<T> extends ArrayList<T> {
|
||||
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;
|
||||
}
|
||||
|
||||
//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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user