sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1446193 - in /sis/branches/JDK7/sis-utility/src: main/java/org/apache/sis/measure/ test/java/org/apache/sis/measure/
Date Thu, 14 Feb 2013 14:15:01 GMT
Author: desruisseaux
Date: Thu Feb 14 14:15:00 2013
New Revision: 1446193

URL: http://svn.apache.org/r1446193
Log:
Completed the new approach regarding parameterized type ("foo(…)" and "fooAny(…)" method
separation).

Modified:
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/MeasurementRange.java
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/NumberRange.java
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/Range.java
    sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/measure/MeasurementRangeTest.java
    sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/measure/RangeTest.java

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/MeasurementRange.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/MeasurementRange.java?rev=1446193&r1=1446192&r2=1446193&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/MeasurementRange.java
(original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/MeasurementRange.java
Thu Feb 14 14:15:00 2013
@@ -28,14 +28,20 @@ import java.util.Objects;
 
 
 /**
- * A range of numbers associated with a unit of measurement. Unit conversions are applied
as
- * needed by {@linkplain #union union} and {@linkplain #intersect intersection} operations.
+ * A range of numbers associated with a unit of measurement. All operations performed by
this
+ * class ({@linkplain #union union}, {@linkplain #intersect intersection}, <i>etc.</i>)
are
+ * performed in the units of measurement of {@code this} range object - values of the range
+ * object given in argument are converted if needed before an operation is applied.
  *
- * {@section Construction}
- * This class provides convenience {@code create(…)} static methods for every floating
point
- * primitive types. Usage of {@code MeasurementRange} with integer types is possible, but
no
- * convenience methods is provided for integers because they are usually not representative
- * of the nature of physical measurements.
+ * <p>Other methods defined in this class:</p>
+ * <ul>
+ *   <li>Convenience {@code create(…)} static methods for every floating point
primitive types.
+ *       Usage of {@code MeasurementRange} with integer types is possible, but no convenience
+ *       method is provided for integers because they are usually not representative of the
+ *       nature of physical measurements.</li>
+ *   <li>{@link #convertTo(Unit)} for converting the units of measurement.</li>
+ *   <li>{@link #castTo(Class)} for casting the range values to an other type.</li>
+ * </ul>
  *
  * @param <T> The type of range elements as a subclass of {@link Number}.
  *
@@ -53,6 +59,8 @@ public class MeasurementRange<T extends 
 
     /**
      * The units of measurement, or {@code null} if unknown.
+     *
+     * @see #getUnits()
      */
     private final Unit<?> units;
 
@@ -161,34 +169,32 @@ public class MeasurementRange<T extends 
     /**
      * Constructs a range of {@link Number} objects.
      *
-     * @param type          The element type, usually one of {@link Byte}, {@link Short},
-     *                      {@link Integer}, {@link Long}, {@link Float} or {@link Double}.
-     * @param minimum       The minimum value.
-     * @param maximum       The maximum value.
+     * @param type     The element type, usually one of {@link Float} or {@link Double}.
+     * @param minValue The minimum value, inclusive, or {@code null} if none.
+     * @param maxValue The maximum value, <strong>inclusive</strong>, or {@code
null} if none.
      * @param units         The units of measurement, or {@code null} if unknown.
      */
-    public MeasurementRange(final Class<T> type, final T minimum, final T maximum,
final Unit<?> units) {
-        super(type, minimum, maximum);
+    public MeasurementRange(final Class<T> type, final T minValue, final T maxValue,
final Unit<?> units) {
+        super(type, minValue, maxValue);
         this.units = units;
     }
 
     /**
      * Constructs a range of {@link Number} objects.
      *
-     * @param type          The element type, usually one of {@link Byte}, {@link Short},
-     *                      {@link Integer}, {@link Long}, {@link Float} or {@link Double}.
-     * @param minimum       The minimum value.
-     * @param isMinIncluded Defines whether the minimum value is included in the Range.
-     * @param maximum       The maximum value.
-     * @param isMaxIncluded Defines whether the maximum value is included in the Range.
+     * @param type          The element type, usually one of {@link Float} or {@link Double}.
+     * @param minValue      The minimal value, or {@code null} if none.
+     * @param isMinIncluded {@code true} if the minimal value is inclusive, or {@code false}
if exclusive.
+     * @param maxValue      The maximal value, or {@code null} if none.
+     * @param isMaxIncluded {@code true} if the maximal value is inclusive, or {@code false}
if exclusive.
      * @param units         The units of measurement, or {@code null} if unknown.
      */
     public MeasurementRange(final Class<T> type,
-                            final T minimum, final boolean isMinIncluded,
-                            final T maximum, final boolean isMaxIncluded,
+                            final T minValue, final boolean isMinIncluded,
+                            final T maxValue, final boolean isMaxIncluded,
                             final Unit<?> units)
     {
-        super(type, minimum, isMinIncluded, maximum, isMaxIncluded);
+        super(type, minValue, isMinIncluded, maxValue, isMaxIncluded);
         this.units = units;
     }
 
@@ -262,9 +268,9 @@ public class MeasurementRange<T extends 
      * @throws IllegalArgumentException if the given target unit is not compatible with
      *         the unit of this range.
      */
-    private Range<T> convert(final Range<T> range) throws IllegalArgumentException
{
+    private <N extends T> Range<N> convert(final Range<N> range) throws
IllegalArgumentException {
         if (range instanceof MeasurementRange<?>) try {
-            return ((MeasurementRange<T>) range).convertAndCast(elementType, units);
+            return ((MeasurementRange<N>) range).convertAndCast(range.elementType,
units);
         } catch (ConversionException e) {
             throw new IllegalArgumentException(Errors.format(Errors.Keys.IncompatibleUnits_2,
                     ((MeasurementRange<?>) range).units, units), e);
@@ -297,6 +303,8 @@ public class MeasurementRange<T extends 
 
     /**
      * Casts this range to the specified type and converts to the specified units.
+     * This method is invoked on the {@code other} instance in expressions like
+     * {@code this.operation(other)}.
      *
      * @param  type The class to cast to. Must be one of {@link Byte}, {@link Short},
      *             {@link Integer}, {@link Long}, {@link Float} or {@link Double}.
@@ -356,10 +364,36 @@ public class MeasurementRange<T extends 
      *         {@code MeasurementRange} using incommensurable units of measurement.
      */
     @Override
-    public MeasurementRange<T> union(final Range<T> range) throws IllegalArgumentException
{
-        return (MeasurementRange<T>) super.union(convert(range));
-        // Should never throw ClassCastException because super.union(Range) invokes create(...),
-        // convertAndCast(…) which is overridden in this class to create MeasurementRange.
+    public boolean contains(final Range<? extends T> range) throws IllegalArgumentException
{
+        return super.contains(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.
+     *
+     * @throws IllegalArgumentException is the given range is an instance of
+     *         {@code MeasurementRange} using incommensurable units of measurement.
+     */
+    @Override
+    public boolean intersects(final Range<? extends T> range) throws IllegalArgumentException
{
+        return super.intersects(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.
+     *
+     * @throws IllegalArgumentException is the given range is an instance of
+     *         {@code MeasurementRange} using incommensurable units of measurement.
+     */
+    @Override
+    public Range<T> intersect(final Range<T> range) throws IllegalArgumentException
{
+        return super.intersect(convert(range));
     }
 
     /**
@@ -372,10 +406,8 @@ public class MeasurementRange<T extends 
      *         {@code MeasurementRange} using incommensurable units of measurement.
      */
     @Override
-    public MeasurementRange<T> intersect(final Range<T> range) throws IllegalArgumentException
{
-        return (MeasurementRange<T>) super.intersect(convert(range));
-        // Should never throw ClassCastException because super.intersect(Range) invokes
-        // convertAndCast(…) which is overridden in this class to create MeasurementRange.
+    public Range<T> union(final Range<T> range) throws IllegalArgumentException
{
+        return super.union(convert(range));
     }
 
     /**
@@ -388,10 +420,8 @@ public class MeasurementRange<T extends 
      *         {@code MeasurementRange} using incommensurable units of measurement.
      */
     @Override
-    public MeasurementRange<T>[] subtract(final Range<T> range) throws IllegalArgumentException
{
-        return (MeasurementRange<T>[]) super.subtract(convert(range));
-        // Should never throw ClassCastException because super.subtract(Range) invokes newArray(int)
-        // convertAndCast(…) which is overridden in this class to create MeasurementRange.
+    public Range<T>[] subtract(final Range<T> range) throws IllegalArgumentException
{
+        return super.subtract(convert(range));
     }
 
     /**
@@ -401,8 +431,7 @@ public class MeasurementRange<T extends 
     public boolean equals(final Object object) {
         if (super.equals(object)) {
             if (object instanceof MeasurementRange<?>) {
-                final MeasurementRange<?> that = (MeasurementRange<?>) object;
-                return Objects.equals(this.units, that.units);
+                return Objects.equals(units, ((MeasurementRange<?>) object).units);
             }
             return true;
         }

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/NumberRange.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/NumberRange.java?rev=1446193&r1=1446192&r2=1446193&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/NumberRange.java (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/NumberRange.java Thu
Feb 14 14:15:00 2013
@@ -28,22 +28,28 @@ import org.apache.sis.util.resources.Err
  *
  * <p>Most operations in this class are defined in two versions:</p>
  * <ul>
- *   <li><p>Methods inherited from the {@code Range} parent class
+ *   <li>Methods inherited from the {@code Range} parent class
  *      ({@link #contains(Range) contains}, {@link #intersect(Range) intersect},
  *       {@link #intersects(Range) intersects}, {@link #union(Range) union} and
  *       {@link #subtract(Range) subtract}) requires argument or range elements
- *       of type {@code <T>}. No type conversion is performed.</p></li>
+ *       of type {@code <T>}. No type conversion is performed.</li>
  *
- *   <li><p>Methods defined in this class with the {@code Any} suffix
+ *   <li>Methods defined in this class with the {@code Any} suffix
  *      ({@link #containsAny(NumberRange) containsAny}, {@link #intersectAny(NumberRange)
intersectAny},
  *       {@link #intersectsAny(NumberRange) intersectsAny}, {@link #unionAny(NumberRange)
unionAny} and
  *       {@link #subtractAny(NumberRange) subtractAny}) are more lenient on the argument
or range element
- *       type {@code <T>}. Widening conversions are performed as needed.</p></li>
+ *       type {@code <T>}. Widening conversions are performed as needed.</li>
  * </ul>
  *
- * {@section Construction}
- * This class provides convenience {@code create(…)} static methods for every
- * numeric primitive types.
+ * The methods from the parent class are preferable when the ranges are known to contain
elements
+ * of the same type, since they avoid the cost of type checks and conversions. The method
in this
+ * class are convenient when the parameterized type is unknown ({@code <?>}).
+ *
+ * <p>Other methods defined in this class:</p>
+ * <ul>
+ *   <li>Convenience {@code create(…)} static methods for every numeric primitive
types.</li>
+ *   <li>{@link #castTo(Class)} for casting the range values to an other type.</li>
+ * </ul>
  *
  * @param <T> The type of range elements as a subclass of {@link Number}.
  *
@@ -263,18 +269,19 @@ public class NumberRange<T extends Numbe
     /**
      * Constructs a range using the smallest type of {@link Number} that can hold the
      * given values. The given numbers don't need to be of the same type since they will
-     * be {@linkplain Numbers#cast(Number, Class) casted} as needed. More specifically:
+     * be {@linkplain Numbers#cast(Number, Class) casted} as needed. More specifically
+     * this method returns:
      *
      * <ul>
-     *   <li>If the values are between {@value java.lang.Byte#MIN_VALUE} and
-     *       {@value java.lang.Byte#MAX_VALUE} inclusive, then the given values are converted
-     *       to {@link Byte} objects and a {@code NumberRange} is created from them.</li>
-     *   <li>Otherwise if the values are between {@value java.lang.Short#MIN_VALUE}
and
-     *       {@value java.lang.Short#MAX_VALUE} inclusive, then the given values are converted
-     *       to {@link Short} objects and a {@code NumberRange} is created from them.</li>
-     *   <li>Otherwise the {@link Integer} type is tested in the same way, then the
-     *       {@link Long} type, and finally the {@link Float} type.</li>
-     *   <li>If none of the above types is suitable, then the {@link Double} type is
used.</li>
+     *   <li>{@code NumberRange<Byte>} if the given values are integers between
+     *       {@value java.lang.Byte#MIN_VALUE} and {@value java.lang.Byte#MAX_VALUE} inclusive.</li>
+     *   <li>{@code NumberRange<Short>} if the given values are integers between
+     *       {@value java.lang.Short#MIN_VALUE} and {@value java.lang.Short#MAX_VALUE} inclusive.</li>
+     *   <li>{@code NumberRange<Integer>} if the given values are integers between
+     *       {@value java.lang.Integer#MIN_VALUE} and {@value java.lang.Integer#MAX_VALUE}
inclusive.</li>
+     *   <li>{@code NumberRange<Long>} if the given values are integers in the
range of {@code long} values.</li>
+     *   <li>{@code NumberRange<Float>} if the given values can be casted to
{@code float} values without data lost.</li>
+     *   <li>{@code NumberRange<Double>} If none of the above types is suitable.</li>
      * </ul>
      *
      * @param  minValue       The minimal value, or {@code null} if none.
@@ -295,16 +302,16 @@ public class NumberRange<T extends Numbe
     }
 
     /**
-     * Wraps the specified {@link Range} in a {@code NumberRange} object. If the specified
+     * Returns the specified {@link Range} as a {@code NumberRange} object. If the specified
      * range is already an instance of {@code NumberRange}, then it is returned unchanged.
      * Otherwise a new number range is created using the {@linkplain #NumberRange(Range)
      * copy constructor}.
      *
      * @param  <N> The type of elements in the given range.
-     * @param  range The range to wrap.
+     * @param  range The range to cast or copy.
      * @return The same range than {@code range} as a {@code NumberRange} object.
      */
-    public static <N extends Number & Comparable<? super N>> NumberRange<N>
wrap(final Range<N> range) {
+    public static <N extends Number & Comparable<? super N>> NumberRange<N>
castOrCopy(final Range<N> range) {
         if (range instanceof NumberRange<?>) {
             return (NumberRange<N>) range;
         }
@@ -603,7 +610,7 @@ public class NumberRange<T extends Numbe
     @SuppressWarnings({"unchecked","rawtypes"})
     public NumberRange<?> intersectAny(final NumberRange<?> range) throws IllegalArgumentException
{
         Class type = Numbers.widestClass(elementType, range.elementType);
-        final NumberRange<?> intersect = castTo(type).intersect(convertAndCast(range,
type));
+        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
@@ -616,16 +623,6 @@ public class NumberRange<T extends Numbe
     }
 
     /**
-     * {@inheritDoc}
-     */
-    @Override
-    public NumberRange<T> intersect(final Range<T> range) {
-        return (NumberRange<T>) super.intersect(range);
-        // Should never throw ClassCastException because super.intersect(Range) invokes
-        // convertAndCast(…),  which is overridden in this class to create NumberRange.
-    }
-
-    /**
      * 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)}.
@@ -638,17 +635,7 @@ public class NumberRange<T extends Numbe
     @SuppressWarnings({"unchecked","rawtypes"})
     public NumberRange<?> unionAny(final NumberRange<?> range) throws IllegalArgumentException
{
         final Class type = Numbers.widestClass(elementType, range.elementType);
-        return castTo(type).union(convertAndCast(range, type));
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public NumberRange<T> union(final Range<T> range) {
-        return (NumberRange<T>) super.union(range);
-        // Should never throw ClassCastException because super.union(Range) invokes
-        // convertAndCast(…),  which is overridden in this class to create NumberRange.
+        return castOrCopy(castTo(type).union(convertAndCast(range, type)));
     }
 
     /**
@@ -664,16 +651,6 @@ public class NumberRange<T extends Numbe
     @SuppressWarnings({"unchecked","rawtypes"})
     public NumberRange<?>[] subtractAny(final NumberRange<?> range) throws IllegalArgumentException
{
         final Class type = Numbers.widestClass(elementType, range.elementType);
-        return castTo(type).subtract(convertAndCast(range, type));
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public NumberRange<T>[] subtract(final Range<T> range) {
-        return (NumberRange<T>[]) super.subtract(range);
-        // Should never throw ClassCastException because super.subtract(Range) invokes
-        // convertAndCast(…),  which is overridden in this class to create NumberRange.
+        return (NumberRange[]) castTo(type).subtract(convertAndCast(range, type));
     }
 }

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/Range.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/Range.java?rev=1446193&r1=1446192&r2=1446193&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/Range.java (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/Range.java Thu Feb
14 14:15:00 2013
@@ -147,6 +147,12 @@ public class Range<T extends Comparable<
     /**
      * Creates a new range using the same element type than this range. This method will
      * be overridden by subclasses in order to create a range of a more specific type.
+     *
+     * {@note This method is invoked by all operations (union, intersection, <i>etc.</i>)
that may
+     * create a new range. But despite this fact, the return type of those methods are nailed
down
+     * to <code>Range</code> (i.e. subclasses shall not override the above-cited
operations with
+     * covariant return type) because those operations may return the given argument directly,
+     * and we have no guarantees on the type of those arguments.}
      */
     Range<T> create(final T minValue, final boolean isMinIncluded,
                     final T maxValue, final boolean isMaxIncluded)
@@ -155,8 +161,12 @@ public class Range<T extends Comparable<
     }
 
     /**
-     * Returns an initially empty array of the given length. To be overridden
-     * by subclasses in order to create arrays of more specific type.
+     * Returns an initially empty array of {@code getClass()} type and of the given length.
+     * This method is overridden by subclasses in order to create arrays of more specific
type.
+     * This method is invoked by the {@link #subtract(Range)} method. It is okay to use the
new
+     * array only if the ranges to store in that array are only {@code this} or new ranges
created
+     * by the {@link #create(Comparable, boolean, Comparable, boolean)} method - otherwise
we may
+     * get an {@link ArrayStoreException}.
      */
     @SuppressWarnings({"unchecked","rawtypes"}) // Generic array creation.
     Range<T>[] newArray(final int length) {
@@ -416,6 +426,10 @@ public class Range<T extends Comparable<
      *         for example because of incommensurable units of measurement.
      */
     public Range<T>[] subtract(final Range<T> range) {
+        /*
+         * Implementation note: never store the 'range' argument value in the array
+         * returned by 'newArray(int)', otherwise we may get an ArrayStoreException.
+         */
         final Range<T> subtract;
         if (!intersects(range)) {
             subtract = this;

Modified: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/measure/MeasurementRangeTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/measure/MeasurementRangeTest.java?rev=1446193&r1=1446192&r2=1446193&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/measure/MeasurementRangeTest.java
(original)
+++ sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/measure/MeasurementRangeTest.java
Thu Feb 14 14:15:00 2013
@@ -36,12 +36,12 @@ import static org.apache.sis.test.Assert
 @DependsOn(NumberRangeTest.class)
 public final strictfp class MeasurementRangeTest extends TestCase {
     /**
-     * Tests unit conversions.
+     * Tests unit conversions by the {@link MeasurementRange#convertTo(Unit)} method.
      *
      * @throws ConversionException Should not happen.
      */
     @Test
-    public void testConversion() throws ConversionException {
+    public void testConvertTo() throws ConversionException {
         final MeasurementRange<Float> range = MeasurementRange.create(1000f, 2000f,
SI.METRE);
         assertSame(range, range.convertTo(SI.METRE));
         assertEquals(MeasurementRange.create(1f, 2f, SI.KILOMETRE), range.convertTo(SI.KILOMETRE));
@@ -51,9 +51,9 @@ public final strictfp class MeasurementR
      * Tests union and intersection involving a unit conversion.
      */
     @Test
-    public void testIntersectWithConversion() {
-        NumberRange<Float> r1 = MeasurementRange.create(1000f, 2000f, SI.METRE);
-        NumberRange<Float> r2 = MeasurementRange.create(1.5f, 3f, SI.KILOMETRE);
+    public void testAutoConversions() {
+        final MeasurementRange<Float> r1 = MeasurementRange.create(1000f, 2000f, SI.METRE);
+        final MeasurementRange<Float> r2 = MeasurementRange.create(1.5f, 3f, SI.KILOMETRE);
         assertEquals(Float.class, r1.getElementType());
         assertEquals(Float.class, r2.getElementType());
         assertEquals(MeasurementRange.create(1000f, 3000f, SI.METRE ),    r1.union    (r2));
@@ -63,6 +63,19 @@ public final strictfp class MeasurementR
     }
 
     /**
+     * Same tests than {@link #testAutoConversions()} but using the {@code *Any} methods.
+     */
+    @Test
+    public void testAutoConversionsOfAny() {
+        final MeasurementRange<?> r1 = MeasurementRange.create(1000f, 2000f, SI.METRE);
+        final MeasurementRange<?> r2 = MeasurementRange.create(1.5f, 3f, SI.KILOMETRE);
+        assertEquals(MeasurementRange.create(1000f, 3000f, SI.METRE ),    r1.unionAny   
(r2));
+        assertEquals(MeasurementRange.create(1f,    3f,    SI.KILOMETRE), r2.unionAny   
(r1));
+        assertEquals(MeasurementRange.create(1500f, 2000f, SI.METRE ),    r1.intersectAny(r2));
+        assertEquals(MeasurementRange.create(1.5f,  2f,    SI.KILOMETRE), r2.intersectAny(r1));
+    }
+
+    /**
      * Tests {@link MeasurementRange#toString()} method.
      */
     @Test

Modified: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/measure/RangeTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/measure/RangeTest.java?rev=1446193&r1=1446192&r2=1446193&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/measure/RangeTest.java (original)
+++ sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/measure/RangeTest.java Thu
Feb 14 14:15:00 2013
@@ -280,6 +280,19 @@ public final strictfp class RangeTest ex
     }
 
     /**
+     * Tests the {@link Range#subtract(Range)} method.
+     */
+    @Test
+    public void testSubtract() {
+        final Range<Integer> range1 = new Range<>(Integer.class, 10, 40);
+        final Range<Integer> range2 = new Range<>(Integer.class, 20, 25);
+        final Range<Integer>[] subtract = range1.subtract(range2);
+        assertEquals(2, subtract.length);
+        assertEquals(new Range<>(Integer.class, 10, true,  20, false), subtract[0]);
+        assertEquals(new Range<>(Integer.class, 25, false, 40, true),  subtract[1]);
+    }
+
+    /**
      * Tests the {@link Range#equals(Object)} method.
      */
     @Test



Mime
View raw message