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