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