You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by di...@apache.org on 2006/03/21 08:10:36 UTC
svn commit: r387445 -
/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTBitwiseAndNode.java
Author: dion
Date: Mon Mar 20 23:10:33 2006
New Revision: 387445
URL: http://svn.apache.org/viewcvs?rev=387445&view=rev
Log:
Basic Implementation of bitwise and
Modified:
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTBitwiseAndNode.java
Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTBitwiseAndNode.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTBitwiseAndNode.java?rev=387445&r1=387444&r2=387445&view=diff
==============================================================================
--- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTBitwiseAndNode.java (original)
+++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTBitwiseAndNode.java Mon Mar 20 23:10:33 2006
@@ -2,6 +2,16 @@
package org.apache.commons.jexl.parser;
+import org.apache.commons.jexl.JexlContext;
+import org.apache.commons.jexl.util.Coercion;
+
+/**
+ * Bitwise And. Syntax:
+ * a & b
+ * Result is a Long
+ * @author Dion Gillard
+ * @since 1.0.1
+ */
public class ASTBitwiseAndNode extends SimpleNode {
public ASTBitwiseAndNode(int id) {
super(id);
@@ -15,5 +25,18 @@
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
+ }
+
+ /**
+ * @return a {@link Long} which is the bitwise and of the two operands.
+ */
+ public Object value(JexlContext context) throws Exception
+ {
+ Object left = ((SimpleNode) jjtGetChild(0)).value(context);
+ Object right = ((SimpleNode) jjtGetChild(1)).value(context);
+
+ Long l = left == null ? new Long(0) : Coercion.coerceLong(left);
+ Long r = right == null ? new Long(0) : Coercion.coerceLong(right);
+ return new Long(l.longValue() & r.longValue());
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org