sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1446211 [2/2] - in /sis/branches/JDK6: ./ sis-utility/src/main/java/org/apache/sis/measure/ sis-utility/src/main/java/org/apache/sis/util/collection/ sis-utility/src/test/java/org/apache/sis/measure/
Date Thu, 14 Feb 2013 14:43:48 GMT
Modified: sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/measure/RangeFormat.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/measure/RangeFormat.java?rev=1446211&r1=1446210&r2=1446211&view=diff
==============================================================================
--- sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/measure/RangeFormat.java (original)
+++ sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/measure/RangeFormat.java Thu
Feb 14 14:43:47 2013
@@ -84,7 +84,7 @@ public class RangeFormat extends Format 
     private static final int MAX_VALUE_FIELD = 1;
 
     /**
-     * The constant value for {@link FieldPosition} which designate the units of measurement.
+     * The constant value for {@link FieldPosition} which designate the unit of measurement.
      *
      * @see Field#UNIT
      */
@@ -230,7 +230,7 @@ public class RangeFormat extends Format 
     protected final Format elementFormat;
 
     /**
-     * The format for units of measurement, or {@code null} if none. This is non-null if
and
+     * The format for unit of measurement, or {@code null} if none. This is non-null if and
      * only if {@link #elementType} is assignable to {@link Number} but not to {@link Angle}.
      */
     protected final UnitFormat unitFormat;
@@ -267,7 +267,7 @@ public class RangeFormat extends Format 
 
     /**
      * Creates a new format for parsing and formatting {@linkplain Range ranges} of
-     * the given element class using the given locale. The element class is typically
+     * the given element type using the given locale. The element type is typically
      * {@code Date.class} or some subclass of {@code Number.class}.
      *
      * @param  locale The locale for parsing and formatting range components.
@@ -494,7 +494,7 @@ public class RangeFormat extends Format 
             switch (field) {
                 case MIN_VALUE_FIELD: value = minValue; break;
                 case MAX_VALUE_FIELD: value = maxValue; break;
-                case UNIT_FIELD:      value = range.getUnits(); break;
+                case UNIT_FIELD:      value = range.unit(); break;
                 default: throw new AssertionError(field);
             }
             int startPosition = toAppendTo.length();
@@ -812,7 +812,7 @@ public class RangeFormat extends Format 
         }
         /*
          * Parses the unit, if any. The units are always optional: if we can not parse
-         * them, then we will consider that the parsing stopped before the units.
+         * them, then we will consider that the parsing stopped before the unit.
          */
         Unit<?> unit = null;
         if (unitFormat != null) {

Modified: sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/BackingStoreException.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/BackingStoreException.java?rev=1446211&r1=1446210&r2=1446211&view=diff
==============================================================================
--- sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/BackingStoreException.java
(original)
+++ sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/BackingStoreException.java
Thu Feb 14 14:43:47 2013
@@ -41,6 +41,13 @@ import java.sql.SQLException;
  *     }
  * }
  *
+ * {@section Relationship with <code>java.io.UncheckedIOException</code>}
+ * JDK8 provides a {@link java.io.UncheckedIOException} which partially overlaps
+ * the purpose of this {@code BackingStoreException}. While Apache SIS still uses
+ * {@code BackingStoreException} as a general mechanism for any kind of checked
+ * exceptions, client code targeting JDK8 would be well advised to catch both kind
+ * of exceptions for robustness.
+ *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @since   0.3 (derived from geotk-2.3)
  * @version 0.3

Modified: sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/measure/MeasurementRangeTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/measure/MeasurementRangeTest.java?rev=1446211&r1=1446210&r2=1446211&view=diff
==============================================================================
--- sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/measure/MeasurementRangeTest.java
(original)
+++ sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/measure/MeasurementRangeTest.java
Thu Feb 14 14:43:47 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/JDK6/sis-utility/src/test/java/org/apache/sis/measure/NumberRangeTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/measure/NumberRangeTest.java?rev=1446211&r1=1446210&r2=1446211&view=diff
==============================================================================
--- sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/measure/NumberRangeTest.java
(original)
+++ sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/measure/NumberRangeTest.java
Thu Feb 14 14:43:47 2013
@@ -39,19 +39,19 @@ public final strictfp class NumberRangeT
     @Test
     public void testIntegerBounds() {
         final NumberRange<Integer> range = NumberRange.create(10, 20);
-        assertEquals(10, range.getMinimum(     ), 0);
-        assertEquals(10, range.getMinimum(true ), 0);
-        assertEquals( 9, range.getMinimum(false), 0);
-        assertEquals(20, range.getMaximum(     ), 0);
-        assertEquals(20, range.getMaximum(true ), 0);
-        assertEquals(21, range.getMaximum(false), 0);
+        assertEquals(10, range.getMinDouble(     ), 0);
+        assertEquals(10, range.getMinDouble(true ), 0);
+        assertEquals( 9, range.getMinDouble(false), 0);
+        assertEquals(20, range.getMaxDouble(     ), 0);
+        assertEquals(20, range.getMaxDouble(true ), 0);
+        assertEquals(21, range.getMaxDouble(false), 0);
     }
 
     /**
-     * Tests union and intersection without units and type change.
+     * Tests union and intersection with {@link Integer} values.
      */
     @Test
