Author: sebb
Date: Tue Jan 26 02:07:26 2010
New Revision: 903046

URL: http://svn.apache.org/viewvc?rev=903046&view=rev
Log:
Document why OK to suppress unchecked warning
Move tag as close as possible to site of warning

Modified:
    
commons/proper/math/trunk/src/main/java/org/apache/commons/math/genetics/OnePointCrossover.java
    
commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractFieldMatrix.java
    
commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/ArrayFieldVector.java
    
commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/FieldLUDecompositionImpl.java
    
commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/MatrixUtils.java

Modified: 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/genetics/OnePointCrossover.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/genetics/OnePointCrossover.java?rev=903046&r1=903045&r2=903046&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/genetics/OnePointCrossover.java
 (original)
+++ 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/genetics/OnePointCrossover.java
 Tue Jan 26 02:07:26 2010
@@ -66,9 +66,9 @@
      * @param second second parent (p2)
      * @return pair of two children (c1,c2)
      */
-    @SuppressWarnings("unchecked")
+    @SuppressWarnings("unchecked") // OK because of instanceof checks
     public ChromosomePair crossover(Chromosome first, Chromosome second) {
-        if (! (first instanceof AbstractListChromosome && second instanceof 
AbstractListChromosome)) {
+        if (! (first instanceof AbstractListChromosome<?> && second instanceof 
AbstractListChromosome<?>)) {
             throw new IllegalArgumentException("One point crossover works on 
FixedLengthChromosomes only.");
         }
         return crossover((AbstractListChromosome<T>) first, 
(AbstractListChromosome<T>) second);

Modified: 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractFieldMatrix.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractFieldMatrix.java?rev=903046&r1=903045&r2=903046&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractFieldMatrix.java
 (original)
+++ 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractFieldMatrix.java
 Tue Jan 26 02:07:26 2010
@@ -146,9 +146,9 @@
      * @param length of the array
      * @return a new array
      */
-    @SuppressWarnings("unchecked")
     protected static <T extends FieldElement<T>> T[] buildArray(final Field<T> 
field,
                                                                 final int 
length) {
+        @SuppressWarnings("unchecked") // OK because field must be correct 
class
         T[] array = (T[]) Array.newInstance(field.getZero().getClass(), 
length);
         Arrays.fill(array, field.getZero());
         return array;
@@ -970,16 +970,15 @@
      * @param object the object to test equality against.
      * @return true if object equals this
      */
-    @SuppressWarnings("unchecked")
     @Override
     public boolean equals(final Object object) {
         if (object == this ) {
             return true;
         }
-        if (object instanceof FieldMatrix == false) {
+        if (object instanceof FieldMatrix<?> == false) {
             return false;
         }
-        FieldMatrix<T> m = (FieldMatrix<T>) object;
+        FieldMatrix<?> m = (FieldMatrix<?>) object;
         final int nRows = getRowDimension();
         final int nCols = getColumnDimension();
         if (m.getColumnDimension() != nCols || m.getRowDimension() != nRows) {

Modified: 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/ArrayFieldVector.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/ArrayFieldVector.java?rev=903046&r1=903045&r2=903046&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/ArrayFieldVector.java
 (original)
+++ 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/ArrayFieldVector.java
 Tue Jan 26 02:07:26 2010
@@ -223,7 +223,7 @@
      * @param length size of the array to build
      * @return a new array
      */
-    @SuppressWarnings("unchecked")
+    @SuppressWarnings("unchecked") // field is of type T
     private T[] buildArray(final int length) {
         return (T[]) Array.newInstance(field.getZero().getClass(), length);
     }
@@ -739,7 +739,6 @@
      *         not equal to this Vector3D instance
      *
      */
-    @SuppressWarnings("unchecked")
     @Override
     public boolean equals(Object other) {
 
@@ -752,7 +751,7 @@
       }
 
       try {
-
+          @SuppressWarnings("unchecked") // May fail, but we ignore 
ClassCastException
           FieldVector<T> rhs = (FieldVector<T>) other;
           if (data.length != rhs.getDimension()) {
               return false;

Modified: 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/FieldLUDecompositionImpl.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/FieldLUDecompositionImpl.java?rev=903046&r1=903045&r2=903046&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/FieldLUDecompositionImpl.java
 (original)
+++ 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/FieldLUDecompositionImpl.java
 Tue Jan 26 02:07:26 2010
@@ -257,7 +257,6 @@
         }
 
         /** {...@inheritdoc} */
-        @SuppressWarnings("unchecked")
         public T[] solve(T[] b)
             throws IllegalArgumentException, InvalidMatrixException {
 
@@ -271,6 +270,7 @@
                 throw new SingularMatrixException();
             }
 
+            @SuppressWarnings("unchecked") // field is of type T
             final T[] bp = (T[]) Array.newInstance(field.getZero().getClass(), 
m);
 
             // Apply permutations to b
@@ -300,7 +300,6 @@
         }
 
         /** {...@inheritdoc} */
-        @SuppressWarnings("unchecked")
         public FieldVector<T> solve(FieldVector<T> b)
             throws IllegalArgumentException, InvalidMatrixException {
             try {
@@ -317,6 +316,7 @@
                     throw new SingularMatrixException();
                 }
 
+                @SuppressWarnings("unchecked") // field is of type T
                 final T[] bp = (T[]) 
Array.newInstance(field.getZero().getClass(), m);
 
                 // Apply permutations to b
@@ -359,7 +359,6 @@
         }
 
         /** {...@inheritdoc} */
-        @SuppressWarnings("unchecked")
         public FieldMatrix<T> solve(FieldMatrix<T> b)
             throws IllegalArgumentException, InvalidMatrixException {
 
@@ -376,6 +375,7 @@
             final int nColB = b.getColumnDimension();
 
             // Apply permutations to b
+            @SuppressWarnings("unchecked") // field is of type T
             final T[][] bp = (T[][]) 
Array.newInstance(field.getZero().getClass(), new int[] { m, nColB });
             for (int row = 0; row < m; row++) {
                 final T[] bpRow = bp[row];

Modified: 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/MatrixUtils.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/MatrixUtils.java?rev=903046&r1=903045&r2=903046&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/MatrixUtils.java
 (original)
+++ 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/MatrixUtils.java
 Tue Jan 26 02:07:26 2010
@@ -156,11 +156,11 @@
      * @throws IllegalArgumentException if dimension is not positive
      * @since 2.0
      */
-    @SuppressWarnings("unchecked")
     public static <T extends FieldElement<T>> FieldMatrix<T>
         createFieldIdentityMatrix(final Field<T> field, final int dimension) {
         final T zero = field.getZero();
         final T one  = field.getOne();
+        @SuppressWarnings("unchecked") // zero is type T
         final T[][] d = (T[][]) Array.newInstance(zero.getClass(), new int[] { 
dimension, dimension });
         for (int row = 0; row < dimension; row++) {
             final T[] dRow = d[row];


Reply via email to