MCPcopy Create free account
hub / github.com/antlr/codebuff / intersect

Method intersect

output/java_guava/1.4.16/GeneralRange.java:176–217  ·  view source on GitHub ↗

Returns the intersection of the two ranges, or an empty range if their intersection is empty.

(GeneralRange<T> other)

Source from the content-addressed store, hash-verified

174 */
175
176 GeneralRange<T> intersect(GeneralRange<T> other) {
177 checkNotNull(other);
178 checkArgument(comparator.equals(other.comparator));
179 boolean hasLowBound = this.hasLowerBound;
180 @Nullable T lowEnd = getLowerEndpoint();
181 BoundType lowType = getLowerBoundType();
182 if (!hasLowerBound()) {
183 hasLowBound = other.hasLowerBound;
184 lowEnd = other.getLowerEndpoint();
185 lowType = other.getLowerBoundType();
186 } else if (other.hasLowerBound()) {
187 int cmp = comparator.compare(getLowerEndpoint(), other.getLowerEndpoint());
188 if (cmp < 0 || (cmp == 0 && other.getLowerBoundType() == OPEN)) {
189 lowEnd = other.getLowerEndpoint();
190 lowType = other.getLowerBoundType();
191 }
192 }
193 boolean hasUpBound = this.hasUpperBound;
194 @Nullable T upEnd = getUpperEndpoint();
195 BoundType upType = getUpperBoundType();
196 if (!hasUpperBound()) {
197 hasUpBound = other.hasUpperBound;
198 upEnd = other.getUpperEndpoint();
199 upType = other.getUpperBoundType();
200 } else if (other.hasUpperBound()) {
201 int cmp = comparator.compare(getUpperEndpoint(), other.getUpperEndpoint());
202 if (cmp > 0 || (cmp == 0 && other.getUpperBoundType() == OPEN)) {
203 upEnd = other.getUpperEndpoint();
204 upType = other.getUpperBoundType();
205 }
206 }
207 if (hasLowBound && hasUpBound) {
208 int cmp = comparator.compare(lowEnd, upEnd);
209 if (cmp > 0 || (cmp == 0 && lowType == OPEN && upType == OPEN)) {
210 // force allowed empty range
211 lowEnd = upEnd;
212 lowType = OPEN;
213 upType = CLOSED;
214 }
215 }
216 return new GeneralRange<T>(comparator, hasLowBound, lowEnd, lowType, hasUpBound, upEnd, upType);
217 }
218
219 @Override
220 public boolean equals(@Nullable Object obj) {

Callers 2

headMultisetMethod · 0.45
tailMultisetMethod · 0.45

Calls 10

getLowerEndpointMethod · 0.95
getLowerBoundTypeMethod · 0.95
hasLowerBoundMethod · 0.95
getUpperEndpointMethod · 0.95
getUpperBoundTypeMethod · 0.95
hasUpperBoundMethod · 0.95
equalsMethod · 0.65
checkNotNullMethod · 0.45
checkArgumentMethod · 0.45
compareMethod · 0.45

Tested by

no test coverage detected