Package org.apache.velocity.runtime.parser.node

# Class ASTMathNode

java.lang.Object
org.apache.velocity.runtime.parser.node.SimpleNode
org.apache.velocity.runtime.parser.node.ASTBinaryOperator
org.apache.velocity.runtime.parser.node.ASTMathNode

All Implemented Interfaces:
  `Cloneable`, `Node`, `Renderable`

Direct Known Subclasses:
  `ASTAddNode`, `ASTDivNode`, `ASTModNode`, `ASTMulNode`, `ASTSubtractNode`

public abstract class ASTMathNode extends ASTBinaryOperator
Helps handle math
Please look at the Parser.jjt file which is what controls the generation of this class.

Version:
  $Id: ASTMathNode.java 517553 2007-03-13 06:09:58Z wglass $
Author:
  Will Glass-Husain, Peter Romianowski, Jason van Zyl, Geir Magnusson Jr., Nathan Bubna

## Field Summary

Fields
Modifier and Type
Field
Description
`protected boolean`
`strictMode`

### Fields inherited from class org.apache.velocity.runtime.parser.node.SimpleNode

`children, column, first, firstImage, id, info, invalid, last, lastImage, line, literal, log, parent, parser, rsvc, state, template`

## Constructor Summary

Constructors
Constructor
Description
`ASTMathNode(int id)`
`ASTMathNode(Parser p, int id)`

## Method Summary

Modifier and Type
Method
Description
`protected Object`
`handleSpecial(Object left, Object right, InternalContextAdapter context)`
Extension hook to allow special behavior by subclasses If this method returns a non-null value, that is returned, rather than the result of the math operation.
`Object`
`init(InternalContextAdapter context, Object data)`
`Object`
`jjtAccept(StandardParserVisitor visitor, Object data)`
`abstract Number`
`perform(Number left, Number right, InternalContextAdapter context)`
Performs the math operation represented by this node.
`Object`
`value(InternalContextAdapter context)`
gets the two args and performs the operation on them

### Methods inherited from class org.apache.velocity.runtime.parser.node.ASTBinaryOperator

`getLiteralOperator, literal`

### Methods inherited from class org.apache.velocity.runtime.parser.node.SimpleNode

`childrenAccept, cleanupParserAndTokens, clone, clone, dump, dump, dump, evaluate, execute, getColumn, getFirstToken, getFirstTokenImage, getInfo, getLastToken, getLastTokenImage, getLine, getLocation, getParser, getRuntimeServices, getTemplate, getTemplateName, getType, isInvalid, jjtAddChild, jjtClose, jjtGetChild, jjtGetNumChildren, jjtGetParent, jjtOpen, jjtSetParent, render, saveTokenImages, setFirstToken, setInfo, setInvalid, toString, toString`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Field Details

### strictMode

protected boolean strictMode

## Constructor Details

### ASTMathNode

public ASTMathNode(int id)

### ASTMathNode

public ASTMathNode(Parser p, int id)

## Method Details

### init

public Object init(InternalContextAdapter context, Object data) throws TemplateInitException

Specified by:
  `init` in interface `Node`
Overrides:
  `init` in class `ASTBinaryOperator`
Parameters:
  `context` -
  `data` -
Returns:
  The init result.
Throws:
  `TemplateInitException`
See Also:
  - `Node.init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)`

### jjtAccept

public Object jjtAccept(StandardParserVisitor visitor, Object data)

Specified by:
  `jjtAccept` in interface `Node`
Overrides:
  `jjtAccept` in class `SimpleNode`
Parameters:
  `visitor` -
  `data` -
Returns:
  The Node execution result object.
See Also:
  - `Node.jjtAccept(org.apache.velocity.runtime.parser.node.StandardParserVisitor, java.lang.Object)`

### value

public Object value(InternalContextAdapter context) throws MethodInvocationException
gets the two args and performs the operation on them

Specified by:
  `value` in interface `Node`
Overrides:
  `value` in class `SimpleNode`
Parameters:
  `context` -
Returns:
  result or null
Throws:
  `MethodInvocationException`
See Also:
  - `Node.value(org.apache.velocity.context.InternalContextAdapter)`

### handleSpecial

protected Object handleSpecial(Object left, Object right, InternalContextAdapter context)
Extension hook to allow special behavior by subclasses If this method returns a non-null value, that is returned, rather than the result of the math operation.

Parameters:
  `left` -
  `right` -
  `context` -
Returns:
  special value
See Also:
  - `ASTAddNode.handleSpecial(java.lang.Object, java.lang.Object, org.apache.velocity.context.InternalContextAdapter)`

### perform

public abstract Number perform(Number left, Number right, InternalContextAdapter context)
Performs the math operation represented by this node.

Parameters:
  `left` -
  `right` -
  `context` -
Returns:
  computed value
See Also:
  - `ASTAddNode.perform(Number, Number, InternalContextAdapter)`