freemarker.template
Class FastHash<V extends TemplateModel>

java.lang.Object
  extended by freemarker.template.FastHash<V>
All Implemented Interfaces:
TemplateHashModel, TemplateModel, TemplateModelRoot, TemplateObjectModel, TemplateWriteableHashModel, java.io.Serializable

public final class FastHash<V extends TemplateModel>
extends java.lang.Object
implements TemplateModelRoot, TemplateObjectModel, java.io.Serializable

An unsynchronized variation of the SimpleHash class to handle key-pair values. This means that FastHash should be significantly faster than SimpleHash in some cases.

Instances of this class should be used in situations where either:

Note that every template process is performed synchronously, so within a single-threaded application instances of this class will always be safe.

Since:
1.7.5
Version:
$Id: FastHash.java 1101 2013-04-01 04:17:32Z run2000 $
See Also:
FastBoolean, FastList, FastNumber, FastScalar, Serialized Form

Constructor Summary
FastHash()
          Default constructor.
FastHash(java.util.Map<java.lang.String,V> hash)
          Constructs an FastHash given the backing Map.
 
Method Summary
 boolean equals(java.lang.Object o)
          Tests this object for equality with the given object.
 TemplateModel get(java.lang.String key)
          Gets a TemplateModel from the hash.
 java.lang.Object getAsObject()
          Return an unmodifiable view of the underlying Map object for manipulation by the freemarker.ext.beans package.
 int hashCode()
          Return the hash value for this object.
 boolean isEmpty()
          Is the model empty?
 void put(java.lang.String key, TemplateModel model)
          Sets a value in the hash model.
 void remove(java.lang.String key)
          Removes a key from the hash model.
 java.lang.String toString()
          Returns a String representation of the object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FastHash

public FastHash()
Default constructor.


FastHash

public FastHash(java.util.Map<java.lang.String,V> hash)
Constructs an FastHash given the backing Map.

Parameters:
hash - The Map to use as the backing for this FastHash.
Throws:
java.lang.NullPointerException - the map is null
Method Detail

isEmpty

public boolean isEmpty()
Is the model empty?

Specified by:
isEmpty in interface TemplateModel
Returns:
true if this object is empty, otherwise false

get

public TemplateModel get(java.lang.String key)
Gets a TemplateModel from the hash.

Specified by:
get in interface 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.

put

public void put(java.lang.String key,
                TemplateModel model)
Sets a value in the hash model.

Specified by:
put in interface TemplateModelRoot
Specified by:
put in interface TemplateWriteableHashModel
Parameters:
key - the hash key.
model - the hash value.

remove

public void remove(java.lang.String key)
Removes a key from the hash model.

Specified by:
remove in interface TemplateModelRoot
Parameters:
key - the key to be removed.

getAsObject

public java.lang.Object getAsObject()
                             throws TemplateModelException

Return an unmodifiable view of the underlying Map object for manipulation by the freemarker.ext.beans package.

Specified by:
getAsObject in interface TemplateObjectModel
Returns:
an unmodifiable view of the underlying Map object
Throws:
TemplateModelException - the object could not be returned

toString

public java.lang.String toString()
Returns a String representation of the object.

Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Tests this object for equality with the given object.

Overrides:
equals in class java.lang.Object
Parameters:
o - the object to be compared with
Returns:
true if the object is equal, otherwise false

hashCode

public int hashCode()
Return the hash value for this object.

Overrides:
hashCode in class java.lang.Object
Returns:
a hash code corresponding to the value of this object