001 /* Licensed to the Apache Software Foundation (ASF) under one
002 * or more contributor license agreements. See the NOTICE file
003 * distributed with this work for additional information
004 * regarding copyright ownership. The ASF licenses this file
005 * to you under the Apache License, Version 2.0 (the
006 * "License"); you may not use this file except in compliance
007 * with the License. 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,
012 * software distributed under the License is distributed on an
013 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
014 * KIND, either express or implied. See the License for the
015 * specific language governing permissions and limitations
016 * under the License.
017 */
018 package org.apache.qpid.filter;
019
020 /**
021 * An expression which performs an operation on two expression values.
022 */
023 public abstract class BinaryExpression implements Expression
024 {
025 protected Expression left;
026 protected Expression right;
027
028 public BinaryExpression(Expression left, Expression right)
029 {
030 this.left = left;
031 this.right = right;
032 }
033
034 public Expression getLeft()
035 {
036 return left;
037 }
038
039 public Expression getRight()
040 {
041 return right;
042 }
043
044 /**
045 * @see Object#toString()
046 */
047 public String toString()
048 {
049 return "(" + left.toString() + " " + getExpressionSymbol() + " " + right.toString() + ")";
050 }
051
052 /**
053 * TODO: more efficient hashCode()
054 *
055 * @see Object#hashCode()
056 */
057 public int hashCode()
058 {
059 return toString().hashCode();
060 }
061
062 /**
063 * TODO: more efficient hashCode()
064 *
065 * @see Object#equals(Object)
066 */
067 public boolean equals(Object o)
068 {
069
070 if ((o == null) || !this.getClass().equals(o.getClass()))
071 {
072 return false;
073 }
074
075 return toString().equals(o.toString());
076
077 }
078
079 /**
080 * Returns the symbol that represents this binary expression. For example, addition is
081 * represented by "+"
082 *
083 * @return
084 */
085 public abstract String getExpressionSymbol();
086
087 /**
088 * @param expression
089 */
090 public void setRight(Expression expression)
091 {
092 right = expression;
093 }
094
095 /**
096 * @param expression
097 */
098 public void setLeft(Expression expression)
099 {
100 left = expression;
101 }
102
103 }
|