activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r1421937 - in /activemq/activemq-apollo/trunk: apollo-selector/src/main/java/org/apache/activemq/apollo/filter/ArithmeticExpression.java apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompParallelTest.scala
Date Fri, 14 Dec 2012 15:35:22 GMT
Author: chirino
Date: Fri Dec 14 15:35:20 2012
New Revision: 1421937

URL: http://svn.apache.org/viewvc?rev=1421937&view=rev
Log:
Fixing invalid selector test.  Also make it possible to do math arithmetic against string
properties.

Modified:
    activemq/activemq-apollo/trunk/apollo-selector/src/main/java/org/apache/activemq/apollo/filter/ArithmeticExpression.java
    activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompParallelTest.scala

Modified: activemq/activemq-apollo/trunk/apollo-selector/src/main/java/org/apache/activemq/apollo/filter/ArithmeticExpression.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-selector/src/main/java/org/apache/activemq/apollo/filter/ArithmeticExpression.java?rev=1421937&r1=1421936&r2=1421937&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-selector/src/main/java/org/apache/activemq/apollo/filter/ArithmeticExpression.java
(original)
+++ activemq/activemq-apollo/trunk/apollo-selector/src/main/java/org/apache/activemq/apollo/filter/ArithmeticExpression.java
Fri Dec 14 15:35:20 2012
@@ -27,6 +27,7 @@ public abstract class ArithmeticExpressi
     protected static final int INTEGER = 1;
     protected static final int LONG = 2;
     protected static final int DOUBLE = 3;
+    boolean convertStringExpressions = false;
 
     /**
      * @param left
@@ -34,6 +35,7 @@ public abstract class ArithmeticExpressi
      */
     public ArithmeticExpression(Expression left, Expression right) {
         super(left, right);
+        convertStringExpressions = ComparisonExpression.CONVERT_STRING_EXPRESSIONS.get()!=null;
     }
 
     public static Expression createPlus(Expression left, Expression right) {
@@ -43,10 +45,9 @@ public abstract class ArithmeticExpressi
                     String text = (String)lvalue;
                     String answer = text + rvalue;
                     return answer;
-                } else if (lvalue instanceof Number) {
-                    return plus((Number)lvalue, asNumber(rvalue));
+                } else {
+                    return plus(asNumber(lvalue), asNumber(rvalue));
                 }
-                throw new RuntimeException("Cannot call plus operation on: " + lvalue + "
and: " + rvalue);
             }
 
             public String getExpressionSymbol() {
@@ -58,10 +59,7 @@ public abstract class ArithmeticExpressi
     public static Expression createMinus(Expression left, Expression right) {
         return new ArithmeticExpression(left, right) {
             protected Object evaluate(Object lvalue, Object rvalue) {
-                if (lvalue instanceof Number) {
-                    return minus((Number)lvalue, asNumber(rvalue));
-                }
-                throw new RuntimeException("Cannot call minus operation on: " + lvalue +
" and: " + rvalue);
+                return minus(asNumber(lvalue), asNumber(rvalue));
             }
 
             public String getExpressionSymbol() {
@@ -74,10 +72,7 @@ public abstract class ArithmeticExpressi
         return new ArithmeticExpression(left, right) {
 
             protected Object evaluate(Object lvalue, Object rvalue) {
-                if (lvalue instanceof Number) {
-                    return multiply((Number)lvalue, asNumber(rvalue));
-                }
-                throw new RuntimeException("Cannot call multiply operation on: " + lvalue
+ " and: " + rvalue);
+                return multiply(asNumber(lvalue), asNumber(rvalue));
             }
 
             public String getExpressionSymbol() {
@@ -90,10 +85,7 @@ public abstract class ArithmeticExpressi
         return new ArithmeticExpression(left, right) {
 
             protected Object evaluate(Object lvalue, Object rvalue) {
-                if (lvalue instanceof Number) {
-                    return divide((Number)lvalue, asNumber(rvalue));
-                }
-                throw new RuntimeException("Cannot call divide operation on: " + lvalue +
" and: " + rvalue);
+                return divide(asNumber(lvalue), asNumber(rvalue));
             }
 
             public String getExpressionSymbol() {
@@ -106,10 +98,7 @@ public abstract class ArithmeticExpressi
         return new ArithmeticExpression(left, right) {
 
             protected Object evaluate(Object lvalue, Object rvalue) {
-                if (lvalue instanceof Number) {
-                    return mod((Number)lvalue, asNumber(rvalue));
-                }
-                throw new RuntimeException("Cannot call mod operation on: " + lvalue + "
and: " + rvalue);
+                return mod(asNumber(lvalue), asNumber(rvalue));
             }
 
             public String getExpressionSymbol() {
@@ -177,6 +166,18 @@ public abstract class ArithmeticExpressi
         if (value instanceof Number) {
             return (Number)value;
         } else {
+            if( convertStringExpressions && value instanceof String) {
+                String v = (String) value;
+                try {
+                    if( v.contains(".") ) {
+                        return new Double(v);
+                    } else {
+                        return new Long(v);
+                    }
+                } catch (NumberFormatException e) {
+                    throw new RuntimeException("Cannot convert value: " + value + " into
a number");
+                }
+            }
             throw new RuntimeException("Cannot convert value: " + value + " into a number");
         }
     }

Modified: activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompParallelTest.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompParallelTest.scala?rev=1421937&r1=1421936&r2=1421937&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompParallelTest.scala
(original)
+++ activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompParallelTest.scala
Fri Dec 14 15:35:20 2012
@@ -552,7 +552,7 @@ class StompParallelTest extends StompTes
     }
 
     test_selector("color = 'red'", List("color:blue", "not:set", "color:red"), List(3))
-    test_selector("hyphen-field = 'red'", List("hyphen-field:blue", "not:set", "hyphen-field:red"),
List(3))
+    test_selector("hyphen-5 = 5", List("hyphen:9", "not:set", "hyphen:10"), List(3))
     test_selector("age >= 21", List("age:3", "not:set", "age:21", "age:30"), List(3, 4))
 
   }



Mime
View raw message