KickJava   Java API By Example, From Geeks To Geeks.

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


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.xquark.extractor.common.SqlWrapperException;
28 import org.xquark.extractor.sql.SqlExpression;
29
30 public final class UnOpSort extends UnaryAlgebra
31 {
32     private static final String JavaDoc RCSRevision = "$Revision: 1.5 $";
33     private static final String JavaDoc RCSName = "$Name: $";
34
35
36     private List _sortSpecificationList;
37
38     public UnOpSort() {}
39
40     public UnOpSort(Expression operand, List sortSpecificationList)
41     {
42         super ( operand ) ;
43         setSortSpecificationList( sortSpecificationList) ;
44     }
45
46     synchronized Object JavaDoc clone(Map clonedExprs) throws CloneNotSupportedException JavaDoc
47     {
48         UnOpSort retVal = (UnOpSort)super.clone(clonedExprs);
49         retVal.setSortSpecificationList(AlgebraTools.clone(_sortSpecificationList, clonedExprs));
50
51         clonedExprs.put(this, retVal);
52         return retVal;
53     }
54
55     /**
56      * Access method for the _sortSpecificationList property.
57      *
58      * @return the current value of the _sortSpecificationList property
59      */

60     public List getSortSpecificationList()
61     {
62         return _sortSpecificationList ;
63     }
64
65     public List getParameterList()
66     {
67         return getSortSpecificationList();
68     }
69
70     /**
71      * Sets the value of the _sortSpecificationList property.
72      *
73      * @param aSortSpecificationList
74      * the new value of the _sortSpecificationList property
75      */

76     public void setSortSpecificationList(List sortSpecificationList) {
77         _sortSpecificationList = sortSpecificationList;
78         if (null != _sortSpecificationList) {
79             Iterator itr;
80             itr = _sortSpecificationList.iterator();
81             while (itr.hasNext()) {
82                 ((Expression) itr.next()).setFather(this);
83             }
84         }
85     }
86
87     public void appendSortSpecification (SortSpecification sortSpec)
88     {
89         if (null != sortSpec) {
90             if (null == _sortSpecificationList) {
91                 _sortSpecificationList = new ArrayList();
92             }
93             _sortSpecificationList.add(sortSpec);
94             sortSpec.setFather(this);
95         }
96     }
97
98     public void insertSortSpecification (SortSpecification sortSpec)
99     {
100         if (null != sortSpec) {
101             if (null == _sortSpecificationList) {
102                 _sortSpecificationList = new ArrayList();
103             }
104             _sortSpecificationList.add(0,sortSpec);
105             sortSpec.setFather(this);
106         }
107     }
108
109     public boolean replaceChild(Expression oldChild, Expression newChild)
110     {
111         boolean retVal = false;
112
113         List list = getSortSpecificationList();
114
115         Expression expr = null ;
116         for (int i = 0; i < list.size(); i++) {
117             expr = (Expression)list.get(i);
118             if (expr.equals(oldChild)) {
119                 list.set(i, newChild);
120                 newChild.setFather(this);
121                 retVal = true;
122                 break;
123             }
124         }
125
126         if (getOperand().equals(oldChild)) {
127             setOperand(newChild);
128             retVal = true;
129         }
130
131         return retVal;
132     }
133
134     public List getKeys() {
135         return ((Relation)getOperand()).getKeys();
136     }
137
138     public SqlExpression accept (GenSqlVisitor visitor) throws SqlWrapperException
139     {
140         return visitor.visit(this);
141     }
142
143     public void accept (AlgebraVisitor visitor) throws SqlWrapperException
144     {
145         visitor.visit(this);
146     }
147
148     /**
149      * @see Expression#deepEquals(Object)
150      */

151     public boolean deepEquals(Object JavaDoc o)
152     {
153         if (o instanceof UnOpSort)
154         {
155             UnOpSort cast = (UnOpSort)o;
156             boolean ret = super.deepEquals(o)
157                     && AlgebraTools.areExprListEquivalent(_sortSpecificationList, cast.getSortSpecificationList());
158         }
159         return false;
160     }
161 }
162
Popular Tags