freemarker.template
Class SimpleSequence

java.lang.Object
  |
  +--freemarker.template.SimpleSequence
All Implemented Interfaces:
java.io.Serializable, TemplateModel, TemplateSequenceModel
Direct Known Subclasses:
SimpleList

public class SimpleSequence
extends java.lang.Object
implements TemplateSequenceModel, java.io.Serializable

A convenient implementation of a list. This object implements TemplateSequenceModel, using an underlying java.util.List implementation.

A SimpleSequence can act as a cache for a TemplateCollectionModel, e.g. one that gets data from a database. When passed a TemplateCollectionModel as an argument to its constructor, the SimpleSequence immediately copies all the elements and discards the TemplateCollectionModel.

Note:
As of 2.0, this class is unsynchronized by default. To obtain a synchronized wrapper, call the synchronizedWrapper() method.

Version:
$Id: SimpleSequence.java,v 1.2 2002/04/16 14:46:00 revusky Exp $
See Also:
SimpleHash, SimpleScalar, Serialized Form

Field Summary
protected  java.util.List list
           
 
Constructor Summary
SimpleSequence()
          Constructs an empty SimpleSequence with an indefinite shelf life.
SimpleSequence(java.util.List list)
          Constructs a SimpleSequence from the given List It makes a copy for internal use.
SimpleSequence(TemplateCollectionModel tcm)
           
 
Method Summary
 void add(boolean b)
          Adds a boolean to the end of this SimpleSequence, by first wrapping the boolean in a SimpleScalar.
 void add(java.lang.String s)
          Adds a string to the end of this SimpleSequence, by first wrapping the string in a SimpleScalar.
 void add(TemplateModel element)
          Adds a string to the end of this SimpleSequence, by first wrapping the string in a SimpleScalar.
 TemplateModel get(int i)
          Retrieves the i-th template model in this sequence.
 boolean isEmpty()
          Is the underlying List empty?
 int size()
           
 SimpleSequence synchronizedWrapper()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

list

protected java.util.List list
Constructor Detail

SimpleSequence

public SimpleSequence()
Constructs an empty SimpleSequence with an indefinite shelf life.

SimpleSequence

public SimpleSequence(java.util.List list)
Constructs a SimpleSequence from the given List It makes a copy for internal use.

SimpleSequence

public SimpleSequence(TemplateCollectionModel tcm)
               throws TemplateModelException
Method Detail

isEmpty

public boolean isEmpty()
                throws TemplateModelException
Is the underlying List empty?
Specified by:
isEmpty in interface TemplateModel
Following copied from interface: freemarker.template.TemplateModel
Returns:
true if this object is empty.

add

public void add(TemplateModel element)
Adds a string to the end of this SimpleSequence, by first wrapping the string in a SimpleScalar.
Parameters:
element - the TemplateModel to be added.

add

public void add(java.lang.String s)
Adds a string to the end of this SimpleSequence, by first wrapping the string in a SimpleScalar.
Parameters:
element - the string to be added.

add

public void add(boolean b)
Adds a boolean to the end of this SimpleSequence, by first wrapping the boolean in a SimpleScalar.
Parameters:
element - the boolean to be added.

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 specified index in the list

size

public int size()
Specified by:
size in interface TemplateSequenceModel
Following copied from interface: freemarker.template.TemplateSequenceModel
Returns:
the number of items in the list.

synchronizedWrapper

public SimpleSequence synchronizedWrapper()
Returns:
a synchronized wrapper for list.