freemarker.ext.beans2
Class IteratorWrapper<T extends java.util.Iterator>

java.lang.Object
  extended by freemarker.ext.beans2.BeanWrapper<T>
      extended by freemarker.ext.beans2.IteratorWrapper<T>
All Implemented Interfaces:
ObjectWrapper, TemplateHashModel, TemplateIteratorModel, TemplateModel, TemplateObjectModel, TemplateScalarModel, TemplateWriteableHashModel, java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
ListIteratorWrapper

public class IteratorWrapper<T extends java.util.Iterator>
extends BeanWrapper<T>
implements TemplateIteratorModel, java.io.Serializable

Wraps an Iterator object as an Iterator model. Provides support for any additional methods provided by the iterator. Also a base class for ListIteratorWrapper.

Since:
1.9
Version:
$Id: IteratorWrapper.java 1067 2011-06-06 10:55:28Z run2000 $
Author:
Nicholas Cull
See Also:
Serialized Form

Field Summary
 
Fields inherited from class freemarker.ext.beans2.BeanWrapper
emptyParams, object
 
Constructor Summary
IteratorWrapper()
          Default constructor where an object is not provided initially.
IteratorWrapper(T iterator)
          Constructor that takes an Iterator object to be wrapped.
 
Method Summary
 boolean hasNext()
          Do we have another item in the list?
 boolean isEmpty()
          Is the object empty?
 TemplateModel next()
          Retrieve the next item in the list.
 
Methods inherited from class freemarker.ext.beans2.BeanWrapper
clone, get, getAsObject, getAsString, put, setObject
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IteratorWrapper

public IteratorWrapper()
Default constructor where an object is not provided initially. This allows the wrapper to be used as a prototype.


IteratorWrapper

public IteratorWrapper(T iterator)
Constructor that takes an Iterator object to be wrapped.

Parameters:
iterator - the iterator object to be wrapped
Method Detail

isEmpty

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

Specified by:
isEmpty in interface TemplateModel
Overrides:
isEmpty in class BeanWrapper<T extends java.util.Iterator>
Returns:
true if this object is empty, otherwise false
Throws:
TemplateModelException

hasNext

public boolean hasNext()
                throws TemplateModelException
Do we have another item in the list?

Specified by:
hasNext in interface TemplateIteratorModel
Returns:
true if there are more items to be iterated over, otherwise false
Throws:
TemplateModelException - there was a problem determining the next item in the list

next

public TemplateModel next()
                   throws TemplateModelException
Retrieve the next item in the list. The item will be a TemplateModel containing the underlying value.

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