freemarker.template
Class SimpleHash

java.lang.Object
  |
  +--freemarker.template.SimpleHash
All Implemented Interfaces:
java.io.Serializable, TemplateHashModel, TemplateModel, TemplateModelRoot

public class SimpleHash
extends java.lang.Object
implements TemplateModelRoot, java.io.Serializable

A simple implementation of the TemplateHashModel and TemplateModelRoot interfaces, using a HashMap.

All the public methods in this implementation are synchronized.

See Also:
Serialized Form

Field Summary
protected  java.util.AbstractMap hash
           
 
Constructor Summary
SimpleHash()
          Constructs an empty SimpleHash.
SimpleHash(java.util.AbstractMap hash)
          Constructs a SimpleHash from the given AbstractMap
 
Method Summary
 TemplateModel get(java.lang.String key)
          Gets a TemplateModel from the hash.
 boolean isEmpty()
           
 void put(java.lang.String key, boolean b)
          Puts a boolean in the hash, by first wrapping the boolean in a SimpleScalar.
 void put(java.lang.String key, java.lang.String s)
          Puts a string in the hash, by first wrapping the string in a SimpleScalar.
 void put(java.lang.String key, TemplateModel model)
          Puts a TemplateModel in the hash.
 void remove(java.lang.String key)
          Removes a key from the hash model.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

hash

protected java.util.AbstractMap hash
Constructor Detail

SimpleHash

public SimpleHash()
Constructs an empty SimpleHash.

SimpleHash

public SimpleHash(java.util.AbstractMap hash)
Constructs a SimpleHash from the given AbstractMap
Parameters:
hash - The AbstractMap to use as the backing for this SimpleHash
Method Detail

isEmpty

public boolean isEmpty()
                throws TemplateModelException
Specified by:
isEmpty in interface TemplateModel
Following copied from interface: freemarker.template.TemplateModel
Returns:
true if this object is empty.

put

public void put(java.lang.String key,
                TemplateModel model)
Puts a TemplateModel in the hash.
Specified by:
put in interface TemplateModelRoot
Parameters:
key - the name by which the TemplateModel is identified in the template.
model - the TemplateModel to store.

put

public void put(java.lang.String key,
                java.lang.String s)
Puts a string in the hash, by first wrapping the string in a SimpleScalar.
Parameters:
key - the name by which the resulting TemplateModel is identified in the template.
s - the string to store.

put

public void put(java.lang.String key,
                boolean b)
Puts a boolean in the hash, by first wrapping the boolean in a SimpleScalar.
Parameters:
key - the name by which the resulting TemplateModel is identified in the template.
b - the boolean to store.

get

public TemplateModel get(java.lang.String key)
                  throws TemplateModelException
Description copied from interface: TemplateHashModel
Gets a TemplateModel from the hash.
Specified by:
get in interface TemplateHashModel
Following copied from interface: freemarker.template.TemplateHashModel
Parameters:
key - the name by which the TemplateModel is identified in the template.
Returns:
the TemplateModel referred to by the key, or null if not found.

remove

public void remove(java.lang.String key)
Description copied from interface: TemplateModelRoot
Removes a key from the hash model.
Specified by:
remove in interface TemplateModelRoot
Following copied from interface: freemarker.template.TemplateModelRoot
Parameters:
key - the key to be removed.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object