Class targetType = categories != null && !categories.isEmpty() ? categories.get(0).getRange().getElementClass() : Double.class; final NumberRange<?> dataRange = configuredRange.castTo(targetType);
/** * Returns a string representation of this category. The returned string is implementation * dependent. It is usually provided for debugging purposes. */ @Override public String toString() { final StringBuilder buffer = new StringBuilder(Classes.getShortClassName(this)); buffer.append("(\"").append(name).append("\":["); if (Classes.isInteger(getRange().getElementClass())) { buffer.append(Math.round(minimum)) .append("...") .append(Math.round(maximum)); // Inclusive } else { buffer.append(minimum).append(" ... ").append(maximum); // Inclusive } return buffer.append("])").toString(); }
int type = DataBuffer.TYPE_FLOAT; final NumberRange<?> range = getRange(); final Class<?> rt = range.getElementClass(); if (Byte.class.equals(rt) || Short.class.equals(rt) || Integer.class.equals(rt)) { final int min = range.getMinValue().intValue();
/** * Returns the {@linkplain #getMinimum() minimum value} with the specified inclusive or * exclusive state. If this range is unbounded, then {@link Double#NEGATIVE_INFINITY} is * returned. * * @param inclusive {@code true} for the minimum value inclusive, or {@code false} for the * minimum value exclusive. * @return The minimum value, inclusive or exclusive as requested. */ public double getMinimum(final boolean inclusive) { double value = getMinimum(); if (inclusive != isMinIncluded()) { value = XMath.rool(getElementClass(), value, inclusive ? +1 : -1); } return value; }
/** * Returns the {@linkplain #getMaximum() maximum value} with the specified inclusive or * exclusive state. If this range is unbounded, then {@link Double#POSITIVE_INFINITY} is * returned. * * @param inclusive {@code true} for the maximum value inclusive, or {@code false} for the * maximum value exclusive. * @return The maximum value, inclusive or exclusive as requested. */ public double getMaximum(final boolean inclusive) { double value = getMaximum(); if (inclusive != isMaxIncluded()) { value = XMath.rool(getElementClass(), value, inclusive ? -1 : +1); } return value; } }
/** Returns the range of values that are in this range but not in the given range. */ @Override @SuppressWarnings({"unchecked", "rawtypes"}) public NumberRange<?>[] subtract(Range<?> range) { Class<? extends Number> type = getWidestClass(elementClass, getElementClass(range)); return (NumberRange[]) castTo((Class) type).subtractNC(convertAndCast((Range) range, (Class) type)); }
/** * Returns the union of this range with the given range. Widening conversions will be applied as * needed. */ @Override @SuppressWarnings({"unchecked", "rawtypes"}) public NumberRange<?> union(Range<?> range) { final Class<? extends Number> type = getWidestClass(elementClass, getElementClass(range)); range = convertAndCast((Range) range, (Class) type); return (NumberRange<?>) castTo((Class) type).unionNC((Range) range); }
/** Returns {@code true} if this range intersects the given range. */ @Override @SuppressWarnings({"unchecked", "rawtypes"}) public boolean intersects(Range<?> range) { final Class<? extends Number> type = getWidestClass(elementClass, getElementClass(range)); /* * The type bounds is actually <? extends Number & Comparable> but I'm unable to express * it it local variable as of Java 6. So we have to bypass the compiler check, but those * casts are actually safes, including Range because getElementClass(range) would have * throw an exception otherwise. */ range = convertAndCast((Range) range, (Class) type); return castTo((Class) type).intersectsNC((Range) range); }
/** Returns {@code true} if the supplied range is fully contained within this range. */ @Override @SuppressWarnings({"unchecked", "rawtypes"}) public boolean contains(Range<?> range) { final Class<? extends Number> type = getWidestClass(elementClass, getElementClass(range)); /* * The type bounds is actually <? extends Number & Comparable> but I'm unable to express * it it local variable as of Java 6. So we have to bypass the compiler check, but those * casts are actually safes, including Range because getElementClass(range) would have * throw an exception otherwise. */ range = convertAndCast((Range) range, (Class) type); return castTo((Class) type).containsNC((Range) range); }
this.ARGB = ARGB; this.range = range; Class<?> type = range.getElementClass(); boolean minInc = range.isMinIncluded(); boolean maxInc = range.isMaxIncluded();
if (lower != min || upper != max || !Classes.isInteger(category.getRange().getElementClass())) { throw new IllegalStateException( Errors.format(ErrorKeys.NON_INTEGER_CATEGORY));
/** * Returns the intersection of this range with the given range. Widening conversions will be * applied as needed. */ @Override @SuppressWarnings({"unchecked", "rawtypes"}) public NumberRange<?> intersect(Range<?> range) { final Class<? extends Number> rangeType = getElementClass(range); Class<? extends Number> type = getWidestClass(elementClass, rangeType); range = castTo((Class) type).intersectNC(convertAndCast((Range) range, (Class) type)); /* * Use a finer type capable to holds the result (since the intersection * may have reduced the range), but not finer than the finest type of * the ranges used in the intersection calculation. */ type = getFinestClass(elementClass, rangeType); if (range.minValue != null) { type = getWidestClass(type, getFinestClass(((Number) range.minValue).doubleValue())); } if (range.maxValue != null) { type = getWidestClass(type, getFinestClass(((Number) range.maxValue).doubleValue())); } return convertAndCast((Range) range, (Class) type); }
} else { sampleValueRange = NumberRange.create(statsMin, statsMax); Class elementClass = targetCellType.getSampleValueRange().getElementClass(); sampleValueRange = sampleValueRange.castTo(elementClass);
/** * Returns {@code true} if the specified value is within this range. */ public boolean contains(final Number value) { final Class type = ClassChanger.getWidestClass(getElementClass(), value.getClass()); return castTo(type)._contains(ClassChanger.cast(value, type)); }
/** * Returns the union of this range with the given range. * Widening conversions will be applied as needed. */ @Override @SuppressWarnings("unchecked") public NumberRange<?> union(Range<?> range) { final Class<? extends Number> type = getWidestClass(elementClass, getElementClass(range)); range = convertAndCast((Range) range, (Class) type); return (NumberRange) castTo((Class) type).unionNC((Range)range); }
/** * Returns the range of values that are in this range but not in the given range. */ @Override @SuppressWarnings("unchecked") public NumberRange<?>[] subtract(Range<?> range) { Class<? extends Number> type = getWidestClass(elementClass, getElementClass(range)); return (NumberRange[]) castTo((Class) type) .subtractNC(convertAndCast((Range) range, (Class) type)); }
/** * Returns {@code true} if this range intersects the given range. */ @Override @SuppressWarnings("unchecked") public boolean intersects(Range<?> range) { final Class<? extends Number> type = getWidestClass(elementClass, getElementClass(range)); /* * The type bounds is actually <? extends Number & Comparable> but I'm unable to express * it it local variable as of Java 6. So we have to bypass the compiler check, but those * casts are actually safes, including Range because getElementClass(range) would have * throw an exception otherwise. */ range = convertAndCast((Range) range, (Class) type); return castTo((Class) type).intersectsNC((Range)range); }
/** * Returns true if this range intersects the given range. */ //@Override public boolean intersects(final Range range) { final Class type = ClassChanger.getWidestClass(getElementClass(), range.getElementClass()); return castTo(type)._intersects(convertAndCast(range, type)); }
/** * Returns true if the supplied range is fully contained within this range. */ //@Override public boolean contains(final Range range) { final Class type = ClassChanger.getWidestClass(getElementClass(), range.getElementClass()); return castTo(type)._contains(convertAndCast(range, type)); }
/** * Returns the union of this range with the given range. * Widening conversions will be applied as needed. * * @todo The return type will be changed to {@code NumberRange} when J2SE 1.5 * will be available. We should then search for NumberRange.warp(...) in all * client classes; some 'warp' may no longer be needed. */ //@Override public Range union(final Range range) { final Class type = ClassChanger.getWidestClass(getElementClass(), range.getElementClass()); return wrap(castTo(type)._union(convertAndCast(range, type))); }