activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r520498 - in /activemq/camel/trunk/camel-core/src/main/java/org/apache/camel: ./ builder/
Date Tue, 20 Mar 2007 18:01:49 GMT
Author: chirino
Date: Tue Mar 20 11:01:41 2007
New Revision: 520498

URL: http://svn.apache.org/viewvc?view=rev&rev=520498
Log:
Moved Expression and Predicates uner builder 

Added:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/PredicateBuilder.java
Removed:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Expressions.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Predicates.java
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/BuilderSupport.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/FilterBuilder.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ValueBuilder.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/BuilderSupport.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/BuilderSupport.java?view=diff&rev=520498&r1=520497&r2=520498
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/BuilderSupport.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/BuilderSupport.java
Tue Mar 20 11:01:41 2007
@@ -17,7 +17,6 @@
 package org.apache.camel.builder;
 
 import org.apache.camel.Expression;
-import org.apache.camel.Expressions;
 import org.apache.camel.Exchange;
 
 /**
@@ -31,6 +30,6 @@
      * Returns a predicate and value builder for headers on an exchange
      */
     public ValueBuilder<E> header(String name) {
-        Expression<E> expression = Expressions.headerExpression(name);
+        Expression<E> expression = ExpressionBuilder.headerExpression(name);
         return new ValueBuilder<E>(expression);
     }}

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java?view=auto&rev=520498
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
(added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
Tue Mar 20 11:01:41 2007
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.builder;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Expression;
+
+/**
+ * @version $Revision: $
+ */
+public class ExpressionBuilder {
+
+    /**
+     * Returns an expression for the header value with the given name
+     *
+     * @param headerName the name of the header the expression will return
+     * @return an expression object which will return the header value
+     */
+    public static <E extends Exchange> Expression<E> headerExpression(final String
headerName) {
+        return new Expression<E>() {
+            public Object evaluate(E exchange) {
+                Object header = exchange.getIn().getHeaders().getHeader(headerName);
+                if (header == null) {
+                    // lets try the exchange header
+                    header = exchange.getHeaders().getHeader(headerName);
+                }
+                return header;
+            }
+
+            @Override
+            public String toString() {
+                return "header(" + headerName + ")";
+            }
+        };
+    }
+    /**
+     * Returns an expression for the contant value
+     *
+     * @param value the value the expression will return
+     * @return an expression object which will return the constant value
+     */
+    public static <E extends Exchange> Expression<E> constantExpression(final
Object value) {
+        return new Expression<E>() {
+            public Object evaluate(E exchange) {
+                return value;
+            }
+
+            @Override
+            public String toString() {
+                return "" + value;
+            }
+        };
+    }
+}

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/FilterBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/FilterBuilder.java?view=diff&rev=520498&r1=520497&r2=520498
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/FilterBuilder.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/FilterBuilder.java
Tue Mar 20 11:01:41 2007
@@ -19,7 +19,6 @@
 import org.apache.camel.processor.FilterProcessor;
 import org.apache.camel.Predicate;
 import org.apache.camel.Exchange;
-import org.apache.camel.Predicates;
 import org.apache.camel.Processor;
 
 /**
@@ -37,7 +36,7 @@
      * Adds another predicate using a logican AND
      */
     public FilterBuilder<E> and(Predicate<E> predicate) {
-        this.predicate = Predicates.and(this.predicate, predicate);
+        this.predicate = PredicateBuilder.and(this.predicate, predicate);
         return this;
     }
 
@@ -45,7 +44,7 @@
      * Adds another predicate using a logican OR
      */
     public FilterBuilder<E> or(Predicate<E> predicate) {
-        this.predicate = Predicates.or(this.predicate, predicate);
+        this.predicate = PredicateBuilder.or(this.predicate, predicate);
         return this;
     }
 

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/PredicateBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/PredicateBuilder.java?view=auto&rev=520498
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/PredicateBuilder.java
(added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/PredicateBuilder.java
Tue Mar 20 11:01:41 2007
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.builder;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Expression;
+import org.apache.camel.Predicate;
+import org.apache.camel.util.ObjectHelper;
+import static org.apache.camel.util.ObjectHelper.notNull;
+
+/**
+ * A helper class for working with predicates
+ *
+ * @version $Revision: 520261 $
+ */
+public class PredicateBuilder {
+    /**
+     * A helper method to combine multiple predicates by a logical AND
+     */
+    public static <E extends Exchange> Predicate<E> and(final Predicate<E>
left, final Predicate<E> right) {
+        notNull(left, "left");
+        notNull(right, "right");
+        return new Predicate<E>() {
+            public boolean evaluate(E exchange) {
+                return left.evaluate(exchange) && right.evaluate(exchange);
+            }
+        };
+    }
+
+    /**
+     * A helper method to combine multiple predicates by a logical OR
+     */
+    public static <E extends Exchange> Predicate<E> or(final Predicate<E>
left, final Predicate<E> right) {
+        notNull(left, "left");
+        notNull(right, "right");
+        return new Predicate<E>() {
+            public boolean evaluate(E exchange) {
+                return left.evaluate(exchange) || right.evaluate(exchange);
+            }
+        };
+    }
+
+
+    public static <E extends Exchange> Predicate<E> isEqualTo(final Expression<E>
left, final Expression<E> right) {
+        notNull(left, "left");
+        notNull(right, "right");
+
+        return new Predicate<E>() {
+            public boolean evaluate(E exchange) {
+                Object value1 = left.evaluate(exchange);
+                Object value2 = right.evaluate(exchange);
+                return ObjectHelper.equals(value1, value2);
+            }
+        };
+    }
+
+    public static <E extends Exchange> Predicate<E> isNotEqualTo(final Expression<E>
left, final Expression<E> right) {
+        notNull(left, "left");
+        notNull(right, "right");
+
+        return new Predicate<E>() {
+            public boolean evaluate(E exchange) {
+                Object value1 = left.evaluate(exchange);
+                Object value2 = right.evaluate(exchange);
+                return !ObjectHelper.equals(value1, value2);
+            }
+        };
+    }
+
+    public static <E extends Exchange> Predicate<E> isLessThan(final Expression<E>
left, final Expression<E> right) {
+        notNull(left, "left");
+        notNull(right, "right");
+
+        return new Predicate<E>() {
+            public boolean evaluate(E exchange) {
+                Object value1 = left.evaluate(exchange);
+                Object value2 = right.evaluate(exchange);
+                return ObjectHelper.compare(value1, value2) < 0;
+            }
+        };
+    }
+
+    public static <E extends Exchange> Predicate<E> isLessThanOrEqualTo(final
Expression<E> left, final Expression<E> right) {
+        notNull(left, "left");
+        notNull(right, "right");
+
+        return new Predicate<E>() {
+            public boolean evaluate(E exchange) {
+                Object value1 = left.evaluate(exchange);
+                Object value2 = right.evaluate(exchange);
+                return ObjectHelper.compare(value1, value2) <= 0;
+            }
+        };
+    }
+
+    public static <E extends Exchange> Predicate<E> isGreaterThan(final Expression<E>
left, final Expression<E> right) {
+        notNull(left, "left");
+        notNull(right, "right");
+
+        return new Predicate<E>() {
+            public boolean evaluate(E exchange) {
+                Object value1 = left.evaluate(exchange);
+                Object value2 = right.evaluate(exchange);
+                return ObjectHelper.compare(value1, value2) > 0;
+            }
+        };
+    }
+
+    public static <E extends Exchange> Predicate<E> isGreaterThanOrEqualTo(final
Expression<E> left, final Expression<E> right) {
+        notNull(left, "left");
+        notNull(right, "right");
+
+        return new Predicate<E>() {
+            public boolean evaluate(E exchange) {
+                Object value1 = left.evaluate(exchange);
+                Object value2 = right.evaluate(exchange);
+                return ObjectHelper.compare(value1, value2) >= 0;
+            }
+        };
+    }
+}

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ValueBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ValueBuilder.java?view=diff&rev=520498&r1=520497&r2=520498
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ValueBuilder.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ValueBuilder.java
Tue Mar 20 11:01:41 2007
@@ -19,8 +19,6 @@
 import org.apache.camel.Exchange;
 import org.apache.camel.Expression;
 import org.apache.camel.Predicate;
-import org.apache.camel.Predicates;
-import org.apache.camel.Expressions;
 
 /**
  * A builder of expressions or predicates based on values.
@@ -35,33 +33,33 @@
     }
 
     public Predicate<E> isNotEqualTo(Object value) {
-        Expression<E> right = Expressions.constantExpression(value);
-        return Predicates.isNotEqualTo(expression, right);
+        Expression<E> right = ExpressionBuilder.constantExpression(value);
+        return PredicateBuilder.isNotEqualTo(expression, right);
     }
 
     public Predicate<E> isEqualTo(Object value) {
-        Expression<E> right = Expressions.constantExpression(value);
-        return Predicates.isEqualTo(expression, right);
+        Expression<E> right = ExpressionBuilder.constantExpression(value);
+        return PredicateBuilder.isEqualTo(expression, right);
     }
 
     public Predicate<E> isLessThan(Object value) {
-        Expression<E> right = Expressions.constantExpression(value);
-        return Predicates.isLessThan(expression, right);
+        Expression<E> right = ExpressionBuilder.constantExpression(value);
+        return PredicateBuilder.isLessThan(expression, right);
     }
 
     public Predicate<E> isLessThanOrEqualTo(Object value) {
-        Expression<E> right = Expressions.constantExpression(value);
-        return Predicates.isLessThanOrEqualTo(expression, right);
+        Expression<E> right = ExpressionBuilder.constantExpression(value);
+        return PredicateBuilder.isLessThanOrEqualTo(expression, right);
     }
 
     public Predicate<E> isGreaterThan(Object value) {
-        Expression<E> right = Expressions.constantExpression(value);
-        return Predicates.isGreaterThan(expression, right);
+        Expression<E> right = ExpressionBuilder.constantExpression(value);
+        return PredicateBuilder.isGreaterThan(expression, right);
     }
 
     public Predicate<E> isGreaterThanOrEqualTo(Object value) {
-        Expression<E> right = Expressions.constantExpression(value);
-        return Predicates.isGreaterThanOrEqualTo(expression, right);
+        Expression<E> right = ExpressionBuilder.constantExpression(value);
+        return PredicateBuilder.isGreaterThanOrEqualTo(expression, right);
     }
 
     public Expression<E> getExpression() {



Mime
View raw message