@SuppressWarnings("unchecked") public int compare(final Range r1, final Range r2) { int cmin = r1.getMinValue().compareTo(r2.getMinValue()); int cmax = r1.getMaxValue().compareTo(r2.getMaxValue()); if (cmin == 0) cmin = (r1.isMinIncluded() ? -1 : 0) - (r2.isMinIncluded() ? -1 : 0); if (cmax == 0) cmax = (r1.isMaxIncluded() ? +1 : 0) - (r2.isMaxIncluded() ? +1 : 0); if (cmin == cmax) return cmax; // Easy case: min and max are both greater, smaller or eq. if (cmin == 0) return cmax; // Easy case: only max value differ. if (cmax == 0) return cmin; // Easy case: only min value differ. // One range is included in the other. throw new IllegalArgumentException("Unordered ranges"); } };
/** * Returns the smallest sample dimension type capable to hold the specified range of values. * * @param range The range of values. * @return The smallest sample dimension type for the specified range. */ public static SampleDimensionType getSampleDimensionType(final Range<?> range) { final Class<?> type = range.getElementClass(); if (Double.class.isAssignableFrom(type)) { return REAL_64BITS; } if (Float.class.isAssignableFrom(type)) { return REAL_32BITS; } long min = ((Number) range.getMinValue()).longValue(); long max = ((Number) range.getMaxValue()).longValue(); if (!range.isMinIncluded()) min++; if (!range.isMaxIncluded()) max--; return getSampleDimensionType(min, max); }
/** * Add a range to this set. Range may be added in any order. If the specified range overlap an * existing range, the two range will be merged as of {@link Range#union}. * * <p>Note: current version do not support open interval (i.e. {@code * Range.is[Min/Max]Included()} must return {@code true}). * * @param range The range to add. * @return {@code true} if this set changed as a result of the call. * @todo support open intervals. */ @Override public boolean add(final Range<T> range) { if (!range.isMinIncluded() || !range.isMaxIncluded()) { throw new UnsupportedOperationException("Open interval not yet supported"); } return add((Comparable) range.getMinValue(), (Comparable) range.getMaxValue()); }
private boolean contiguous(Range r1, Range<T> r2) { if (r1.getMinValue() != null && r2.getMaxValue() != null && (r1.isMinIncluded() || r2.isMaxIncluded())) { return r1.getMinValue().equals(r2.getMaxValue()); } else if (r1.getMaxValue() != null && r2.getMinValue() != null && (r1.isMaxIncluded() || r2.isMinIncluded())) { return r1.getMaxValue().equals(r2.getMinValue()); } else { return false; } }
if (next.getMinValue().equals(curr.getMaxValue())) { if (!next.isMinIncluded() && !curr.isMaxIncluded()) { exclusions.add((T) curr.getMaxValue()); range.getElementClass(), (T) range.getMinValue(), range.isMinIncluded(), (T) curr.getMaxValue(), curr.isMaxIncluded());
/** * 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()); }
/** * Returns {@code true} if this set contains the specified element. * * @param object The object to compare to this set. * @return {@code true} if the given object is equals to this set. */ @Override public boolean contains(final Object object) { @SuppressWarnings("unchecked") // We are going to check just the line after. final Range<T> range = (Range<T>) object; if (elementClass.equals(range.elementClass)) { if (range.isMinIncluded() && range.isMaxIncluded()) { final int index = binarySearch(toArrayElement(range.getMinValue())); if (index >= 0 && (index & 1) == 0) { @SuppressWarnings("unchecked") final int c = get(index + 1).compareTo(range.getMaxValue()); return c == 0; } } } return false; }
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())); } }
/** * Constructs a range with the same values than the specified range, casted to the specified * type. * * @param type The element class, usually one of {@link Byte}, {@link Short}, {@link Integer}, * {@link Long}, {@link Float} or {@link Double}. * @param range The range to copy. The elements must be {@link Number} instances. * @throws IllegalArgumentException if the values are not convertible to the specified class. */ NumberRange(final Class<T> type, final Range<? extends Number> range) throws IllegalArgumentException { // TODO: remove the (Number) casts when we will be allowed to compile for Java 6. this( type, ClassChanger.cast((Number) range.getMinValue(), type), range.isMinIncluded(), ClassChanger.cast((Number) range.getMaxValue(), type), range.isMaxIncluded()); }
private Filter toFilter(FilterFactory ff, Expression variable, Range<T> range) { if (range.getMinValue() == null && range.getMaxValue() == null) { return Filter.INCLUDE; } else if (range.isMinIncluded() && range.isMaxIncluded()) { if (range.getMinValue().equals(range.getMaxValue())) { return ff.equals(variable, ff.literal(range.getMinValue())); } return ff.between( variable, ff.literal(range.getMinValue()), ff.literal(range.getMaxValue())); } else if (range.getMinValue() == null) { return toLessFilter(ff, variable, range); } else if (range.getMaxValue() == null) { return toGreaterFilter(ff, variable, range); } else { Filter less = toLessFilter(ff, variable, range); Filter greater = toGreaterFilter(ff, variable, range); return ff.and(greater, less); } }
@SuppressWarnings("unchecked") public int compare(final Range r1, final Range r2) { int cmin = r1.getMinValue().compareTo(r2.getMinValue()); int cmax = r1.getMaxValue().compareTo(r2.getMaxValue()); if (cmin == 0) cmin = (r1.isMinIncluded() ? -1 : 0) - (r2.isMinIncluded() ? -1 : 0); if (cmax == 0) cmax = (r1.isMaxIncluded() ? +1 : 0) - (r2.isMaxIncluded() ? +1 : 0); if (cmin == cmax) return cmax; // Easy case: min and max are both greater, smaller or eq. if (cmin == 0) return cmax; // Easy case: only max value differ. if (cmax == 0) return cmin; // Easy case: only min value differ. // One range is included in the other. throw new IllegalArgumentException("Unordered ranges"); } };
/** * Show only commits that lie within the specified time range. * * @param commitRange time range to show commits from * @return {@code this} */ public LogOp setTimeRange(final Range<Date> commitRange) { if (commitRange == null) { this.timeRange = ALWAYS; } else { this.timeRange = new Range<Long>(Long.class, commitRange.getMinValue().getTime(), commitRange.isMinIncluded(), commitRange.getMaxValue().getTime(), commitRange.isMaxIncluded()); } return this; }
/** * Returns the smallest sample dimension type capable to hold the specified range of values. * * @param range The range of values. * @return The smallest sample dimension type for the specified range. */ public static SampleDimensionType getSampleDimensionType(final Range<?> range) { final Class<?> type = range.getElementClass(); if (Double.class.isAssignableFrom(type)) { return REAL_64BITS; } if (Float.class.isAssignableFrom(type)) { return REAL_32BITS; } long min = ((Number) range.getMinValue()).longValue(); long max = ((Number) range.getMaxValue()).longValue(); if (!range.isMinIncluded()) min++; if (!range.isMaxIncluded()) max--; return getSampleDimensionType(min, max); }
/** * Show only commits that lie within the specified time range. * * @param commitRange time range to show commits from * @return {@code this} */ public LogOp setTimeRange(final Range<Date> commitRange) { if (commitRange == null) { this.timeRange = ALWAYS; } else { this.timeRange = new Range<Long>(Long.class, commitRange.getMinValue().getTime(), commitRange.isMinIncluded(), commitRange.getMaxValue().getTime(), commitRange.isMaxIncluded()); } return this; }
/** * Show only commits that lie within the specified time range. * * @param commitRange time range to show commits from * @return {@code this} */ public LogOp setTimeRange(final Range<Date> commitRange) { if (commitRange == null) { this.timeRange = ALWAYS; } else { this.timeRange = new Range<Long>(Long.class, commitRange.getMinValue().getTime(), commitRange.isMinIncluded(), commitRange.getMaxValue().getTime(), commitRange.isMaxIncluded()); } return this; }
/** * Add a range to this set. Range may be added in any order. If the specified range * overlap an existing range, the two range will be merged as of {@link Range#union}. * <p> * Note: current version do not support open interval (i.e. {@code Range.is[Min/Max]Included()} * must return {@code true}). * * @param range The range to add. * @return {@code true} if this set changed as a result of the call. * * @todo support open intervals. */ @Override public boolean add(final Range<T> range) { if (!range.isMinIncluded() || !range.isMaxIncluded()) { throw new UnsupportedOperationException("Open interval not yet supported"); } return add((Comparable) range.getMinValue(), (Comparable) range.getMaxValue()); }
/** * 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()); }
/** * Returns {@code true} if this set contains the specified element. * * @param object The object to compare to this set. * @return {@code true} if the given object is equals to this set. */ @Override public boolean contains(final Object object) { @SuppressWarnings("unchecked") // We are going to check just the line after. final Range<T> range = (Range<T>) object; if (elementClass.equals(range.elementClass)) { if (range.isMinIncluded() && range.isMaxIncluded()) { final int index = binarySearch(toArrayElement(range.getMinValue())); if (index >= 0 && (index & 1)==0) { @SuppressWarnings("unchecked") final int c = get(index+1).compareTo(range.getMaxValue()); return c == 0; } } } return false; }
/** * Constructs a range with the same values than the specified range, * casted to the specified type. * * @param type The element class, usually one of {@link Byte}, {@link Short}, * {@link Integer}, {@link Long}, {@link Float} or {@link Double}. * @param range The range to copy. The elements must be {@link Number} instances. * @throws IllegalArgumentException if the values are not convertible to the specified class. */ NumberRange(final Class<T> type, final Range<? extends Number> range) throws IllegalArgumentException { // TODO: remove the (Number) casts when we will be allowed to compile for Java 6. this(type, ClassChanger.cast((Number) range.getMinValue(), type), range.isMinIncluded(), ClassChanger.cast((Number) range.getMaxValue(), type), range.isMaxIncluded()); }