freemarker.template
Class SimpleList

java.lang.Object
  extended by freemarker.template.SimpleList
All Implemented Interfaces:
TemplateIndexedModel, TemplateListModel2, TemplateModel, TemplateObjectModel, java.io.Serializable
Direct Known Subclasses:
ExtendedList

public class SimpleList
extends java.lang.Object
implements TemplateListModel2, TemplateIndexedModel, TemplateObjectModel, java.io.Serializable

A synchronized implementation of the TemplateListModel2 interface, using an underlying List implementation.

A SimpleList can act as a cache for another TemplateListModel, e.g. one that gets data from a database. When passed another TemplateListModel as an argument to its constructor or to its copy(TemplateListModel) method, the SimpleList immediately copies all the elements and discards the TemplateListModel.

All the public methods in this implementation are synchronized.

Note that as of 1.8, this model has been retrofitted to the TemplateListModel2 interface.

Version:
$Id: SimpleList.java 1101 2013-04-01 04:17:32Z run2000 $
See Also:
SimpleHash, SimpleScalar, SimpleNumber, Serialized Form

Field Summary
protected  java.util.List<TemplateModel> list
          The contents of this SimpleList are stored in this List object.
 
Constructor Summary
SimpleList()
          Constructs an empty SimpleList.
SimpleList(java.util.List<? extends TemplateModel> list)
          Constructs a SimpleList from the given List.
SimpleList(TemplateListModel listToCopy)
          Constructs a SimpleList, copying into it the values from another TemplateListModel.
SimpleList(TemplateListModel2 listToCopy)
          Constructs a SimpleList, copying into it the values from another TemplateListModel2.
SimpleList(TemplateModel[] arr)
          Constructs a SimpleList from the given Array of TemplateModels.
 
Method Summary
 void add(boolean bool)
          Adds a boolean to the end of this SimpleList, by wrapping the boolean in a FastBoolean.
 void add(long n)
          Adds a number to the end of this SimpleList, by wrapping the string in a FastNumber.
 void add(java.lang.Number n)
          Adds a number to the end of this SimpleList, by wrapping the string in a FastNumber.
 void add(java.lang.String s)
          Adds a string to the end of this SimpleList, by wrapping the string in a FastScalar.
 void add(TemplateModel element)
          Adds a TemplateModel to the end of this SimpleList.
 void clear()
          Removes all the elements from this SimpleList.
 void copy(TemplateListModel listToCopy)
          Discards the contents of this SimpleList, and copies into it the values from a TemplateListModel object.
 void copy(TemplateListModel2 listToCopy)
          Discards the contents of this SimpleList, and copies into it the values from another TemplateListModel2.
 void copy(TemplateModel[] arr)
          Discards the contents of this SimpleList, and copies into it the values from the given Array of TemplateModels.
 boolean equals(java.lang.Object o)
          Tests this object for equality with the given object.
 java.lang.Object getAsObject()
          Return an unmodifiable copy of the underlying List object for manipulation by the freemarker.ext.beans package.
 TemplateModel getAtIndex(long index)
          Retrieves the specified item from the list.
 int hashCode()
          Return the hash value for this object.
 boolean isEmpty()
          Is the underlying List empty?
 void releaseIterator(TemplateIteratorModel iterator)
          Returns the used iterator to the list model.
 TemplateIteratorModel templateIterator()
          Retrieves an iterator to iterate over this list.
 java.lang.String toString()
          Retrieve the value of this object as a String.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

list

protected java.util.List<TemplateModel> list
The contents of this SimpleList are stored in this List object.

Constructor Detail

SimpleList

public SimpleList()
Constructs an empty SimpleList.


SimpleList

public SimpleList(java.util.List<? extends TemplateModel> list)
Constructs a SimpleList from the given List. A defensive copy of the list is made.

Parameters:
list - the list of values to be copied into this SimpleList
Throws:
java.lang.NullPointerException - the list value is null

SimpleList

public SimpleList(TemplateModel[] arr)
Constructs a SimpleList from the given Array of TemplateModels.

Parameters:
arr - the array to be copied into the underlying List.
Throws:
java.lang.NullPointerException - the array to be copied is null

SimpleList

public SimpleList(TemplateListModel listToCopy)
           throws TemplateModelException
Constructs a SimpleList, copying into it the values from another TemplateListModel.

