KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > extractor > algebra > BinaryOperator


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

22
23 package org.xquark.extractor.algebra;
24
25 import java.util.*;
26
27 import org.apache.commons.collections.set.ListOrderedSet;
28
29 public abstract class BinaryOperator extends Expression
30 {
31
32     private static final String JavaDoc RCSRevision = "$Revision: 1.5 $";
33     private static final String JavaDoc RCSName = "$Name: $";
34
35     protected Expression _rightOperand;
36     protected Expression _leftOperand;
37     protected Set _visibleTableInstance = null;
38
39     public BinaryOperator() {}
40
41     public BinaryOperator(Expression leftOperand, Expression rightOperand)
42     {
43         setLeftOperand ( leftOperand ) ;
44         setRightOperand ( rightOperand ) ;
45     }
46
47     synchronized Object JavaDoc clone(Map clonedExprs) throws CloneNotSupportedException JavaDoc
48     {
49         BinaryOperator retVal = (BinaryOperator)super.clone(clonedExprs);
50         retVal.setLeftOperand((getLeftOperand() == null) ? null : (Expression)getLeftOperand().clone (clonedExprs));
51         retVal.setRightOperand((getRightOperand() == null) ? null : (Expression) getRightOperand().clone (clonedExprs));
52
53         clonedExprs.put(this, retVal);
54         return retVal;
55
56     }
57
58     public Expression getLeftOperand()
59     {
60         return _leftOperand ;
61     }
62
63     public Expression getRightOperand()
64     {
65         return _rightOperand ;
66     }
67
68     public void setLeftOperand(Expression leftOperand)
69     {
70         _leftOperand = leftOperand ;
71         _leftOperand.setFather ( this ) ;
72     }
73
74     public void setRightOperand(Expression rightOperand)
75     {
76         _rightOperand = rightOperand ;
77         _rightOperand.setFather ( this ) ;
78     }
79
80     public List getOperands()
81     {
82         ArrayList retVal = new ArrayList () ;
83         retVal.add( _leftOperand ) ;
84         retVal.add( _rightOperand );
85         return retVal ;
86     }
87
88     public Set visibleTableInstances() {
89         if (null == _visibleTableInstance)
90             _visibleTableInstance = ListOrderedSet.decorate(new HashSet());
91         
92         _visibleTableInstance.clear();
93         _visibleTableInstance.addAll( ((Relation)getLeftOperand()).providedTableInstances());
94         _visibleTableInstance.addAll( ((Relation)getRightOperand()).providedTableInstances());
95         return _visibleTableInstance;
96     }
97
98     /**
99      * @see Expression#deepEquals(Object)
100      */

101     public boolean deepEquals(Object JavaDoc o)
102     {
103         if (o instanceof BinaryOperator)
104         {
105             BinaryOperator cast = (BinaryOperator)o;
106             return (_leftOperand.deepEquals(cast.getLeftOperand())
107                         && _rightOperand.deepEquals(cast.getRightOperand()))
108                     ||
109                     (_leftOperand.deepEquals(cast.getRightOperand())
110                         && _rightOperand.deepEquals(cast.getLeftOperand()));
111         }
112         return false;
113     }
114 }
115
Popular Tags