/** * Implementation of {@link #intersects(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 boolean intersectsNC(final Range<? extends T> range) { return !isEmpty() && !range.isEmpty() && compareMinTo(range.maxValue, range.isMaxIncluded ? 0 : -1) <= 0 && compareMaxTo(range.minValue, range.isMinIncluded ? 0 : +1) >= 0; }
/** Returns a string representation of this range. */ @Override public String toString() { if (isEmpty()) { return "[]"; } final StringBuilder buffer = new StringBuilder(); buffer.append(isMinIncluded ? '[' : '('); if (minValue == null) { buffer.append("-\u221E"); // Infinity } else { buffer.append(minValue); } buffer.append(", "); if (maxValue == null) { buffer.append('\u221E'); // Infinity } else { buffer.append(maxValue); } buffer.append(isMaxIncluded ? ']' : ')'); final Unit<?> units = getUnits(); if (units != null) { buffer.append(' ').append(units); } return buffer.toString(); } }
public void removeRange(Range<T> range) { List<Range<T>> overlapping = getOverlappingRanges(range); if (overlapping != null) { ranges.remove(overlapping); List<Range<?>> removed = new ArrayList<>(); for (Range<T> r : overlapping) { Range<?>[] difference = r.subtract(range); for (Range<?> d : difference) { if (!d.isEmpty()) { removed.add(d); } } } for (Range<?> r : removed) { ranges.add((Range<T>) r); } } }
/** * Compares this range with the given object for equality. * * @param object The object to compare with this range for equality. * @return {@code true} if the given object is equals to this range. */ @Override public boolean equals(final Object object) { if (object == this) { return true; } if (object != null && object.getClass().equals(getClass())) { final Range<?> other = (Range<?>) object; if (Utilities.equals(elementClass, other.elementClass)) { if (isEmpty()) { return other.isEmpty(); } return Utilities.equals(minValue, other.minValue) && Utilities.equals(maxValue, other.maxValue) && isMinIncluded == other.isMinIncluded && isMaxIncluded == other.isMaxIncluded; } } return false; }
public void addRange(Range<T> range) { if (range.isEmpty()) { return; } List<Range<T>> overlapping = getOverlappingRanges(range); if (overlapping != null && !overlapping.isEmpty()) { ranges.removeAll(overlapping); Range combined = range; for (Range r : overlapping) { combined = combined.union(r); } ranges.add(combined); } else { ranges.add(range); } }
/** Returns a hash code value for this range. */ @Override public int hashCode() { int result = (int) serialVersionUID; if (!isEmpty()) { result += elementClass.hashCode(); result = Utilities.hash(isMaxIncluded, result); result = Utilities.hash(isMinIncluded, result); result = Utilities.hash(maxValue, result); result = Utilities.hash(minValue, result); } return result; }
/** * 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; }
public static Selector combineAnd(List<ScaleRange> selectors, Object ctx) { if (selectors.size() == 1) { return selectors.get(0); } Range<?> range = selectors.get(0).range; for (ScaleRange selector : selectors) { range = range.intersect(selector.range); if (range.isEmpty()) { return REJECT; } } return new ScaleRange((Range<Double>) range); }
/** * Returns a string representation of this range. */ @Override public String toString() { if (isEmpty()) { return "[]"; } final StringBuilder buffer = new StringBuilder(); buffer.append(isMinIncluded ? '[' : '('); if (minValue == null) { buffer.append("-\u221E"); // Infinity } else { buffer.append(minValue); } buffer.append(", "); if (maxValue == null) { buffer.append('\u221E'); // Infinity } else { buffer.append(maxValue); } buffer.append(isMaxIncluded ? ']' : ')'); final Unit<?> units = getUnits(); if (units != null) { buffer.append(' ').append(units); } return buffer.toString(); } }
/** * Compares this range with the given object for equality. * * @param object The object to compare with this range for equality. * @return {@code true} if the given object is equals to this range. */ @Override public boolean equals(final Object object) { if (object == this) { return true; } if (object != null && object.getClass().equals(getClass())) { final Range<?> other = (Range) object; if (Utilities.equals(elementClass, other.elementClass)) { if (isEmpty()) { return other.isEmpty(); } return Utilities.equals(minValue, other.minValue) && Utilities.equals(maxValue, other.maxValue) && isMinIncluded == other.isMinIncluded && isMaxIncluded == other.isMaxIncluded; } } return false; }
/** * Returns a hash code value for this range. */ @Override public int hashCode() { int result = (int) serialVersionUID; if (!isEmpty()) { result += elementClass.hashCode(); result = Utilities.hash(isMaxIncluded, result); result = Utilities.hash(isMinIncluded, result); result = Utilities.hash(maxValue, result); result = Utilities.hash(minValue, result); } return result; }
/** * 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 (scaleRange != null && scaleRange.isEmpty()) { return;