-    public void testIntegerIntersect() {
+    public void testWithIntegers() {
         NumberRange<Integer> r1 = NumberRange.create(10, 20);
         NumberRange<Integer> r2 = NumberRange.create(15, 30);
         assertTrue (r1.equals(r1));
@@ -64,10 +64,10 @@ public final strictfp class NumberRangeT
     }
 
     /**
-     * Tests union and intersection with type change.
+     * Tests union and intersection with {@link Double} values.
      */
     @Test
-    public void testDoubleIntersect() {
+    public void testWithDoubles() {
         NumberRange<Double> r1 = NumberRange.create(10.0, 20.0);
         NumberRange<Double> r2 = NumberRange.create(15.0, 30.0);
         assertEquals(Double.class, r1.getElementType());
@@ -77,39 +77,39 @@ public final strictfp class NumberRangeT
     }
 
     /**
-     * Tests union and intersection with type change.
+     * Tests union and intersection involving a cast from integer to double values.
      */
     @Test
-    public void testIntegerDoubleIntersect() {
+    public void testIntegerWithDoubleArguments() {
         NumberRange<Integer> r1 = NumberRange.create(10, 20);
         NumberRange<Double>  r2 = NumberRange.create(15.0, 30.0);
         assertEquals(Integer.class, r1.getElementType());
         assertEquals(Double .class, r2.getElementType());
-        assertEquals(NumberRange.create(10.0, 30.0), r1.union(r2));
-        assertEquals(NumberRange.create(15, 20), r1.intersect(r2));
+        assertEquals(NumberRange.create(10.0, 30.0), r1.unionAny(r2));
+        assertEquals(NumberRange.create(15, 20), r1.intersectAny(r2));
 
         r2 = NumberRange.create(15.5, 30.0);
-        assertEquals(NumberRange.create(15.5f, 20.0f), r1.intersect(r2));
+        assertEquals(NumberRange.create(15.5f, 20.0f), r1.intersectAny(r2));
     }
 
     /**
-     * Tests union and intersection with type change.
+     * Tests union and intersection involving a cast from integer to double values.
      */
     @Test
-    public void testDoubleIntegerIntersect() {
+    public void testDoubleWithIntegerArguments() {
         NumberRange<Double>  r1 = NumberRange.create(10.0, 20.0);
         NumberRange<Integer> r2 = NumberRange.create(15, 30);
         assertEquals(Double .class, r1.getElementType());
         assertEquals(Integer.class, r2.getElementType());
-        assertEquals(NumberRange.create(10.0, 30.0), r1.union(r2));
-        assertEquals(NumberRange.create(15, 20), r1.intersect(r2));
+        assertEquals(NumberRange.create(10.0, 30.0), r1.unionAny(r2));
+        assertEquals(NumberRange.create(15, 20), r1.intersectAny(r2));
 
         r1 = NumberRange.create(10.0, 20.5);
-        assertEquals(NumberRange.create(15.0f, 20.5f), r1.intersect(r2));
+        assertEquals(NumberRange.create(15.0f, 20.5f), r1.intersectAny(r2));
     }
 
     /**
-     * Tests the {@link NumberRange#createBestFit} method.
+     * Tests the {@link NumberRange#createBestFit(Number, boolean, Number, boolean)} method.
      */
     @Test
     public void testCreateBestFit() {

Modified: sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/measure/RangeFormatTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/measure/RangeFormatTest.java?rev=1446211&r1=1446210&r2=1446211&view=diff
==============================================================================
--- sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/measure/RangeFormatTest.java
(original)
+++ sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/measure/RangeFormatTest.java
Thu Feb 14 14:43:47 2013
@@ -19,7 +19,6 @@ package org.apache.sis.measure;
 import java.util.Date;
 import java.util.Locale;
 import java.util.TimeZone;
-import java.text.Format;
 import java.text.DateFormat;
 import java.text.FieldPosition;
 import java.text.ParsePosition;

Modified: sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/measure/RangeTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/measure/RangeTest.java?rev=1446211&r1=1446210&r2=1446211&view=diff
==============================================================================
--- sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/measure/RangeTest.java (original)
+++ sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/measure/RangeTest.java Thu
Feb 14 14:43:47 2013
@@ -19,6 +19,7 @@ package org.apache.sis.measure;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
 
+import static org.junit.Assume.*;
 import static org.apache.sis.test.Assert.*;
 
 
@@ -75,10 +76,13 @@ public final strictfp class RangeTest ex
      * Note that such error should never happen when parameterized types are used.
      * The check performed by the constructor is a safety in case the user bypass
      * the parameterized type check by using the raw type instead.
+     *
+     * <p>This test requires assertions to be enabled.</p>
      */
     @Test(expected = IllegalArgumentException.class)
     @SuppressWarnings({"unchecked", "rawtypes"})
     public void testConstructorErrors00() {
+        assumeTrue(Range.class.desiredAssertionStatus());
         new Range(Double.class, "error", "blast");
     }
 
@@ -87,10 +91,13 @@ public final strictfp class RangeTest ex
      * Note that such error should never happen when parameterized types are used.
      * The check performed by the constructor is a safety in case the user bypass
      * the parameterized type check by using the raw type instead.
+     *
+     * <p>This test requires assertions to be enabled.</p>
      */
     @Test(expected = IllegalArgumentException.class)
     @SuppressWarnings({"unchecked", "rawtypes"})
     public void testConstructorErrors01() {
+        assumeTrue(Range.class.desiredAssertionStatus());
         new Range(String.class, 123.233, 8740.09);
     }
 
@@ -203,28 +210,6 @@ public final strictfp class RangeTest ex
     }
 
     /**
-     * Tests the {@link Range#contains(Range)} method with a range of incompatible type.
-     */
-    @Test(expected = IllegalArgumentException.class)
-    public void testIncompatibleTypeRangeContains() {
-        final Range<Integer> intRange = new Range<Integer>(Integer.class, 0,
10);
-        final Range<Double> doubleRange = new Range<Double>(Double.class, 2.0,
5.0);
-
-        intRange.contains(doubleRange);
-    }
-
-    /**
-     * Tests the {@link Range#contains(Range)} method with a range of incompatible type.
-     */
-    @Test(expected = IllegalArgumentException.class)
-    public void testIncompatibleTypeContains() {
-        final Range<Integer> intRange = new Range<Integer>(Integer.class, 0,
10);
-        final Range<Double> doubleRange = new Range<Double>(Double.class, 2.0,
5.0);
-
-        intRange.contains(doubleRange);
-    }
-
-    /**
      * Tests the {@link Range#intersects(Range)} method.
      */
     @Test
@@ -240,17 +225,6 @@ public final strictfp class RangeTest ex
     }
 
     /**
-     * Tests the {@link Range#intersects(Range)} method with a range of incompatible type.
-     */
-    @Test(expected = IllegalArgumentException.class)
-    public void testIntersectsIncompatibleTypes() {
-        final Range<Character> range1 = new Range<Character>(Character.class,
'a', 'g');
-        final Range<Integer>   range2 = new Range<Integer>(Integer.class, 5,
7);
-
-        range1.intersects(range2);
-    }
-
-    /**
      * Tests the {@link Range#intersect(Range)} method.
      */
     @Test
@@ -306,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>(Integer.class, 10, 40);
+        final Range<Integer> range2 = new Range<Integer>(Integer.class, 20, 25);
+        final Range<Integer>[] subtract = range1.subtract(range2);
+        assertEquals(2, subtract.length);
+        assertEquals(new Range<Integer>(Integer.class, 10, true,  20, false), subtract[0]);
+        assertEquals(new Range<Integer>(Integer.class, 25, false, 40, true),  subtract[1]);
+    }
+
+    /**
      * Tests the {@link Range#equals(Object)} method.
      */
     @Test



Mime
View raw message