sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1546491 - in /sis/branches/JDK7/core/sis-referencing/src: main/java/org/apache/sis/internal/referencing/ main/java/org/apache/sis/referencing/cs/ main/java/org/apache/sis/referencing/datum/ test/java/org/apache/sis/internal/referencing/
Date Fri, 29 Nov 2013 01:30:12 GMT
Author: desruisseaux
Date: Fri Nov 29 01:30:11 2013
New Revision: 1546491

URL: http://svn.apache.org/r1546491
Log:
Consolidation of the way axis properties are validated.

Modified:
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/AxisDirections.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultAffineCS.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCartesianCS.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCylindricalCS.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultEllipsoidalCS.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/AbstractDatum.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/AxisDirectionsTest.java

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/AxisDirections.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/AxisDirections.java?rev=1546491&r1=1546490&r2=1546491&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/AxisDirections.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/AxisDirections.java
[UTF-8] Fri Nov 29 01:30:11 2013
@@ -16,8 +16,6 @@
  */
 package org.apache.sis.internal.referencing;
 
-import java.util.Map;
-import java.util.HashMap;
 import org.opengis.referencing.cs.AxisDirection;
 import org.opengis.referencing.cs.CoordinateSystem;
 import org.apache.sis.util.Characters;
@@ -26,9 +24,6 @@ import org.apache.sis.util.Static;
 import static org.opengis.referencing.cs.AxisDirection.*;
 import static org.apache.sis.util.CharSequences.*;
 
-// Related to JDK7
-import java.util.Objects;
-
 
 /**
  * Utilities methods related to {@link AxisDirection}.
@@ -48,30 +43,31 @@ public final class AxisDirections extend
     /**
      * For each direction, the opposite direction.
      */
