/** * {@inheritDoc} * If the given range is an instance of {@code MeasurementRange}, then this method converts * the value of the other range to the unit of measurement of this range before to perform * the operation. * * @return {@inheritDoc} * @throws IllegalArgumentException if the given range is an instance of * {@code MeasurementRange} using incommensurable unit of measurement. */ @Override public Range<E> union(final Range<E> range) throws IllegalArgumentException { return super.union(convert(range)); }
/** * {@inheritDoc} * If the given range is an instance of {@code MeasurementRange}, then this method converts * the value of the other range to the unit of measurement of this range before to perform * the operation. * * @return {@inheritDoc} * @throws IllegalArgumentException if the given range is an instance of * {@code MeasurementRange} using incommensurable unit of measurement. */ @Override public Range<E> union(final Range<E> range) throws IllegalArgumentException { return super.union(convert(range)); }
/** * 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))); }
/** * Tests union and intersection with {@link Double} values. */ @Test public void testWithDoubles() { NumberRange<Double> r1 = NumberRange.create(10.0, true, 20.0, true); NumberRange<Double> r2 = NumberRange.create(15.0, true, 30.0, true); assertEquals(Double.class, r1.getElementType()); assertEquals(Double.class, r2.getElementType()); assertEquals(NumberRange.create(10.0, true, 30.0, true), r1.union(r2)); assertEquals(NumberRange.create(15.0, true, 20.0, true), r1.intersect(r2)); }
/** * Tests union and intersection with {@link Integer} values. */ @Test public void testWithIntegers() { NumberRange<Integer> r1 = NumberRange.create(10, true, 20, true); NumberRange<Integer> r2 = NumberRange.create(15, true, 30, true); assertTrue (r1.equals(r1)); assertTrue (r2.equals(r2)); assertFalse(r1.equals(r2)); assertEquals(Integer.class, r1.getElementType()); assertEquals(Integer.class, r2.getElementType()); assertEquals(NumberRange.create(10, true, 30, true), r1.union(r2)); assertEquals(NumberRange.create(15, true, 20, true), r1.intersect(r2)); }