/** * Returns {@code true} if the supplied range is fully contained within this range. * This method converts {@code this} or the given argument to the widest numeric type, * then delegates to {@link #intersects(Range)}. * * @param range the range to check for inclusion in this range. * @return {@code true} if the given range is included in this range. * @throws IllegalArgumentException if the given range can not be converted to a valid type * through widening conversion, or if the units of measurement are not convertible. */ @SuppressWarnings({"unchecked","rawtypes"}) public boolean intersectsAny(final NumberRange<?> range) throws IllegalArgumentException { final Class type = Numbers.widestClass(elementType, range.elementType); return castTo(type).intersects(convertAndCast(range, type)); }
/** * Returns {@code true} if the supplied range is fully contained within this range. * This method converts {@code this} or the given argument to the widest numeric type, * then delegates to {@link #intersects(Range)}. * * @param range the range to check for inclusion in this range. * @return {@code true} if the given range is included in this range. * @throws IllegalArgumentException if the given range can not be converted to a valid type * through widening conversion, or if the units of measurement are not convertible. */ @SuppressWarnings({"unchecked","rawtypes"}) public boolean intersectsAny(final NumberRange<?> range) throws IllegalArgumentException { final Class type = Numbers.widestClass(elementType, range.elementType); return castTo(type).intersects(convertAndCast(range, type)); }
/** * Returns the range of values that are in this range but not in the given range. * This method converts {@code this} or the given argument to the widest numeric type, * then delegates to {@link #subtract(Range)}. * * @param range the range to subtract. * @return this range without the given range, as an array of length 0, 1 or 2. * @throws IllegalArgumentException if the given range can not be converted to a valid type * through widening conversion, or if the units of measurement are not convertible. */ @SuppressWarnings({"unchecked","rawtypes"}) public NumberRange<?>[] subtractAny(final NumberRange<?> range) throws IllegalArgumentException { final Class type = Numbers.widestClass(elementType, range.elementType); return (NumberRange[]) castTo(type).subtract(convertAndCast(range, type)); } }
/** * Returns the range of values that are in this range but not in the given range. * This method converts {@code this} or the given argument to the widest numeric type, * then delegates to {@link #subtract(Range)}. * * @param range the range to subtract. * @return this range without the given range, as an array of length 0, 1 or 2. * @throws IllegalArgumentException if the given range can not be converted to a valid type * through widening conversion, or if the units of measurement are not convertible. */ @SuppressWarnings({"unchecked","rawtypes"}) public NumberRange<?>[] subtractAny(final NumberRange<?> range) throws IllegalArgumentException { final Class type = Numbers.widestClass(elementType, range.elementType); return (NumberRange[]) castTo(type).subtract(convertAndCast(range, type)); } }
/** * Returns {@code true} if the supplied range is fully contained within this range. * This method converts {@code this} or the given argument to the widest numeric type, * then delegates to {@link #contains(Range)}. * * @param range the range to check for inclusion in this range. * @return {@code true} if the given range is included in this range. * @throws IllegalArgumentException if the given range can not be converted to a valid type * through widening conversion, or if the units of measurement are not convertible. */ @SuppressWarnings({"unchecked","rawtypes"}) public boolean containsAny(final NumberRange<?> range) throws IllegalArgumentException { /* * The type bounds is actually <? extends Number & Comparable> but I'm unable to express * it as local variable as of Java 7. So we have to bypass the compiler check, but those * casts are actually safes. */ final Class type = Numbers.widestClass(elementType, range.elementType); return castTo(type).contains(convertAndCast(range, type)); }
/** * Returns {@code true} if the supplied range is fully contained within this range. * This method converts {@code this} or the given argument to the widest numeric type, * then delegates to {@link #contains(Range)}. * * @param range the range to check for inclusion in this range. * @return {@code true} if the given range is included in this range. * @throws IllegalArgumentException if the given range can not be converted to a valid type * through widening conversion, or if the units of measurement are not convertible. */ @SuppressWarnings({"unchecked","rawtypes"}) public boolean containsAny(final NumberRange<?> range) throws IllegalArgumentException { /* * The type bounds is actually <? extends Number & Comparable> but I'm unable to express * it as local variable as of Java 7. So we have to bypass the compiler check, but those * casts are actually safes. */ final Class type = Numbers.widestClass(elementType, range.elementType); return castTo(type).contains(convertAndCast(range, type)); }
/** * Returns the union of this range with the given range. * This method converts {@code this} or the given argument to the widest numeric type, * then delegates to {@link #union(Range)}. * * @param range the range to add to this range. * @return the union of this range with the given range. * @throws IllegalArgumentException if the given range can not be converted to a valid type * through widening conversion, or if the units of measurement are not convertible. */ @SuppressWarnings({"unchecked","rawtypes"}) public NumberRange<?> unionAny(final NumberRange<?> range) throws IllegalArgumentException { final Class type = Numbers.widestClass(elementType, range.elementType); return castOrCopy(castTo(type).union(convertAndCast(range, type))); }
/** * Returns the union of this range with the given range. * This method converts {@code this} or the given argument to the widest numeric type, * then delegates to {@link #union(Range)}. * * @param range the range to add to this range. * @return the union of this range with the given range. * @throws IllegalArgumentException if the given range can not be converted to a valid type * through widening conversion, or if the units of measurement are not convertible. */ @SuppressWarnings({"unchecked","rawtypes"}) public NumberRange<?> unionAny(final NumberRange<?> range) throws IllegalArgumentException { final Class type = Numbers.widestClass(elementType, range.elementType); return castOrCopy(castTo(type).union(convertAndCast(range, type))); }
/** * Returns the union of this range with the given range. * This method converts {@code this} or the given argument to the widest numeric type, * then delegates to {@link #intersect(Range)}. * * @param range the range to add to this range. * @return the union of this range with the given range. * @throws IllegalArgumentException if the given range can not be converted to a valid type * through widening conversion, or if the units of measurement are not convertible. */ @SuppressWarnings({"unchecked","rawtypes"}) public NumberRange<?> intersectAny(final NumberRange<?> range) throws IllegalArgumentException { Class type = Numbers.widestClass(elementType, range.elementType); final NumberRange<?> intersect = castOrCopy(castTo(type).intersect(convertAndCast(range, 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 = Numbers.narrowestClass(elementType, range.elementType); type = Numbers.widestClass(type, Numbers.narrowestClass((Number) intersect.minValue)); type = Numbers.widestClass(type, Numbers.narrowestClass((Number) intersect.maxValue)); return intersect.castTo(type); }
/** * Returns the union of this range with the given range. * This method converts {@code this} or the given argument to the widest numeric type, * then delegates to {@link #intersect(Range)}. * * @param range the range to add to this range. * @return the union of this range with the given range. * @throws IllegalArgumentException if the given range can not be converted to a valid type * through widening conversion, or if the units of measurement are not convertible. */ @SuppressWarnings({"unchecked","rawtypes"}) public NumberRange<?> intersectAny(final NumberRange<?> range) throws IllegalArgumentException { Class type = Numbers.widestClass(elementType, range.elementType); final NumberRange<?> intersect = castOrCopy(castTo(type).intersect(convertAndCast(range, 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 = Numbers.narrowestClass(elementType, range.elementType); type = Numbers.widestClass(type, Numbers.narrowestClass((Number) intersect.minValue)); type = Numbers.widestClass(type, Numbers.narrowestClass((Number) intersect.maxValue)); return intersect.castTo(type); }