1 module hunt.sql.ast.expr.SQLNotExpr;
2 import hunt.sql.ast.SQLExprImpl;
3 import hunt.sql.ast.SQLExpr;
4 import hunt.collection;
5 import hunt.sql.ast.SQLDataType;
6 import hunt.sql.visitor.SQLASTVisitor;
7 import hunt.sql.ast.SQLObject;
8 import hunt.sql.ast.expr.SQLBooleanExpr;
9 import hunt.util.StringBuilder;
10 
11 public  class SQLNotExpr : SQLExprImpl //, Serializable 
12 {
13     public SQLExpr            expr;
14 
15     public this(){
16 
17     }
18 
19     public this(SQLExpr expr){
20 
21         this.expr = expr;
22     }
23 
24     public SQLExpr getExpr() {
25         return this.expr;
26     }
27 
28     public void setExpr(SQLExpr expr) {
29         this.expr = expr;
30     }
31 
32     override public void output(StringBuilder buf) {
33         buf.append(" NOT ");
34         this.expr.output(buf);
35     }
36 
37     override  protected void accept0(SQLASTVisitor visitor) {
38         if (visitor.visit(this)) {
39             acceptChild(visitor, this.expr);
40         }
41 
42         visitor.endVisit(this);
43     }
44 
45    override
46     public List!SQLObject getChildren() {
47         return Collections.singletonList!SQLObject(this.expr);
48     }
49 
50    override
51     public size_t toHash() @trusted nothrow {
52          int prime = 31;
53         size_t result = 1;
54         result = prime * result + ((expr is null) ? 0 : (cast(Object)expr).toHash());
55         return result;
56     }
57 
58    override
59     public bool opEquals(Object obj) {
60         if (this is obj) {
61             return true;
62         }
63         if (obj is null) {
64             return false;
65         }
66         if (typeid(this) != typeid(obj)) {
67             return false;
68         }
69         SQLNotExpr other = cast(SQLNotExpr) obj;
70         if (expr is null) {
71             if (other.expr !is null) {
72                 return false;
73             }
74         } else if (!(cast(Object)(expr)).opEquals(cast(Object)(other.expr))) {
75             return false;
76         }
77         return true;
78     }
79 
80     override public SQLNotExpr clone() {
81         SQLNotExpr x = new SQLNotExpr();
82         if (expr !is null) {
83             x.setExpr(expr.clone());
84         }
85         return x;
86     }
87 
88     override public SQLDataType computeDataType() {
89         return SQLBooleanExpr.DEFAULT_DATA_TYPE;
90     }
91 }