You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2012/12/21 10:23:46 UTC
svn commit: r1424825 - in /sis/branches/JDK7:
sis-referencing/src/main/java/org/apache/sis/geometry/
sis-utility/src/main/java/org/apache/sis/util/
sis-utility/src/main/java/org/apache/sis/util/resources/
Author: desruisseaux
Date: Fri Dec 21 09:23:46 2012
New Revision: 1424825
URL: http://svn.apache.org/viewvc?rev=1424825&view=rev
Log:
Moved the 'ensureDimensionMatch' methods to the ArgumentChecks class.
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/Envelope2D.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
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/ArgumentChecks.java
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
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=1424825&r1=1424824&r2=1424825&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 Fri Dec 21 09:23:46 2012
@@ -26,7 +26,9 @@ 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.CoordinateSystemAxis;
import org.opengis.referencing.cs.CoordinateSystem;
+import org.opengis.referencing.cs.RangeMeaning;
import org.apache.sis.util.Utilities;
import org.apache.sis.util.CharSequences;
import org.apache.sis.util.resources.Errors;
@@ -34,11 +36,10 @@ import org.apache.sis.util.resources.Err
import static java.lang.Double.doubleToLongBits;
import static org.apache.sis.util.Arrays.resize;
import static org.apache.sis.util.StringBuilders.trimFractionalPart;
+import static org.apache.sis.util.ArgumentChecks.ensureDimensionMatches;
// Related to JDK7
import java.util.Objects;
-import org.opengis.referencing.cs.CoordinateSystemAxis;
-import org.opengis.referencing.cs.RangeMeaning;
/**
@@ -104,7 +105,7 @@ public abstract class AbstractDirectPosi
{
final int dimension = getDimension();
if (position != null) {
- ensureDimensionMatch("position", position.getDimension(), dimension);
+ ensureDimensionMatches("position", dimension, position);
final CoordinateReferenceSystem crs = getCoordinateReferenceSystem();
if (crs != null) {
final CoordinateReferenceSystem other = position.getCoordinateReferenceSystem();
@@ -175,46 +176,6 @@ public abstract class AbstractDirectPosi
}
/**
- * Ensures that the given CRS, if non-null, has the expected number of dimensions.
- * This method presumes that the argument name is {@code "crs"}.
- *
- * @param crs The coordinate reference system to check, or {@code null}.
- * @param expected The expected number of dimensions.
- * @throws MismatchedDimensionException if the CRS dimension is not valid.
- */
- static void ensureDimensionMatch(final CoordinateReferenceSystem crs,
- final int expected) throws MismatchedDimensionException
- {
- if (crs != null) {
- 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));
- }
- }
- }
- }
-
- /**
- * Ensures that the given number of dimensions is equals to the expected value.
- *
- * @param name The name of the argument to check.
- * @param dimension The object dimension.
- * @param expectedDimension The Expected dimension for the object.
- * @throws MismatchedDimensionException if the object doesn't have the expected dimension.
- */
- static void ensureDimensionMatch(final String name, final int dimension,
- final int expectedDimension) throws MismatchedDimensionException
- {
- if (dimension != expectedDimension) {
- throw new MismatchedDimensionException(Errors.format(Errors.Keys.MismatchedDimension_3,
- name, dimension, expectedDimension));
- }
- }
-
- /**
* Returns {@code true} if every values in the given {@code double} array could be casted
* to the {@code float} type without precision lost. This method treats all {@code NaN} values
* as equal.
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=1424825&r1=1424824&r2=1424825&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 Fri Dec 21 09:23:46 2012
@@ -40,6 +40,7 @@ import org.apache.sis.util.resources.Err
import static java.lang.Double.doubleToLongBits;
import static org.apache.sis.internal.util.Utilities.SIGN_BIT_MASK;
import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
+import static org.apache.sis.util.ArgumentChecks.ensureDimensionMatches;
import static org.apache.sis.util.StringBuilders.trimFractionalPart;
import static org.apache.sis.math.MathFunctions.epsilonEqual;
import static org.apache.sis.math.MathFunctions.isNegative;
@@ -569,7 +570,7 @@ public abstract class AbstractEnvelope i
public boolean contains(final DirectPosition position) throws MismatchedDimensionException {
ensureNonNull("position", position);
final int dimension = getDimension();
- AbstractDirectPosition.ensureDimensionMatch("point", position.getDimension(), dimension);
+ ensureDimensionMatches("point", dimension, position);
assert equalsIgnoreMetadata(getCoordinateReferenceSystem(),
position.getCoordinateReferenceSystem(), true) : position;
for (int i=0; i<dimension; i++) {
@@ -625,7 +626,7 @@ public abstract class AbstractEnvelope i
public boolean contains(final Envelope envelope, final boolean edgesInclusive) throws MismatchedDimensionException {
ensureNonNull("envelope", envelope);
final int dimension = getDimension();
- AbstractDirectPosition.ensureDimensionMatch("envelope", envelope.getDimension(), dimension);
+ ensureDimensionMatches("envelope", dimension, envelope);
assert equalsIgnoreMetadata(getCoordinateReferenceSystem(),
envelope.getCoordinateReferenceSystem(), true) : envelope;
final DirectPosition lowerCorner = envelope.getLowerCorner();
@@ -715,7 +716,7 @@ public abstract class AbstractEnvelope i
public boolean intersects(final Envelope envelope, final boolean edgesInclusive) throws MismatchedDimensionException {
ensureNonNull("envelope", envelope);
final int dimension = getDimension();
- AbstractDirectPosition.ensureDimensionMatch("envelope", envelope.getDimension(), dimension);
+ ensureDimensionMatches("envelope", dimension, envelope);
assert equalsIgnoreMetadata(getCoordinateReferenceSystem(),
envelope.getCoordinateReferenceSystem(), true) : envelope;
final DirectPosition lowerCorner = envelope.getLowerCorner();
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=1424825&r1=1424824&r2=1424825&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 Fri Dec 21 09:23:46 2012
@@ -86,7 +86,7 @@ class ArrayEnvelope extends AbstractEnve
{
crs = getCommonCRS(lowerCorner, upperCorner); // This performs also an argument check.
final int dimension = lowerCorner.getDimension();
- AbstractDirectPosition.ensureDimensionMatch(crs, dimension);
+ ensureDimensionMatches("crs", dimension, crs);
ensureSameDimension(dimension, upperCorner.getDimension());
ordinates = new double[dimension * 2];
for (int i=0; i<dimension; 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=1424825&r1=1424824&r2=1424825&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 Fri Dec 21 09:23:46 2012
@@ -27,6 +27,8 @@ import org.opengis.geometry.DirectPositi
import org.opengis.geometry.MismatchedDimensionException;
import org.apache.sis.util.resources.Errors;
+import static org.apache.sis.util.ArgumentChecks.ensureDimensionMatches;
+
/**
* Holds the coordinates for a one-dimensional position within some coordinate reference system.
@@ -68,7 +70,7 @@ public class DirectPosition1D extends Ab
* @param crs The coordinate reference system.
*/
public DirectPosition1D(final CoordinateReferenceSystem crs) {
- ensureDimensionMatch(crs, 1);
+ ensureDimensionMatches("crs", 1, crs);
this.crs = crs;
}
@@ -103,7 +105,7 @@ public class DirectPosition1D extends Ab
throw new IllegalArgumentException(Errors.format(
Errors.Keys.UnparsableStringForClass_2, "POINT", wkt));
}
- ensureDimensionMatch("wkt", ordinates.length, 1);
+ ensureDimensionMatches("wkt", 1, ordinates);
ordinate = ordinates[0];
}
@@ -136,7 +138,7 @@ public class DirectPosition1D extends Ab
* @param crs The new coordinate reference system, or {@code null}.
*/
public void setCoordinateReferenceSystem(final CoordinateReferenceSystem crs) {
- ensureDimensionMatch(crs, 1);
+ ensureDimensionMatches("crs", 1, crs);
this.crs = crs;
}
@@ -199,7 +201,7 @@ public class DirectPosition1D extends Ab
*/
@Override
public void setLocation(final DirectPosition position) throws MismatchedDimensionException {
- ensureDimensionMatch("position", position.getDimension(), 1);
+ ensureDimensionMatches("position", 1, position);
setCoordinateReferenceSystem(position.getCoordinateReferenceSystem());
ordinate = position.getOrdinate(0);
}
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=1424825&r1=1424824&r2=1424825&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 Fri Dec 21 09:23:46 2012
@@ -25,11 +25,7 @@ import org.apache.sis.util.resources.Err
import static java.lang.Double.doubleToLongBits;
import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
-
-// 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;
+import static org.apache.sis.util.ArgumentChecks.ensureDimensionMatches;
// Related to JDK7
import java.util.Objects;
@@ -94,7 +90,7 @@ public class DirectPosition2D extends Po
* @param crs The coordinate reference system, or {@code null}.
*/
public DirectPosition2D(final CoordinateReferenceSystem crs) {
- ensureDimensionMatch(crs, 2);
+ ensureDimensionMatches("crs", 2, crs);
this.crs = crs;
}
@@ -127,7 +123,7 @@ public class DirectPosition2D extends Po
public DirectPosition2D(final double x, final double y, final CoordinateReferenceSystem crs) {
super(x, y);
this.crs = crs;
- ensureDimensionMatch(crs, 2);
+ ensureDimensionMatches("crs", 2, crs);
}
/**
@@ -140,7 +136,7 @@ public class DirectPosition2D extends Po
*/
public DirectPosition2D(final DirectPosition position) throws MismatchedDimensionException {
ensureNonNull("position", position);
- ensureDimensionMatch("position", position.getDimension(), 2);
+ ensureDimensionMatches("position", 2, position);
x = position.getOrdinate(0);
y = position.getOrdinate(1);
crs = position.getCoordinateReferenceSystem();
@@ -163,12 +159,12 @@ public class DirectPosition2D extends Po
* @see org.apache.sis.measure.CoordinateFormat
*/
public DirectPosition2D(final CharSequence wkt) throws IllegalArgumentException {
- final double[] ordinates = parse(wkt);
+ final double[] ordinates = AbstractDirectPosition.parse(wkt);
if (ordinates == null) {
throw new IllegalArgumentException(Errors.format(
Errors.Keys.UnparsableStringForClass_2, "POINT", wkt));
}
- ensureDimensionMatch("wkt", ordinates.length, 2);
+ ensureDimensionMatches("wkt", 2, ordinates);
x = ordinates[0];
y = ordinates[1];
}
@@ -211,7 +207,7 @@ public class DirectPosition2D extends Po
* @param crs The new coordinate reference system, or {@code null}.
*/
public void setCoordinateReferenceSystem(final CoordinateReferenceSystem crs) {
- ensureDimensionMatch(crs, 2);
+ ensureDimensionMatches("crs", 2, crs);
this.crs = crs;
}
Modified: sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/Envelope2D.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/Envelope2D.java?rev=1424825&r1=1424824&r2=1424825&view=diff
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/Envelope2D.java (original)
+++ sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/Envelope2D.java Fri Dec 21 09:23:46 2012
@@ -37,6 +37,7 @@ import static java.lang.Double.doubleToL
import static org.apache.sis.math.MathFunctions.isPositive;
import static org.apache.sis.math.MathFunctions.isNegative;
import static org.apache.sis.math.MathFunctions.isSameSign;
+import static org.apache.sis.util.ArgumentChecks.ensureDimensionMatches;
import static org.apache.sis.internal.referencing.Utilities.isPoleToPole;
// Following imports are needed because we can't extend AbstractEnvelope.
@@ -152,7 +153,7 @@ public class Envelope2D extends Rectangl
*/
this(lowerCorner.getOrdinate(0), lowerCorner.getOrdinate(1),
upperCorner.getOrdinate(0), upperCorner.getOrdinate(1));
- AbstractDirectPosition.ensureDimensionMatch(crs, 2);
+ ensureDimensionMatches("crs", 2, crs);
this.crs = crs;
}
@@ -224,7 +225,7 @@ public class Envelope2D extends Rectangl
throws MismatchedDimensionException
{
super(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight()); // Really 'super', not 'this'.
- AbstractDirectPosition.ensureDimensionMatch(crs, 2);
+ ensureDimensionMatches("crs", 2, crs);
this.crs = crs;
}
@@ -247,7 +248,7 @@ public class Envelope2D extends Rectangl
final CoordinateReferenceSystem crs) throws MismatchedDimensionException
{
super(x, y, width, height); // Really 'super', not 'this'.
- AbstractDirectPosition.ensureDimensionMatch(crs, 2);
+ ensureDimensionMatches("crs", 2, crs);
this.crs = crs;
}
@@ -270,7 +271,7 @@ public class Envelope2D extends Rectangl
* @param crs The new coordinate reference system, or {@code null}.
*/
public void setCoordinateReferenceSystem(final CoordinateReferenceSystem crs) {
- AbstractDirectPosition.ensureDimensionMatch(crs, 2);
+ ensureDimensionMatches("crs", 2, crs);
this.crs = crs;
}
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=1424825&r1=1424824&r2=1424825&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 Fri Dec 21 09:23:46 2012
@@ -29,6 +29,8 @@ import org.opengis.geometry.MismatchedDi
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.apache.sis.util.resources.Errors;
+import static org.apache.sis.util.ArgumentChecks.ensureDimensionMatches;
+
// JDK7 related
import java.util.Objects;
@@ -118,7 +120,7 @@ public class GeneralDirectPosition exten
public GeneralDirectPosition(final DirectPosition point) {
ordinates = point.getCoordinate(); // Should already be cloned.
crs = point.getCoordinateReferenceSystem();
- ensureDimensionMatch(crs, ordinates.length);
+ ensureDimensionMatches("crs", ordinates.length, crs);
}
/**
@@ -178,7 +180,7 @@ public class GeneralDirectPosition exten
public void setCoordinateReferenceSystem(final CoordinateReferenceSystem crs)
throws MismatchedDimensionException
{
- ensureDimensionMatch(crs, getDimension());
+ ensureDimensionMatches("crs", getDimension(), crs);
this.crs = crs;
}
@@ -208,7 +210,7 @@ public class GeneralDirectPosition exten
if (ordinates == null) {
Arrays.fill(this.ordinates, Double.NaN);
} else {
- ensureDimensionMatch("ordinates", ordinates.length, this.ordinates.length);
+ ensureDimensionMatches("ordinates", this.ordinates.length, ordinates);
System.arraycopy(ordinates, 0, this.ordinates, 0, ordinates.length);
}
}
@@ -254,7 +256,7 @@ public class GeneralDirectPosition exten
if (position == null) {
Arrays.fill(ordinates, Double.NaN);
} else {
- ensureDimensionMatch("position", position.getDimension(), ordinates.length);
+ ensureDimensionMatches("position", ordinates.length, position);
setCoordinateReferenceSystem(position.getCoordinateReferenceSystem());
for (int i=0; i<ordinates.length; i++) {
ordinates[i] = position.getOrdinate(i);
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=1424825&r1=1424824&r2=1424825&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 Fri Dec 21 09:23:46 2012
@@ -258,7 +258,7 @@ public class GeneralEnvelope extends Arr
public void setCoordinateReferenceSystem(final CoordinateReferenceSystem crs)
throws MismatchedDimensionException
{
- AbstractDirectPosition.ensureDimensionMatch(crs, getDimension());
+ ensureDimensionMatches("crs", getDimension(), crs);
this.crs = crs;
}
@@ -318,7 +318,7 @@ public class GeneralEnvelope extends Arr
public void setEnvelope(final Envelope envelope) throws MismatchedDimensionException {
ensureNonNull("envelope", envelope);
final int dimension = ordinates.length >>> 1;
- AbstractDirectPosition.ensureDimensionMatch("envelope", envelope.getDimension(), dimension);
+ ensureDimensionMatches("envelope", dimension, envelope);
if (envelope instanceof ArrayEnvelope) {
System.arraycopy(((ArrayEnvelope) envelope).ordinates, 0, ordinates, 0, ordinates.length);
} else {
@@ -408,7 +408,7 @@ public class GeneralEnvelope extends Arr
public void add(final DirectPosition position) throws MismatchedDimensionException {
ensureNonNull("position", position);
final int dim = ordinates.length >>> 1;
- AbstractDirectPosition.ensureDimensionMatch("position", position.getDimension(), dim);
+ ensureDimensionMatches("position", dim, position);
assert equalsIgnoreMetadata(crs, position.getCoordinateReferenceSystem(), true) : position;
for (int i=0; i<dim; i++) {
final double value = position.getOrdinate(i);
@@ -478,7 +478,7 @@ public class GeneralEnvelope extends Arr
public void add(final Envelope envelope) throws MismatchedDimensionException {
ensureNonNull("envelope", envelope);
final int dim = ordinates.length >>> 1;
- AbstractDirectPosition.ensureDimensionMatch("envelope", envelope.getDimension(), dim);
+ ensureDimensionMatches("envelope", dim, envelope);
assert equalsIgnoreMetadata(crs, envelope.getCoordinateReferenceSystem(), true) : envelope;
final DirectPosition lower = envelope.getLowerCorner();
final DirectPosition upper = envelope.getUpperCorner();
@@ -597,7 +597,7 @@ public class GeneralEnvelope extends Arr
public void intersect(final Envelope envelope) throws MismatchedDimensionException {
ensureNonNull("envelope", envelope);
final int dim = ordinates.length >>> 1;
- AbstractDirectPosition.ensureDimensionMatch("envelope", envelope.getDimension(), dim);
+ ensureDimensionMatches("envelope", dim, envelope);
assert equalsIgnoreMetadata(crs, envelope.getCoordinateReferenceSystem(), true) : envelope;
final DirectPosition lower = envelope.getLowerCorner();
final DirectPosition upper = envelope.getUpperCorner();
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=1424825&r1=1424824&r2=1424825&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 Fri Dec 21 09:23:46 2012
@@ -30,6 +30,8 @@ import org.opengis.geometry.MismatchedRe
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.metadata.extent.GeographicBoundingBox;
+import static org.apache.sis.util.ArgumentChecks.ensureDimensionMatches;
+
/**
* Immutable representation of an {@linkplain Envelope envelope}.
@@ -78,7 +80,7 @@ public final class ImmutableEnvelope ext
{
super(lowerCorner, upperCorner);
this.crs = crs;
- AbstractDirectPosition.ensureDimensionMatch(crs, getDimension());
+ ensureDimensionMatches("crs", getDimension(), crs);
}
/**
@@ -124,7 +126,7 @@ public final class ImmutableEnvelope ext
{
super(envelope);
this.crs = crs;
- AbstractDirectPosition.ensureDimensionMatch(crs, getDimension());
+ ensureDimensionMatches("crs", getDimension(), crs);
}
/**
@@ -151,7 +153,7 @@ public final class ImmutableEnvelope ext
{
super(wkt);
this.crs = crs;
- AbstractDirectPosition.ensureDimensionMatch(crs, getDimension());
+ ensureDimensionMatches("crs", getDimension(), crs);
}
/**
Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/ArgumentChecks.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/ArgumentChecks.java?rev=1424825&r1=1424824&r2=1424825&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/ArgumentChecks.java (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/ArgumentChecks.java Fri Dec 21 09:23:46 2012
@@ -16,6 +16,9 @@
*/
package org.apache.sis.util;
+import org.opengis.referencing.cs.CoordinateSystem;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.opengis.geometry.Envelope;
import org.opengis.geometry.DirectPosition;
import org.opengis.geometry.MismatchedDimensionException;
@@ -531,7 +534,54 @@ public final class ArgumentChecks extend
}
/**
- * Ensures that the given direct position has the expected number of dimensions.
+ * Ensures that the given CRS, if non-null, has the expected number of dimensions.
+ * This method does nothing if the given coordinate reference system is null.
+ *
+ * @param name The name of the argument to be checked. Used only if an exception is thrown.
+ * @param expected The expected number of dimensions.
+ * @param crs The coordinate reference system to check for its dimension, or {@code null}.
+ * @throws MismatchedDimensionException If the given coordinate reference system is non-null
+ * and does not have the expected number of dimensions.
+ */
+ public static void ensureDimensionMatches(final String name, final int expected,
+ final CoordinateReferenceSystem crs) throws MismatchedDimensionException
+ {
+ if (crs != null) {
+ 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, name, dimension, expected));
+ }
+ }
+ }
+ }
+
+ /**
+ * Ensures that the given vector, if non-null, has the expected number of dimensions
+ * (taken as its length). This method does nothing if the given vector is null.
+ *
+ * @param name The name of the argument to be checked. Used only if an exception is thrown.
+ * @param expected The expected number of dimensions.
+ * @param vector The vector to check for its number of dimensions, or {@code null}.
+ * @throws MismatchedDimensionException If the given vector is non-null and does not have the
+ * expected number of dimensions (taken as its length).
+ */
+ public static void ensureDimensionMatches(final String name, final int expected, final double[] vector)
+ throws MismatchedDimensionException
+ {
+ if (vector != null) {
+ final int dimension = vector.length;
+ if (dimension != expected) {
+ throw new MismatchedDimensionException(Errors.format(
+ Errors.Keys.MismatchedDimension_3, name, dimension, expected));
+ }
+ }
+ }
+
+ /**
+ * Ensures that the given direct position, if non-null, has the expected number of dimensions.
* This method does nothing if the given direct position is null.
*
* @param name The name of the argument to be checked. Used only if an exception is thrown.
@@ -547,7 +597,29 @@ public final class ArgumentChecks extend
final int dimension = position.getDimension();
if (dimension != expected) {
throw new MismatchedDimensionException(Errors.format(
- Errors.Keys.UnexpectedArgumentDimension_3, name, dimension, expected));
+ Errors.Keys.MismatchedDimension_3, name, dimension, expected));
+ }
+ }
+ }
+
+ /**
+ * Ensures that the given envelope, if non-null, has the expected number of dimensions.
+ * This method does nothing if the given envelope is null.
+ *
+ * @param name The name of the argument to be checked. Used only if an exception is thrown.
+ * @param expected The expected number of dimensions.
+ * @param envelope The envelope to check for its dimension, or {@code null}.
+ * @throws MismatchedDimensionException If the given envelope is non-null and does
+ * not have the expected number of dimensions.
+ */
+ public static void ensureDimensionMatches(final String name, final int expected, final Envelope envelope)
+ throws MismatchedDimensionException
+ {
+ if (envelope != null) {
+ final int dimension = envelope.getDimension();
+ if (dimension != expected) {
+ throw new MismatchedDimensionException(Errors.format(
+ Errors.Keys.MismatchedDimension_3, name, dimension, expected));
}
}
}
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=1424825&r1=1424824&r2=1424825&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 Fri Dec 21 09:23:46 2012
@@ -153,7 +153,7 @@ public final class Errors extends Indexe
/**
* The [{0} ⦠{1}] range of ordinate values is not valid for the â{2}â axis.
*/
- public static final int IllegalOrdinateRange_3 = 63;
+ public static final int IllegalOrdinateRange_3 = 5;
/**
* Property â{0}â can be associated to an instance of â{1}â.
@@ -301,11 +301,6 @@ public final class Errors extends Indexe
public static final int RequireDecimalSeparator = 33;
/**
- * Argument â{0}â has {1} dimensions, while {2} was expected.
- */
- public static final int UnexpectedArgumentDimension_3 = 5;
-
- /**
* Unexpected change in â{0}â.
*/
public static final int UnexpectedChange_1 = 56;
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=1424825&r1=1424824&r2=1424825&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 Fri Dec 21 09:23:46 2012
@@ -63,7 +63,6 @@ NullArgument_1 = Argume
OddArrayLength_1 = Array length is {0}, while we expected an even length.
RecursiveCreateCallForKey_1 = Recursive call while creating an object for the \u201c{0}\u201d key.
RequireDecimalSeparator = A decimal separator is required.
-UnexpectedArgumentDimension_3 = Argument \u2018{0}\u2019 has {1} dimensions, while {2} was expected.
UnexpectedChange_1 = Unexpected change in \u2018{0}\u2019.
UnexpectedEndOfString_1 = More characters were expected at the end of \u201c{0}\u201d.
UnmodifiableAffineTransform = This affine transform is unmodifiable.
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=1424825&r1=1424824&r2=1424825&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 Fri Dec 21 09:23:46 2012
@@ -63,7 +63,6 @@ NullArgument_1 = L\u201
OddArrayLength_1 = La longueur du tableau est {0}, alors qu\u2019on attendait une longueur paire.
RecursiveCreateCallForKey_1 = Appel r\u00e9cursif lors de la cr\u00e9ation d\u2019un objet pour la cl\u00e9 \u201c{0}\u201d.
RequireDecimalSeparator = Un s\u00e9parateur d\u00e9cimal est requis.
-UnexpectedArgumentDimension_3 = L\u2019argument \u2018{0}\u2019 a {1} dimensions, alors qu\u2019on en attendait {2}.
UnexpectedChange_1 = Changement inattendu dans \u2018{0}\u2019.
UnexpectedEndOfString_1 = D\u2019autres caract\u00e8res \u00e9taient attendus \u00e0 la fin du texte \u201c{0}\u201d.
UnmodifiableAffineTransform = Cette transformation affine n\u2019est pas modifiable.