113 return UnsignedMath.belowThan(left, right); |
113 return UnsignedMath.belowThan(left, right); |
114 } |
114 } |
115 throw new IllegalArgumentException(this.toString()); |
115 throw new IllegalArgumentException(this.toString()); |
116 } |
116 } |
117 |
117 |
|
118 public static final class CanonicalizedCondition { |
|
119 private final CanonicalCondition canonicalCondition; |
|
120 private final boolean mirror; |
|
121 private final boolean negate; |
|
122 |
|
123 private CanonicalizedCondition(CanonicalCondition canonicalCondition, boolean mirror, boolean negate) { |
|
124 this.canonicalCondition = canonicalCondition; |
|
125 this.mirror = mirror; |
|
126 this.negate = negate; |
|
127 } |
|
128 |
|
129 public CanonicalCondition getCanonicalCondition() { |
|
130 return canonicalCondition; |
|
131 } |
|
132 |
|
133 public boolean mustMirror() { |
|
134 return mirror; |
|
135 } |
|
136 |
|
137 public boolean mustNegate() { |
|
138 return negate; |
|
139 } |
|
140 } |
|
141 |
|
142 public CanonicalizedCondition canonicalize() { |
|
143 CanonicalCondition canonicalCondition; |
|
144 switch (this) { |
|
145 case EQ: |
|
146 case NE: |
|
147 canonicalCondition = CanonicalCondition.EQ; |
|
148 break; |
|
149 case LT: |
|
150 case LE: |
|
151 case GT: |
|
152 case GE: |
|
153 canonicalCondition = CanonicalCondition.LT; |
|
154 break; |
|
155 case BT: |
|
156 case BE: |
|
157 case AT: |
|
158 case AE: |
|
159 canonicalCondition = CanonicalCondition.BT; |
|
160 break; |
|
161 default: |
|
162 throw new IllegalArgumentException(this.toString()); |
|
163 } |
|
164 return new CanonicalizedCondition(canonicalCondition, canonicalMirror(), canonicalNegate()); |
|
165 } |
|
166 |
118 /** |
167 /** |
119 * Given a condition and its negation, this method returns true for one of the two and false for |
168 * Given a condition and its negation, this method returns true for one of the two and false for |
120 * the other one. This can be used to keep comparisons in a canonical form. |
169 * the other one. This can be used to keep comparisons in a canonical form. |
121 * |
170 * |
122 * @return true if this condition is considered to be the canonical form, false otherwise. |
171 * @return true if this condition is considered to be the canonical form, false otherwise. |