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.SQLArrayExpr; 17 18 19 20 import hunt.sql.ast.SQLExpr; 21 import hunt.sql.ast.SQLExprImpl; 22 import hunt.sql.ast.SQLObject; 23 import hunt.sql.visitor.SQLASTVisitor; 24 import hunt.collection; 25 26 public class SQLArrayExpr : SQLExprImpl { 27 28 private SQLExpr expr; 29 30 private List!SQLExpr values; 31 32 this() 33 { 34 values = new ArrayList!SQLExpr(); 35 } 36 37 override public SQLArrayExpr clone() { 38 SQLArrayExpr x = new SQLArrayExpr(); 39 if (expr !is null) { 40 x.setExpr(expr.clone()); 41 } 42 foreach (SQLExpr value ; values) { 43 SQLExpr value2 = value.clone(); 44 value2.setParent(x); 45 x.values.add(value2); 46 } 47 return x; 48 } 49 50 public SQLExpr getExpr() { 51 return expr; 52 } 53 54 public void setExpr(SQLExpr expr) { 55 this.expr = expr; 56 } 57 58 public List!SQLExpr getValues() { 59 return values; 60 } 61 62 public void setValues(List!SQLExpr values) { 63 this.values = values; 64 } 65 66 override protected void accept0(SQLASTVisitor visitor) { 67 if (visitor.visit(this)) { 68 acceptChild(visitor, expr); 69 acceptChild!SQLExpr(visitor, values); 70 } 71 visitor.endVisit(this); 72 } 73 74 override public List!SQLObject getChildren() { 75 List!SQLObject children = new ArrayList!SQLObject(); 76 children.add(this.expr); 77 children.addAll(cast(List!SQLObject)(this.values)); 78 return children; 79 } 80 81 override 82 public size_t toHash() @trusted nothrow { 83 int prime = 31; 84 size_t result = 1; 85 result = prime * result + ((expr is null) ? 0 : (cast(Object)expr).toHash()); 86 result = prime * result + ((values is null) ? 0 : (cast(Object)values).toHash()); 87 return result; 88 } 89 90 override 91 public bool opEquals(Object obj) { 92 if (this is obj) return true; 93 if (obj is null) return false; 94 if (typeid(this) != typeid(obj)) return false; 95 SQLArrayExpr other = cast(SQLArrayExpr) obj; 96 if (expr is null) { 97 if (other.expr !is null) return false; 98 } else if (!(cast(Object)expr).opEquals(cast(Object)(other.expr))) return false; 99 if (values is null) { 100 if (other.values !is null) return false; 101 } else if (!(cast(Object)values).opEquals(cast(Object)(other.values))) return false; 102 return true; 103 } 104 105 106 107 }