Author: desruisseaux
Date: Mon Feb 11 16:43:44 2013
New Revision: 1444858
URL: http://svn.apache.org/r1444858
Log:
Ported MeasurementRange.
Added:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/MeasurementRange.java
(with props)
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/measure/MeasurementRangeTest.java
(with props)
Modified:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/measure/NumberRangeTest.java
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
Added:
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=1444858&view=auto
==============================================================================
---
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/MeasurementRange.java
(added)
+++
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/MeasurementRange.java
Mon Feb 11 16:43:44 2013
@@ -0,0 +1,370 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.measure;
+
+import javax.measure.unit.Unit;
+import javax.measure.converter.UnitConverter;
+import javax.measure.converter.ConversionException;
+import net.jcip.annotations.Immutable;
+import org.apache.sis.util.Numbers;
+import org.apache.sis.util.resources.Errors;
+
+// Related to JDK7
+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.
+ *
+ * @param <T> The type of range elements as a subclass of {@link Number}.
+ *
+ * @author Martin Desruisseaux (IRD)
+ * @since 0.3 (derived from geotk-2.4)
+ * @version 0.3
+ * @module
+ */
+@Immutable
+public class MeasurementRange<T extends Number & Comparable<? super T>>
extends NumberRange<T> {
+ /**
+ * Serial number for inter-operability with different versions.
+ */
+ private static final long serialVersionUID = 3980319420337513745L;
+
+ /**
+ * The units of measurement, or {@code null} if unknown.
+ */
+ private final Unit<?> units;
+
+ /**
+ * Constructs an inclusive range of {@code float} values.
+ *
+ * @param minValue The minimal value, inclusive, or {@link
Float#NEGATIVE_INFINITY} if none..
+ * @param maxValue The maximal value, <strong>inclusive</strong>, or
{@link Float#POSITIVE_INFINITY} if none.
+ * @param units The units of measurement, or {@code null} if unknown.
+ * @return The new range of numeric values for the given bounds and unit
of measurement.
+ */
+ public static MeasurementRange<Float> create(float minValue, float
maxValue, Unit<?> units) {
+ return new MeasurementRange<>(Float.class,
+ valueOf("minValue", minValue, Float.NEGATIVE_INFINITY),
+ valueOf("maxValue", maxValue, Float.POSITIVE_INFINITY), units);
+ }
+
+ /**
+ * Constructs a range of {@code float} values.
+ *
+ * @param minValue The minimal value, or {@link
Float#NEGATIVE_INFINITY} if none.
+ * @param isMinIncluded {@code true} if the minimal value is inclusive,
or {@code false} if exclusive.
+ * @param maxValue The maximal value, or {@link
Float#POSITIVE_INFINITY} 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.
+ * @return The new range of numeric values for the given bounds and unit
of measurement.
+ */
+ public static MeasurementRange<Float> create(float minValue, boolean
isMinIncluded,
+ float maxValue, boolean
isMaxIncluded, Unit<?> units)
+ {
+ return new MeasurementRange<>(Float.class,
+ valueOf("minValue", minValue, Float.NEGATIVE_INFINITY),
isMinIncluded,
+ valueOf("maxValue", maxValue, Float.POSITIVE_INFINITY),
isMaxIncluded, units);
+ }
+
+ /**
+ * Constructs an inclusive range of {@code double} values.
+ *
+ * @param minValue The minimal value, inclusive, or {@link
Double#NEGATIVE_INFINITY} if none..
+ * @param maxValue The maximal value, <strong>inclusive</strong>, or
{@link Double#POSITIVE_INFINITY} if none.
+ * @param units The units of measurement, or {@code null} if unknown.
+ * @return The new range of numeric values for the given bounds and unit
of measurement.
+ */
+ public static MeasurementRange<Double> create(double minValue, double
maxValue, Unit<?> units) {
+ return new MeasurementRange<>(Double.class,
+ valueOf("minValue", minValue, Double.NEGATIVE_INFINITY),
+ valueOf("maxValue", maxValue, Double.POSITIVE_INFINITY),
units);
+ }
+
+ /**
+ * Constructs a range of {@code double} values.
+ *
+ * @param minValue The minimal value, or {@link
Double#NEGATIVE_INFINITY} if none.
+ * @param isMinIncluded {@code true} if the minimal value is inclusive,
or {@code false} if exclusive.
+ * @param maxValue The maximal value, or {@link
Double#POSITIVE_INFINITY} 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.
+ * @return The new range of numeric values for the given bounds and unit
of measurement.
+ */
+ public static MeasurementRange<Double> create(double minValue, boolean
isMinIncluded,
+ double maxValue, boolean
isMaxIncluded, Unit<?> units)
+ {
+ return new MeasurementRange<>(Double.class,
+ valueOf("minValue", minValue, Double.NEGATIVE_INFINITY),
isMinIncluded,
+ valueOf("maxValue", maxValue, Double.POSITIVE_INFINITY),
isMaxIncluded, units);
+ }
+
+ /**
+ * Constructs a range using the smallest type of {@link Number} that can
hold the given values.
+ * This method performs the same work than {@link NumberRange#createBestFit
+ * NumberRange.createBestFit(â¦)} with an additional {@code units}
argument.
+ *
+ * @param minimum The minimum value, or {@code null} for negative
infinity.
+ * @param isMinIncluded Defines whether the minimum value is included in
the range.
+ * @param maximum The maximum value, or {@code null} for positive
infinity.
+ * @param isMaxIncluded Defines whether the maximum value is included in
the range.
+ * @param units The units of measurement, or {@code null} if
unknown.
+ * @return The new range, or {@code null}Â if both {@code minimum} and
{@code maximum}
+ * are {@code null}.
+ *
+ * @see NumberRange#createBestFit(Number, boolean, Number, boolean)
+ */
+ @SuppressWarnings({"rawtypes","unchecked"})
+ public static MeasurementRange<?> createBestFit(final Number minimum,
final boolean isMinIncluded,
+ final Number maximum, final boolean isMaxIncluded, final Unit<?>
units)
+ {
+ final Class<? extends Number> type = Numbers.widestClass(
+ Numbers.narrowestClass(minimum),
Numbers.narrowestClass(maximum));
+ return (type == null) ? null :
+ new MeasurementRange(type, Numbers.cast(minimum, type),
isMinIncluded,
+ Numbers.cast(maximum, type),
isMaxIncluded, units);
+ }
+
+ /**
+ * Constructs a range with the same values than the specified range and
the given units.
+ * This is a copy constructor, with the addition of a unit of measurement.
+ *
+ * @param range The range to copy. The elements must be {@link Number}
instances.
+ * @param units The units of measurement, or {@code null} if unknown.
+ */
+ public MeasurementRange(final Range<T> range, final Unit<?> units) {
+ super(range);
+ this.units = units;
+ }
+
+ /**
+ * Constructs a range of {@link Number} objects.
+ *
+ * @param type The element class, 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 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);
+ this.units = units;
+ }
+
+ /**
+ * Constructs a range of {@link Number} objects.
+ *
+ * @param type The element class, 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 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 Unit<?> units)
+ {
+ super(type, minimum, isMinIncluded, maximum, isMaxIncluded);
+ this.units = units;
+ }
+
+ /**
+ * Constructs a range with the same values than the specified range,
+ * casted to the specified type.
+ *
+ * @param type The element class, usually one of {@link Byte}, {@link
Short},
+ * {@link Integer}, {@link Long}, {@link Float} or {@link
Double}.
+ * @param range The range to copy. The elements must be {@link Number}
instances.
+ * @param units The units of measurement, or {@code null} if unknown.
+ */
+ private MeasurementRange(Class<T> type, Range<? extends Number> range,
final Unit<?> units) {
+ super(type, range);
+ this.units = units;
+ }
+
+ /**
+ * Creates a new range using the same element class than this range.
+ */
+ @Override
+ MeasurementRange<T> create(final T minValue, final boolean isMinIncluded,
+ final T maxValue, final boolean isMaxIncluded)
+ {
+ return new MeasurementRange<>(elementType, minValue, isMinIncluded,
maxValue, isMaxIncluded, units);
+ }
+
+ /**
+ * Returns the units of measurement, or {@code null} if unknown.
+ *
+ * @return The units of measurement, or {@code null}.
+ */
+ @Override
+ public Unit<?> getUnits() {
+ return units;
+ }
+
+ /**
+ * Converts this range to the specified units. If this measurement range
has null units,
+ * then the specified target units are simply assigned to the returned
range with no
+ * other changes.
+ *
+ * @param targetUnits the target units, or {@code null} for keeping the
units unchanged.
+ * @return The converted range, or {@code this} if no conversion is needed.
+ * @throws ConversionException if the target units are not compatible with
+ * this {@linkplain #getUnits range units}.
+ */
+ public MeasurementRange<T> convertTo(final Unit<?> targetUnits) throws
ConversionException {
+ return convertAndCast(elementType, targetUnits);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public <N extends Number & Comparable<? super N>> MeasurementRange<N>
castTo(Class<N> type) {
+ return convertAndCast(this, type);
+ }
+
+ /**
+ * Casts the specified range to the specified type. If this class is
associated to a unit of
+ * measurement, then this method convert the {@code range} units to the
same units than this
+ * instance.
+ *
+ * @param type The class to cast to. Must be one of {@link Byte}, {@link
Short},
+ * {@link Integer}, {@link Long}, {@link Float} or {@link
Double}.
+ * @return The casted range, or {@code range} if no cast is needed.
+ */
+ @Override
+ <N extends Number & Comparable<? super N>>
+ MeasurementRange<N> convertAndCast(final Range<? extends Number> range,
final Class<N> type)
+ throws IllegalArgumentException
+ {
+ if (range instanceof MeasurementRange<?>) {
+ final MeasurementRange<?> casted = (MeasurementRange<?>) range;
+ try {
+ return casted.convertAndCast(type, units);
+ } catch (ConversionException e) {
+ throw new IllegalArgumentException(Errors.format(
+ Errors.Keys.IncompatibleUnits_2, casted.units, units),
e);
+ }
+ }
+ return new MeasurementRange<>(type, range, units);
+ }
+
+ /**
+ * Casts this range to the specified type and converts to the specified
units.
+ *
+ * @param type The class to cast to. Must be one of {@link Byte}, {@link
Short},
+ * {@link Integer}, {@link Long}, {@link Float} or {@link
Double}.
+ * @param targetUnit the target units, or {@code null} for no change.
+ * @return The casted range, or {@code this}.
+ * @throws ConversionException if the target units are not compatible with
+ * this {@linkplain #getUnits range units}.
+ */
+ @SuppressWarnings("unchecked")
+ private <N extends Number & Comparable<? super N>> MeasurementRange<N>
+ convertAndCast(final Class<N> type, final Unit<?> targetUnits)
throws ConversionException
+ {
+ if (targetUnits == null || targetUnits.equals(units)) {
+ if (type.equals(elementType)) {
+ return (MeasurementRange<N>) this;
+ } else {
+ return new MeasurementRange<>(type, this, units);
+ }
+ }
+ if (units == null) {
+ return new MeasurementRange<>(type, this, targetUnits);
+ }
+ final UnitConverter converter = units.getConverterToAny(targetUnits);
+ if (converter.equals(UnitConverter.IDENTITY)) {
+ return new MeasurementRange<>(type, this, targetUnits);
+ }
+ boolean isMinIncluded = isMinIncluded();
+ boolean isMaxIncluded = isMaxIncluded();
+ Double minimum = converter.convert(getMinimum());
+ Double maximum = converter.convert(getMaximum());
+ if (minimum.compareTo(maximum) > 0) {
+ final Double td = minimum;
+ minimum = maximum;
+ maximum = td;
+ final boolean tb = isMinIncluded;
+ isMinIncluded = isMaxIncluded;
+ isMaxIncluded = tb;
+ }
+ return new MeasurementRange<>(type,
+ Numbers.cast(minimum, type), isMinIncluded,
+ Numbers.cast(maximum, type), isMaxIncluded, targetUnits);
+ }
+
+ /**
+ * Returns an initially empty array of the given length.
+ */
+ @Override
+ @SuppressWarnings({"unchecked","rawtypes"}) // Generic array creation.
+ MeasurementRange<T>[] newArray(final int length) {
+ return new MeasurementRange[length];
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public MeasurementRange<?> union(final Range<?> range) throws
IllegalArgumentException {
+ return (MeasurementRange<?>) super.union(range);
+ // Should never throw ClassCastException because super.union(Range)
invokes create(...),
+ // which is overridden in this class with MeasurementRange return type.
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public MeasurementRange<?> intersect(final Range<?> range) throws
IllegalArgumentException {
+ return (MeasurementRange<?>) super.intersect(range);
+ // Should never throw ClassCastException because
super.intersect(Range) invokes
+ // convertAndCast(...), which is overridden in this class with
MeasurementRange
+ // return type.
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public MeasurementRange<?>[] subtract(final Range<?> range) throws
IllegalArgumentException {
+ return (MeasurementRange<?>[]) super.subtract(range);
+ // Should never throw ClassCastException because super.subtract(Range)
invokes newArray(int)
+ // and create(...), which are overridden in this class with
MeasurementRange return type.
+ }
+
+ /**
+ * Compares this range with the specified object for equality.
+ */
+ @Override
+ 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 true;
+ }
+ return false;
+ }
+}
Propchange:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/MeasurementRange.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/MeasurementRange.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java?rev=1444858&r1=1444857&r2=1444858&view=diff
==============================================================================
---
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
(original)
+++
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
Mon Feb 11 16:43:44 2013
@@ -175,6 +175,11 @@ public final class Errors extends Indexe
public static final int IllegalRange_2 = 11;
/**
+ * Units â{0}â and â{1}â are incompatible.
+ */
+ public static final int IncompatibleUnits_2 = 67;
+
+ /**
* Value â{1}â of attribute â{0}â is inconsistent with other
attributes.
*/
public static final int InconsistentAttribute_2 = 27;
Modified:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties?rev=1444858&r1=1444857&r2=1444858&view=diff
==============================================================================
---
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
(original)
+++
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
Mon Feb 11 16:43:44 2013
@@ -46,6 +46,7 @@ IllegalLanguageCode_1 = The \u
IllegalOrdinateRange_3 = The [{0} \u2026 {1}] range of ordinate
values is not valid for the \u201c{2}\u201d axis.
IllegalPropertyClass_2 = Property \u2018{0}\u2019 can be associated
to an instance of \u2018{1}\u2019.
IllegalRange_2 = Range [{0} \u2026 {1}] is not valid.
+IncompatibleUnits_2 = Units \u201c{0}\u201d and \u201c{1}\u201d
are incompatible.
InconsistentAttribute_2 = Value \u201c{1}\u201d of attribute
\u2018{0}\u2019 is inconsistent with other attributes.
InconsistentTableColumns = Inconsistent table columns.
IdentifierAlreadyBound_1 = Identifier \u201c{0}\u201d is already
associated to another object.
Modified:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties?rev=1444858&r1=1444857&r2=1444858&view=diff
==============================================================================
---
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
(original)
+++
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
Mon Feb 11 16:43:44 2013
@@ -35,6 +35,7 @@ IllegalLanguageCode_1 = Le cod
IllegalOrdinateRange_3 = La plage de valeurs de coordonn\u00e9es [{1}
\u2026 {2}] n\u2019est pas valide pour l\u2019axe \u201c{0}\u201d.
IllegalPropertyClass_2 = La propri\u00e9t\u00e9 \u2018{0}\u2019 ne
peut pas \u00eatre associ\u00e9e \u00e0 une valeur de type \u2018{1}\u2019.
IllegalRange_2 = La plage [{0} \u2026 {1}] n\u2019est pas
valide.
+IncompatibleUnits_2 = Les unit\u00e9s \u201c{0}\u201d et
\u201c{1}\u201d ne sont pas compatibles.
InconsistentAttribute_2 = La valeur \u201c{1}\u201d de l\u2019attribut
\u2018{0}\u2019 n\u2019est pas coh\u00e9rente avec celles des autres attributs.
InconsistentTableColumns = Les colonnes des tables ne sont pas
coh\u00e9rentes.
IdentifierAlreadyBound_1 = L\u2019identifiant \u201c{0}\u201d est
d\u00e9j\u00e0 associ\u00e9 \u00e0 un autre objet.
Added:
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=1444858&view=auto
==============================================================================
---
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/measure/MeasurementRangeTest.java
(added)
+++
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/measure/MeasurementRangeTest.java
Mon Feb 11 16:43:44 2013
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.measure;
+
+import javax.measure.unit.SI;
+import javax.measure.converter.ConversionException;
+import org.junit.Test;
+import org.apache.sis.test.DependsOn;
+
+import static org.apache.sis.test.Assert.*;
+
+
+/**
+ * Tests the {@link MeasurementRange} class.
+ *
+ * @author Martin Desruisseaux (IRD)
+ * @since 0.3 (derived from geotk-2.4)
+ * @version 0.3
+ * @module
+ */
+@DependsOn(NumberRangeTest.class)
+public final strictfp class MeasurementRangeTest {
+ /**
+ * Tests unit conversions.
+ *
+ * @throws ConversionException Should not happen.
+ */
+ @Test
+ public void testConversion() 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));
+ }
+
+ /**
+ * 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);
+ assertEquals(Float.class, r1.getElementType());
+ assertEquals(Float.class, r2.getElementType());
+ assertEquals(MeasurementRange.create(1000f, 3000f, SI.METRE ),
r1.union (r2));
+ assertEquals(MeasurementRange.create(1f, 3f, SI.KILOMETRE),
r2.union (r1));
+ assertEquals(MeasurementRange.create(1500f, 2000f, SI.METRE ),
r1.intersect(r2));
+ assertEquals(MeasurementRange.create(1.5f, 2f, SI.KILOMETRE),
r2.intersect(r1));
+ }
+
+ /**
+ * Tests {@link MeasurementRange#toString()} method.
+ */
+ @Test
+ public void testToString() {
+ final MeasurementRange<Float> range = MeasurementRange.create(10f,
20f, SI.KILOMETRE);
+ assertEquals("[10.0ââ¦â20.0] km", range.toString());
+ }
+
+ /**
+ * Tests serialization.
+ */
+ @Test
+ public void testSerialization() {
+ NumberRange<Float> r1 = MeasurementRange.create(1000f, 2000f,
SI.METRE);
+ NumberRange<Float> r2 = MeasurementRange.create(1.5f, 3f,
SI.KILOMETRE);
+ assertNotSame(r1, assertSerializedEquals(r1));
+ assertNotSame(r2, assertSerializedEquals(r2));
+ }
+}
Propchange:
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/measure/MeasurementRangeTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/measure/MeasurementRangeTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/measure/NumberRangeTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/measure/NumberRangeTest.java?rev=1444858&r1=1444857&r2=1444858&view=diff
==============================================================================
---
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/measure/NumberRangeTest.java
(original)
+++
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/measure/NumberRangeTest.java
Mon Feb 11 16:43:44 2013
@@ -23,7 +23,7 @@ import static org.junit.Assert.*;
/**
- * Tests the {@link NumberRange}.
+ * Tests the {@link NumberRange} class.
*
* @author Martin Desruisseaux (IRD)
* @since 0.3 (derived from geotk-2.4)
Modified:
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java?rev=1444858&r1=1444857&r2=1444858&view=diff
==============================================================================
---
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
(original)
+++
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
Mon Feb 11 16:43:44 2013
@@ -73,6 +73,7 @@ import org.junit.runners.Suite;
org.apache.sis.measure.UnitsTest.class,
org.apache.sis.measure.RangeTest.class,
org.apache.sis.measure.NumberRangeTest.class,
+ org.apache.sis.measure.MeasurementRangeTest.class,
org.apache.sis.measure.FormattedCharacterIteratorTest.class,
org.apache.sis.measure.AngleFormatTest.class,
org.apache.sis.measure.AngleTest.class,