freemarker.ext.beans
Class SimpleNumberModel

java.lang.Object
  |
  +--freemarker.ext.beans.SimpleNumberModel
All Implemented Interfaces:
TemplateModel, TemplateNumberModel, TemplateObjectModel, TemplateScalarModel

public class SimpleNumberModel
extends java.lang.Object
implements TemplateNumberModel, TemplateScalarModel, TemplateObjectModel

Holds subclasses of Number for evaluation as TemplateNumberModel or unwrapped as an object. We also implement TemplateScalarModel so that floats or doubles are printed with full precision.

Version:
$Id: SimpleNumberModel.java,v 1.2 2003/11/02 07:06:40 run2000 Exp $
Author:
Nicholas Cull

Constructor Summary
SimpleNumberModel(java.lang.Number number)
          Constructor that takes the Number object to be wrapped.
 
Method Summary
 long getAsNumber()
          Retrieve the underlying value as a long.
 java.lang.Object getAsObject()
          Retrieve the underlying object for object unwrapping purposes.
 java.lang.String getAsString()
          Retrieve the underlying value as a String.
 boolean isEmpty()
          Is there an underlying number in this model?
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleNumberModel

public SimpleNumberModel(java.lang.Number number)
Constructor that takes the Number object to be wrapped.
Parameters:
number - the number to be wrapped
Method Detail

getAsNumber

public long getAsNumber()
                 throws TemplateModelException
Retrieve the underlying value as a long. Numbers that use decimal places will be rounded appropriately.
Specified by:
getAsNumber in interface TemplateNumberModel
Returns:
a long value representing the underlying number
Throws:
TemplateModelException -  

getAsString

public java.lang.String getAsString()
                             throws TemplateModelException
Retrieve the underlying value as a String. This preserves any decimal places held in the underlying object.
Specified by:
getAsString in interface TemplateScalarModel
Returns:
a String representation of the underlying number
Throws:
TemplateModelException -  

isEmpty

public boolean isEmpty()
                throws TemplateModelException
Is there an underlying number in this model?
Specified by:
isEmpty in interface TemplateModel
Returns:
true if there is a Number object present, otherwise false

getAsObject

public java.lang.Object getAsObject()
                             throws TemplateModelException
Retrieve the underlying object for object unwrapping purposes.
Specified by:
getAsObject in interface TemplateObjectModel
Returns:
the underlying Number object