camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/8] camel git commit: CAMEL-9838 - Add starts with operator to simple language
Date Sat, 09 Apr 2016 07:23:22 GMT
CAMEL-9838 - Add starts with operator to simple language


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a23f82fc
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a23f82fc
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a23f82fc

Branch: refs/heads/camel-2.17.x
Commit: a23f82fc58f21b93a2fdca928944bbe2308cb860
Parents: 10d69f2
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sat Apr 9 08:49:22 2016 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sat Apr 9 08:49:45 2016 +0200

----------------------------------------------------------------------
 .../apache/camel/language/simple/SimpleTokenizer.java |  1 +
 .../camel/language/simple/ast/BinaryExpression.java   |  2 ++
 .../language/simple/types/BinaryOperatorType.java     |  8 +++++++-
 .../camel/language/simple/SimpleOperatorTest.java     | 14 ++++++++++++--
 4 files changed, 22 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/a23f82fc/camel-core/src/main/java/org/apache/camel/language/simple/SimpleTokenizer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/language/simple/SimpleTokenizer.java
b/camel-core/src/main/java/org/apache/camel/language/simple/SimpleTokenizer.java
index 8956fad..37f83f4 100644
--- a/camel-core/src/main/java/org/apache/camel/language/simple/SimpleTokenizer.java
+++ b/camel-core/src/main/java/org/apache/camel/language/simple/SimpleTokenizer.java
@@ -66,6 +66,7 @@ public final class SimpleTokenizer {
         KNOWN_TOKENS.add(new SimpleTokenType(TokenType.binaryOperator, "in"));
         KNOWN_TOKENS.add(new SimpleTokenType(TokenType.binaryOperator, "range"));
         KNOWN_TOKENS.add(new SimpleTokenType(TokenType.binaryOperator, "not range"));
+        KNOWN_TOKENS.add(new SimpleTokenType(TokenType.binaryOperator, "starts with"));
         KNOWN_TOKENS.add(new SimpleTokenType(TokenType.binaryOperator, "ends with"));
 
         // unary operators

http://git-wip-us.apache.org/repos/asf/camel/blob/a23f82fc/camel-core/src/main/java/org/apache/camel/language/simple/ast/BinaryExpression.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/language/simple/ast/BinaryExpression.java
b/camel-core/src/main/java/org/apache/camel/language/simple/ast/BinaryExpression.java
index 3c76c31..4b6e821 100644
--- a/camel-core/src/main/java/org/apache/camel/language/simple/ast/BinaryExpression.java
+++ b/camel-core/src/main/java/org/apache/camel/language/simple/ast/BinaryExpression.java
@@ -104,6 +104,8 @@ public class BinaryExpression extends BaseSimpleNode {
             return createInExpression(leftExp, rightExp);
         } else if (operator == BinaryOperatorType.RANGE || operator == BinaryOperatorType.NOT_RANGE)
{
             return createRangeExpression(expression, leftExp, rightExp);
+        } else if (operator == BinaryOperatorType.STARTS_WITH) {
+            return createExpression(leftExp, rightExp, PredicateBuilder.startsWith(leftExp,
rightExp));
         } else if (operator == BinaryOperatorType.ENDS_WITH) {
             return createExpression(leftExp, rightExp, PredicateBuilder.endsWith(leftExp,
rightExp));
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/a23f82fc/camel-core/src/main/java/org/apache/camel/language/simple/types/BinaryOperatorType.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/language/simple/types/BinaryOperatorType.java
b/camel-core/src/main/java/org/apache/camel/language/simple/types/BinaryOperatorType.java
index 02e7665..5a7751b 100644
--- a/camel-core/src/main/java/org/apache/camel/language/simple/types/BinaryOperatorType.java
+++ b/camel-core/src/main/java/org/apache/camel/language/simple/types/BinaryOperatorType.java
@@ -22,7 +22,7 @@ package org.apache.camel.language.simple.types;
 public enum BinaryOperatorType {
 
     EQ, EQ_IGNORE, GT, GTE, LT, LTE, NOT_EQ, CONTAINS, NOT_CONTAINS, REGEX, NOT_REGEX,
-    IN, NOT_IN, IS, NOT_IS, RANGE, NOT_RANGE, ENDS_WITH;
+    IN, NOT_IN, IS, NOT_IS, RANGE, NOT_RANGE, STARTS_WITH, ENDS_WITH;
 
     public static BinaryOperatorType asOperator(String text) {
         if ("==".equals(text)) {
@@ -59,6 +59,8 @@ public enum BinaryOperatorType {
             return RANGE;
         } else if ("not range".equals(text)) {
             return NOT_RANGE;
+        } else if ("starts with".equals(text)) {
+            return STARTS_WITH;
         } else if ("ends with".equals(text)) {
             return ENDS_WITH;
         }
@@ -100,6 +102,8 @@ public enum BinaryOperatorType {
             return "range";
         } else if (operator == NOT_RANGE) {
             return "not range";
+        } else if (operator == STARTS_WITH) {
+            return "starts with";
         } else if (operator == ENDS_WITH) {
             return "ends with";
         }
@@ -186,6 +190,8 @@ public enum BinaryOperatorType {
             return new ParameterType[]{ParameterType.LiteralWithFunction, ParameterType.Function};
         } else if (operator == NOT_RANGE) {
             return new ParameterType[]{ParameterType.LiteralWithFunction, ParameterType.Function};
+        } else if (operator == STARTS_WITH) {
+            return null;
         } else if (operator == ENDS_WITH) {
             return null;
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/a23f82fc/camel-core/src/test/java/org/apache/camel/language/simple/SimpleOperatorTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/language/simple/SimpleOperatorTest.java
b/camel-core/src/test/java/org/apache/camel/language/simple/SimpleOperatorTest.java
index dd315bf..e40154f 100644
--- a/camel-core/src/test/java/org/apache/camel/language/simple/SimpleOperatorTest.java
+++ b/camel-core/src/test/java/org/apache/camel/language/simple/SimpleOperatorTest.java
@@ -500,16 +500,26 @@ public class SimpleOperatorTest extends LanguageTestSupport {
         assertPredicate("${in.header.bar}-- == 124", false);
     }
 
+    public void testStartsWith() throws Exception {
+        exchange.getIn().setBody("Hello there");
+        assertPredicate("${in.body} starts with 'Hello'", true);
+        assertPredicate("${in.body} starts with 'H'", true);
+        assertPredicate("${in.body} starts with 'Hello there'", true);
+        assertPredicate("${in.body} starts with 'Hello ther'", true);
+        assertPredicate("${in.body} starts with 'ello there'", false);
+        assertPredicate("${in.body} starts with 'Hi'", false);
+    }
+    
     public void testEndsWith() throws Exception {
         exchange.getIn().setBody("Hello there");
         assertPredicate("${in.body} ends with 'there'", true);
         assertPredicate("${in.body} ends with 're'", true);
         assertPredicate("${in.body} ends with ' there'", true);
         assertPredicate("${in.body} ends with 'Hello there'", true);
-        assertPredicate("${in.body} ends with 'Hello ther'", false);        
+        assertPredicate("${in.body} ends with 'Hello ther'", false);
         assertPredicate("${in.body} ends with 'Hi'", false);
     }
-    
+
     protected String getLanguageName() {
         return "simple";
     }


Mime
View raw message