commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r1178009 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/ main/java/org/apache/commons/math/complex/ main/java/org/apache/commons/math/dfp/ main/java/org/apache/commons/math/fraction/ main/java/org/apache/commons/math...
Date Sat, 01 Oct 2011 15:15:00 GMT
Author: luc
Date: Sat Oct  1 15:15:00 2011
New Revision: 1178009

URL: http://svn.apache.org/viewvc?rev=1178009&view=rev
Log:
Added a getRuntimeClass method to the Field interface.

This interface allows using a complete hierarchy of fields sharing a
common interface.

JIRA: MATH-284

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/Field.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/complex/ComplexField.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/dfp/DfpField.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/BigFractionField.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/FractionField.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/FieldLUDecomposition.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/MatrixUtils.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/SparseFieldVector.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/BigRealField.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/OpenIntToFieldHashMap.java
    commons/proper/math/trunk/src/site/xdoc/changes.xml
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/ArrayFieldVectorTest.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/Field.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/Field.java?rev=1178009&r1=1178008&r2=1178009&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/Field.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/Field.java Sat Oct  1
15:15:00 2011
@@ -48,4 +48,12 @@ public interface Field<T> {
      */
     T getOne();
 
+    /**
+     * Returns the runtime class of the FieldElement. 
+     * 
+     * @return The {@code Class} object that represents the runtime
+     *         class of this object.
+     */
+    Class<? extends FieldElement<T>> getRuntimeClass();
+
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/complex/ComplexField.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/complex/ComplexField.java?rev=1178009&r1=1178008&r2=1178009&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/complex/ComplexField.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/complex/ComplexField.java
Sat Oct  1 15:15:00 2011
@@ -20,6 +20,7 @@ package org.apache.commons.math.complex;
 import java.io.Serializable;
 
 import org.apache.commons.math.Field;
+import org.apache.commons.math.FieldElement;
 
 /**
  * Representation of the complex numbers field.
@@ -57,6 +58,11 @@ public class ComplexField implements Fie
         return Complex.ZERO;
     }
 
+    /** {@inheritDoc} */
+    public Class<? extends FieldElement<Complex>> getRuntimeClass() {
+        return Complex.class;
+    }
+
     // CHECKSTYLE: stop HideUtilityClassConstructor
     /** Holder for the instance.
      * <p>We use here the Initialization On Demand Holder Idiom.</p>

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/dfp/DfpField.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/dfp/DfpField.java?rev=1178009&r1=1178008&r2=1178009&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/dfp/DfpField.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/dfp/DfpField.java Sat
Oct  1 15:15:00 2011
@@ -18,6 +18,7 @@
 package org.apache.commons.math.dfp;
 
 import org.apache.commons.math.Field;
+import org.apache.commons.math.FieldElement;
 
 /** Field for Decimal floating point instances.
  * @version $Id$
@@ -407,6 +408,11 @@ public class DfpField implements Field<D
         return one;
     }
 
+    /** {@inheritDoc} */
+    public Class<? extends FieldElement<Dfp>> getRuntimeClass() {
+        return Dfp.class;
+    }
+
     /** Get the constant 2.
      * @return a {@link Dfp} with value 2
      */

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/BigFractionField.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/BigFractionField.java?rev=1178009&r1=1178008&r2=1178009&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/BigFractionField.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/BigFractionField.java
Sat Oct  1 15:15:00 2011
@@ -20,6 +20,7 @@ package org.apache.commons.math.fraction
 import java.io.Serializable;
 
 import org.apache.commons.math.Field;
+import org.apache.commons.math.FieldElement;
 
 /**
  * Representation of the fractional numbers  without any overflow field.
@@ -57,6 +58,10 @@ public class BigFractionField implements
         return BigFraction.ZERO;
     }
 
+    /** {@inheritDoc} */
+    public Class<? extends FieldElement<BigFraction>> getRuntimeClass() {
+        return BigFraction.class;
+    }
     // CHECKSTYLE: stop HideUtilityClassConstructor
     /** Holder for the instance.
      * <p>We use here the Initialization On Demand Holder Idiom.</p>

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/FractionField.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/FractionField.java?rev=1178009&r1=1178008&r2=1178009&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/FractionField.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/FractionField.java
Sat Oct  1 15:15:00 2011
@@ -20,6 +20,7 @@ package org.apache.commons.math.fraction
 import java.io.Serializable;
 
 import org.apache.commons.math.Field;
+import org.apache.commons.math.FieldElement;
 
 /**
  * Representation of the fractional numbers field.
@@ -57,6 +58,10 @@ public class FractionField implements Fi
         return Fraction.ZERO;
     }
 
+    /** {@inheritDoc} */
+    public Class<? extends FieldElement<Fraction>> getRuntimeClass() {
+        return Fraction.class;
+    }
     // CHECKSTYLE: stop HideUtilityClassConstructor
     /** Holder for the instance.
      * <p>We use here the Initialization On Demand Holder Idiom.</p>

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=1178009&r1=1178008&r2=1178009&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
Sat Oct  1 15:15:00 2011
@@ -137,11 +137,11 @@ public abstract class AbstractFieldMatri
                                                                   final int rows,
                                                                   final int columns) {
         if (columns < 0) {
-            T[] dummyRow = (T[]) Array.newInstance(field.getZero().getClass(), 0);
+            T[] dummyRow = (T[]) Array.newInstance(field.getRuntimeClass(), 0);
             return (T[][]) Array.newInstance(dummyRow.getClass(), rows);
         }
         T[][] array =
-            (T[][]) Array.newInstance(field.getZero().getClass(), new int[] { rows, columns
});
+            (T[][]) Array.newInstance(field.getRuntimeClass(), new int[] { rows, columns
});
         for (int i = 0; i < array.length; ++i) {
             Arrays.fill(array[i], field.getZero());
         }
@@ -160,7 +160,7 @@ public abstract class AbstractFieldMatri
     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);
+        T[] array = (T[]) Array.newInstance(field.getRuntimeClass(), length);
         Arrays.fill(array, field.getZero());
         return array;
     }

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=1178009&r1=1178008&r2=1178009&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
Sat Oct  1 15:15:00 2011
@@ -383,7 +383,7 @@ public class ArrayFieldVector<T extends 
      */
     @SuppressWarnings("unchecked") // field is of type T
     private T[] buildArray(final int length) {
-        return (T[]) Array.newInstance(field.getZero().getClass(), length);
+        return (T[]) Array.newInstance(field.getRuntimeClass(), length);
     }
 
     /** {@inheritDoc} */

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/FieldLUDecomposition.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/FieldLUDecomposition.java?rev=1178009&r1=1178008&r2=1178009&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/FieldLUDecomposition.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/FieldLUDecomposition.java
Sat Oct  1 15:15:00 2011
@@ -308,7 +308,7 @@ public class FieldLUDecomposition<T exte
                 }
 
                 @SuppressWarnings("unchecked") // field is of type T
