KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > filter > BinaryExpression


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.filter;
19
20
21
22 /**
23  * An expression which performs an operation on two expression values.
24  *
25  * @version $Revision: 1.2 $
26  */

27 abstract public class BinaryExpression implements Expression {
28     protected Expression left;
29     protected Expression right;
30
31     public BinaryExpression(Expression left, Expression right) {
32         this.left = left;
33         this.right = right;
34     }
35
36     public Expression getLeft() {
37         return left;
38     }
39
40     public Expression getRight() {
41         return right;
42     }
43
44
45     /**
46      * @see java.lang.Object#toString()
47      */

48     public String JavaDoc toString() {
49         return "(" + left.toString() + " " + getExpressionSymbol() + " " + right.toString() + ")";
50     }
51
52     /**
53      * TODO: more efficient hashCode()
54      *
55      * @see java.lang.Object#hashCode()
56      */

57     public int hashCode() {
58         return toString().hashCode();
59     }
60
61     /**
62      * TODO: more efficient hashCode()
63      *
64      * @see java.lang.Object#equals(java.lang.Object)
65      */

66     public boolean equals(Object JavaDoc o) {
67
68         if (o == null || !this.getClass().equals(o.getClass())) {
69             return false;
70         }
71         return toString().equals(o.toString());
72
73     }
74
75     /**
76      * Returns the symbol that represents this binary expression. For example, addition is
77      * represented by "+"
78      *
79      * @return
80      */

81     abstract public String JavaDoc getExpressionSymbol();
82
83     /**
84      * @param expression
85      */

86     public void setRight(Expression expression) {
87         right = expression;
88     }
89
90     /**
91      * @param expression
92      */

93     public void setLeft(Expression expression) {
94         left = expression;
95     }
96     
97 }
98
Popular Tags