001/** 002 * GRANITE DATA SERVICES 003 * Copyright (C) 2006-2013 GRANITE DATA SERVICES S.A.S. 004 * 005 * This file is part of the Granite Data Services Platform. 006 * 007 * Granite Data Services is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * Granite Data Services is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 015 * General Public License for more details. 016 * 017 * You should have received a copy of the GNU Lesser General Public 018 * License along with this library; if not, write to the Free Software 019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 020 * USA, or see <http://www.gnu.org/licenses/>. 021 */ 022package org.granite.gravity.selector; 023 024/** 025 * An expression which performs an operation on two expression values. 026 * 027 * @version $Revision: 1.2 $ 028 */ 029abstract public class BinaryExpression implements Expression { 030 protected Expression left; 031 protected Expression right; 032 033 public BinaryExpression(Expression left, Expression right) { 034 this.left = left; 035 this.right = right; 036 } 037 038 public Expression getLeft() { 039 return left; 040 } 041 042 public Expression getRight() { 043 return right; 044 } 045 046 047 /** 048 * @see java.lang.Object#toString() 049 */ 050 @Override 051 public String toString() { 052 return "(" + left.toString() + " " + getExpressionSymbol() + " " + right.toString() + ")"; 053 } 054 055 /** 056 * TODO: more efficient hashCode() 057 * 058 * @see java.lang.Object#hashCode() 059 */ 060 @Override 061 public int hashCode() { 062 return toString().hashCode(); 063 } 064 065 /** 066 * TODO: more efficient hashCode() 067 * 068 * @see java.lang.Object#equals(java.lang.Object) 069 */ 070 @Override 071 public boolean equals(Object o) { 072 073 if (o == null || !this.getClass().equals(o.getClass())) { 074 return false; 075 } 076 return toString().equals(o.toString()); 077 078 } 079 080 /** 081 * Returns the symbol that represents this binary expression. For example, addition is 082 * represented by "+" 083 * 084 * @return the symbol 085 */ 086 abstract public String getExpressionSymbol(); 087 088 /** 089 * @param expression 090 */ 091 public void setRight(Expression expression) { 092 right = expression; 093 } 094 095 /** 096 * @param expression 097 */ 098 public void setLeft(Expression expression) { 099 left = expression; 100 } 101 102}