freemarker.template
Class FastIndexedIterator

java.lang.Object
  extended by freemarker.template.FastIndexedIterator
All Implemented Interfaces:
TemplateHashModel, TemplateIteratorModel, TemplateModel

public class FastIndexedIterator
extends java.lang.Object
implements TemplateIteratorModel, TemplateHashModel

An iterator that operates over a TemplateIndexedModel implementation. The assumption here is that we have constant-time random access to the underlying implementation.

Since:
1.8
Version:
$Id: FastIndexedIterator.java 1153 2013-04-15 10:59:37Z run2000 $
See Also:
FastIndexedWriteableIterator

Field Summary
protected  long currentIndex
          The current index into the model.
protected  long endIndex
          The end index of the model.
protected  TemplateIndexedModel indexModel
          The model that we will index into.
protected  long startIndex
          The beginning index of the model.
 
Constructor Summary
FastIndexedIterator(TemplateIndexedModel model, long startIndex, long endIndex)
          Constructor that takes the object we're iterating over as an argument
 
Method Summary
 TemplateModel get(java.lang.String key)
          Gets a TemplateModel from the hash.
 boolean hasNext()
          Do we have a next value?
 boolean isEmpty()
          Is the iterator empty?
 TemplateModel next()
          Return the next value in the indexModel, and increment the counter to point to the next value.
 java.lang.String toString()
          Returns a string representation of the object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

indexModel

protected final TemplateIndexedModel indexModel
The model that we will index into.


startIndex

protected final long startIndex
The beginning index of the model.


endIndex

protected final long endIndex
The end index of the model.


currentIndex

protected long currentIndex
The current index into the model.

Constructor Detail

FastIndexedIterator

public FastIndexedIterator(TemplateIndexedModel model,
                           long startIndex,
                           long endIndex)
Constructor that takes the object we're iterating over as an argument

Parameters:
model - the indexed list model to iterate over
Method Detail

isEmpty

public boolean isEmpty()
                throws TemplateModelException
Is the iterator empty?

Specified by:
isEmpty in interface TemplateModel
Returns:
false, indicating the iterator is not empty
Throws:
TemplateModelException

hasNext

public boolean hasNext()
Do we have a next value?

Specified by:
hasNext in interface TemplateIteratorModel
Returns:
true if more values exist in the list, otherwise false

next

public TemplateModel next()
                   throws TemplateModelException
Return the next value in the indexModel, and increment the counter to point to the next value.

Specified by:
next in interface TemplateIteratorModel
Returns:
a TemplateModel representing the next value in the list
Throws:
TemplateModelException - the next item couldn't be retrieved, or we're at the end of the list

get

public TemplateModel get(java.lang.String key)
                  throws TemplateModelException
Gets a TemplateModel from the hash. The one key is "index", which returns the current index of the iterator.

Specified by:
get in interface TemplateHashModel
Parameters:
key - the name by which the TemplateModel is identified in the template.
Returns:
the TemplateModel referred to by the key, or null if not found.
Throws:
TemplateModelException - there was a problem getting the value for the given key

toString

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

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the object.