An ArrayList with convenience methods for use in templates and scripts, such as getting a random element, a reversed copy, or a truncated sub-list. Also yields cooperatively to the Governor on each iteration of forEach, so a large collection cannot be used to run a long-lived script or template loop past its execution limit.
Extends: ArrayList
Properties
| Property | Returns | Description |
|---|---|---|
| first | T | The first element in the list. |
| last | T | The last element in the list. |
| random | T | A single element chosen at random from the list. |
| reverse | KademiArrayList<T> | A new list containing the same elements as this one, in reverse order. Does not modify this list. |
Methods
getFirst()
Returns: T
The first element in the list.
getLast()
Returns: T
The last element in the list.
getRandom()
Returns: T
A single element chosen at random from the list.
getReverse()
Returns: KademiArrayList<T>
A new list containing the same elements as this one, in reverse order. Does not modify this list.
upTo(int n)
Returns: KademiArrayList<T>
Returns a new list containing at most the first n elements of this list.
| Parameter | Description |
|---|---|
n | the maximum number of leading elements to include |
after(int n)
Returns: KademiArrayList<T>
Returns a new list with the first n elements skipped. For example after(2) returns a list without the first 2 elements. The count is 1-indexed, so after(1) skips the first element while after(0) skips none.
| Parameter | Description |
|---|---|
n | the number of leading elements to skip |
truncate(int maxSize)
Returns: KademiArrayList<T>
Returns a new list with a size no greater than the given argument.
| Parameter | Description |
|---|---|
maxSize | the maximum number of elements in the new list |