KickJava   Java API By Example, From Geeks To Geeks.

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


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.Map JavaDoc;
26
27 import org.xquark.extractor.common.SqlWrapperException;
28 import org.xquark.extractor.sql.SqlExpression;
29
30 public final class FunAggregate extends UnaryOperator
31 {
32
33     private static final String JavaDoc RCSRevision = "$Revision: 1.4 $";
34     private static final String JavaDoc RCSName = "$Name: $";
35
36     public final static int AVG = 0;
37     public final static int COUNT = 1;
38     public final static int MAX = 2;
39     public final static int MIN = 3;
40     public final static int SUM = 4;
41
42     public final static String JavaDoc[] AGGREGATE_FUNCTIONS = {
43                     "AVG",
44                     "COUNT",
45                     "MAX",
46                     "MIN",
47                     "SUM"
48                     };
49
50     private boolean _distinct;
51     private int _operator ;
52
53     /**
54      * @param operand
55      * @param distinct
56      * @roseuid 3AB864A901C7
57      */

58     public FunAggregate( int operator ,Expression operand, boolean distinct)
59     {
60
61         super ( operand );
62         setDistinct (distinct );
63         setOperator (operator) ;
64     }
65
66     synchronized Object JavaDoc clone(Map JavaDoc clonedExprs) throws CloneNotSupportedException JavaDoc
67     {
68         //Trace.enter(this, "clone(Map clonedExprs)");
69
FunAggregate retVal = (FunAggregate)super.clone(clonedExprs);
70         clonedExprs.put(this, retVal);
71         //Trace.exit(this, "clone(Map clonedExprs)");
72
return retVal;
73     }
74
75     /**
76      * @return boolean
77      * @roseuid 3AB87D14027A
78      */

79     public boolean getDistinct()
80     {
81         return _distinct ;
82     }
83
84     /**
85      * @param distinct
86      * @roseuid 3B288B1300CD
87      */

88     public void setDistinct(boolean distinct)
89     {
90         _distinct = distinct ;
91     }
92     public void setOperator ( int operator )
93     {
94         _operator = operator ;
95     }
96
97     public int getOperator ()
98     {
99         return _operator ;
100     }
101
102
103     public boolean replaceChild(Expression oldChild, Expression newChild)
104     {
105         //Trace.enter(this, "replaceChild(Expression oldChild, Expression newChild)");
106
boolean retVal = false;
107
108         if (getOperand().equals(oldChild)) {
109             setOperand(newChild);
110             retVal = true;
111         }
112
113         //Trace.exit(this, "replaceChild(Expression oldChild, Expression newChild)");
114
return retVal;
115     }
116
117     public SqlExpression accept (GenSqlVisitor visitor) throws SqlWrapperException
118     {
119         return visitor.visit(this);
120     }
121
122     public void accept (AlgebraVisitor visitor) throws SqlWrapperException
123     {
124         visitor.visit(this);
125     }
126
127     /**
128      * @see Expression#deepEquals(Object)
129      */

130     public boolean deepEquals(Object JavaDoc o)
131     {
132         if (o instanceof FunAggregate)
133         {
134             FunAggregate cast = (FunAggregate)o;
135             return super.deepEquals(o) && _distinct == cast.getDistinct()
136                         && _operator == cast.getOperator();
137         }
138         return false;
139     }
140 }
141
Popular Tags