-    private static final Map<AxisDirection,AxisDirection> opposites = new HashMap<>(35);
+    private static final AxisDirection[] OPPOSITES = new AxisDirection[DISPLAY_DOWN.ordinal()
+ 1];
     static {
-        opposites.put(OTHER, OTHER);
-        final AxisDirection[] dir = {
-            NORTH,            SOUTH,
-            NORTH_NORTH_EAST, SOUTH_SOUTH_WEST,
-            NORTH_EAST,       SOUTH_WEST,
-            EAST_NORTH_EAST,  WEST_SOUTH_WEST,
-            EAST,             WEST,
-            EAST_SOUTH_EAST,  WEST_NORTH_WEST,
-            SOUTH_EAST,       NORTH_WEST,
-            SOUTH_SOUTH_EAST, NORTH_NORTH_WEST,
-            UP,               DOWN,
-            FUTURE,           PAST,
-            COLUMN_POSITIVE,  COLUMN_NEGATIVE,
-            ROW_POSITIVE,     ROW_NEGATIVE,
-            DISPLAY_RIGHT,    DISPLAY_LEFT,
-            DISPLAY_DOWN,     DISPLAY_UP // y values increase toward down.
-        };
-        for (int i=0; i<dir.length; i++) {
-            if (opposites.put(dir[i], dir[i ^ 1]) != null) {
-                throw new AssertionError(i);
-            }
-        }
+        put(OTHER,            OTHER);
+        put(NORTH,            SOUTH);
+        put(NORTH_NORTH_EAST, SOUTH_SOUTH_WEST);
+        put(NORTH_EAST,       SOUTH_WEST);
+        put(EAST_NORTH_EAST,  WEST_SOUTH_WEST);
+        put(EAST,             WEST);
+        put(EAST_SOUTH_EAST,  WEST_NORTH_WEST);
+        put(SOUTH_EAST,       NORTH_WEST);
+        put(SOUTH_SOUTH_EAST, NORTH_NORTH_WEST);
+        put(UP,               DOWN);
+        put(FUTURE,           PAST);
+        put(COLUMN_POSITIVE,  COLUMN_NEGATIVE);
+        put(ROW_POSITIVE,     ROW_NEGATIVE);
+        put(DISPLAY_RIGHT,    DISPLAY_LEFT);
+        put(DISPLAY_UP,       DISPLAY_DOWN);
+    }
+
+    /**
+     * Stores the given directions in the {@link #OPPOSITES} array.
+     */
+    private static void put(final AxisDirection dir, final AxisDirection opposite) {
+        OPPOSITES[dir.ordinal()] = opposite;
+        OPPOSITES[opposite.ordinal()] = dir;
     }
 
     /**
@@ -109,16 +105,14 @@ public final class AxisDirections extend
      *   <tr align="center"><td width='50%'>{@code OTHER}</td><td width='50%'>{@code
OTHER}</td></tr>
      * </table>
      *
-     * @param  dir The direction for which to return the absolute direction.
-     * @return The direction from the above table.
+     * @param  dir The direction for which to return the absolute direction, or {@code null}.
+     * @return The direction from the above table, or {@code null} if the given direction
was null.
      */
     public static AxisDirection absolute(final AxisDirection dir) {
-        if (dir != null) {
-            final AxisDirection opposite = opposite(dir);
-            if (opposite != null) {
-                if (opposite.ordinal() < dir.ordinal()) {
-                    return opposite;
-                }
+        final AxisDirection opposite = opposite(dir);
+        if (opposite != null) {
+            if (opposite.ordinal() < dir.ordinal()) {
+                return opposite;
             }
         }
         return dir;
@@ -130,23 +124,64 @@ public final class AxisDirections extend
      * The same applies to {@code EAST}-{@code WEST}, {@code UP}-{@code DOWN} and {@code
FUTURE}-{@code PAST},
      * <i>etc.</i> If the given axis direction has no opposite, then this method
returns {@code null}.
      *
-     * @param  dir The direction for which to return the opposite direction.
+     * @param  dir The direction for which to return the opposite direction, or {@code null}.
      * @return The opposite direction, or {@code null} if none or unknown.
      */
-    public static AxisDirection opposite(final AxisDirection dir) {
-        return opposites.get(dir);
+    public static AxisDirection opposite(AxisDirection dir) {
+        if (dir != null) {
+            final int ordinal = dir.ordinal();
+            if (ordinal >= 0 && ordinal < OPPOSITES.length) {
+                dir = OPPOSITES[ordinal];
+            }
+        }
+        return dir;
     }
 
     /**
      * Returns {@code true} if the given direction is an "opposite" direction.
-     * If this method can not determine if the given direction is an "opposite"
-     * one, then it conservatively returns {@code true}.
+     * If the given argument is {@code null} or is not a known direction, then
+     * this method conservatively returns {@code false}.
      *
      * @param  dir The direction to test, or {@code null}.
      * @return {@code true} if the given direction is an "opposite".
      */
     public static boolean isOpposite(final AxisDirection dir) {
-        return Objects.equals(dir, opposite(absolute(dir)));
+        final AxisDirection opposite = opposite(dir);
+        return (opposite != null) && opposite.ordinal() < dir.ordinal();
+    }
+
+    /**
+     * Returns {@code true} if the given direction is a spatial axis direction (including
vertical and geocentric axes).
+     * The current implementation conservatively returns {@code true} for every non-null
directions except a hard-coded
+     * set of directions which are known to be non-spatial. We conservatively accept unknown
axis directions because
+     * some of them are created from strings like "South along 90°E".
+     *
+     * <p>If the {@code image} argument is {@code true}, then this method additionally
accepts grid and display
+     * axis directions.</p>
+     *
+     * <p>The rules implemented by this method may change in any future SIS version.</p>
+     *
+     * @param  dir The direction to test, or {@code null}.
+     * @param  image {@code true} for accepting grid and image axis directions in addition
to spatial ones.
+     * @return {@code true} if the given direction is presumed for spatial CS.
+     */
+    public static boolean isSpatialOrCustom(final AxisDirection dir, final boolean image)
{
+        if (dir == null) return false;
+        final int ordinal = dir.ordinal();
+        return ordinal < FUTURE.ordinal() || ordinal > (image ? PAST : DISPLAY_DOWN).ordinal();
+    }
+
+    /**
+     * Returns {@code true} if the given direction is {@code COLUMN_POSITIVE}, {@code COLUMN_NEGATICE},
+     * {@code ROW_POSITIVE} or {@code ROW_NEGATIVE}.
+     *
+     * @param  dir The direction to test, or {@code null}.
+     * @return {@code true} if the given direction is presumed for grid CS.
+     */
+    public static boolean isGrid(final AxisDirection dir) {
+        if (dir == null) return false;
+        final int ordinal = dir.ordinal();
+        return ordinal >= COLUMN_POSITIVE.ordinal() && ordinal <= ROW_NEGATIVE.ordinal();
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java?rev=1546491&r1=1546490&r2=1546491&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java
[UTF-8] Fri Nov 29 01:30:11 2013
@@ -67,6 +67,11 @@ public class AbstractCS extends Abstract
     private static final long serialVersionUID = 6757665252533744744L;
 
     /**
+     * Return value for {@link #validateAxis(AxisDirection, Unit)}
+     */
+    static final int VALID = 0, INVALID_DIRECTION = 1, INVALID_UNIT = 2;
+
+    /**
      * The sequence of axes for this coordinate system.
      */
     @XmlElement(name = "axis")
@@ -120,20 +125,22 @@ public class AbstractCS extends Abstract
             ensureNonNullElement("axes[#].name", i, name);
             final AxisDirection direction = axis.getDirection();
             ensureNonNullElement("axes[#].direction", i, direction);
+            final Unit<?> unit = axis.getUnit();
+            ensureNonNullElement("axes[#].unit", i, unit);
             /*
              * Ensures that axis direction and units are compatible with the
              * coordinate system to be created. For example CartesianCS will
-             * accepts only linear or dimensionless units.
+             * accept only linear or dimensionless units.
              */
-            if (!isCompatibleDirection(direction)) {
-                throw new IllegalArgumentException(Errors.format(
-                        Errors.Keys.IllegalAxisDirection_2, getClass(), direction));
-            }
-            final Unit<?> unit = axis.getUnit();
-            ensureNonNullElement("axes[#].unit", i, unit);
-            if (!isCompatibleUnit(direction, unit)) {
-                throw new IllegalArgumentException(Errors.format(
-                        Errors.Keys.IllegalUnitFor_2, name, unit));
+            switch (validateAxis(direction, unit)) {
+                case INVALID_DIRECTION: {
+                    throw new IllegalArgumentException(Errors.format(
+                            Errors.Keys.IllegalAxisDirection_2, getClass(), direction));
+                }
+                case INVALID_UNIT: {
+                    throw new IllegalArgumentException(Errors.format(
+                            Errors.Keys.IllegalUnitFor_2, name, unit));
+                }
             }
             /*
              * Ensures there is no axis along the same direction
@@ -176,36 +183,22 @@ public class AbstractCS extends Abstract
     }
 
     /**
-     * Returns {@code true} if the specified axis direction is allowed for this coordinate
system.
-     * This method is invoked at construction time for checking argument validity. The default
implementation
-     * returns {@code true} for all axis directions. Subclasses will override this method
in order to put more
-     * restrictions on allowed axis directions.
+     * Returns {@link #VALID} if the given argument values are allowed for an axis in this
coordinate system,
+     * or an {@code INVALID_*} error code otherwise. This method is invoked at construction
time for checking
+     * argument validity. The default implementation returns {@code VALID} in all cases.
Subclasses override
+     * this method in order to put more restrictions on allowed axis directions and check
for compatibility
+     * with {@linkplain SI#METRE metre} or {@linkplain NonSI#DEGREE_ANGLE degree} units.
      *
-     * <p><b>Note for implementors:</b> since this method is invoked at
construction time, it shall not depends
+     * <p><b>Note for implementors:</b> since this method is invoked at
construction time, it shall not depend
      * on this object's state. This method is not in public API for that reason.</p>
      *
      * @param  direction The direction to test for compatibility.
-     * @return {@code true} if the given direction is compatible with this coordinate system.
-     */
-    boolean isCompatibleDirection(final AxisDirection direction) {
-        return true;
-    }
-
-    /**
-     * Returns {@code true} is the specified unit is legal for the specified axis direction.
-     * This method is invoked at construction time for checking units compatibility. The
default implementation
-     * returns {@code true} in all cases. Subclasses can override this method and check for
compatibility with
-     * {@linkplain SI#METRE metre} or {@linkplain NonSI#DEGREE_ANGLE degree} units.
-     *
-     * <p><b>Note for implementors:</b> since this method is invoked at
construction time, it shall not depends
-     * on this object's state. This method is not in public API for that reason.</p>
-     *
-     * @param  direction The direction of the axis having the given unit.
      * @param  unit The unit to test for compatibility.
-     * @return {@code true} if the given unit is compatible with this coordinate system.
+     * @return {@link #VALID} if the given direction and unit are compatible with this coordinate
system,
+     *         {@link #DIRECTION} if the direction is invalid or {@link #UNIT} if the unit
is invalid.
      */
-    boolean isCompatibleUnit(final AxisDirection direction, final Unit<?> unit) {
-        return true;
+    int validateAxis(final AxisDirection direction, final Unit<?> unit) {
+        return VALID;
     }
 
     /**
@@ -242,17 +235,18 @@ public class AbstractCS extends Abstract
      */
     @Override
     public boolean equals(final Object object, final ComparisonMode mode) {
-        if (object == this) {
-            return true; // Slight optimization.
-        }
-        if (!(object instanceof CoordinateSystem && super.equals(object, mode)))
{
+        if (!super.equals(object, mode)) {
             return false;
         }
         switch (mode) {
             case STRICT: {
+                // No need to check the class - this check has been done by super.equals(…).
                 return Arrays.equals(axes, ((AbstractCS) object).axes);
             }
             default: {
+                if (!(object instanceof CoordinateSystem)) {
+                    return false;
+                }
                 final CoordinateSystem that = (CoordinateSystem) object;
                 final int dimension = getDimension();
                 if (dimension != that.getDimension()) {

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultAffineCS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultAffineCS.java?rev=1546491&r1=1546490&r2=1546491&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultAffineCS.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultAffineCS.java
[UTF-8] Fri Nov 29 01:30:11 2013
@@ -17,7 +17,6 @@
 package org.apache.sis.referencing.cs;
 
 import java.util.Map;
-import javax.measure.unit.SI;
 import javax.measure.unit.Unit;
 import org.opengis.referencing.cs.AffineCS;
 import org.opengis.referencing.cs.CartesianCS;
@@ -30,7 +29,7 @@ import org.apache.sis.util.ComparisonMod
 
 
 /**
- * A 2- or 3-dimensional coordinate system with straight axes that are not necessarily orthogonal.
+ * A 2- or 3-dimensional coordinate system made of straight axes (not necessarily orthogonal).
  *
  * <table class="sis"><tr>
  *   <th>Used with</th>
@@ -162,24 +161,25 @@ public class DefaultAffineCS extends Abs
     }
 
     /**
-     * Returns {@code true} if the given axis direction is allowed for this coordinate system.
-     * The default implementation accepts all directions except temporal ones
-     * (i.e. {@link AxisDirection#FUTURE FUTURE} and {@link AxisDirection#PAST PAST}).
-     */
-    @Override
-    final boolean isCompatibleDirection(final AxisDirection direction) {
-        return !AxisDirection.FUTURE.equals(AxisDirections.absolute(direction));
-    }
-
-    /**
-     * Returns {@code true} if the given unit is compatible with {@linkplain SI#METRE metres}.
-     * In addition, this method also accepts {@link Unit#ONE}, which is used for coordinates
in a grid.
-     * This method is invoked at construction time for checking units compatibility.
+     * Returns {@code VALID} if the given argument values are allowed for this coordinate
system,
+     * or an {@code INVALID_*} error code otherwise. This method is invoked at construction
time.
+     *
+     * <p>The current implementation rejects all directions that are known to be non-spatial,
not
+     * for grids and not for display. We conservatively accept all others axis directions
because
+     * some of them are created from strings like "South along 90°E".</p>
+     *
+     * <p>This method accepts linear units, but also accepts the dimensionless units
because the
+     * later are used for grid and display coordinates.</p>
      */
     @Override
-    final boolean isCompatibleUnit(final AxisDirection direction, final Unit<?> unit)
{
-        return Units.isLinear(unit) || Unit.ONE.equals(unit);
-        // Note: this condition is also coded in PredefinedCS.rightHanded(AffineCS).
+    final int validateAxis(final AxisDirection direction, final Unit<?> unit) {
+        if (!AxisDirections.isSpatialOrCustom(direction, true)) {
+            return INVALID_DIRECTION;
+        }
+        if (!Units.isLinear(unit) && !Unit.ONE.equals(unit)) {
+            return INVALID_UNIT;
+        }
+        return VALID;
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCartesianCS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCartesianCS.java?rev=1546491&r1=1546490&r2=1546491&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCartesianCS.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCartesianCS.java
[UTF-8] Fri Nov 29 01:30:11 2013
@@ -27,7 +27,7 @@ import org.apache.sis.util.Immutable;
 
 
 /**
- * A 1-, 2-, or 3-dimensional Cartesian coordinate system with straight orthogonal axes.
+ * A 1-, 2-, or 3-dimensional Cartesian coordinate system made of straight orthogonal axes.
  * All axes shall have the same linear unit of measure.
  *
  * <table class="sis"><tr>

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCylindricalCS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCylindricalCS.java?rev=1546491&r1=1546490&r2=1546491&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCylindricalCS.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCylindricalCS.java
[UTF-8] Fri Nov 29 01:30:11 2013
@@ -17,16 +17,18 @@
 package org.apache.sis.referencing.cs;
 
 import java.util.Map;
+import javax.measure.unit.Unit;
 import org.opengis.referencing.cs.CylindricalCS;
 import org.opengis.referencing.cs.AxisDirection;
 import org.opengis.referencing.cs.CoordinateSystemAxis;
 import org.apache.sis.internal.referencing.AxisDirections;
 import org.apache.sis.util.ComparisonMode;
 import org.apache.sis.util.Immutable;
+import org.apache.sis.measure.Units;
 
 
 /**
- * A 3-dimensional coordinate system consisting of a
+ * A 3-dimensional coordinate system made of a
  * {@linkplain DefaultPolarCS polar coordinate system} extended by a straight perpendicular
axis.
  *
  * <table class="sis"><tr>
@@ -129,12 +131,22 @@ public class DefaultCylindricalCS extend
     }
 
     /**
-     * Returns {@code true} if the specified axis direction is allowed for this coordinate
system.
-     * Current implementation accepts all directions except temporal ones.
+     * Returns {@code VALID} if the given argument values are allowed for this coordinate
system,
+     * or an {@code INVALID_*} error code otherwise. This method is invoked at construction
time.
+     *
+     * <p>The current implementation rejects all directions that are known to be non-spatial.
+     * We conservatively accept custom axis directions because some of them are created from
+     * strings like "South along 90°E".</p>
      */
     @Override
-    final boolean isCompatibleDirection(final AxisDirection direction) {
-        return !AxisDirection.FUTURE.equals(AxisDirections.absolute(direction));
+    final int validateAxis(final AxisDirection direction, final Unit<?> unit) {
+        if (!AxisDirections.isSpatialOrCustom(direction, false)) {
+            return INVALID_DIRECTION;
+        }
+        if (!Units.isLinear(unit)) {
+            return INVALID_UNIT;
+        }
+        return VALID;
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultEllipsoidalCS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultEllipsoidalCS.java?rev=1546491&r1=1546490&r2=1546491&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultEllipsoidalCS.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultEllipsoidalCS.java
[UTF-8] Fri Nov 29 01:30:11 2013
@@ -21,15 +21,14 @@ import javax.measure.unit.Unit;
 import org.opengis.referencing.cs.EllipsoidalCS;
 import org.opengis.referencing.cs.AxisDirection;
 import org.opengis.referencing.cs.CoordinateSystemAxis;
-import org.apache.sis.measure.Units;
-import org.apache.sis.util.Immutable;
-import org.apache.sis.util.ComparisonMode;
 import org.apache.sis.internal.referencing.AxisDirections;
+import org.apache.sis.util.ComparisonMode;
+import org.apache.sis.util.Immutable;
+import org.apache.sis.measure.Units;
 
 
 /**
- * A 2- or 3-dimensional coordinate system in which position is specified by geodetic latitude
and longitude,
- * and optionally by ellipsoidal height.
+ * A 2- or 3-dimensional coordinate system for geodetic latitude and longitude, optionally
with ellipsoidal height.
  *
  * <table class="sis"><tr>
  *   <th>Used with</th>
@@ -148,32 +147,26 @@ public class DefaultEllipsoidalCS extend
     }
 
     /**
-     * Returns {@code true} if the specified axis direction is allowed for this coordinate
system.
-     * The current implementation accepts only the following directions:
+     * Returns {@code VALID} if the given argument values are allowed for this coordinate
system,
+     * or an {@code INVALID_*} error code otherwise. This method is invoked at construction
time.
+     *
+     * <p>The current implementation accepts only the following directions:
      * {@link AxisDirection#NORTH NORTH}, {@link AxisDirection#SOUTH SOUTH},
      * {@link AxisDirection#EAST  EAST},  {@link AxisDirection#WEST  WEST},
      * {@link AxisDirection#UP    UP} and {@link AxisDirection#DOWN  DOWN}.
+     * The units shall be angular, except the vertical ones which shall be linear.</p>
      */
     @Override
-    final boolean isCompatibleDirection(AxisDirection direction) {
+    final int validateAxis(AxisDirection direction, final Unit<?> unit) {
         direction = AxisDirections.absolute(direction);
-        return AxisDirection.NORTH.equals(direction) ||
-               AxisDirection.EAST .equals(direction) ||
-               AxisDirection.UP   .equals(direction);
-    }
-
-    /**
-     * Returns {@code true} if the specified unit is an angular units, or a linear one in
the
-     * special case of height. This method is invoked at construction time for checking units
-     * compatibility.
-     */
-    @Override
-    final boolean isCompatibleUnit(AxisDirection direction, final Unit<?> unit) {
-        direction = AxisDirections.absolute(direction);
-        if (AxisDirection.UP.equals(direction)) {
-            return Units.isLinear(unit);
+        final boolean isVertical = AxisDirection.UP.equals(direction);
+        if (!isVertical && !AxisDirection.NORTH.equals(direction) && !AxisDirection.EAST.equals(direction))
{
+            return INVALID_DIRECTION;
+        }
+        if (!(isVertical ? Units.isLinear(unit) : Units.isAngular(unit))) {
+            return INVALID_UNIT;
         }
-        return Units.isAngular(unit);
+        return VALID;
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/AbstractDatum.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/AbstractDatum.java?rev=1546491&r1=1546490&r2=1546491&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/AbstractDatum.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/AbstractDatum.java
[UTF-8] Fri Nov 29 01:30:11 2013
@@ -299,11 +299,10 @@ public class AbstractDatum extends Abstr
      * with the following additional flexibility:
      *
      * <ul>
-     *   <li>The {@code "D_"} prefix, if presents in the given name or this datum name,
is ignored.</li>
+     *   <li>The {@code "D_"} prefix (used in ESRI datum names), if presents in the
given name or in this datum name,
+     *       is ignored.</li>
      * </ul>
      *
-     * {@note The <code>"D_"</code> prefix is used in ESRI datum names.}
-     *
      * {@section Future evolutions}
      * This method implements heuristic rules learned from experience while trying to provide
inter-operability
      * with different data producers. Those rules may be adjusted in any future SIS version
according experience

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/AxisDirectionsTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/AxisDirectionsTest.java?rev=1546491&r1=1546490&r2=1546491&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/AxisDirectionsTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/AxisDirectionsTest.java
[UTF-8] Fri Nov 29 01:30:11 2013
@@ -16,6 +16,7 @@
  */
 package org.apache.sis.internal.referencing;
 
+import org.opengis.referencing.cs.AxisDirection;
 import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
@@ -34,6 +35,110 @@ import static org.opengis.referencing.cs
  */
 public final strictfp class AxisDirectionsTest extends TestCase {
     /**
+     * Tests {@link AxisDirections#absolute(AxisDirection)}.
+     */
+    @Test
+    public void testAbsolute() {
+        assertEquals(NORTH,             AxisDirections.absolute(NORTH));
+        assertEquals(NORTH,             AxisDirections.absolute(SOUTH));
+        assertEquals(EAST,              AxisDirections.absolute(EAST));
+        assertEquals(EAST,              AxisDirections.absolute(WEST));
+        assertEquals(NORTH_EAST,        AxisDirections.absolute(NORTH_EAST));
+        assertEquals(NORTH_EAST,        AxisDirections.absolute(SOUTH_WEST));
+        assertEquals(NORTH_NORTH_EAST,  AxisDirections.absolute(NORTH_NORTH_EAST));
+        assertEquals(NORTH_NORTH_EAST,  AxisDirections.absolute(SOUTH_SOUTH_WEST));
+        assertEquals(UP,                AxisDirections.absolute(UP));
+        assertEquals(UP,                AxisDirections.absolute(DOWN));
+        assertEquals(FUTURE,            AxisDirections.absolute(FUTURE));
+        assertEquals(FUTURE,            AxisDirections.absolute(PAST));
+    }
+
+    /**
+     * Tests {@link AxisDirections#opposite(AxisDirection)}.
+     */
+    @Test
+    public void testOpposite() {
+        assertEquals(SOUTH,             AxisDirections.opposite(NORTH));
+        assertEquals(NORTH,             AxisDirections.opposite(SOUTH));
+        assertEquals(WEST,              AxisDirections.opposite(EAST));
+        assertEquals(EAST,              AxisDirections.opposite(WEST));
+        assertEquals(SOUTH_WEST,        AxisDirections.opposite(NORTH_EAST));
+        assertEquals(NORTH_EAST,        AxisDirections.opposite(SOUTH_WEST));
+        assertEquals(SOUTH_SOUTH_WEST,  AxisDirections.opposite(NORTH_NORTH_EAST));
+        assertEquals(NORTH_NORTH_EAST,  AxisDirections.opposite(SOUTH_SOUTH_WEST));
+        assertEquals(DOWN,              AxisDirections.opposite(UP));
+        assertEquals(UP,                AxisDirections.opposite(DOWN));
+        assertEquals(PAST,              AxisDirections.opposite(FUTURE));
+        assertEquals(FUTURE,            AxisDirections.opposite(PAST));
+    }
+
+    /**
+     * Tests {@link AxisDirections#isOpposite(AxisDirection)}.
+     */
+    @Test
+    @DependsOnMethod("testOpposite")
+    public void testIsOpposite() {
+        assertFalse(AxisDirections.isOpposite(NORTH ));
+        assertTrue (AxisDirections.isOpposite(SOUTH ));
+        assertFalse(AxisDirections.isOpposite(EAST  ));
+        assertTrue (AxisDirections.isOpposite(WEST  ));
+        assertFalse(AxisDirections.isOpposite(UP    ));
+        assertTrue (AxisDirections.isOpposite(DOWN  ));
+        assertFalse(AxisDirections.isOpposite(FUTURE));
+        assertTrue (AxisDirections.isOpposite(PAST  ));
+        assertFalse(AxisDirections.isOpposite(OTHER ));
+    }
+
+    /**
+     * Tests {@link AxisDirections#isSpatialOrCustom(AxisDirection, boolean)} and
+     * {@link AxisDirections#isGrid(AxisDirection)}.
+     */
+    @Test
+    public void testIsSpatialOrGrid() {
+        /*
+         * Spatial directions.
+         */
+        verifyProperties(true, false, false,
+                NORTH, EAST, SOUTH, WEST, NORTH_EAST, SOUTH_EAST, SOUTH_WEST, NORTH_WEST,
+                NORTH_NORTH_EAST, EAST_NORTH_EAST, EAST_SOUTH_EAST, SOUTH_SOUTH_EAST,
+                SOUTH_SOUTH_WEST, WEST_SOUTH_WEST, WEST_NORTH_WEST, NORTH_NORTH_WEST,
+                UP, DOWN, GEOCENTRIC_X, GEOCENTRIC_Y, GEOCENTRIC_Z);
+        /*
+         * Grid directions.
+         */
+        verifyProperties(false, true, false,
+            COLUMN_POSITIVE, COLUMN_NEGATIVE, ROW_POSITIVE, ROW_NEGATIVE);
+        /*
+         * Display directions.
+         */
+        verifyProperties(false, false, true,
+            DISPLAY_RIGHT, DISPLAY_LEFT, DISPLAY_UP, DISPLAY_DOWN);
+        /*
+         * Temporal directions.
+         */
+        verifyProperties(false, false, false,
+            FUTURE, PAST);
+    }
+
+    /**
+     * Asserts that
+     * {@link AxisDirections#isSpatialOrCustom(AxisDirection)},
+     * {@link AxisDirections#isCartesianOrCustom(AxisDirection)} and
+     * {@link AxisDirections#isGrid(AxisDirection)}
+     * returns the expected value for all the given axis directions.
+     */
+    private static void verifyProperties(final boolean isSpatial, final boolean isGrid, final
boolean isDisplay,
+            final AxisDirection... directions)
+    {
+        for (final AxisDirection dir : directions) {
+            final String name = dir.name();
+            assertEquals(name, isGrid, AxisDirections.isGrid(dir));
+            assertEquals(name, isSpatial, AxisDirections.isSpatialOrCustom(dir, false));
+            assertEquals(name, isSpatial | isGrid | isDisplay, AxisDirections.isSpatialOrCustom(dir,
true));
+        }
+    }
+
+    /**
      * Tests {@link AxisDirections#valueOf(String)} for the North, South, East and West directions.
      */
     @Test



Mime
View raw message