sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1447736 - in /sis/branches/JDK7/sis-utility/src: main/java/org/apache/sis/measure/ test/java/org/apache/sis/measure/
Date Tue, 19 Feb 2013 14:37:18 GMT
Author: desruisseaux
Date: Tue Feb 19 14:37:17 2013
New Revision: 1447736

URL: http://svn.apache.org/r1447736
Log:
Explain in the documentation the relationship with the ISO 19123 definition of "ranges".
Also make the string representation closer to the ISO 31-11 standard.

Modified:
    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/main/java/org/apache/sis/measure/RangeFormat.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/RangeFormatTest.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/NumberRange.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/NumberRange.java?rev=1447736&r1=1447735&r2=1447736&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 Tue
Feb 19 14:37:17 2013
@@ -26,7 +26,9 @@ import org.apache.sis.util.resources.Err
  * {@code NumberRange} has no unit of measurement. For a range of physical measurements
  * with unit of measure, see {@link MeasurementRange}.
  *
- * <p>Most operations in this class are defined in two versions:</p>
+ * <p>{@code NumberRange} has some capability to convert different number types before
to
+ * perform operations. In order to provide both this flexibility and the safety of generic
+ * types, most operations in this class are defined in two versions:</p>
  * <ul>
  *   <li>Methods inherited from the {@code Range} parent class
  *      ({@link #contains(Range) contains}, {@link #intersect(Range) intersect},
@@ -51,6 +53,14 @@ import org.apache.sis.util.resources.Err
  *   <li>{@link #castTo(Class)} for casting the range values to an other type.</li>
  * </ul>
  *
+ * {@section Relationship with standards}
+ * {@code NumberRange} is the SIS class closest to the
+ * <a href="http://en.wikipedia.org/wiki/Interval_%28mathematics%29">mathematical definition
of interval</a>.
+ * It is closely related, while not identical, to the ISO 19123 (<cite>Coverage geometry
and functions</cite>)
+ * definition of "ranges". At the difference of the parent {@link Range} class, which can
be used only with
+ * {@linkplain org.opengis.coverage.DiscreteCoverage discrete coverages}, the {@code NumberRange}
class can
+ * also be used with {@linkplain org.opengis.coverage.ContinuousCoverage continuous coverages}.
+ *
  * @param <E> The type of range elements as a subclass of {@link Number}.
  *
  * @author  Martin Desruisseaux (IRD)
@@ -61,6 +71,7 @@ import org.apache.sis.util.resources.Err
  *
  * @see RangeFormat
  * @see org.apache.sis.util.collection.RangeSet
+ * @see <a href="http://en.wikipedia.org/wiki/Interval_%28mathematics%29">Wikipedia:
Interval</a>
  */
 @Immutable
 public class NumberRange<E extends Number & Comparable<? super E>> extends
Range<E> {

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=1447736&r1=1447735&r2=1447736&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 Tue Feb
19 14:37:17 2013
@@ -40,16 +40,29 @@ import java.util.Objects;
  * {@section Type and value of range elements}
  * To be a member of a {@code Range}, the {@code <E>} type defining the range must
implement the
  * {@link Comparable} interface. All argument values given to the methods of this class shall
be
- * or contain instances of the same {@code <E>} type. The type is enforced by parameterized
type,
+ * or contain instances of that {@code <E>} type. The type is enforced by parameterized
type,
  * but some subclasses may put additional constraints. For example {@link MeasurementRange}
will
- * additionally checks the units of measurement. Every methods defined in this class may
throw
- * an {@link IllegalArgumentException} if a given argument does not meet a constraint other
than
- * the type.
+ * additionally checks the units of measurement. Consequently every methods defined in this
class
+ * may throw an {@link IllegalArgumentException} if a given argument does not meet some constraint
+ * beyond the type.
  *
- * {@section String representation}
- * The {@linkplain #toString() string representation} of a {@code Range} is defined
- * in a locale-insensitive way. In order to format a range using a different locale,
- * or for parsing a range, use {@link RangeFormat}.
+ * {@section Relationship with ISO 19123 definition of range}
+ * The ISO 19123 standard (<cite>Coverage geometry and functions</cite>) defines
the range as the set
+ * (either finite or {@linkplain org.opengis.geometry.TransfiniteSet transfinite}) of feature
attribute
+ * values associated by a function (the {@linkplain org.opengis.coverage.Coverage coverage})
with the
+ * elements of the coverage domain. In other words, if we see a coverage as a function, then
a range
+ * is the set of possible return values.
+ *
+ * <p>The characteristics of the spatial domain are defined by the ISO 19123 standard
whereas the
+ * characteristics of the attribute range are not part of that standard. In Apache SIS, those
+ * characteristics are described by the {@link org.apache.sis.coverage.SampleDimension} class,
+ * which may contain one or many {@code Range} instances. Consequently this {@code Range}
class
+ * is closely related, but not identical, to the ISO 19123 definition or range.</p>
+ *
+ * <p>Ranges are not necessarily numeric. Numeric and non-numeric ranges can be associated
to
+ * {@linkplain org.opengis.coverage.DiscreteCoverage discrete coverages}, while typically
only
+ * numeric ranges can be associated to {@linkplain org.opengis.coverage.ContinuousCoverage
+ * continuous coverages}.</p>
  *
  * @param <E> The type of range elements, typically a {@link Number} subclass or {@link
java.util.Date}.
  *
@@ -579,57 +592,55 @@ public class Range<E extends Comparable<
     }
 
     /**
-     * Returns a string representation of this range.
-     * The string representation is defined as below:
+     * Returns a unlocalized string representation of this range. This method complies to
the format
+     * described in the <a href="http://en.wikipedia.org/wiki/ISO_31-11">ISO 31-11</a>
standard,
+     * except that the minimal and maximal values are separated by the "{@code …}" character
+     * instead than coma. More specifically, the string representation is defined as below:
      *
      * <ul>
-     *   <li>If the range is empty, then this method returns {@code "[]"}.</li>
-     *   <li>Otherwise if the minimal value is equals to the maximal value, then
-     *       the string representation of that value is returned directly.</li>
-     *   <li>Otherwise the string representation of the minimal and maximal values
-     *       are formatted like {@code [min … max]} for inclusive bounds or
-     *       {@code (min … max)} for exclusive bounds, or a mix of both styles.
-     *       The ∞ symbol is used in place of {@code min} or {@code max} for
-     *       unbounded ranges.</li>
+     *   <li>If the range {@linkplain #isEmpty() is empty}, then this method returns
"{@code {}}".</li>
+     *   <li>Otherwise if the minimal value is equals to the maximal value, then the
string
+     *       representation of that value is returned inside braces as in "{@code {value}}".</li>
+     *   <li>Otherwise the string representation of the minimal and maximal values
are formatted
+     *       like "{@code [min … max]}" for inclusive bounds or "{@code (min …
max)}" for exclusive
+     *       bounds, or a mix of both styles. The "{@code ∞}" symbol is used in place
of
+     *       {@code min} or {@code max} for unbounded ranges.</li>
      * </ul>
      *
-     * If this range is a {@link MeasurementRange}, then the unit of measurement is
-     * appended to the above string representation.
+     * If this range is a {@link MeasurementRange}, then the {@linkplain Unit unit of measurement}
+     * is appended to the above string representation except for empty ranges.
      *
      * @see RangeFormat
+     * @see <a href="http://en.wikipedia.org/wiki/ISO_31-11">Wikipedia: ISO 31-11</a>
      */
     @Override
     public String toString() {
         if (isEmpty()) {
-            return "[]";
-        }
-        if (minValue != null && minValue.equals(maxValue)) {
-            String value = minValue.toString();
-            final Unit<?> unit = unit();
-            if (unit != null) {
-                value = value + ' ' + unit;
-            }
-            return value;
+            return "{}";
         }
         final StringBuilder buffer = new StringBuilder(20);
-        buffer.append(isMinIncluded ? '[' : '(');
-        if (minValue == null) {
-            buffer.append("−∞");
-        } else {
-            buffer.append(minValue);
-        }
-        // Compact representation for integers, more space for real numbers.
-        if (Numbers.isInteger(elementType) && isCompact(minValue, false) &&
isCompact(maxValue, true)) {
-            buffer.append('…');
-        } else {
-            buffer.append(" … ");
-        }
-        if (maxValue == null) {
-            buffer.append('∞');
+        if (minValue != null && minValue.equals(maxValue)) {
+            buffer.append('{').append(minValue).append('}');
         } else {
-            buffer.append(maxValue);
+            buffer.append(isMinIncluded ? '[' : '(');
+            if (minValue == null) {
+                buffer.append("−∞");
+            } else {
+                buffer.append(minValue);
+            }
+            // Compact representation for integers, more space for real numbers.
+            if (Numbers.isInteger(elementType) && isCompact(minValue, false) &&
isCompact(maxValue, true)) {
+                buffer.append('…');
+            } else {
+                buffer.append(" … ");
+            }
+            if (maxValue == null) {
+                buffer.append('∞');
+            } else {
+                buffer.append(maxValue);
+            }
+            buffer.append(isMaxIncluded ? ']' : ')');
         }
-        buffer.append(isMaxIncluded ? ']' : ')');
         final Unit<?> unit = unit();
         if (unit != null) {
             buffer.append(' ').append(unit);

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/RangeFormat.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/RangeFormat.java?rev=1447736&r1=1447735&r2=1447736&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/RangeFormat.java (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/RangeFormat.java Tue
Feb 19 14:37:17 2013
@@ -38,17 +38,51 @@ import org.apache.sis.util.resources.Err
 
 
 /**
- * Parses and formats {@linkplain Range ranges} of the given type. The kind of ranges created
- * by the {@code parse} method is determined by the class of range elements:
+ * Parses and formats {@linkplain Range ranges} in the given locale for the given type.
+ * This class complies to the format described in the <a href="http://en.wikipedia.org/wiki/ISO_31-11">ISO
31-11</a>
+ * standard, except that the minimal and maximal values are separated by the "{@code …}"
character
+ * instead than coma. More specifically, the format is defined as below:
  *
  * <ul>
- *   <li>If the elements type is assignable to {@link Date}, then the {@code parse}
method
+ *   <li>If the range {@linkplain Range#isEmpty() is empty}, then the range is represented
by "{@code {}}".</li>
+ *   <li>Otherwise if the {@linkplain Range#getMinValue() minimal value} is equals
to the
+ *       {@linkplain Range#getMaxValue() maximal value}, then that single value is formatted
+ *       inside braces as in "{@code {value}}".</li>
+ *   <li>Otherwise the minimal and maximal values are formatted inside bracket or parenthesis,
+ *       depending on whether each bound is inclusive or exclusive:
+ *     <ul>
+ *       <li>"{@code [min … max]}" if both bounds are inclusive;</li>
+ *       <li>"{@code (min … max)}" if both bounds are exclusive;</li>
+ *       <li>or a mix of both styles if a bound is inclusive while the other is exclusive.</li>
+ *     </ul>
+ *     The "{@code ∞}" symbol is used in place of {@code min} or {@code max} for unbounded
ranges.</li>
+ * </ul>
+ *
+ * If the range to format is an instance of {@link MeasurementRange}, then the
+ * {@linkplain Unit unit of measurement} is appended except for empty ranges.
+ *
+ * {@section Lenient parsing}
+ * At parsing time, the above formatting rules are relaxed as below:
+ *
+ * <ul>
+ *   <li>Empty ranges can be represented by "{@code []}"or "{@code ()}" in addition
to the
+ *       standard "{@code {}}".</li>
+ *   <li>The braces are optional for singleton values, i.e. "{@code value}" is accepted
+ *       as well as "{@code {value}}".</li>
+ * </ul>
+ *
+ * {@section Range type and type of range elements}
+ * The kind of ranges created by the {@link #parse(String) parse(…)} methods is determined
+ * by the class of range elements:
+ *
+ * <ul>
+ *   <li>If the elements type is assignable to {@link Date}, then the {@code parse(…)}
methods
  *       will create {@code Range<Date>} objects.</li>
  *   <li>If the elements type is assignable to {@link Number}, then:
  *     <ul>
- *       <li>If the text to parse contains a {@linkplain Unit unit} of measure, then
- *           the {@code parse} method will create {@link MeasurementRange} objects.</li>
- *       <li>Otherwise the {@code parse} method will create {@link NumberRange} objects.</li>
+ *       <li>If the text to parse contains a {@linkplain Unit unit of measure}, then
+ *           the {@code parse(…)} methods will create {@link MeasurementRange} objects.</li>
+ *       <li>Otherwise the {@code parse(…)} methods will create {@link NumberRange}
objects.</li>
  *     </ul>
  *   </li>
  * </ul>
@@ -58,9 +92,8 @@ import org.apache.sis.util.resources.Err
  * @version 0.3
  * @module
  *
- * @see Range
- * @see NumberRange
- * @see MeasurementRange
+ * @see Range#toString()
+ * @see <a href="http://en.wikipedia.org/wiki/ISO_31-11">Wikipedia: ISO 31-11</a>
  */
 public class RangeFormat extends Format {
     /**
@@ -147,6 +180,12 @@ public class RangeFormat extends Format 
     }
 
     /**
+     * The character opening an empty range or a range containing only one element.
+     * The default value is {@code '{'}.
+     */
+    private final char openSet;
+
+    /**
      * The character opening a range in which the minimal value is inclusive.
      * The default value is {@code '['}.
      */
@@ -167,6 +206,12 @@ public class RangeFormat extends Format 
     private final char openExclusiveAlt;
 
     /**
+     * The character closing an empty range or a range containing only one element.
+     * The default value is {@code '}'}.
+     */
+    private final char closeSet;
+
+    /**
      * The character closing a range in which the maximal value is inclusive.
      * The default value is {@code ']'}.
      */
@@ -295,9 +340,11 @@ public class RangeFormat extends Format 
         }
         minusSign         = ds.getMinusSign();
         infinity          = ds.getInfinity();
+        openSet           = '{';
         openInclusive     = '['; // Future SIS version may determine those characters from
the locale.
         openExclusive     = '('; // We may also provide an 'applyPattern(String)' method
for setting those char.
         openExclusiveAlt  = ']';
+        closeSet          = '}';
         closeInclusive    = ']';
         closeExclusive    = ')';
         closeExclusiveAlt = '[';
@@ -414,19 +461,7 @@ public class RangeFormat extends Format 
 
     /**
      * Formats a {@link Range} and appends the resulting text to a given string buffer.
-     * This method formats then given range as below:
-     *
-     * <ul>
-     *   <li>If the range is empty, then this method appends {@code "[]"}.</li>
-     *   <li>Otherwise if the minimal value is equals to the maximal value, then
-     *       that value is formatted alone.</li>
-     *   <li>Otherwise the minimal and maximal values are formatted like {@code [min
… max]} for
-     *       inclusive bounds or {@code (min … max)} for exclusive bounds, or a mix
of both styles.
-     *       The ∞ symbol is used in place of {@code min} or {@code max} for unbounded
ranges.</li>
-     * </ul>
-     *
-     * If the given range is a {@link MeasurementRange}, then the unit of measurement is
-     * appended to the above string representation.
+     * See the <a href="#skip-navbar_top">class javadoc</a> for a description
of the format.
      *
      * @param  range      The {@link Range} object to format.
      * @param  toAppendTo Where the text is to be appended.
@@ -455,18 +490,18 @@ public class RangeFormat extends Format 
             final AttributedCharacterIterator characterIterator)
     {
         /*
-         * Special case for an empty range. This is typically formatted as "[]". The field
+         * Special case for an empty range. This is typically formatted as "{}". The field
          * position is unconditionally set to the empty substring inside the brackets.
          */
         int fieldPos = getField(pos);
         if (range.isEmpty()) {
-            toAppendTo.append(openInclusive);
+            toAppendTo.append(openSet);
             if (fieldPos >= MIN_VALUE_FIELD && fieldPos <= UNIT_FIELD) {
                 final int p = toAppendTo.length();
                 pos.setBeginIndex(p); // First index, inclusive.
                 pos.setEndIndex  (p); // Last index, exclusive
             }
-            toAppendTo.append(closeInclusive);
+            toAppendTo.append(closeSet);
             return;
         }
         /*
@@ -478,16 +513,15 @@ public class RangeFormat extends Format 
         final Comparable<?> minValue = range.getMinValue();
         final Comparable<?> maxValue = range.getMaxValue();
         final boolean isSingleton = (minValue != null) && minValue.equals(maxValue);
-        int field;
+        int field = MIN_VALUE_FIELD;
         if (isSingleton) {
             if (fieldPos == MIN_VALUE_FIELD) {
                 fieldPos = MAX_VALUE_FIELD;
             }
             field = MAX_VALUE_FIELD;
-        } else {
-            field = MIN_VALUE_FIELD;
-            toAppendTo.append(range.isMinIncluded() ? openInclusive : openExclusive);
         }
+        toAppendTo.append(isSingleton ? openSet :
+                range.isMinIncluded() ? openInclusive : openExclusive);
         for (; field <= UNIT_FIELD; field++) {
             final Object value;
             switch (field) {
@@ -535,9 +569,8 @@ public class RangeFormat extends Format 
                     break;
                 }
                 case MAX_VALUE_FIELD: {
-                    if (!isSingleton) {
-                        toAppendTo.append(range.isMaxIncluded() ? closeInclusive : closeExclusive);
-                    }
+                    toAppendTo.append(isSingleton ? closeSet :
+                            range.isMaxIncluded() ? closeInclusive : closeExclusive);
                     break;
                 }
             }
@@ -690,31 +723,67 @@ public class RangeFormat extends Format 
             c = source.codePointAt(index);
             if (!Character.isWhitespace(c)) break;
         }
-        /*
-         * Get the minimal and maximal values, and whatever they are inclusive or exclusive.
-         */
         final Object minValue, maxValue;
         final boolean isMinIncluded, isMaxIncluded;
         if (!isOpen(c)) {
             /*
-             * No bracket. Assume that we have a single value for the range.
+             * No bracket, or curly bracket. We have eigher an empty range (as in "{}")
+             * or a single value for the range. The braces are optional for single value.
+             * In other words, this block parses all of the following cases:
+             *
+             *  - {}
+             *  - {value}
+             *  - value         (not standard, but accepted by this parser)
              */
-            pos.setIndex(index);
-            final Object value = elementFormat.parseObject(source, pos);
-            if (value == null) {
-                return null;
+            final boolean hasBraces = (c == openSet);
+            if (hasBraces) {
+                // Skip the opening brace and following whitespaces.
+                while ((index += Character.charCount(c)) < length) {
+                    c = source.codePointAt(index);
+                    if (!Character.isWhitespace(c)) break;
+                }
+            }
+            if (hasBraces && c == closeSet) {
+                // Empty range represented by {}
+                minValue = maxValue = valueOfNil();
+            } else {
+                // Singleton value, with or without braces.
+                pos.setIndex(index);
+                final Object value = elementFormat.parseObject(source, pos);
+                if (value == null) {
+                    return null;
+                }
+                pos.setErrorIndex(index); // In case of failure during the conversion.
+                minValue = maxValue = convert(value);
+                index = pos.getIndex();
+            }
+            if (hasBraces) {
+                // Skip whitespaces, then skip the closing brace.
+                // Absence of closing brace is considered an error.
+                for (;; index += Character.charCount(c)) {
+                    if (index < length) {
+                        c = source.codePointAt(index);
+                        if (Character.isWhitespace(c)) {
+                            continue;
+                        }
+                        if (c == closeSet) {
+                            break;
+                        }
+                    }
+                    pos.setErrorIndex(length);
+                    return null;
+                }
             }
-            pos.setErrorIndex(index); // In case of failure during the conversion.
-            minValue = maxValue = convert(value);
             isMinIncluded = isMaxIncluded = true;
-            index = pos.getIndex();
         } else {
             /*
              * We found an opening bracket. Skip the whitespaces. If the next
              * character is a closing bracket, then we have an empty range.
+             * The later case is an extension to the standard format, since
+             * empty ranges are usually represented by {} instead than [].
              */
             isMinIncluded = (c == openInclusive);
-            do {
+            do { // Skip whitespaces.
                 index += Character.charCount(c);
                 if (index >= length) {
                     pos.setErrorIndex(length);
@@ -724,7 +793,7 @@ public class RangeFormat extends Format 
             } while (Character.isWhitespace(c));
             if (isClose(c)) {
                 pos.setErrorIndex(index);  // In case of failure during the conversion.
-                minValue = maxValue = convert(0);
+                minValue = maxValue = valueOfNil();
                 isMaxIncluded = false;
                 index += Character.charCount(c);
             } else {
@@ -791,7 +860,7 @@ public class RangeFormat extends Format 
                      */
                     for (index = pos.getIndex(); ; index += Character.charCount(c)) {
                         if (index >= length) {
-                           pos.setErrorIndex(length);
+                            pos.setErrorIndex(length);
                             return null;
                         }
                         c = source.charAt(index);
@@ -883,4 +952,19 @@ public class RangeFormat extends Format 
         throw new UnconvertibleObjectException(Errors.format(
                 Errors.Keys.IllegalClass_2, elementType, value.getClass()));
     }
+
+    /**
+     * Returns a "nil" value. This is used for creating empty ranges.
+     */
+    private Object valueOfNil() {
+        Object value = Numbers.valueOfNil(elementType);
+        if (value == null) {
+            if (Date.class.isAssignableFrom(elementType)) {
+                value = new Date();
+            } else {
+                value = 0;
+            }
+        }
+        return convert(value);
+    }
 }

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=1447736&r1=1447735&r2=1447736&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
Tue Feb 19 14:37:17 2013
@@ -81,7 +81,7 @@ public final strictfp class MeasurementR
     @Test
     public void testToString() {
         final MeasurementRange<Float> range = MeasurementRange.create(10f, true, 20f,
true, SI.KILOMETRE);
-        assertEquals("[10.0 … 20.0] km", range.toString());
+        assertEquals("[10.0 … 20.0] km", range.toString());
     }
 
     /**

Modified: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/measure/RangeFormatTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/measure/RangeFormatTest.java?rev=1447736&r1=1447735&r2=1447736&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/measure/RangeFormatTest.java
(original)
+++ sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/measure/RangeFormatTest.java
Tue Feb 19 14:37:17 2013
@@ -130,14 +130,14 @@ public final strictfp class RangeFormatT
         assertEquals("maxPos.endIndex",   8, maxPos.getEndIndex());
 
         // Single value
-        assertEquals("300", format(NumberRange.create(300, true, 300, true)));
-        assertEquals("minPos.beginIndex", 0, minPos.getBeginIndex());
-        assertEquals("minPos.endIndex",   3, minPos.getEndIndex());
-        assertEquals("maxPos.beginIndex", 0, maxPos.getBeginIndex());
-        assertEquals("maxPos.endIndex",   3, maxPos.getEndIndex());
+        assertEquals("{300}", format(NumberRange.create(300, true, 300, true)));
+        assertEquals("minPos.beginIndex", 1, minPos.getBeginIndex());
+        assertEquals("minPos.endIndex",   4, minPos.getEndIndex());
+        assertEquals("maxPos.beginIndex", 1, maxPos.getBeginIndex());
+        assertEquals("maxPos.endIndex",   4, maxPos.getEndIndex());
 
         // Empty range
-        assertEquals("[]", format(NumberRange.create(300, true, 300, false)));
+        assertEquals("{}", format(NumberRange.create(300, true, 300, false)));
         assertEquals("minPos.beginIndex", 1, minPos.getBeginIndex());
         assertEquals("minPos.endIndex",   1, minPos.getEndIndex());
         assertEquals("maxPos.beginIndex", 1, maxPos.getBeginIndex());

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=1447736&r1=1447735&r2=1447736&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 Tue
Feb 19 14:37:17 2013
@@ -293,6 +293,19 @@ public final strictfp class RangeTest ex
     }
 
     /**
+     * Tests the {@link Range#toString()} method.
+     */
+    @Test
+    public void testToString() {
+        assertEquals("{}",        new Range<>(Integer.class, 10, false, 10, false).toString());
+        assertEquals("{10}",      new Range<>(Integer.class, 10, true,  10, true ).toString());
+        assertEquals("[10 … 20]", new Range<>(Integer.class, 10, true,  20, true
).toString());
+        assertEquals("(10 … 20)", new Range<>(Integer.class, 10, false, 20, false).toString());
+        assertEquals("[10 … 20)", new Range<>(Integer.class, 10, true,  20, false).toString());
+        assertEquals("(10 … 20]", new Range<>(Integer.class, 10, false, 20, true
).toString());
+    }
+
+    /**
      * Tests the {@link Range#equals(Object)} method.
      */
     @Test



Mime
View raw message