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

PropertyReturnsDescription
dirsResourceListReturns a new list containing only the elements of this list that are a CollectionResource, that is only the folders/directories.
filesResourceListReturns a new list containing only the elements of this list that match the "file" type, as determined by CommonResource.is.
ofTypeMap<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.
parentsResourceListReturns 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.
readableResourceList<T>Returns a new list containing only the elements of this list that are an AbstractResource for which isReadable returns true.
sortByModifiedDateResourceListReturns 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.
sortByNameResourceListReturns a new list with the same elements as this one, sorted alphabetically by resource name.
sortByTitleResourceListReturns 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

PropertyReturnsDescription
attributesMap<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.
firstTThe first element in this list.
lastTThe last element in this list.
randomTPicks a single element from this list at random.
randomSortCommonList<T>Builds a new list containing this list's elements in a random order. This list is not modified.
reverseCommonList<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.

ParameterDescription
tthe 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.

ParameterDescription
nthe 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.

ParameterDescription
nthe 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.

ParameterDescription
maxSizethe 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.

ParameterDescription
actionthe 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.

ParameterDescription
propertyNamethe 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.

ParameterDescription
otherListthe 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.

ParameterDescription
namethe name of the resource to find

hasChild(String name)

Returns: boolean

Checks whether this list contains a resource with the given name.

ParameterDescription
namethe 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.

ParameterDescription
othe 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.

ParameterDescription
sthe 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.

ParameterDescription
s1a resource name to exclude
s2a 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.

ParameterDescription
s1a resource name to exclude
s2a resource name to exclude
s3a 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.

ParameterDescription
s1a resource name to exclude
s2a resource name to exclude
s3a resource name to exclude
s4a 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.

ParameterDescription
sthe 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.

ParameterDescription
sthe 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.

ParameterDescription
s1a type to exclude
s2a 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.

ParameterDescription
s1a type to exclude
s2a type to exclude
s3a 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.

ParameterDescription
s1a type to exclude
s2a type to exclude
s3a type to exclude
s4a 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.

ParameterDescription
sthe 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.

ParameterDescription
sthe 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.

ParameterDescription
orTypesthe 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.

ParameterDescription
fromthe 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.

ParameterDescription
fromthe 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.

ParameterDescription
fieldNamethe 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.

ParameterDescription
fieldNamethe 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.

ParameterDescription
fieldNamethe 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.

ParameterDescription
mvelExpran 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.

ParameterDescription
fieldNamethe 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.

To get full access to the Kademi Hub existing customers can login here, or new customers can register here.