1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.modeshape.graph.query.model;
25
26 import net.jcip.annotations.Immutable;
27 import org.modeshape.common.util.CheckArg;
28 import org.modeshape.common.util.HashCode;
29
30
31
32
33 @Immutable
34 public class Comparison implements Constraint {
35
36 private static final long serialVersionUID = 1L;
37
38 private final DynamicOperand operand1;
39 private final StaticOperand operand2;
40 private final Operator operator;
41 private final int hc;
42
43 public Comparison( DynamicOperand operand1,
44 Operator operator,
45 StaticOperand operand2 ) {
46 CheckArg.isNotNull(operand1, "operand1");
47 CheckArg.isNotNull(operator, "operator");
48 CheckArg.isNotNull(operand2, "operand2");
49 this.operand1 = operand1;
50 this.operand2 = operand2;
51 this.operator = operator;
52 this.hc = HashCode.compute(this.operand1, this.operand2, this.operator);
53 }
54
55
56
57
58
59
60 public DynamicOperand operand1() {
61 return operand1;
62 }
63
64
65
66
67
68
69 public StaticOperand operand2() {
70 return operand2;
71 }
72
73
74
75
76
77
78 public final Operator operator() {
79 return operator;
80 }
81
82
83
84
85
86
87 @Override
88 public String toString() {
89 return Visitors.readable(this);
90 }
91
92
93
94
95
96
97 @Override
98 public int hashCode() {
99 return hc;
100 }
101
102
103
104
105
106
107 @Override
108 public boolean equals( Object obj ) {
109 if (obj == this) return true;
110 if (obj instanceof Comparison) {
111 Comparison that = (Comparison)obj;
112 if (this.hc != that.hc) return false;
113 if (!this.operator.equals(that.operator)) return false;
114 if (!this.operand1.equals(that.operand1)) return false;
115 if (!this.operand2.equals(that.operand2)) return false;
116 return true;
117 }
118 return false;
119 }
120
121
122
123
124
125
126 public void accept( Visitor visitor ) {
127 visitor.visit(this);
128 }
129 }