freemarker.template
Class FastIndexedIterator

java.lang.Object
  |
  +--freemarker.template.FastIndexedIterator
All Implemented Interfaces:
TemplateIteratorModel, TemplateModel

public class FastIndexedIterator
extends java.lang.Object
implements TemplateIteratorModel

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,v 1.6 2003/11/24 05:49:49 run2000 Exp $

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
 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

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

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.