sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1521945 - in /sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix: Matrix1.java Matrix2.java Matrix3.java Matrix4.java
Date Wed, 11 Sep 2013 17:25:47 GMT
Author: desruisseaux
Date: Wed Sep 11 17:25:47 2013
New Revision: 1521945

URL: http://svn.apache.org/r1521945
Log:
Added an explanation about why many methods are declared final in this class.

Modified:
    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

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=1521945&r1=1521944&r2=1521945&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] Wed Sep 11 17:25:47 2013
@@ -94,6 +94,15 @@ public final class Matrix1 extends Matri
         m00 = matrix.getElement(0,0);
     }
 
+    /*
+     * 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
+     * if this class was modified to a non-final class. Some methods should stay final because:
+     *
+     *  - returning a different value would make no-sense for this class (e.g. 'getNumRow()');
+     *  - they are invoked by a constructor or by an other method expecting this exact semantic.
+     */
+
     /**
      * Returns the number of rows in this matrix, which is always {@value #SIZE} in this
implementation.
      *
@@ -125,7 +134,7 @@ public final class Matrix1 extends Matri
      * @return       The current value.
      */
     @Override
-    public double getElement(final int row, final int column) {
+    public final double getElement(final int row, final int column) {
         if (row == 0 && column == 0) {
             return m00;
         } else {
@@ -144,7 +153,7 @@ public final class Matrix1 extends Matri
      * @param value  The new value to set.
      */
     @Override
-    public void setElement(final int row, final int column, final double value) {
+    public final void setElement(final int row, final int column, final double value) {
         if (row == 0 && column == 0) {
             m00 = value;
         } else {
@@ -157,7 +166,7 @@ public final class Matrix1 extends Matri
      * The array length is 1.
      */
     @Override
-    public double[] getElements() {
+    public final double[] getElements() {
         return new double[] {m00};
     }
 
@@ -166,7 +175,7 @@ public final class Matrix1 extends Matri
      * The array length shall be 1.
      */
     @Override
-    public void setElements(final double[] elements) {
+    public final void setElements(final double[] elements) {
         ensureLengthMatch(SIZE*SIZE, elements);
         m00 = elements[0];
     }
@@ -175,7 +184,7 @@ public final class Matrix1 extends Matri
      * {@inheritDoc}
      */
     @Override
-    public boolean isAffine() {
+    public final boolean isAffine() {
         return m00 == 1;
     }
 
@@ -183,7 +192,7 @@ public final class Matrix1 extends Matri
      * {@inheritDoc}
      */
     @Override
-    public boolean isIdentity() {
+    public final boolean isIdentity() {
         return m00 == 1;
     }
 
@@ -191,7 +200,7 @@ public final class Matrix1 extends Matri
      * {@inheritDoc}
      */
     @Override
-    public boolean isIdentity(final double tolerance) {
+    public final boolean isIdentity(final double tolerance) {
         return Math.abs(m00 - 1) <= Math.abs(tolerance);
     }
 
@@ -199,7 +208,7 @@ public final class Matrix1 extends Matri
      * {@inheritDoc}
      */
     @Override
-    public void setToIdentity() {
+    public final void setToIdentity() {
         m00 = 1;
     }
 
@@ -207,7 +216,7 @@ public final class Matrix1 extends Matri
      * {@inheritDoc}
      */
     @Override
-    public void setToZero() {
+    public final void setToZero() {
         m00 = 0;
     }
 

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=1521945&r1=1521944&r2=1521945&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] Wed Sep 11 17:25:47 2013
@@ -106,6 +106,15 @@ public final class Matrix2 extends Matri
         m11 = matrix.getElement(1,1);
     }
 
+    /*
+     * 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
+     * if this class was modified to a non-final class. Some methods should stay final because:
+     *
+     *  - returning a different value would make no-sense for this class (e.g. 'getNumRow()');
+     *  - they are invoked by a constructor or by an other method expecting this exact semantic.
+     */
+
     /**
      * Returns the number of rows in this matrix, which is always {@value #SIZE} in this
implementation.
      *
@@ -137,7 +146,7 @@ public final class Matrix2 extends Matri
      * @return       The current value at the given row and column.
      */
     @Override
-    public double getElement(final int row, final int column) {
+    public final double getElement(final int row, final int column) {
         if (row >= 0 && row < SIZE && column >= 0 && column
< SIZE) {
             switch (row*SIZE + column) {
                 case 0: return m00;
@@ -160,7 +169,7 @@ public final class Matrix2 extends Matri
      * @param value  The new value to set at the given row and column.
      */
     @Override
-    public void setElement(final int row, final int column, final double value) {
+    public final void setElement(final int row, final int column, final double value) {
         if (row >= 0 && row < SIZE && column >= 0 && column
< SIZE) {
             switch (row*SIZE + column) {
                 case 0: m00 = value; return;
@@ -177,7 +186,7 @@ public final class Matrix2 extends Matri
      * The array length is 4.
      */
     @Override
-    public double[] getElements() {
+    public final double[] getElements() {
         return new double[] {m00, m01, m10, m11};
     }
 
@@ -186,7 +195,7 @@ public final class Matrix2 extends Matri
      * The array length shall be 4.
      */
     @Override
-    public void setElements(final double[] elements) {
+    public final void setElements(final double[] elements) {
         ensureLengthMatch(SIZE*SIZE, elements);
         m00 = elements[0];
         m01 = elements[1];
@@ -198,7 +207,7 @@ public final class Matrix2 extends Matri
      * {@inheritDoc}
      */
     @Override
-    public boolean isAffine() {
+    public final boolean isAffine() {
         return m10 == 0 && m11 == 1;
     }
 
@@ -206,7 +215,7 @@ public final class Matrix2 extends Matri
      * {@inheritDoc}
      */
     @Override
-    public boolean isIdentity() {
+    public final boolean isIdentity() {
         return m00 == 1 && m10 == 0 &&
                m01 == 0 && m11 == 1;
     }
@@ -215,7 +224,7 @@ public final class Matrix2 extends Matri
      * {@inheritDoc}
      */
     @Override
-    public void setToIdentity() {
+    public final void setToIdentity() {
         m01 = m10 = 0;
         m00 = m11 = 1;
     }
@@ -224,7 +233,7 @@ public final class Matrix2 extends Matri
      * {@inheritDoc}
      */
     @Override
-    public void setToZero() {
+    public final void setToZero() {
         m00 = m01 = m10 = m11 = 0;
     }
 

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=1521945&r1=1521944&r2=1521945&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] Wed Sep 11 17:25:47 2013
@@ -45,10 +45,6 @@ import org.apache.sis.math.MathFunctions
  * @see Matrix4
  */
 public final class Matrix3 extends MatrixSIS {
-// Note: if the above 'final' keyword is removed, revisit the methods in this class
-// which invoke other methods: Matrix3(Matrix) constructor, setToIdentity(), etc.
-// We may want to protect them against overriding of the method they invoke.
-
     /**
      * Serial number for inter-operability with different versions.
      */
@@ -130,6 +126,15 @@ public final class Matrix3 extends Matri
         }
     }
 
+    /*
+     * 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
+     * if this class was modified to a non-final class. Some methods should stay final because:
+     *
+     *  - returning a different value would make no-sense for this class (e.g. 'getNumRow()');
+     *  - they are invoked by a constructor or by an other method expecting this exact semantic.
+     */
+
     /**
      * Returns the number of rows in this matrix, which is always {@value #SIZE} in this
implementation.
      *
@@ -161,7 +166,7 @@ public final class Matrix3 extends Matri
      * @return       The current value at the given row and column.
      */
     @Override
-    public double getElement(final int row, final int column) {
+    public final double getElement(final int row, final int column) {
         if (row >= 0 && row < SIZE && column >= 0 && column
< SIZE) {
             switch (row*SIZE + column) {
                 case 0: return m00;
@@ -189,7 +194,7 @@ public final class Matrix3 extends Matri
      * @param value  The new value to set at the given row and column.
      */
     @Override
-    public void setElement(final int row, final int column, final double value) {
+    public final void setElement(final int row, final int column, final double value) {
         if (row >= 0 && row < SIZE && column >= 0 && column
< SIZE) {
             switch (row*SIZE + column) {
                 case 0: m00 = value; return;
@@ -211,7 +216,7 @@ public final class Matrix3 extends Matri
      * The array length is 9.
      */
     @Override
-    public double[] getElements() {
+    public final double[] getElements() {
         return new double[] {
             m00, m01, m02,
             m10, m11, m12,
@@ -224,7 +229,7 @@ public final class Matrix3 extends Matri
      * The array length shall be 9.
      */
     @Override
-    public void setElements(final double[] elements) {
+    public final void setElements(final double[] elements) {
         ensureLengthMatch(SIZE*SIZE, elements);
         m00 = elements[0];
         m01 = elements[1];
@@ -241,7 +246,7 @@ public final class Matrix3 extends Matri
      * {@inheritDoc}
      */
     @Override
-    public boolean isAffine() {
+    public final boolean isAffine() {
         return m20 == 0 && m21 == 0 && m22 == 1;
     }
 
@@ -249,7 +254,7 @@ public final class Matrix3 extends Matri
      * {@inheritDoc}
      */
     @Override
-    public boolean isIdentity() {
+    public final boolean isIdentity() {
         return m00 == 1 && m01 == 0 && m02 == 0 &&
                m10 == 0 && m11 == 1 && m12 == 0 &&
                isAffine();
@@ -259,7 +264,7 @@ public final class Matrix3 extends Matri
      * {@inheritDoc}
      */
     @Override
-    public void setToIdentity() {
+    public final void setToIdentity() {
         setToZero();
         m00 = m11 = m22 = 1;
     }
@@ -268,7 +273,7 @@ public final class Matrix3 extends Matri
      * {@inheritDoc}
      */
     @Override
-    public void setToZero() {
+    public final void setToZero() {
         m00 = m01 = m02 = 0;
         m10 = m11 = m12 = 0;
         m20 = m21 = m22 = 0;

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=1521945&r1=1521944&r2=1521945&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] Wed Sep 11 17:25:47 2013
@@ -46,10 +46,6 @@ import org.apache.sis.math.MathFunctions
  * @see Matrix3
  */
 public final class Matrix4 extends MatrixSIS {
-// Note: if the above 'final' keyword is removed, revisit the methods in this class
-// which invoke other methods: Matrix3(Matrix) constructor, setToIdentity(), etc.
-// We may want to protect them against overriding of the method they invoke.
-
     /**
      * Serial number for inter-operability with different versions.
      */
@@ -154,6 +150,15 @@ public final class Matrix4 extends Matri
         }
     }
 
+    /*
+     * 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
+     * if this class was modified to a non-final class. Some methods should stay final because:
+     *
+     *  - returning a different value would make no-sense for this class (e.g. 'getNumRow()');
+     *  - they are invoked by a constructor or by an other method expecting this exact semantic.
+     */
+
     /**
      * Returns the number of rows in this matrix, which is always {@value #SIZE} in this
implementation.
      *
@@ -185,7 +190,7 @@ public final class Matrix4 extends Matri
      * @return       The current value at the given row and column.
      */
     @Override
-    public double getElement(final int row, final int column) {
+    public final double getElement(final int row, final int column) {
         if (row >= 0 && row < SIZE && column >= 0 && column
< SIZE) {
             switch (row*SIZE + column) {
                 case  0: return m00;
@@ -220,7 +225,7 @@ public final class Matrix4 extends Matri
      * @param value  The new value to set at the given row and column.
      */
     @Override
-    public void setElement(final int row, final int column, final double value) {
+    public final void setElement(final int row, final int column, final double value) {
         if (row >= 0 && row < SIZE && column >= 0 && column
< SIZE) {
             switch (row*SIZE + column) {
                 case  0: m00 = value; return;
@@ -249,7 +254,7 @@ public final class Matrix4 extends Matri
      * The array length is 16.
      */
     @Override
-    public double[] getElements() {
+    public final double[] getElements() {
         return new double[] {
             m00, m01, m02, m03,
             m10, m11, m12, m13,
@@ -263,7 +268,7 @@ public final class Matrix4 extends Matri
      * The array length shall be 16.
      */
     @Override
-    public void setElements(final double[] elements) {
+    public final void setElements(final double[] elements) {
         ensureLengthMatch(SIZE*SIZE, elements);
         m00 = elements[ 0];
         m01 = elements[ 1];
@@ -287,7 +292,7 @@ public final class Matrix4 extends Matri
      * {@inheritDoc}
      */
     @Override
-    public boolean isAffine() {
+    public final boolean isAffine() {
         return m30 == 0 && m31 == 0 && m32 == 0 && m33 == 1;
     }
 
@@ -295,7 +300,7 @@ public final class Matrix4 extends Matri
      * {@inheritDoc}
      */
     @Override
-    public boolean isIdentity() {
+    public final boolean isIdentity() {
         return m00 == 1 && m01 == 0 && m02 == 0 && m03 == 0 &&
                m10 == 0 && m11 == 1 && m12 == 0 && m13 == 0 &&
                m20 == 0 && m21 == 0 && m22 == 1 && m23 == 0 &&
@@ -306,7 +311,7 @@ public final class Matrix4 extends Matri
      * {@inheritDoc}
      */
     @Override
-    public void setToIdentity() {
+    public final void setToIdentity() {
         setToZero();
         m00 = m11 = m22 = m33 = 1;
     }
@@ -315,7 +320,7 @@ public final class Matrix4 extends Matri
      * {@inheritDoc}
      */
     @Override
-    public void setToZero() {
+    public final void setToZero() {
         m00 = m01 = m02 = m03 = 0;
         m10 = m11 = m12 = m13 = 0;
         m20 = m21 = m22 = m23 = 0;
@@ -363,7 +368,7 @@ public final class Matrix4 extends Matri
      * {@inheritDoc}
      */
     @Override
-    public final void normalizeColumns() {
+    public void normalizeColumns() {
         double m;
         final double[] v = new double[4];
         v[0]=m00; v[1]=m10; v[2]=m20; v[3]=m30; m = MathFunctions.magnitude(v); m00 /= m;
m10 /= m; m20 /= m; m30 /= m;



Mime
View raw message