public class SimpleSequence extends WrappingTemplateModel implements TemplateSequenceModel, 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.
This class is thread-safe if you don't call the add method after you have made the object available for multiple threads, and you have published it safely.
Note:
As of 2.0, this class is unsynchronized by default.
To obtain a synchronized wrapper, call the synchronizedWrapper() method.
SimpleHash,
SimpleScalar,
Serialized Form| Modifier and Type | Field and Description |
|---|---|
protected List |
list |
NOTHING| Constructor and Description |
|---|
SimpleSequence()
Deprecated.
Use
SimpleSequence(ObjectWrapper) instead. |
SimpleSequence(Collection collection)
Deprecated.
|
SimpleSequence(Collection collection,
ObjectWrapper wrapper)
Constructs a simple sequence that will contain the elements
from the specified
Collection and will use the specified object
wrapper. |
SimpleSequence(int capacity)
Deprecated.
|
SimpleSequence(int capacity,
ObjectWrapper wrapper)
Constructs an empty simple sequence with preallocated capacity.
|
SimpleSequence(ObjectWrapper wrapper)
Constructs an empty simple sequence using the specified object wrapper.
|
SimpleSequence(TemplateCollectionModel tcm)
Constructs a simple sequence from the passed collection model using the
default object wrapper set in
WrappingTemplateModel.setDefaultObjectWrapper(ObjectWrapper). |
| Modifier and Type | Method and Description |
|---|---|
void |
add(boolean b)
Adds a boolean to the end of this SimpleSequence, by
coercing the boolean into
TemplateBooleanModel.TRUE or
TemplateBooleanModel.FALSE. |
void |
add(Object obj)
Adds an arbitrary object to the end of this SimpleSequence.
|
TemplateModel |
get(int i)
Retrieves the i-th template model in this sequence.
|
int |
size() |
SimpleSequence |
synchronizedWrapper() |
List |
toList()
Note that this method creates and returns a deep-copy of the underlying list used
internally.
|
String |
toString() |
getDefaultObjectWrapper, getObjectWrapper, setDefaultObjectWrapper, setObjectWrapper, wrapprotected final List list
public SimpleSequence()
SimpleSequence(ObjectWrapper) instead.WrappingTemplateModel.setDefaultObjectWrapper(ObjectWrapper).public SimpleSequence(int capacity)
SimpleSequence(Collection, ObjectWrapper).WrappingTemplateModel.setDefaultObjectWrapper(ObjectWrapper).public SimpleSequence(Collection collection)
SimpleSequence(Collection, ObjectWrapper).Collection and will use the the default
object wrapper set in
WrappingTemplateModel.setDefaultObjectWrapper(ObjectWrapper).collection - the collection containing initial values. Note that a
copy of the collection is made for internal use.public SimpleSequence(TemplateCollectionModel tcm) throws TemplateModelException
WrappingTemplateModel.setDefaultObjectWrapper(ObjectWrapper).TemplateModelExceptionpublic SimpleSequence(ObjectWrapper wrapper)
wrapper - The object wrapper to use to wrap objects into
TemplateModel instances. If null, the default wrapper set in
WrappingTemplateModel.setDefaultObjectWrapper(ObjectWrapper) is
used.public SimpleSequence(int capacity,
ObjectWrapper wrapper)
public SimpleSequence(Collection collection, ObjectWrapper wrapper)
Collection and will use the specified object
wrapper.collection - the collection containing initial values. Note that a
copy of the collection is made for internal use.wrapper - The object wrapper to use to wrap objects into
TemplateModel instances. If null, the default wrapper set in
WrappingTemplateModel.setDefaultObjectWrapper(ObjectWrapper) is
used.public void add(Object obj)
TemplateModel
interface, it will be wrapped into an appropriate adapter on the first
call to get(int).obj - the boolean to be added.public void add(boolean b)
TemplateBooleanModel.TRUE or
TemplateBooleanModel.FALSE.b - the boolean to be added.public List toList() throws TemplateModelException
TemplateModelExceptionpublic TemplateModel get(int i) throws TemplateModelException
TemplateSequenceModelget in interface TemplateSequenceModelTemplateModelExceptionpublic int size()
size in interface TemplateSequenceModelpublic SimpleSequence synchronizedWrapper()