freemarker.core

Class CollectionAndSequence

Implemented Interfaces:
Serializable, TemplateCollectionModel, TemplateModel, TemplateSequenceModel

public final class CollectionAndSequence
extends java.lang.Object
implements TemplateCollectionModel, TemplateSequenceModel, Serializable

Add sequence capabilities to an existing collection, or vice versa. Used by ?keys and ?values built-ins.

Fields inherited from interface freemarker.template.TemplateModel

NOTHING

Constructor Summary

CollectionAndSequence(TemplateCollectionModel collection)
CollectionAndSequence(TemplateSequenceModel sequence)

Method Summary

TemplateModel
get(int i)
Retrieves the i-th template model in this sequence.
TemplateModelIterator
iterator()
Retrieves a template model iterator that is used to iterate over the elements in this collection.
int
size()

Constructor Details

CollectionAndSequence

public CollectionAndSequence(TemplateCollectionModel collection)

CollectionAndSequence

public CollectionAndSequence(TemplateSequenceModel sequence)

Method Details

get

public TemplateModel get(int i)
            throws TemplateModelException
Retrieves the i-th template model in this sequence.
Specified by:
get in interface TemplateSequenceModel
Returns:
the item at the specified index, or null if the index is out of bounds. Note that a null value is interpreted by FreeMarker as "variable does not exist", and accessing a missing variables is usually considered as an error in the FreeMarker Template Language, so the usage of a bad index will not remain hidden.

iterator

public TemplateModelIterator iterator()
            throws TemplateModelException
Retrieves a template model iterator that is used to iterate over the elements in this collection.
Specified by:
iterator in interface TemplateCollectionModel

size

public int size()
            throws TemplateModelException
Specified by:
size in interface TemplateSequenceModel
Returns:
the number of items in the list.