|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object freemarker.ext.misc.AsNumber
public final class AsNumber
Performs a type conversion from a String model to a number model. This is useful when we want to perform numeric operations on a value that was introduced as a scalar value, or when we only want a number from a multimodel.
Usage:
From java:
TemplateModelRoot root = new SimpleHash(); root.put( "asNumber", freemarker.ext.misc.AsNumber.getInstance() ); ...
From your FM-Classic template:
<assign var1 = "5"> <assign var2 = "3"> <assign var3 = asNumber( var1 ) + asNumber( var2 )> <p>The sum of ${var1} and ${var2} is: ${var3}</p> ...
Note:
AsNumber
is a singleton instance. Use the
getInstance()
method to retrieve instances of this model.
Method Summary | |
---|---|
TemplateModel |
exec(java.util.List<TemplateModel> arguments)
Performs a String to number conversion using the rules that Long.parseLong() uses. |
static AsNumber |
getInstance()
Retrieve a singleton instance of this class. |
boolean |
isEmpty()
Is this model empty? |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static AsNumber getInstance()
AsNumber
classpublic TemplateModel exec(java.util.List<TemplateModel> arguments) throws TemplateModelException
Long.parseLong()
uses.
exec
in interface TemplateMethodModel2
arguments
- a List of exactly one TemplateScalarModel
to be converted
TemplateNumberModel
of the converted String
TemplateModelException
- More than one argument is supplied,
or the model is neither a number nor a string model.public boolean isEmpty() throws TemplateModelException
isEmpty
in interface TemplateModel
false
to indicate that this model is non-empty
TemplateModelException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |