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