sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1422640 - /sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/
Date Sun, 16 Dec 2012 17:55:29 GMT
Author: desruisseaux
Date: Sun Dec 16 17:55:28 2012
New Revision: 1422640

URL: http://svn.apache.org/viewvc?rev=1422640&view=rev
Log:
Constructor expecting a WKT can accept a CharSequence instead than a String.

Modified:
    sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractDirectPosition.java
    sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractEnvelope.java
    sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/ArrayEnvelope.java
    sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/DirectPosition1D.java
    sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/DirectPosition2D.java
    sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralDirectPosition.java
    sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java
    sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/ImmutableEnvelope.java

Modified: sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractDirectPosition.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractDirectPosition.java?rev=1422640&r1=1422639&r2=1422640&view=diff
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractDirectPosition.java
(original)
+++ sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractDirectPosition.java
Sun Dec 16 17:55:28 2012
@@ -27,6 +27,7 @@ import org.opengis.geometry.DirectPositi
 import org.opengis.geometry.MismatchedDimensionException;
 import org.opengis.geometry.MismatchedReferenceSystemException;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.opengis.referencing.cs.CoordinateSystem;
 import org.apache.sis.util.Utilities;
 import org.apache.sis.util.CharSequences;
 import org.apache.sis.util.resources.Errors;
@@ -129,10 +130,13 @@ public abstract class AbstractDirectPosi
             final int expected) throws MismatchedDimensionException
     {
         if (crs != null) {
-            final int dimension = crs.getCoordinateSystem().getDimension();
-            if (dimension != expected) {
-                throw new MismatchedDimensionException(Errors.format(
-                        Errors.Keys.MismatchedDimension_3, "crs", dimension, expected));
+            final CoordinateSystem cs = crs.getCoordinateSystem();
+            if (cs != null) { // Should never be null, but let be safe.
+                final int dimension = cs.getDimension();
+                if (dimension != expected) {
+                    throw new MismatchedDimensionException(Errors.format(
+                            Errors.Keys.MismatchedDimension_3, "crs", dimension, expected));
+                }
             }
         }
     }
@@ -163,7 +167,7 @@ public abstract class AbstractDirectPosi
      *   POINT(x₀ x₁ x₂ …)
      * }
      *
-     * The string returned by this method can be {@linkplain GeneralDirectPosition#GeneralDirectPosition(String)
parsed}
+     * The string returned by this method can be {@linkplain GeneralDirectPosition#GeneralDirectPosition(CharSequence)
parsed}
      * by the {@code GeneralDirectPosition} constructor.
      *
      * @return This position as a {@code POINT} in <cite>Well Known Text</cite>
(WKT) format.

Modified: sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractEnvelope.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractEnvelope.java?rev=1422640&r1=1422639&r2=1422640&view=diff
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractEnvelope.java
(original)
+++ sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractEnvelope.java
Sun Dec 16 17:55:28 2012
@@ -155,6 +155,8 @@ public abstract class AbstractEnvelope i
                                                   final DirectPosition upperCorner)
             throws MismatchedReferenceSystemException
     {
+        ensureNonNull("lowerCorner", lowerCorner);
+        ensureNonNull("upperCorner", upperCorner);
         final CoordinateReferenceSystem crs1 = lowerCorner.getCoordinateReferenceSystem();
         final CoordinateReferenceSystem crs2 = upperCorner.getCoordinateReferenceSystem();
         if (crs1 == null) {
@@ -905,7 +907,7 @@ public abstract class AbstractEnvelope i
      *   BOX3D(-90 -180 0, 90 180 1)
      * }
      *
-     * The string returned by this method can be {@linkplain GeneralEnvelope#GeneralEnvelope(String)
parsed}
+     * The string returned by this method can be {@linkplain GeneralEnvelope#GeneralEnvelope(CharSequence)
parsed}
      * by the {@code GeneralEnvelope} constructor.
      *
      * @return This envelope as a {@code BOX2D} or {@code BOX3D} (most typical dimensions)
in WKT format.

Modified: sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/ArrayEnvelope.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/ArrayEnvelope.java?rev=1422640&r1=1422639&r2=1422640&view=diff
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/ArrayEnvelope.java
(original)
+++ sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/ArrayEnvelope.java
Sun Dec 16 17:55:28 2012
@@ -82,17 +82,15 @@ class ArrayEnvelope extends AbstractEnve
     public ArrayEnvelope(final DirectPosition lowerCorner, final DirectPosition upperCorner)
             throws MismatchedDimensionException, MismatchedReferenceSystemException
     {
-        ensureNonNull("lowerCorner", lowerCorner);
-        ensureNonNull("upperCorner", upperCorner);
+        crs = getCommonCRS(lowerCorner, upperCorner); // This performs also an argument check.
         final int dimension = lowerCorner.getDimension();
+        AbstractDirectPosition.ensureDimensionMatch(crs, dimension);
         ensureSameDimension(dimension, upperCorner.getDimension());
         ordinates = new double[dimension * 2];
         for (int i=0; i<dimension; i++) {
             ordinates[i            ] = lowerCorner.getOrdinate(i);
             ordinates[i + dimension] = upperCorner.getOrdinate(i);
         }
-        crs = getCommonCRS(lowerCorner, upperCorner);
-        AbstractDirectPosition.ensureDimensionMatch(crs, dimension);
     }
 
     /**
@@ -148,9 +146,11 @@ class ArrayEnvelope extends AbstractEnve
             crs = envelope.getCoordinateReferenceSystem();
             final int dimension = envelope.getDimension();
             ordinates = new double[dimension * 2];
+            final DirectPosition lowerCorner = envelope.getLowerCorner();
+            final DirectPosition upperCorner = envelope.getUpperCorner();
             for (int i=0; i<dimension; i++) {
-                ordinates[i]           = envelope.getMinimum(i);
-                ordinates[i+dimension] = envelope.getMaximum(i);
+                ordinates[i]           = lowerCorner.getOrdinate(i);
+                ordinates[i+dimension] = upperCorner.getOrdinate(i);
             }
         }
     }

Modified: sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/DirectPosition1D.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/DirectPosition1D.java?rev=1422640&r1=1422639&r2=1422640&view=diff
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/DirectPosition1D.java
(original)
+++ sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/DirectPosition1D.java
Sun Dec 16 17:55:28 2012
@@ -97,7 +97,7 @@ public class DirectPosition1D extends Ab
      * @see #toString()
      * @see org.apache.sis.measure.CoordinateFormat
      */
-    public DirectPosition1D(final String wkt) throws IllegalArgumentException {
+    public DirectPosition1D(final CharSequence wkt) throws IllegalArgumentException {
         final double[] ordinates = parse(wkt);
         if (ordinates == null) {
             throw new IllegalArgumentException(Errors.format(

Modified: sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/DirectPosition2D.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/DirectPosition2D.java?rev=1422640&r1=1422639&r2=1422640&view=diff
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/DirectPosition2D.java
(original)
+++ sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/DirectPosition2D.java
Sun Dec 16 17:55:28 2012
@@ -25,8 +25,14 @@ import org.opengis.referencing.cs.AxisDi
 import org.apache.sis.util.resources.Errors;
 
 import static java.lang.Double.doubleToLongBits;
+import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
 import static org.apache.sis.util.StringBuilders.trimFractionalPart;
 
+// Following imports are needed because we can't extend AbstractDirectPosition.
+// We want to write this class as if it was an AbstractDirectPosition subclass.
+import static org.apache.sis.geometry.AbstractDirectPosition.ensureDimensionMatch;
+import static org.apache.sis.geometry.AbstractDirectPosition.parse;
+
 
 /**
  * Holds the coordinates for a two-dimensional position on top of {@link Point2D}.
@@ -82,11 +88,12 @@ public class DirectPosition2D extends Po
     }
 
     /**
-     * Constructs a position with the specified coordinate reference system.
+     * Constructs a position initialized to (0,0) with the specified coordinate reference
system.
      *
      * @param crs The coordinate reference system, or {@code null}.
      */
     public DirectPosition2D(final CoordinateReferenceSystem crs) {
+        ensureDimensionMatch(crs, 2);
         this.crs = crs;
     }
 
@@ -112,32 +119,30 @@ public class DirectPosition2D extends Po
      * The actual axis orientations are determined by the specified CRS.
      * See the <a href="#skip-navbar_top">class javadoc</a> for details.
      *
+     * @param x   The first ordinate value (not necessarily horizontal).
+     * @param y   The second ordinate value (not necessarily vertical).
      * @param crs The coordinate reference system, or {@code null}.
-     * @param x The first ordinate value (not necessarily horizontal).
-     * @param y The second ordinate value (not necessarily vertical).
      */
-    public DirectPosition2D(final CoordinateReferenceSystem crs,
-                            final double x, final double y)
-    {
+    public DirectPosition2D(final double x, final double y, final CoordinateReferenceSystem
crs) {
         super(x, y);
-        AbstractDirectPosition.ensureDimensionMatch(crs, 2);
         this.crs = crs;
+        ensureDimensionMatch(crs, 2);
     }
 
     /**
-     * Constructs a position from the specified {@link Point2D}.
-     * If the given point implements also the {@code DirectPosition} interface, then this
-     * constructor will set the CRS of this {@code DirectPosition2D} to the CRS of the given
point.
-     * Otherwise the CRS of this {@code DirectPosition2D} will be initially null.
-     *
-     * @param point The point to copy.
-     */
-    public DirectPosition2D(final Point2D point) {
-        super(point.getX(), point.getY());
-        if (point instanceof DirectPosition) {
-            crs = ((DirectPosition) point).getCoordinateReferenceSystem();
-            AbstractDirectPosition.ensureDimensionMatch(crs, 2);
-        }
+     * Constructs a position initialized to the same values than the specified point.
+     *
+     * @param  position The position to copy.
+     * @throws MismatchedDimensionException if the given position is not two-dimensional.
+     *
+     * @see #setLocation(Point2D)
+     */
+    public DirectPosition2D(final DirectPosition position) throws MismatchedDimensionException
{
+        ensureNonNull("position", position);
+        ensureDimensionMatch("position", position.getDimension(), 2);
+        x   = position.getOrdinate(0);
+        y   = position.getOrdinate(1);
+        crs = position.getCoordinateReferenceSystem();
     }
 
     /**
@@ -156,13 +161,13 @@ public class DirectPosition2D extends Po
      * @see #toString()
      * @see org.apache.sis.measure.CoordinateFormat
      */
-    public DirectPosition2D(final String wkt) throws IllegalArgumentException {
-        final double[] ordinates = AbstractDirectPosition.parse(wkt);
+    public DirectPosition2D(final CharSequence wkt) throws IllegalArgumentException {
+        final double[] ordinates = parse(wkt);
         if (ordinates == null) {
             throw new IllegalArgumentException(Errors.format(
                     Errors.Keys.UnparsableStringForClass_2, "POINT", wkt));
         }
-        AbstractDirectPosition.ensureDimensionMatch("wkt", ordinates.length, 2);
+        ensureDimensionMatch("wkt", ordinates.length, 2);
         x = ordinates[0];
         y = ordinates[1];
     }
@@ -205,7 +210,7 @@ public class DirectPosition2D extends Po
      * @param crs The new coordinate reference system, or {@code null}.
      */
     public void setCoordinateReferenceSystem(final CoordinateReferenceSystem crs) {
-        AbstractDirectPosition.ensureDimensionMatch(crs, 2);
+        ensureDimensionMatch(crs, 2);
         this.crs = crs;
     }
 
@@ -259,18 +264,21 @@ public class DirectPosition2D extends Po
     }
 
     /**
-     * Sets this coordinate to the specified direct position. If the specified position
-     * contains a coordinate reference system (CRS), then the CRS for this position will
-     * be set to the CRS of the specified position.
-     *
-     * @param  position The new position for this point.
-     * @throws MismatchedDimensionException if this point doesn't have the expected dimension.
-     */
-    public void setLocation(final DirectPosition position) throws MismatchedDimensionException
{
-        AbstractDirectPosition.ensureDimensionMatch("position", position.getDimension(),
2);
-        setCoordinateReferenceSystem(position.getCoordinateReferenceSystem());
-        x = position.getOrdinate(0);
-        y = position.getOrdinate(1);
+     * Sets this coordinate to the specified point. If the specified position is also a
+     * {@code DirectPosition} containing a non-null coordinate reference system (CRS),
+     * then the CRS for this position will be set to the CRS of the given point.
+     *
+     * @param position The new position for this point.
+     */
+    @Override
+    public void setLocation(final Point2D position) {
+        super.setLocation(position);
+        if (position instanceof DirectPosition) {
+            final CoordinateReferenceSystem candidate = ((DirectPosition) position).getCoordinateReferenceSystem();
+            if (candidate != null) {
+                setCoordinateReferenceSystem(candidate);
+            }
+        }
     }
 
     /**
@@ -281,7 +289,7 @@ public class DirectPosition2D extends Po
      *   POINT(x y)
      * }
      *
-     * The string returned by this method can be {@linkplain #DirectPosition2D(String) parsed}
+     * The string returned by this method can be {@linkplain #DirectPosition2D(CharSequence)
parsed}
      * by the {@code DirectPosition2D} constructor.
      */
     @Override

Modified: sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralDirectPosition.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralDirectPosition.java?rev=1422640&r1=1422639&r2=1422640&view=diff
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralDirectPosition.java
(original)
+++ sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralDirectPosition.java
Sun Dec 16 17:55:28 2012
@@ -128,7 +128,7 @@ public class GeneralDirectPosition exten
      * @see #toString()
      * @see org.apache.sis.measure.CoordinateFormat
      */
-    public GeneralDirectPosition(final String wkt) throws IllegalArgumentException {
+    public GeneralDirectPosition(final CharSequence wkt) throws IllegalArgumentException
{
         if ((ordinates = parse(wkt)) == null) {
             throw new IllegalArgumentException(Errors.format(
                     Errors.Keys.UnparsableStringForClass_2, "POINT", wkt));

Modified: sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java?rev=1422640&r1=1422639&r2=1422640&view=diff
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java
(original)
+++ sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java
Sun Dec 16 17:55:28 2012
@@ -58,7 +58,8 @@ import static org.apache.sis.math.MathFu
  *   <li>{@linkplain #GeneralEnvelope(double[], double[]) From two coordinate points}.</li>
  *   <li>{@linkplain #GeneralEnvelope(Envelope) From a an other envelope} (copy constructor).</li>
  *   <li>{@linkplain #GeneralEnvelope(GeographicBoundingBox) From a geographic bounding
box}.</li>
- *   <li>{@linkplain #GeneralEnvelope(String) From a string} representing a {@code
BBOX} in <cite>Well Known Text</cite> (WKT) format.</li>
+ *   <li>{@linkplain #GeneralEnvelope(CharSequence) From a character sequence}
+ *       representing a {@code BBOX} in <cite>Well Known Text</cite> (WKT) format.</li>
  * </ul>
  *
  * {@section Spanning the anti-meridian of a Geographic CRS}
@@ -216,7 +217,7 @@ public class GeneralEnvelope extends Arr
      * @see Envelopes#parseWKT(String)
      * @see Envelopes#toWKT(Envelope)
      */
-    public GeneralEnvelope(final String wkt) throws IllegalArgumentException {
+    public GeneralEnvelope(final CharSequence wkt) throws IllegalArgumentException {
         super(wkt);
     }
 

Modified: sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/ImmutableEnvelope.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/ImmutableEnvelope.java?rev=1422640&r1=1422639&r2=1422640&view=diff
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/ImmutableEnvelope.java
(original)
+++ sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/ImmutableEnvelope.java
Sun Dec 16 17:55:28 2012
@@ -129,7 +129,7 @@ public final class ImmutableEnvelope ext
      * @throws MismatchedDimensionException If the dimension of the given CRS is not equals
      *         to the dimension of the parsed envelope.
      */
-    public ImmutableEnvelope(final String wkt, final CoordinateReferenceSystem crs)
+    public ImmutableEnvelope(final CharSequence wkt, final CoordinateReferenceSystem crs)
             throws IllegalArgumentException, MismatchedDimensionException
     {
         super(wkt);



Mime
View raw message