1 /* 2 * Copyright 2015-2018 HuntLabs.cn 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 module hunt.sql.ast.expr.SQLGroupingSetExpr; 17 18 19 import hunt.sql.ast.SQLExpr; 20 import hunt.sql.ast.SQLExprImpl; 21 import hunt.sql.ast.SQLObject; 22 import hunt.sql.ast.statement.SQLExplainStatement; 23 import hunt.sql.visitor.SQLASTVisitor; 24 import hunt.collection; 25 26 public class SQLGroupingSetExpr : SQLExprImpl { 27 28 private List!SQLExpr parameters; 29 30 this() 31 { 32 parameters = new ArrayList!SQLExpr(); 33 } 34 35 override public SQLGroupingSetExpr clone() { 36 SQLGroupingSetExpr x = new SQLGroupingSetExpr(); 37 foreach (SQLExpr p ; parameters) { 38 SQLExpr p2 = p.clone(); 39 p2.setParent(x); 40 x.parameters.add(p2); 41 } 42 return x; 43 } 44 45 public List!SQLExpr getParameters() { 46 return parameters; 47 } 48 49 public void addParameter(SQLExpr parameter) { 50 if (parameter !is null) { 51 parameter.setParent(this); 52 } 53 this.parameters.add(parameter); 54 } 55 56 override protected void accept0(SQLASTVisitor visitor) { 57 if (visitor.visit(this)) { 58 acceptChild!SQLExpr(visitor, parameters); 59 } 60 visitor.endVisit(this); 61 } 62 63 override 64 public List!SQLObject getChildren() { 65 return cast(List!SQLObject)this.parameters; 66 } 67 68 override 69 public size_t toHash() @trusted nothrow { 70 int prime = 31; 71 size_t result = 1; 72 result = prime * result + ((parameters is null) ? 0 : (cast(Object)parameters).toHash()); 73 return result; 74 } 75 76 override 77 public bool opEquals(Object obj) { 78 if (this is obj) { 79 return true; 80 } 81 if (obj is null) { 82 return false; 83 } 84 if (!(cast(SQLGroupingSetExpr)obj !is null)) { 85 return false; 86 } 87 SQLGroupingSetExpr other = cast(SQLGroupingSetExpr) obj; 88 if (parameters is null) { 89 if (other.parameters !is null) { 90 return false; 91 } 92 } else if (!(cast(Object)(parameters)).opEquals(cast(Object)(other.parameters))) { 93 return false; 94 } 95 return true; 96 } 97 98 }