/** * 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); }