freemarker.template
Class SimpleNumber

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

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

A synchronized implementation of the TemplateNumberModel interface using a long.

All the public methods in this implementation are synchronized.

Since:
1.8
Version:
$Id: SimpleNumber.java 1101 2013-04-01 04:17:32Z run2000 $
See Also:
SimpleHash, SimpleList, SimpleScalar, Serialized Form

Field Summary
protected  boolean empty
          Whether this SimpleNumber is currently empty.
protected  long numberValue
          The number stored in this SimpleNumber
 
Constructor Summary
SimpleNumber()
          Constructs a new SimpleNumber with a default value of 0.
SimpleNumber(long numberValue)
          Constructs a new SimpleNumber with the given long value.
SimpleNumber(java.lang.Number numberValue)
          Constructs a new SimpleNumber with the given Number value.
SimpleNumber(java.lang.String stringValue)
          Constructs a new SimpleNumber with the given String value.
 
Method Summary
 boolean equals(java.lang.Object o)
          Tests this object for equality with the given object.
 long getAsNumber()
          Return the number value as a long.
 int hashCode()
          Return the hash value for this object.
 boolean isEmpty()
          Is this SimpleNumber empty?
 void setValue(long value)
          Sets the value of this SimpleNumber
 void setValue(java.lang.Number value)
          Sets the value of this SimpleNumber
 void setValue(java.lang.String stringValue)
          Sets the value of this SimpleNumber to the given String value.
 java.lang.String toString()
          Retrieve the String value of this object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

numberValue

protected long numberValue
The number stored in this SimpleNumber


empty

protected boolean empty
Whether this SimpleNumber is currently empty.

Constructor Detail

SimpleNumber

public SimpleNumber()
Constructs a new SimpleNumber with a default value of 0.


SimpleNumber

public SimpleNumber(long numberValue)
Constructs a new SimpleNumber with the given long value.

Parameters:
numberValue - the long value

SimpleNumber

public SimpleNumber(java.lang.Number numberValue)
Constructs a new SimpleNumber with the given Number value.

Parameters:
numberValue - the Number value

SimpleNumber

public SimpleNumber(java.lang.String stringValue)
Constructs a new SimpleNumber with the given String value.

Parameters:
stringValue - the String to be converted to a number
Throws:
java.lang.NullPointerException - the String is null
java.lang.NumberFormatException - the String could not be parsed as a long
Method Detail

isEmpty

public boolean isEmpty()
                throws TemplateModelException
Is this SimpleNumber empty?

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

getAsNumber

public long getAsNumber()
                 throws TemplateModelException
Return the number value as a long.

Specified by:
getAsNumber in interface TemplateNumberModel
Returns:
the number value
Throws:
TemplateModelException

setValue

public void setValue(long value)
Sets the value of this SimpleNumber

Parameters:
value - the long value

setValue

public void setValue(java.lang.Number value)
Sets the value of this SimpleNumber

Parameters:
value - the Number value

setValue

public void setValue(java.lang.String stringValue)
Sets the value of this SimpleNumber to the given String value.

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

toString

public java.lang.String toString()
Retrieve the String value of this 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 compare 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:
the hash code corresponding to the value of this object