A general-purpose list of resources with extra convenience operations for templates and JS controllers. Extends KillableList with helpers for sorting, shuffling, truncating and paging over the contents, and with a scratch attributes map for stashing values alongside the list. Subclasses such as query results override newList so that these operations return an instance of the correct subtype.
Extends: KillableList
Properties
| Property | Returns | Description |
|---|---|---|
| attributes | Map<String,Object> | A general-purpose map for stashing arbitrary values alongside this list, for example to cache data computed while rendering a template. Lazily created on first access, so it is never null. |
| first | T | The first element in this list. |
| last | T | The last element in this list. |
| random | T | Picks a single element from this list at random. |
| randomSort | CommonList<T> | Builds a new list containing this list's elements in a random order. This list is not modified. |
| reverse | CommonList<T> | Builds a new list with the elements of this one in reverse order. This list is not modified. |
Methods
getAttributes() · addQuiet(T t) · getFirst() · getLast() · removeLast() · removeFirst() · getRandom() · getReverse() · getRandomSort() · upTo(int n) · after(int n) · truncate(int maxSize) · forEach(Consumer<? super T> action) · sortByProperty(String propertyName) · sortReverse()
getAttributes()
Returns: Map<String,Object>
A general-purpose map for stashing arbitrary values alongside this list, for example to cache data computed while rendering a template. Lazily created on first access, so it is never null.
addQuiet(T t)
Returns: String
Appends an element to this list, for use directly inside a template expression. Behaves like add(), but returns an empty string instead of a boolean so it does not generate unwanted output when called from a template.
| Parameter | Description |
|---|---|
t | the element to append |
getFirst()
Returns: T
The first element in this list.
getLast()
Returns: T
The last element in this list.
removeLast()
Returns: T
Removes and returns the last element of this list.
removeFirst()
Returns: T
Removes and returns the first element of this list.
getRandom()
Returns: T
Picks a single element from this list at random.
getReverse()
Returns: CommonList<T>
Builds a new list with the elements of this one in reverse order. This list is not modified.
getRandomSort()
Returns: CommonList<T>
Builds a new list containing this list's elements in a random order. This list is not modified.
upTo(int n)
Returns: CommonList<T>
Builds a new list containing at most the first n elements of this list.
| Parameter | Description |
|---|---|
n | the maximum number of leading elements to keep |
after(int n)
Returns: CommonList<T>
Builds a new list with the leading n elements of this list skipped. For example after(2) returns a list without the first 2 elements. The count is 1-indexed, so after(1) skips only the first element and after(0) skips none.
| Parameter | Description |
|---|---|
n | the number of leading elements to skip |
truncate(int maxSize)
Returns: CommonList<T>
Builds a new list containing at most maxSize elements of this list, taken from the start.
| Parameter | Description |
|---|---|
maxSize | the maximum number of elements the new list may contain |
forEach(Consumer<? super T> action)
Returns: void
Applies the given action to each element in this list, in order. Yields to the Governor between elements so that long-running iterations over large lists can be interrupted or throttled.
| Parameter | Description |
|---|---|
action | the action to apply to each element |
sortByProperty(String propertyName)
Returns: CommonList<T>
Builds a new list containing this list's elements sorted by a named bean property, using reflection to read the property from each element. If propertyName is null, or sorting fails for any reason, this same list is returned unchanged.
| Parameter | Description |
|---|---|
propertyName | the name of the bean property to sort elements by |
sortReverse()
Returns: CommonList<T>
Builds a new list with this list's elements in reverse order, by inserting each element at the head of the new list.