Author: desruisseaux
Date: Fri Sep 20 19:57:28 2013
New Revision: 1525116
URL: http://svn.apache.org/r1525116
Log:
Moved Matrices.castOrCopy to MatrixSIS and added variants in sub-classes for
consistency with
what we are doing in other classes. Added missing 'swap' method for consistency
with the rest
of the ArraysExt class. Added a link to the pending part of GeoAPI for the
javadoc parts that
talk about grid coverages.
Modified:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix1.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix2.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix3.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix4.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/MatrixSIS.java
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/ArraysExt.java
sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/ArraysExtTest.java
sis/branches/JDK7/pom.xml
Modified:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java?rev=1525116&r1=1525115&r2=1525116&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java
[UTF-8] Fri Sep 20 19:57:28 2013
@@ -43,17 +43,14 @@ import java.util.Objects;
* {@link #createIdentity createIdentity},
* {@link #createDiagonal createDiagonal},
* {@link #createZero createZero},
- * {@link #create create}.
+ * {@link #create create},
+ * {@link #copy copy}.
* </li>
* <li>Creating new matrices for coordinate operation steps:
* {@link #createTransform(Envelope, AxisDirection[], Envelope,
AxisDirection[]) createTransform},
* {@link #createDimensionSelect createDimensionSelect},
* {@link #createPassThrough createPassThrough}.
* </li>
- * <li>Copies matrices to a SIS implementation:
- * {@link #copy copy},
- * {@link #castOrCopy castOrCopy}.
- * </li>
* <li>Information:
* {@link #isAffine isAffine},
* {@link #isIdentity isIdentity},
@@ -646,6 +643,7 @@ public final class Matrices extends Stat
* @return A copy of the given matrix, or {@code null} if the given matrix
was null.
*
* @see MatrixSIS#clone()
+ * @see MatrixSIS#castOrCopy(Matrix)
*/
public static MatrixSIS copy(final Matrix matrix) {
if (matrix == null) {
@@ -664,22 +662,6 @@ public final class Matrices extends Stat
}
/**
- * Casts or copies the given matrix to a SIS implementation. If {@code
matrix} is already
- * an instance of {@code MatrixSIS}, then it is returned unchanged.
Otherwise all elements
- * are copied in a new {@code MatrixSIS} object.
- *
- * @param matrix The matrix to cast or copy, or {@code null}.
- * @return The matrix argument if it can be safely casted (including
{@code null} argument),
- * or a copy of the given matrix otherwise.
- */
- public static MatrixSIS castOrCopy(final Matrix matrix) {
- if (matrix instanceof MatrixSIS) {
- return (MatrixSIS) matrix;
- }
- return copy(matrix);
- }
-
- /**
* Returns {@code true} if the given matrix represents an affine transform.
* A transform is affine if the matrix is square and its last row contains
* only zeros, except in the last column which contains 1.
@@ -716,6 +698,11 @@ public final class Matrices extends Stat
* of identical size, and returning {@code true} if and only if all
differences are smaller than or equal
* to {@code tolerance}.
*
+ * <p><b>Caution:</b> {@linkplain
org.apache.sis.referencing.datum.BursaWolfParameters Bursa-Wolf parameters},
+ * when represented as a matrix, are close to an identity transform and
could easily be confused with rounding
+ * errors. In case of doubt, it is often safer to use the strict {@link
MatrixSIS#isIdentity()} method instead
+ * than this one.</p>
+ *
* @param matrix The matrix to test for identity.
* @param tolerance The tolerance value, or 0 for a strict comparison.
* @return {@code true} if this matrix is close to the identity matrix
given the tolerance threshold.
Modified:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix1.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix1.java?rev=1525116&r1=1525115&r2=1525116&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix1.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix1.java
[UTF-8] Fri Sep 20 19:57:28 2013
@@ -100,6 +100,24 @@ public final class Matrix1 extends Matri
m00 = matrix.getElement(0,0);
}
+ /**
+ * Casts or copies the given matrix to a {@code Matrix1} implementation.
If the given {@code matrix}
+ * is already an instance of {@code Matrix1}, then it is returned
unchanged. Otherwise this method
+ * verifies the matrix size, then copies the element in a new {@code
Matrix1} object.
+ *
+ * @param matrix The matrix to cast or copy, or {@code null}.
+ * @return The matrix argument if it can be safely casted (including
{@code null} argument),
+ * or a copy of the given matrix otherwise.
+ * @throws MismatchedMatrixSizeException If the size of the given matrix
is not {@value #SIZE}×{@value #SIZE}.
+ */
+ public static Matrix1 castOrCopy(final Matrix matrix) throws
MismatchedMatrixSizeException {
+ if (matrix == null || matrix instanceof Matrix1) {
+ return (Matrix1) matrix;
+ }
+ ensureSizeMatch(SIZE, matrix);
+ return new Matrix1(matrix);
+ }
+
/*
* The 'final' modifier in following method declarations is redundant with
the 'final' modifier
* in this class declaration, but we keep them as a reminder of which
methods should stay final
Modified:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix2.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix2.java?rev=1525116&r1=1525115&r2=1525116&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix2.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix2.java
[UTF-8] Fri Sep 20 19:57:28 2013
@@ -112,6 +112,24 @@ public final class Matrix2 extends Matri
m11 = matrix.getElement(1,1);
}
+ /**
+ * Casts or copies the given matrix to a {@code Matrix2} implementation.
If the given {@code matrix}
+ * is already an instance of {@code Matrix2}, then it is returned
unchanged. Otherwise this method
+ * verifies the matrix size, then copies all elements in a new {@code
Matrix2} object.
+ *
+ * @param matrix The matrix to cast or copy, or {@code null}.
+ * @return The matrix argument if it can be safely casted (including
{@code null} argument),
+ * or a copy of the given matrix otherwise.
+ * @throws MismatchedMatrixSizeException If the size of the given matrix
is not {@value #SIZE}×{@value #SIZE}.
+ */
+ public static Matrix2 castOrCopy(final Matrix matrix) throws
MismatchedMatrixSizeException {
+ if (matrix == null || matrix instanceof Matrix2) {
+ return (Matrix2) matrix;
+ }
+ ensureSizeMatch(SIZE, matrix);
+ return new Matrix2(matrix);
+ }
+
/*
* The 'final' modifier in following method declarations is redundant with
the 'final' modifier
* in this class declaration, but we keep them as a reminder of which
methods should stay final
Modified:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix3.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix3.java?rev=1525116&r1=1525115&r2=1525116&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix3.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix3.java
[UTF-8] Fri Sep 20 19:57:28 2013
@@ -131,6 +131,24 @@ public final class Matrix3 extends Matri
}
}
+ /**
+ * Casts or copies the given matrix to a {@code Matrix3} implementation.
If the given {@code matrix}
+ * is already an instance of {@code Matrix3}, then it is returned
unchanged. Otherwise this method
+ * verifies the matrix size, then copies all elements in a new {@code
Matrix3} object.
+ *
+ * @param matrix The matrix to cast or copy, or {@code null}.
+ * @return The matrix argument if it can be safely casted (including
{@code null} argument),
+ * or a copy of the given matrix otherwise.
+ * @throws MismatchedMatrixSizeException If the size of the given matrix
is not {@value #SIZE}×{@value #SIZE}.
+ */
+ public static Matrix3 castOrCopy(final Matrix matrix) throws
MismatchedMatrixSizeException {
+ if (matrix == null || matrix instanceof Matrix3) {
+ return (Matrix3) matrix;
+ }
+ ensureSizeMatch(SIZE, matrix);
+ return new Matrix3(matrix);
+ }
+
/*
* The 'final' modifier in following method declarations is redundant with
the 'final' modifier
* in this class declaration, but we keep them as a reminder of which
methods should stay final
Modified:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix4.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix4.java?rev=1525116&r1=1525115&r2=1525116&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix4.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix4.java
[UTF-8] Fri Sep 20 19:57:28 2013
@@ -155,6 +155,24 @@ public final class Matrix4 extends Matri
}
}
+ /**
+ * Casts or copies the given matrix to a {@code Matrix4} implementation.
If the given {@code matrix}
+ * is already an instance of {@code Matrix4}, then it is returned
unchanged. Otherwise this method
+ * verifies the matrix size, then copies all elements in a new {@code
Matrix4} object.
+ *
+ * @param matrix The matrix to cast or copy, or {@code null}.
+ * @return The matrix argument if it can be safely casted (including
{@code null} argument),
+ * or a copy of the given matrix otherwise.
+ * @throws MismatchedMatrixSizeException If the size of the given matrix
is not {@value #SIZE}×{@value #SIZE}.
+ */
+ public static Matrix4 castOrCopy(final Matrix matrix) throws
MismatchedMatrixSizeException {
+ if (matrix == null || matrix instanceof Matrix4) {
+ return (Matrix4) matrix;
+ }
+ ensureSizeMatch(SIZE, matrix);
+ return new Matrix4(matrix);
+ }
+
/*
* The 'final' modifier in following method declarations is redundant with
the 'final' modifier
* in this class declaration, but we keep them as a reminder of which
methods should stay final
Modified:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/MatrixSIS.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/MatrixSIS.java?rev=1525116&r1=1525115&r2=1525116&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/MatrixSIS.java
(original)
+++
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/MatrixSIS.java
Fri Sep 20 19:57:28 2013
@@ -108,6 +108,24 @@ public abstract class MatrixSIS implemen
}
/**
+ * Casts or copies the given matrix to a SIS implementation. If {@code
matrix} is already
+ * an instance of {@code MatrixSIS}, then it is returned unchanged.
Otherwise all elements
+ * are copied in a new {@code MatrixSIS} object.
+ *
+ * @param matrix The matrix to cast or copy, or {@code null}.
+ * @return The matrix argument if it can be safely casted (including
{@code null} argument),
+ * or a copy of the given matrix otherwise.
+ *
+ * @see Matrices#copy(Matrix)
+ */
+ public static MatrixSIS castOrCopy(final Matrix matrix) {
+ if (matrix == null || matrix instanceof MatrixSIS) {
+ return (MatrixSIS) matrix;
+ }
+ return Matrices.copy(matrix);
+ }
+
+ /**
* Returns a copy of all matrix elements in a flat, row-major (column
indices vary fastest) array.
* The array length is <code>{@linkplain #getNumRow()} * {@linkplain
#getNumCol()}</code>.
*
Modified:
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/ArraysExt.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/ArraysExt.java?rev=1525116&r1=1525115&r2=1525116&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/ArraysExt.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/ArraysExt.java
[UTF-8] Fri Sep 20 19:57:28 2013
@@ -1715,6 +1715,24 @@ public final class ArraysExt extends Sta
}
/**
+ * Swaps the elements at the given indices in the given array of {@code
Object} values.
+ *
+ * {@note While trivial, this method is provided because its need occurs
relatively often
+ * and the availability of a <code>swap</code> method makes the
code easier to read.}
+ *
+ * @param data The array in which to swap elements.
+ * @param i0 Index of one element to be swapped.
+ * @param i1 Index of the other element to be swapped.
+ *
+ * @since 0.4
+ */
+ public static void swap(final Object[] data, final int i0, final int i1) {
+ final Object t = data[i0];
+ data[i0] = data[i1];
+ data[i1] = t;
+ }
+
+ /**
* Swaps the elements at the given indices in the given array of {@code
double} values.
*
* {@note While trivial, this method is provided because its need occurs
relatively often
Modified:
sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/ArraysExtTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/ArraysExtTest.java?rev=1525116&r1=1525115&r2=1525116&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/ArraysExtTest.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/ArraysExtTest.java
[UTF-8] Fri Sep 20 19:57:28 2013
@@ -181,6 +181,16 @@ public final strictfp class ArraysExtTes
}
/**
+ * Tests the {@link ArraysExt#swap(Object[], int, int)} method.
+ */
+ @Test
+ public void testSwapObject() {
+ final Integer[] array = new Integer[] {4, 8, 12, 15, 18};
+ ArraysExt.swap(array, 1, 3);
+ assertArrayEquals(new Integer[] {4, 15, 12, 8, 18}, array);
+ }
+
+ /**
* Tests the {@link ArraysExt#swap(double[], int, int)} method.
*/
@Test
Modified: sis/branches/JDK7/pom.xml
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/pom.xml?rev=1525116&r1=1525115&r2=1525116&view=diff
==============================================================================
--- sis/branches/JDK7/pom.xml (original)
+++ sis/branches/JDK7/pom.xml Fri Sep 20 19:57:28 2013
@@ -619,6 +619,7 @@ Apache SIS is a free software, Java lang
<validateLinks>true</validateLinks>
<links>
<link>http://www.geoapi.org/snapshot/javadoc</link>
+ <link>http://www.geoapi.org/snapshot/pending</link>
</links>
<!-- Separates packages on the overview page into the groups
specified. -->