private List<Range<T>> getOverlappingRanges(Range<T> range) { List<Range<T>> overlapping = new ArrayList<>(); for (Range r : ranges) { if (r.intersects(range) || contiguous(r, range)) { overlapping.add(r); } } return overlapping; }
public MultiRange<T> intersect(MultiRange<T> other) { List<Range<T>> intersections = new ArrayList<>(); for (Range<T> r1 : ranges) { for (Range<T> r2 : other.ranges) { if (r1.intersects(r2)) { intersections.add((Range<T>) r1.intersect(r2)); } } } return new MultiRange<>(intersections); }
/** * Implementation of {@link #intersect(Range)} to be invoked directly by subclasses. "NC" stands * for "No Cast" - this method do not try to cast the value to a compatible type. */ final Range<? extends T> intersectNC(final Range<? extends T> range) throws IllegalArgumentException { final Range<? extends T> intersect, min, max; min = compareMinTo(range.minValue, range.isMinIncluded ? 0 : +1) < 0 ? range : this; max = compareMaxTo(range.maxValue, range.isMaxIncluded ? 0 : -1) > 0 ? range : this; if (min == max) { intersect = min; } else { intersect = create(min.minValue, min.isMinIncluded, max.maxValue, max.isMaxIncluded); } assert intersect.isEmpty() == !intersects(range) : intersect; return intersect; }
if (!intersects(range)) { subtract = this; } else { assert !subtract.intersects(range) : subtract; final Range<T>[] array = newArray(1); array[0] = subtract;
private boolean rangeFilterAccepts(Range rangeFilter, Object domainValue) { if (rangeFilter == null) { return true; } if (domainValue instanceof Range) { return rangeFilter.intersects((Range) domainValue); } else { return rangeFilter.contains((Comparable) domainValue); } }
Range rb = (Range) b; if (ra.intersects(rb)) { return 0; } else if (ra.getMinValue().compareTo(rb.getMaxValue()) >= 0) {
/** * Implementation of {@link #intersect(Range)} to be invoked directly by subclasses. * "NC" stands for "No Cast" - this method do not try to cast the value to a compatible type. */ final Range<? extends T> intersectNC(final Range<? extends T> range) throws IllegalArgumentException { final Range<? extends T> intersect, min, max; min = compareMinTo(range.minValue, range.isMinIncluded ? 0 : +1) < 0 ? range : this; max = compareMaxTo(range.maxValue, range.isMaxIncluded ? 0 : -1) > 0 ? range : this; if (min == max) { intersect = min; } else { intersect = create(min.minValue, min.isMinIncluded, max.maxValue, max.isMaxIncluded); } assert intersect.isEmpty() == !intersects(range) : intersect; return intersect; }
if (!intersects(range)) { subtract = this; } else { assert !subtract.intersects(range) : subtract; final Range<T>[] array = newArray(1); array[0] = subtract;