freemarker.ext.beans
Class IteratorModel

java.lang.Object
  |
  +--freemarker.ext.beans.BeanModelBase
        |
        +--freemarker.ext.beans.BeanModel
              |
              +--freemarker.ext.beans.IteratorModel
All Implemented Interfaces:
TemplateHashModel, TemplateModel, TemplateModelIterator, TemplateScalarModel

public final class IteratorModel
extends BeanModel
implements TemplateModelIterator

A class that adds TemplateModelIterator functionality to the Iterator interface implementers. Also, it implements TemplateListModel because of certain backward-compatibility reasons.

It differs from the SimpleIterator in that it inherits from BeanModel, and therefore you can call methods on it directly, even to the effect of calling iterator.remove() in the template.

Using the model as a list model is NOT thread-safe, as iterators are inherently not thread-safe.

Version:
1.0
Author:
Attila Szegedi, szegedia@freemail.hu

Fields inherited from class freemarker.ext.beans.BeanModel
TYPE_ARRAY, TYPE_COLLECTION, TYPE_ENUMERATION, TYPE_ITERATOR, TYPE_MAP, TYPE_OBJECT, TYPE_OBJECT_BASE, TYPE_RESOURCE_BUNDLE
 
Constructor Summary
IteratorModel(java.util.Iterator iterator)
          Creates a new model that wraps the specified iterator object.
 
Method Summary
static IteratorModel getInstance(java.util.Iterator object)
          Returns a model wrapping the specified iterator object.
 int getType()
          Returns the type of this object (which is TYPE_ITERATOR)
 boolean hasNext()
          Calls Iterator.hasNext().
 TemplateModel next()
          Calls Iterator.next().
 
Methods inherited from class freemarker.ext.beans.BeanModel
get, getAsString, getInstance, getInstance, getObject, invokeGenericGet, isEmpty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface freemarker.template.TemplateModel
isEmpty
 

Constructor Detail

IteratorModel

public IteratorModel(java.util.Iterator iterator)
Creates a new model that wraps the specified iterator object.
Parameters:
object - the iterator object to wrap into a model.
Method Detail

getInstance

public static IteratorModel getInstance(java.util.Iterator object)
Returns a model wrapping the specified iterator object. It always returns a new object, as Iterators are considered short-lived and caching them would have little sense.
Returns:
the model for the iterator

getType

public int getType()
Returns the type of this object (which is TYPE_ITERATOR)
Overrides:
getType in class BeanModel

hasNext

public boolean hasNext()
Calls Iterator.hasNext().
Specified by:
hasNext in interface TemplateModelIterator
Following copied from interface: freemarker.template.TemplateModelIterator
Returns:
whether there are any more items to iterate over.

next

public TemplateModel next()
Calls Iterator.next().
Specified by:
next in interface TemplateModelIterator