Parameters:
listToCopy - the list to be copied into this one.
Throws:
TemplateModelException - something went wrong while copying the given list into the SimpleList.
java.lang.NullPointerException - the list to be copied is null

SimpleList

public SimpleList(TemplateListModel2 listToCopy)
           throws TemplateModelException
Constructs a SimpleList, copying into it the values from another TemplateListModel2.

Parameters:
listToCopy - the list to be copied into this one.
Throws:
TemplateModelException - something went wrong while copying the given list into the SimpleList.
java.lang.NullPointerException - the list to be copied is null
Method Detail

clear

public void clear()
Removes all the elements from this SimpleList.


copy

public void copy(TemplateListModel listToCopy)
          throws TemplateModelException
Discards the contents of this SimpleList, and copies into it the values from a TemplateListModel object.

Parameters:
listToCopy - the list to be copied into this one.
Throws:
TemplateModelException - something went wrong while copying the given list into the SimpleList.
java.lang.NullPointerException - the list to be copied is null

copy

public void copy(TemplateListModel2 listToCopy)
          throws TemplateModelException
Discards the contents of this SimpleList, and copies into it the values from another TemplateListModel2.

Parameters:
listToCopy - the list to be copied into this one.
Throws:
TemplateModelException - something went wrong while copying the given list into the SimpleList.
java.lang.NullPointerException - the list to be copied is null

copy

public void copy(TemplateModel[] arr)
Discards the contents of this SimpleList, and copies into it the values from the given Array of TemplateModels.

Parameters:
arr - the array to be copied into the underlying list.
Throws:
java.lang.NullPointerException - the array to be copied is null

isEmpty

public boolean isEmpty()
                throws TemplateModelException
Is the underlying List empty?

Specified by:
isEmpty in interface TemplateModel
Returns:
true if the list is empty, otherwise false
Throws:
TemplateModelException

add

public void add(TemplateModel element)
Adds a TemplateModel to the end of this SimpleList.

Parameters:
element - the TemplateModel to be added.

add

public void add(java.lang.String s)
Adds a string to the end of this SimpleList, by wrapping the string in a FastScalar.

Parameters:
s - the String to be added.

add

public void add(java.lang.Number n)
Adds a number to the end of this SimpleList, by wrapping the string in a FastNumber.

Parameters:
n - the Number to be added.

add

public void add(long n)
Adds a number to the end of this SimpleList, by wrapping the string in a FastNumber.

Parameters:
n - the Number to be added.

add

public void add(boolean bool)
Adds a boolean to the end of this SimpleList, by wrapping the boolean in a FastBoolean.

Parameters:
bool - the boolean to be added.

templateIterator

public TemplateIteratorModel templateIterator()
                                       throws TemplateModelException
Retrieves an iterator to iterate over this list.

Specified by:
templateIterator in interface TemplateListModel2
Returns:
an iterator to iterate over the current list.
Throws:
TemplateModelException - the next item in the list can't be retrieved, or no next item exists.

releaseIterator

public void releaseIterator(TemplateIteratorModel iterator)
Returns the used iterator to the list model.

Specified by:
releaseIterator in interface TemplateListModel2
Parameters:
iterator - the iterator to be returned to the object pool, if any

getAtIndex

public TemplateModel getAtIndex(long index)
                         throws TemplateModelException
Retrieves the specified item from the list.

Specified by:
getAtIndex in interface TemplateIndexedModel
Parameters:
index - the index of the item to be retrieved.
Returns:
the specified index in the list.
Throws:
TemplateModelException - the specified item in the list can't be retrieved, or the index is out of bounds.

getAsObject

public java.lang.Object getAsObject()
                             throws TemplateModelException
Return an unmodifiable copy of the underlying List object for manipulation by the freemarker.ext.beans package.

Specified by:
getAsObject in interface TemplateObjectModel
Returns:
an unmodifiable view of the underlying List object
Throws:
TemplateModelException - the object could not be returned

toString

public java.lang.String toString()
Retrieve the value of this object as a String.

Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Tests this object for equality with the given object.

Overrides:
equals in class java.lang.Object
Parameters:
o - the object to be compared with
Returns:
true if the objects are equal, otherwise false

hashCode

public int hashCode()
Return the hash value for this object.

Overrides:
hashCode in class java.lang.Object
Returns:
the hash code corresponding to the value of this object