freemarker.template
Class FastList<T extends TemplateModel>

java.lang.Object
  extended by freemarker.template.FastList<T>
All Implemented Interfaces:
TemplateIndexedModel, TemplateListModel2, TemplateModel, TemplateObjectModel, TemplateWriteableIndexedModel, java.io.Serializable

public final class FastList<T extends TemplateModel>
extends java.lang.Object
implements TemplateListModel2, TemplateIndexedModel, TemplateWriteableIndexedModel, TemplateObjectModel, java.io.Serializable

An unsynchronized variation of the SimpleList class. This allows FastList to be significantly faster than SimpleList in some cases.

Note that every template process is performed synchronously, so within a single-threaded application instances of this class will always be safe.

Note also that this class was retrofitted with the TemplateListModel2 interface as of 1.8.

Since:
1.7.5
Version:
$Id: FastList.java 1101 2013-04-01 04:17:32Z run2000 $
See Also:
FastBoolean, FastHash, FastNumber, FastScalar, Serialized Form

Constructor Summary
FastList()
          Constructs an empty FastList.
FastList(java.util.List<T> list)
          Constructs a FastList from the given List.
 
Method Summary
 boolean equals(java.lang.Object o)
          Tests this object for equality with the given object.
 java.lang.Object getAsObject()
          Return an unmodifiable view 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 putAtIndex(long index, TemplateModel model)
          Set the value corresponding to the given index.
 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()
          Returns a String representation of the object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FastList

public FastList()
Constructs an empty FastList.


FastList

public FastList(java.util.List<T> list)
Constructs a FastList from the given List.

Throws:
java.lang.NullPointerException - the list value is null
Method Detail

isEmpty

public boolean isEmpty()
Is the underlying List empty?

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

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.

putAtIndex

public void putAtIndex(long index,
                       TemplateModel model)
                throws TemplateModelException
Set the value corresponding to the given index. Traditionally this would correspond to an index into an array, or similar structure, such as a java.util.Vector.

Specified by:
putAtIndex in interface TemplateWriteableIndexedModel
Parameters:
index - the index of the underlying value we're interested in
model - the model to be added to the list
Throws:
TemplateModelException - the value could not be determined, possibly due to an index out-of-bounds, or an otherwise undefined value

getAsObject

public java.lang.Object getAsObject()

Return an unmodifiable view 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

toString

public java.lang.String toString()
Returns a String representation of the object.

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:
a hash code corresponding to the value of this object