dizpers

Extended Interpreter class

Nov 30th, 2011
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 KB | None | 0 0
  1. package ru.dizpers.core;
  2.  
  3. import org.apache.commons.jexl2.JexlContext;
  4.  
  5. import org.apache.commons.jexl2.JexlContext;
  6. import org.apache.commons.jexl2.JexlEngine;
  7. import org.apache.commons.jexl2.JexlException;
  8. import org.apache.commons.jexl2.parser.ASTBitwiseXorNode;
  9.  
  10. public class Interpreter extends org.apache.commons.jexl2.Interpreter {
  11.     public Interpreter(JexlEngine jexl, JexlContext aContext) {
  12.         super(jexl, aContext);
  13.     }
  14.    
  15.     @Override
  16.     public Object visit(ASTBitwiseXorNode node, Object data) {
  17.         Object left = node.jjtGetChild(0).jjtAccept(this, data);
  18.         Object right = node.jjtGetChild(1).jjtAccept(this, data);
  19.         int n = 0;
  20.         // coerce these two values longs and 'xor'.
  21.         try {
  22.             long l = arithmetic.toLong(left);
  23.             n = 1;
  24.             long r = arithmetic.toLong(right);
  25.             return Double.valueOf(Math.pow(l, r));
  26.         } catch (RuntimeException xrt) {
  27.             throw new JexlException(node.jjtGetChild(n), "long coercion error", xrt);
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment