ArrayModel (FreeMarker 2.3.23 API)
Date: 2015-07-05

freemarker.ext.beans

## Class ArrayModel

- java.lang.Object
- - freemarker.ext.beans.BeanModel
  - - freemarker.ext.beans.ArrayModel

- All Implemented Interfaces:
    WrapperTemplateModel, AdapterTemplateModel, TemplateCollectionModel, TemplateHashModel, TemplateHashModelEx, TemplateModel, TemplateModelWithAPISupport, TemplateSequenceModel

      public class ArrayModel
      extends BeanModel
      implements TemplateCollectionModel, TemplateSequenceModel

  A class that will wrap an arbitrary array into `TemplateCollectionModel` and `TemplateSequenceModel` interfaces. It supports element retrieval through the `array[index]` syntax and can be iterated as a list.

- - ### Field Summary

    - ### Fields inherited from class freemarker.ext.beans.BeanModel

      `object, wrapper`

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

      `NOTHING`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ArrayModel(Object array, BeansWrapper wrapper)` Creates a new model that wraps the specified array object.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `TemplateModel` | `get(int index)` Retrieves the i-th template model in this sequence.
    `boolean` | `isEmpty()` Tells whether the model is empty.
    `TemplateModelIterator` | `iterator()` Retrieves a template model iterator that is used to iterate over the elements in this collection.
    `int` | `size()`

    - ### Methods inherited from class freemarker.ext.beans.BeanModel

      `get, getAdaptedObject, getAPI, getWrappedObject, hasPlainGetMethod, invokeGenericGet, keys, keySet, toString, unwrap, values, wrap`

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

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

- - ### Constructor Detail

    - #### ArrayModel

          public ArrayModel(Object array,
                            BeansWrapper wrapper)

      Creates a new model that wraps the specified array object.
      Parameters:
        `array` - the array 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.
      Throws:
        `IllegalArgumentException` - if the passed object is not a Java array.

  - ### Method Detail

    - #### iterator

          public TemplateModelIterator iterator()

      Description copied from interface: `TemplateCollectionModel`
      Retrieves a template model iterator that is used to iterate over the elements in this collection.
      Specified by:
        `iterator` in interface `TemplateCollectionModel`

    - #### get

          public TemplateModel get(int index)
                            throws TemplateModelException

      Description copied from interface: `TemplateSequenceModel`
      Retrieves the i-th template model in this sequence.
      Specified by:
        `get` in interface `TemplateSequenceModel`
      Returns:
        the item at the specified index, or `null` if the index is out of bounds. Note that a `null` value is interpreted by FreeMarker as "variable does not exist", and accessing a missing variables is usually considered as an error in the FreeMarker Template Language, so the usage of a bad index will not remain hidden, unless the default value for that case was also specified in the template.
      Throws:
        `TemplateModelException`

    - #### size

          public int size()

      Specified by:
        `size` in interface `TemplateHashModelEx`
      Specified by:
        `size` in interface `TemplateSequenceModel`
      Overrides:
        `size` in class `BeanModel`
      Returns:
        the number of key/value mappings in the hash.

    - #### isEmpty

          public boolean isEmpty()

      Description copied from class: `BeanModel`
      Tells whether the model is empty. It is empty if either the wrapped object is null, or it's a Boolean with false value.
      Specified by:
        `isEmpty` in interface `TemplateHashModel`
      Overrides:
        `isEmpty` in class `BeanModel`