001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * 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, 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 */ 017package org.apache.activemq.filter; 018 019 020 021/** 022 * An expression which performs an operation on two expression values. 023 * 024 * 025 */ 026public abstract 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 public abstract 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}