JythonHashModel (FreeMarker 2.3.35 API)
Description: declaration: package: freemarker.ext.jython, class: JythonHashModel

Package freemarker.ext.jython

# Class JythonHashModel

java.lang.Object
freemarker.ext.jython.JythonModel
freemarker.ext.jython.JythonHashModel

All Implemented Interfaces:
  `WrapperTemplateModel`, `AdapterTemplateModel`, `TemplateBooleanModel`, `TemplateHashModel`, `TemplateHashModelEx`, `TemplateMethodModel`, `TemplateMethodModelEx`, `TemplateModel`, `TemplateScalarModel`

public class JythonHashModel extends JythonModel implements TemplateHashModelEx
Model for Jython dictionaries (`PyDictionary` and `PyStringMap`). Note that the basic `JythonModel` already provides access to the `PyObject.__finditem__(String)` method. This class only adds `TemplateHashModelEx` functionality in a somewhat skewed way. One could say it even violates TemplateHashModelEx semantics, as both the returned keys and values are only those from the item mapping, while the `get()` method works for attributes as well. However, in practice when you ask for `dict?keys` inside a template, you'll really want to retrieve only items, not attributes so this is considered OK.

- ## Field Summary

  ### Fields inherited from class freemarker.ext.jython.JythonModel

  `object, wrapper`

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

  `FALSE, TRUE`

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

  `NOTHING`

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

  `EMPTY_STRING`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `JythonHashModel​(org.python.core.PyObject object, JythonWrapper wrapper)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `TemplateCollectionModel`
  `keys()`
  Returns either `object.__findattr__("keys").__call__()` or `object.__findattr__("keySet").__call__()`.
  `int`
  `size()`
  Returns `PyObject.__len__()`.
  `TemplateCollectionModel`
  `values()`
  Returns `object.__findattr__("values").__call__()`.

  ### Methods inherited from class freemarker.ext.jython.JythonModel

  `exec, get, getAdaptedObject, getAsBoolean, getAsString, getWrappedObject, 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.TemplateHashModel

  `get, isEmpty`

- ## Constructor Details

  - ### JythonHashModel

    public JythonHashModel​(org.python.core.PyObject object, JythonWrapper wrapper)

- ## Method Details

  - ### size

    public int size() throws TemplateModelException
    Returns `PyObject.__len__()`.
    Specified by:
      `size` in interface `TemplateHashModelEx`
    Returns:
      the number of key/value mappings in the hash.
    Throws:
      `TemplateModelException`

  - ### keys

    public TemplateCollectionModel keys() throws TemplateModelException
    Returns either `object.__findattr__("keys").__call__()` or `object.__findattr__("keySet").__call__()`.
    Specified by:
      `keys` in interface `TemplateHashModelEx`
    Returns:
      a collection containing the keys in the hash. Every element of the returned collection must implement the `TemplateScalarModel` (as the keys of hashes are always strings).
    Throws:
      `TemplateModelException`

  - ### values

    public TemplateCollectionModel values() throws TemplateModelException
    Returns `object.__findattr__("values").__call__()`.
    Specified by:
      `values` in interface `TemplateHashModelEx`
    Returns:
      a collection containing the values in the hash. The elements of the returned collection can be any kind of `TemplateModel`-s.
    Throws:
      `TemplateModelException`