freemarker.template
Class FastNumber

java.lang.Object
  extended by freemarker.template.FastNumber
All Implemented Interfaces:
TemplateModel, TemplateNumberModel, java.io.Serializable

public final class FastNumber
extends java.lang.Object
implements TemplateNumberModel, java.io.Serializable

An unsynchronized, immutable implementation of the TemplateNumberModel interface. This avoids the need for synchronization, since we don't have any situations where the underlying value changes.

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

Constructor Summary
FastNumber(long longValue)
          Constructs an instance of this object with an initial value.
FastNumber(java.lang.Number numberValue)
          Constructs an instance of this object with an initial value.
FastNumber(java.lang.String stringValue)
          Constructs an instance of this object with an initial value.
 
Method Summary
 boolean equals(java.lang.Object o)
          Tests this object for equality with the given object.
 long getAsNumber()
          Returns the scalar's value as a String.
 int hashCode()
          Return the hash value for this object.
 boolean isEmpty()
          Is the scalar value empty?
 java.lang.String toString()
          Return the value of this object as a String.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FastNumber

public FastNumber(java.lang.String stringValue)
Constructs an instance of this object with an initial value.

Parameters:
stringValue - the value to store
Throws:
java.lang.NullPointerException - the value is null
java.lang.NumberFormatException - the value could not be parsed as a long

FastNumber

public FastNumber(long longValue)
Constructs an instance of this object with an initial value.

Parameters:
longValue - the value to store

FastNumber

public FastNumber(java.lang.Number numberValue)
Constructs an instance of this object with an initial value.

Parameters:
numberValue - the value to store
Method Detail

getAsNumber

public long getAsNumber()
                 throws TemplateModelException
Returns the scalar's value as a String.

Specified by:
getAsNumber in interface TemplateNumberModel
Returns:
the String value of this scalar.
Throws:
TemplateModelException

isEmpty

public boolean isEmpty()
                throws TemplateModelException
Is the scalar value empty?

Specified by:
isEmpty in interface TemplateModel
Returns:
true if this String is empty or null, otherwise false.
Throws:
TemplateModelException

toString

public java.lang.String toString()
Return the value of this object as a String.

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 against
Returns:
true if the objects are 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