/** * Constructs a range with the same type and the same values than the specified range. This is a * copy constructor. * * @param range The range to copy. The elements must be {@link Number} instances. * @since 2.4 */ public NumberRange(final Range<T> range) { super( range.getElementClass(), range.getMinValue(), range.isMinIncluded(), range.getMaxValue(), range.isMaxIncluded()); }
/** * Creates a new range using the same element class than this range. This method will be * overriden by subclasses in order to create a range of a more specific type. */ Range<T> create( final T minValue, final boolean isMinIncluded, final T maxValue, final boolean isMaxIncluded) { return new Range<T>(elementClass, minValue, isMinIncluded, maxValue, isMaxIncluded); }
if (!intersects(range)) { subtract = this; } else { final boolean clipMin = compareMinTo(range.minValue, range.isMinIncluded ? 0 : +1) >= 0; final boolean clipMax = compareMaxTo(range.maxValue, range.isMaxIncluded ? 0 : -1) <= 0; if (clipMin) { if (clipMax) { assert range.contains(this) : range; return newArray(0); subtract = create(range.maxValue, !range.isMaxIncluded, maxValue, isMaxIncluded); } else { if (!clipMax) { final Range<T>[] array = newArray(2); array[0] = create(minValue, isMinIncluded, range.minValue, !range.isMinIncluded); array[1] = create(range.maxValue, !range.isMaxIncluded, maxValue, isMaxIncluded); return array; subtract = create(minValue, isMinIncluded, range.minValue, !range.isMinIncluded); assert contains(subtract) : subtract; assert !subtract.intersects(range) : subtract; final Range<T>[] array = newArray(1); array[0] = subtract; return array;
public Range getSearchRange(Object value) { if (value instanceof Range) { Range range = (Range) value; Range before = getSearchRangeOnSingleValue(range.getMinValue()); Range after = getSearchRangeOnSingleValue(range.getMaxValue()); return before.union(after); } else { return getSearchRangeOnSingleValue(value); } }
/** * Implementation of {@link #union(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<?> unionNC(final Range<? extends T> range) throws IllegalArgumentException { final Range<? extends T> union, 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) { union = min; } else { union = create(min.minValue, min.isMinIncluded, max.maxValue, max.isMaxIncluded); } assert union.contains(min) : min; assert union.contains(max) : max; return union; }
public SymbolizerKey(Symbolizer symbolizer, Range scaleRange) { this.symbolizer = symbolizer; if (scaleRange == null) { minScale = 0; maxScale = Double.POSITIVE_INFINITY; } else { minScale = ((Number) scaleRange.getMinValue()).doubleValue(); maxScale = ((Number) scaleRange.getMaxValue()).doubleValue(); } }
@Override public Object getDefaultValue( ResourceInfo resource, String dimensionName, DimensionInfo dimension, Class clz) { if (value instanceof Range) { Range r = (Range) value; if (clz.isAssignableFrom(r.getElementClass())) { return r; } else { Comparable min = (Comparable) Converters.convert(r.getMinValue(), clz); Comparable max = (Comparable) Converters.convert(r.getMaxValue(), clz); return new Range(clz, min, max); } } else { return Converters.convert(this.value, clz); } }
Range rb = (Range) b; if (ra.intersects(rb)) { return 0; } else if (ra.getMinValue().compareTo(rb.getMaxValue()) >= 0) { return 1; } else {
if (scaleRange != null && scaleRange.isEmpty()) { return; Double minValue = scaleRange.getMinValue(); if (minValue != null && minValue > 0) { ruleBuilder.min(minValue); Double maxValue = scaleRange.getMaxValue(); if (maxValue != null && maxValue < Double.POSITIVE_INFINITY) { ruleBuilder.max(maxValue);
@Override public int compare(Range<T> o1, Range<T> o2) { if (o1 == null) { return o2 != null ? -1 : 0; } else if (o2 == null) { return 1; } else if (o1.getMinValue() == null) { return o2.getMinValue() == null ? 0 : -1; } else if (o2.getMinValue() == null) { return 1; } else { return o1.getMinValue().compareTo(o2.getMinValue()); } } }
/** Returns the end time. */ @Override public Date getMaxValue() { return clone(super.getMaxValue()); } }
private Filter toGreaterFilter(FilterFactory ff, Expression variable, Range<T> range) { if (range.isMinIncluded()) { return ff.greaterOrEqual(variable, ff.literal(range.getMinValue())); } else { return ff.greater(variable, ff.literal(range.getMinValue())); } }
private Filter toLessFilter(FilterFactory ff, Expression variable, Range<T> range) { if (range.isMaxIncluded()) { return ff.lessOrEqual(variable, ff.literal(range.getMaxValue())); } else { return ff.less(variable, ff.literal(range.getMaxValue())); } }
/** * If the specified value is inside a range, returns the index of this range. Otherwise, returns * {@code -1}. * * @param value The value to search. * @return The index of the range which contains this value, or -1 if there is no such range. */ public int indexOfRange(final Comparable value) { int index = binarySearch(toArrayElement(value)); if (index < 0) { // Found an insertion point. Make sure that the insertion // point is inside a range (i.e. before the maximum value). index = ~index; // Tild sign, not minus. if ((index & 1) == 0) { return -1; } } index /= 2; // Round toward 0 (odd index are maximum values). assert newRange(get(2 * index), get(2 * index + 1)).contains(value) : value; return index; }
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); } }
/** * Casts the specified range to the specified type. If this class is associated to a unit of * measurement, then this method convert the {@code range} units to the same units than this * instance. This method is overriden by {@link MeasurementRange} only in the way described * above. * * @param type The class to cast to. Must be one of {@link Byte}, {@link Short}, {@link * Integer}, {@link Long}, {@link Float} or {@link Double}. * @return The casted range, or {@code range} if no cast is needed. * @throws IllegalArgumentException if the values are not convertible to the specified class. */ <N extends Number & Comparable<? super N>> NumberRange<N> convertAndCast( final Range<? extends Number> range, final Class<N> type) throws IllegalArgumentException { if (type.equals(range.getElementClass())) { @SuppressWarnings({ "unchecked", "rawtypes" }) // Safe because we checked in the line just above. final NumberRange<N> cast = (NumberRange) wrap((Range) range); return cast; } return new NumberRange<N>(type, range); }
FF.between( attribute, FF.literal(range.getMinValue()), FF.literal(range.getMaxValue())); query.setFilter(rangeFilter); query.setMaxFeatures(maxEntries);
/** Returns the start time. */ @Override public Date getMinValue() { return clone(super.getMinValue()); }
/** * Returns the end time. */ @Override public Date getMaxValue() { return clone(super.getMaxValue()); } }
/** * Implementation of {@link #union(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<?> unionNC(final Range<? extends T> range) throws IllegalArgumentException { final Range<? extends T> union, 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) { union = min; } else { union = create(min.minValue, min.isMinIncluded, max.maxValue, max.isMaxIncluded); } assert union.contains(min) : min; assert union.contains(max) : max; return union; }