Holds an ordered collection of resources with convenience operations for filtering, excluding, grouping and sorting, used throughout Velocity templates and controller code. Each item is also indexed by name in an internal map so lookups by name, and duplicate-name detection, are cheap. Methods such as exclude, excludeType, ofType, sortByField and groupByField return a new list of the same runtime type rather than mutating this one, which makes them safe to chain from a template expression.
Extends: CommonList
Properties
| Property | Returns | Description |
|---|---|---|
| dirs | ResourceList | Returns a new list containing only the elements of this list that are a CollectionResource, that is only the folders/directories. |
| files | ResourceList | Returns a new list containing only the elements of this list that match the "file" type, as determined by CommonResource.is. |
| ofType | Map<String,ResourceList> | Returns a map-like view that filters this list by type on lookup, for example folder.children.ofType.folder or folder.find("/blogs").articles.ofType.news in a template. |
| parents | ResourceList | Returns a new list of the distinct ancestors of every element in this list, walking up each element's parent chain to the root. The walk for each element is capped at 100 iterations as a defensive guard against a cyclic parent chain. |
| readable | ResourceList<T> | Returns a new list containing only the elements of this list that are an AbstractResource for which isReadable returns true. |
| sortByModifiedDate | ResourceList | Returns a new list with the same elements as this one, sorted by modified date with the most recently modified resource first. Resources with a null modified date are treated as most recent. |
| sortByName | ResourceList | Returns a new list with the same elements as this one, sorted alphabetically by resource name. |
| sortByTitle | ResourceList | Returns a new list with the same elements as this one, sorted alphabetically by title for any resource that implements TitledPage, falling back to the resource name for the rest. |
Inherited from CommonList
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.
Methods
add(ResourceList otherList) · get(String name) · hasChild(String name) · remove(Object o) · getSortByModifiedDate() · getSortByName() · getSortByTitle() · exclude(String s) · exclude(String s1, String s2) · exclude(String s1, String s2, String s3) · exclude(String s1, String s2, String s3, String s4) · _exclude(String s) · excludeType(String s) · excludeType(String s1, String s2) · excludeType(String s1, String s2, String s3) · excludeType(String s1, String s2, String s3, String s4) · _excludeType(String s) · ofType(String s) · ofTypeOr(String orTypes) · getOfType() · next(Resource from) · previous(Resource from) · groupByField(String fieldName) · groupByIntField(String fieldName) · sortByField(String fieldName) · sortByExpr(String mvelExpr) · sortByIntField(String fieldName) · getDirs() · getFiles() · getParents() · dedupe() · getReadable()
add(ResourceList otherList)
Returns: ResourceList
Adds every element of the given list to this list and returns this list, so the call can be chained from a template expression.
| Parameter | Description |
|---|---|
otherList | the list whose elements are added to this one |
get(String name)
Returns: CommonResource
Looks up a single resource in this list by its name, using the internal name index rather than a linear scan.
| Parameter | Description |
|---|---|
name | the name of the resource to find |
hasChild(String name)
Returns: boolean
Checks whether this list contains a resource with the given name.
| Parameter | Description |
|---|---|
name | the name to look for |
remove(Object o)
Returns: boolean
Removes the given resource from this list, also removing it from the internal name index if it is a CommonResource.
| Parameter | Description |
|---|---|
o | the element to remove |
getSortByModifiedDate()
Returns: ResourceList
Returns a new list with the same elements as this one, sorted by modified date with the most recently modified resource first. Resources with a null modified date are treated as most recent.
getSortByName()
Returns: ResourceList
Returns a new list with the same elements as this one, sorted alphabetically by resource name.
getSortByTitle()
Returns: ResourceList
Returns a new list with the same elements as this one, sorted alphabetically by title for any resource that implements TitledPage, falling back to the resource name for the rest.
exclude(String s)
Returns: ResourceList
Returns a new list containing the current elements except any resource whose name equals the given value.
| Parameter | Description |
|---|---|
s | the resource name to exclude |
exclude(String s1, String s2)
Returns: ResourceList
Returns a new list containing the current elements except any resource whose name equals one of the given values.
| Parameter | Description |
|---|---|
s1 | a resource name to exclude |
s2 | a resource name to exclude |
exclude(String s1, String s2, String s3)
Returns: ResourceList
Returns a new list containing the current elements except any resource whose name equals one of the given values.
| Parameter | Description |
|---|---|
s1 | a resource name to exclude |
s2 | a resource name to exclude |
s3 | a resource name to exclude |
exclude(String s1, String s2, String s3, String s4)
Returns: ResourceList
Returns a new list containing the current elements except any resource whose name equals one of the given values.
| Parameter | Description |
|---|---|
s1 | a resource name to exclude |
s2 | a resource name to exclude |
s3 | a resource name to exclude |
s4 | a resource name to exclude |
_exclude(String s)
Returns: ResourceList
Returns a new list containing the current elements except any resource whose name is one of the given values. This is the shared implementation behind the fixed-arity exclude overloads.
| Parameter | Description |
|---|---|
s | the resource names to exclude |
excludeType(String s)
Returns: ResourceList
Returns a new list containing the current elements except any resource that matches the given type, as determined by CommonResource.is.
| Parameter | Description |
|---|---|
s | the type to exclude |
excludeType(String s1, String s2)
Returns: ResourceList
Returns a new list containing the current elements except any resource that matches one of the given types, as determined by CommonResource.is.
| Parameter | Description |
|---|---|
s1 | a type to exclude |
s2 | a type to exclude |
excludeType(String s1, String s2, String s3)
Returns: ResourceList
Returns a new list containing the current elements except any resource that matches one of the given types, as determined by CommonResource.is.
| Parameter | Description |
|---|---|
s1 | a type to exclude |
s2 | a type to exclude |
s3 | a type to exclude |
excludeType(String s1, String s2, String s3, String s4)
Returns: ResourceList
Returns a new list containing the current elements except any resource that matches one of the given types, as determined by CommonResource.is.
| Parameter | Description |
|---|---|
s1 | a type to exclude |
s2 | a type to exclude |
s3 | a type to exclude |
s4 | a type to exclude |
_excludeType(String s)
Returns: ResourceList
Returns a new list containing the current elements except any resource whose type matches one of the given values. This is the shared implementation behind the fixed-arity excludeType overloads.
| Parameter | Description |
|---|---|
s | the types to exclude |
ofType(String s)
Returns: ResourceList<T>
Returns a new list containing only the elements of this list that match the given type, as determined by CommonResource.is.
| Parameter | Description |
|---|---|
s | the type to keep |
ofTypeOr(String orTypes)
Returns: ResourceList<T>
Returns a new list containing only the elements of this list that match at least one of the given types, as determined by CommonResource.is.
| Parameter | Description |
|---|---|
orTypes | the types to keep, combined with logical or |
getOfType()
Returns: Map<String,ResourceList>
Returns a map-like view that filters this list by type on lookup, for example folder.children.ofType.folder or folder.find("/blogs").articles.ofType.news in a template.
next(Resource from)
Returns: Resource
Returns the resource immediately after the given one in this list, comparing by reference. If from is null, returns the first item in the list instead.
| Parameter | Description |
|---|---|
from | the resource to find the successor of, or null to get the first item |
previous(Resource from)
Returns: Resource
Returns the resource immediately before the given one in this list, comparing by reference. If from is null, or is not present in this list, or is the first item, returns null.
| Parameter | Description |
|---|---|
from | the resource to find the predecessor of |
groupByField(String fieldName)
Returns: Map<Object,ResourceList<T>>
Groups the elements of this list into new lists keyed on the value of the given field, read from each element via ParameterisedResource.getParam. Elements that are not a ParameterisedResource are silently skipped.
| Parameter | Description |
|---|---|
fieldName | the parameterised field to group by |
groupByIntField(String fieldName)
Returns: Map<Integer,ResourceList<T>>
Groups the elements of this list into new lists keyed on the integer value of the given field, read from each element via ParameterisedResource.getParam and parsed as an Integer. Elements that are not a ParameterisedResource are silently skipped, and unparsable values group under a null key.
| Parameter | Description |
|---|---|
fieldName | the parameterised field to group by |
sortByField(String fieldName)
Returns: ResourceList<T>
Returns a new list with the same elements as this one, sorted by the value of the given field. The field is read from a ParameterisedResource via getParam, or from a Map entry, and compared as a Comparable when possible; elements without a value, or whose values are not comparable, sort first.
| Parameter | Description |
|---|---|
fieldName | the field to sort by |
sortByExpr(String mvelExpr)
Returns: ResourceList
Returns a new list with the same elements as this one, sorted by the result of evaluating the given MVEL expression against each element. Values are compared as a Comparable when possible; elements whose expression result is null, or not comparable, sort first.
| Parameter | Description |
|---|---|
mvelExpr | an MVEL expression evaluated against each resource to obtain the sort value |
sortByIntField(String fieldName)
Returns: ResourceList<CommonResource>
Returns a new list with the same elements as this one, sorted by the integer value of the given field, read from each element via ParameterisedResource.getParam and parsed as an Integer. Elements without a value sort first.
| Parameter | Description |
|---|---|
fieldName | the field to sort by |
getDirs()
Returns: ResourceList
Returns a new list containing only the elements of this list that are a CollectionResource, that is only the folders/directories.
getFiles()
Returns: ResourceList
Returns a new list containing only the elements of this list that match the "file" type, as determined by CommonResource.is.
getParents()
Returns: ResourceList
Returns a new list of the distinct ancestors of every element in this list, walking up each element's parent chain to the root. The walk for each element is capped at 100 iterations as a defensive guard against a cyclic parent chain.
dedupe()
Returns: ResourceList<T>
Returns a new list with the same items as this one, but with any resource sharing an href already seen removed, keeping the first occurrence.
getReadable()
Returns: ResourceList<T>
Returns a new list containing only the elements of this list that are an AbstractResource for which isReadable returns true.