001 /**
002 *
003 * Copyright 2004 Hiram Chirino
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 *
017 **/
018 package org.activemq.filter;
019
020
021 /**
022 * An expression which performs an operation on two expression values.
023 *
024 * @version $Revision: 1.1.1.1 $
025 */
026 abstract public class BinaryExpression implements Expression {
027 protected Expression left;
028 protected Expression right;
029
030 public BinaryExpression(Expression left, Expression right) {
031 this.left = left;
032 this.right = right;
033 }
034
035 public Expression getLeft() {
036 return left;
037 }
038
039 public Expression getRight() {
040 return right;
041 }
042
043
044 /**
045 * @see java.lang.Object#toString()
046 */
047 public String toString() {
048 return "(" + left.toString() + " " + getExpressionSymbol() + " " + right.toString() + ")";
049 }
050
051 /**
052 * TODO: more efficient hashCode()
053 *
054 * @see java.lang.Object#hashCode()
055 */
056 public int hashCode() {
057 return toString().hashCode();
058 }
059
060 /**
061 * TODO: more efficient hashCode()
062 *
063 * @see java.lang.Object#equals(java.lang.Object)
064 */
065 public boolean equals(Object o) {
066
067 if (o == null || !this.getClass().equals(o.getClass())) {
068 return false;
069 }
070 return toString().equals(o.toString());
071
072 }
073
074 /**
075 * Returns the symbol that represents this binary expression. For example, addition is
076 * represented by "+"
077 *
078 * @return
079 */
080 abstract public String getExpressionSymbol();
081
082 /**
083 * @param expression
084 */
085 public void setRight(Expression expression) {
086 right = expression;
087 }
088
089 /**
090 * @param expression
091 */
092 public void setLeft(Expression expression) {
093 left = expression;
094 }
095
096 }