freemarker.core
Class CollectionAndSequence

java.lang.Object
  extended by freemarker.core.CollectionAndSequence
All Implemented Interfaces:
TemplateCollectionModel, TemplateModel, TemplateSequenceModel, java.io.Serializable

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

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

See Also:
Serialized Form

Field Summary
 
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()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CollectionAndSequence

public CollectionAndSequence(TemplateCollectionModel collection)

CollectionAndSequence

public CollectionAndSequence(TemplateSequenceModel sequence)
Method Detail

iterator

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

Specified by:
iterator in interface TemplateCollectionModel
Throws:
TemplateModelException

get

public TemplateModel get(int i)
                  throws TemplateModelException
Description copied from interface: TemplateSequenceModel
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.
Throws:
TemplateModelException

size

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