-                final T[] bp = (T[]) Array.newInstance(field.getZero().getClass(), m);
+                final T[] bp = (T[]) Array.newInstance(field.getRuntimeClass(), m);
 
                 // Apply permutations to b
                 for (int row = 0; row < m; row++) {
@@ -355,7 +355,7 @@ public class FieldLUDecomposition<T exte
 
             @SuppressWarnings("unchecked")
             // field is of type T
-            final T[] bp = (T[]) Array.newInstance(field.getZero().getClass(),
+            final T[] bp = (T[]) Array.newInstance(field.getRuntimeClass(),
                                                    m);
 
             // Apply permutations to b
@@ -397,7 +397,7 @@ public class FieldLUDecomposition<T exte
 
             // Apply permutations to b
             @SuppressWarnings("unchecked") // field is of type T
-            final T[][] bp = (T[][]) Array.newInstance(field.getZero().getClass(), new int[]
{ m, nColB });
+            final T[][] bp = (T[][]) Array.newInstance(field.getRuntimeClass(), new int[]
{ m, nColB });
             for (int row = 0; row < m; row++) {
                 final T[] bpRow = bp[row];
                 final int pRow = pivot[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=1178009&r1=1178008&r2=1178009&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
Sat Oct  1 15:15:00 2011
@@ -179,8 +179,8 @@ public class MatrixUtils {
         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 });
+        @SuppressWarnings("unchecked")
+        final T[][] d = (T[][]) Array.newInstance(field.getRuntimeClass(), new int[] { dimension,
dimension });
         for (int row = 0; row < dimension; row++) {
             final T[] dRow = d[row];
             Arrays.fill(dRow, zero);

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/SparseFieldVector.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/SparseFieldVector.java?rev=1178009&r1=1178008&r2=1178009&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/SparseFieldVector.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/SparseFieldVector.java
Sat Oct  1 15:15:00 2011
@@ -513,7 +513,7 @@ public class SparseFieldVector<T extends
      */
     @SuppressWarnings("unchecked") // field is type T
     private T[] buildArray(final int length) {
-        return (T[]) Array.newInstance(field.getZero().getClass(), length);
+        return (T[]) Array.newInstance(field.getRuntimeClass(), length);
     }
 
 

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/BigRealField.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/BigRealField.java?rev=1178009&r1=1178008&r2=1178009&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/BigRealField.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/BigRealField.java
Sat Oct  1 15:15:00 2011
@@ -20,6 +20,7 @@ package org.apache.commons.math.util;
 import java.io.Serializable;
 
 import org.apache.commons.math.Field;
+import org.apache.commons.math.FieldElement;
 
 /**
  * Representation of real numbers with arbitrary precision field.
@@ -57,6 +58,11 @@ public class BigRealField implements Fie
         return BigReal.ZERO;
     }
 
+    /** {@inheritDoc} */
+    public Class<? extends FieldElement<BigReal>> getRuntimeClass() {
+        return BigReal.class;
+    }
+
     // CHECKSTYLE: stop HideUtilityClassConstructor
     /** Holder for the instance.
      * <p>We use here the Initialization On Demand Holder Idiom.</p>

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/OpenIntToFieldHashMap.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/OpenIntToFieldHashMap.java?rev=1178009&r1=1178008&r2=1178009&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/OpenIntToFieldHashMap.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/OpenIntToFieldHashMap.java
Sat Oct  1 15:15:00 2011
@@ -614,7 +614,7 @@ public class OpenIntToFieldHashMap<T ext
      */
     @SuppressWarnings("unchecked") // field is of type T
     private T[] buildArray(final int length) {
-        return (T[]) Array.newInstance(field.getZero().getClass(), length);
+        return (T[]) Array.newInstance(field.getRuntimeClass(), length);
     }
 
 }

Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=1178009&r1=1178008&r2=1178009&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Sat Oct  1 15:15:00 2011
@@ -52,6 +52,10 @@ The <action> type attribute can be add,u
     If the output is not quite correct, check for invisible trailing spaces!
      -->
     <release version="3.0" date="TBD" description="TBD">
+      <action dev="luc" type="fix" issue="MATH-284" due-to="Klaus Hartlage">
+        Added a getRuntimeClass method to the Field interface allowing to use a
+        complete hierarchy of fields sharing a common interface.
+      </action>
       <action dev="luc" type="fix" issue="MATH-457" >
         The last remaining uses of OptimizationException have been replaced by unchecked
         exceptions (UnboundSolutionException, NoFeasibleSolutionException,

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/ArrayFieldVectorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/ArrayFieldVectorTest.java?rev=1178009&r1=1178008&r2=1178009&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/ArrayFieldVectorTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/ArrayFieldVectorTest.java
Sat Oct  1 15:15:00 2011
@@ -76,7 +76,7 @@ public class ArrayFieldVectorTest {
          */
         @SuppressWarnings("unchecked") // field is of type T
         private T[] buildArray(final int length) {
-            return (T[]) Array.newInstance(field.getZero().getClass(), length);
+            return (T[]) Array.newInstance(field.getRuntimeClass(), length);
         }
 
         public FieldVectorTestImpl(T[] d) {



Mime
View raw message