SimpleCollection (FreeMarker 2.3.35 API)
Description: declaration: package: freemarker.template, class: SimpleCollection

Package freemarker.template

# Class SimpleCollection

java.lang.Object
freemarker.template.WrappingTemplateModel
freemarker.template.SimpleCollection

All Implemented Interfaces:
  `TemplateCollectionModel`, `TemplateModel`, `Serializable`

public class SimpleCollection extends WrappingTemplateModel implements TemplateCollectionModel, Serializable
A simple implementation of `TemplateCollectionModel`. It's able to wrap `java.util.Iterator`-s and `java.util.Collection`-s. If you wrap an `Iterator`, the variable can be <#list>-ed only once!

Consider using `SimpleSequence` instead of this class if you want to wrap `Iterator`s. `SimpleSequence` will read all elements of the `Iterator`, and store them in a `List` (this may cause too high resource consumption in some applications), so you can list the variable for unlimited times. Also, if you want to wrap `Collection`s, and then list the resulting variable for many times, `SimpleSequence` may gives better performance, as the wrapping of non-`TemplateModel` objects happens only once.

This class is thread-safe. The returned `TemplateModelIterator`-s are not thread-safe.

See Also:
  Serialized Form

- ## Field Summary

  ### Fields inherited from interface freemarker.template.TemplateModel

  `NOTHING`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `SimpleCollection​(Iterable iterable)`
  Deprecated.
  Use `SimpleCollection(Iterable, ObjectWrapper)` instead.
  `SimpleCollection​(Iterable iterable, ObjectWrapper wrapper)`
  `SimpleCollection​(Collection collection)`
  Deprecated.
  Use `SimpleCollection(Iterable, ObjectWrapper)` instead.
  `SimpleCollection​(Collection collection, ObjectWrapper wrapper)`
  Same as `SimpleCollection(Iterable, ObjectWrapper)`; kept for binary compatibility.
  `SimpleCollection​(Iterator iterator)`
  Deprecated.
  Use `SimpleCollection(Iterator, ObjectWrapper)`
  `SimpleCollection​(Iterator iterator, ObjectWrapper wrapper)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `TemplateModelIterator`
  `iterator()`
  Retrieves a template model iterator that is used to iterate over the elements in this collection.

  ### Methods inherited from class freemarker.template.WrappingTemplateModel

  `getDefaultObjectWrapper, getObjectWrapper, setDefaultObjectWrapper, setObjectWrapper, wrap`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### SimpleCollection

    @Deprecated public SimpleCollection​(Iterator iterator)
    Deprecated.
    Use `SimpleCollection(Iterator, ObjectWrapper)`

  - ### SimpleCollection

    @Deprecated public SimpleCollection​(Iterable iterable)
    Deprecated.
    Use `SimpleCollection(Iterable, ObjectWrapper)` instead.

  - ### SimpleCollection

    @Deprecated public SimpleCollection​(Collection collection)
    Deprecated.
    Use `SimpleCollection(Iterable, ObjectWrapper)` instead.
    Same as `SimpleCollection(Iterable)`; kept for binary compatibility.

  - ### SimpleCollection

    public SimpleCollection​(Collection collection, ObjectWrapper wrapper)
    Same as `SimpleCollection(Iterable, ObjectWrapper)`; kept for binary compatibility.

  - ### SimpleCollection

    public SimpleCollection​(Iterator iterator, ObjectWrapper wrapper)

  - ### SimpleCollection

    public SimpleCollection​(Iterable iterable, ObjectWrapper wrapper)
    Parameters:
      `iterable` - Note that this was a `Collection` before 2.3.27, not an `Iterable`

- ## Method Details

  - ### iterator

    public TemplateModelIterator iterator()
    Retrieves a template model iterator that is used to iterate over the elements in this collection.

    When you wrap an `Iterator` and you get `TemplateModelIterator` for multiple times, only on of the returned `TemplateModelIterator` instances can be really used. When you have called a method of a `TemplateModelIterator` instance, all other instance will throw a `TemplateModelException` when you try to call their methods, since the wrapped `Iterator` can't return the first element anymore.

    Specified by:
      `iterator` in interface `TemplateCollectionModel`