public class IteratorModel extends BeanModel implements TemplateModelIterator, TemplateCollectionModel
A class that adds TemplateModelIterator functionality to the
Iterator interface implementers.
It differs from the SimpleCollection 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 collection model is NOT
thread-safe, as iterators are inherently not thread-safe.
Further, you can iterate over it only once. Attempts to call the
iterator() method after it was already driven to the end once will
throw an exception.
NOTHING| Constructor and Description |
|---|
IteratorModel(java.util.Iterator iterator,
BeansWrapper wrapper)
Creates a new model that wraps the specified iterator object.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
getAsBoolean()
Returns
Iterator.hasNext(). |
boolean |
hasNext()
Calls underlying
Iterator.hasNext(). |
TemplateModelIterator |
iterator()
This allows the iterator to be used in a <#list> block.
|
TemplateModel |
next()
Calls underlying
Iterator.next() and wraps the result. |
get, getAdaptedObject, getAPI, getWrappedObject, hasPlainGetMethod, invokeGenericGet, isEmpty, keys, keySet, size, toString, unwrap, values, wrappublic IteratorModel(java.util.Iterator iterator,
BeansWrapper wrapper)
iterator - the iterator object to wrap into a model.wrapper - the BeansWrapper associated with this model.
Every model has to have an associated BeansWrapper instance. The
model gains many attributes from its wrapper, including the caching
behavior, method exposure level, method-over-item shadowing policy etc.public TemplateModelIterator iterator() throws TemplateModelException
iterator in interface TemplateCollectionModelTemplateModelExceptionpublic boolean hasNext()
Iterator.hasNext().hasNext in interface TemplateModelIteratorpublic TemplateModel next() throws TemplateModelException
Iterator.next() and wraps the result.next in interface TemplateModelIteratorTemplateModelException - if the next model can not be retrieved
(i.e. because the iterator is exhausted).public boolean getAsBoolean()
Iterator.hasNext(). Therefore, an
iterator that has no more element evaluates to false, and an
iterator that has further elements evaluates to true.