commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From billbar...@apache.org
Subject svn commit: r778256 - in /commons/proper/math/trunk/src: java/org/apache/commons/math/linear/ test/org/apache/commons/math/linear/
Date Sun, 24 May 2009 23:27:03 GMT
Author: billbarker
Date: Sun May 24 23:27:03 2009
New Revision: 778256

URL: http://svn.apache.org/viewvc?rev=778256&view=rev
Log:
Serializable changes for FieldVector and FieldMatrix

Modified:
    commons/proper/math/trunk/src/java/org/apache/commons/math/linear/AbstractFieldMatrix.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/linear/DenseFieldMatrix.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/linear/FieldMatrix.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/linear/FieldMatrixImpl.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/linear/FieldVector.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/linear/FieldVectorImpl.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SparseFieldVector.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/linear/DenseFieldMatrixTest.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/linear/FieldMatrixImplTest.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/linear/FieldVectorImplTest.java

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/linear/AbstractFieldMatrix.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/AbstractFieldMatrix.java?rev=778256&r1=778255&r2=778256&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/linear/AbstractFieldMatrix.java
(original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/linear/AbstractFieldMatrix.java
Sun May 24 23:27:03 2009
@@ -17,7 +17,6 @@
 
 package org.apache.commons.math.linear;
 
-import java.io.Serializable;
 import java.lang.reflect.Array;
 import java.util.Arrays;
 
@@ -35,11 +34,8 @@
  * @version $Revision$ $Date$
  * @since 2.0
  */
-public abstract class AbstractFieldMatrix<T extends FieldElement<T>> implements
FieldMatrix<T>, Serializable {
+public abstract class AbstractFieldMatrix<T extends FieldElement<T>> implements
FieldMatrix<T> {
     
-    /** Serializable version identifier. */
-    private static final long serialVersionUID = -3665653040524315561L;
-
     /** Field to which the elements belong. */
     private final Field<T> field;
 
@@ -121,6 +117,13 @@
     }
 
     /**
+     * Constructor for use with Serializable
+     */
+    protected AbstractFieldMatrix() {
+        field = null;
+    }
+    
+    /**
      * Creates a matrix with no data
      * @param field field to which the elements belong
      */

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/linear/DenseFieldMatrix.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/DenseFieldMatrix.java?rev=778256&r1=778255&r2=778256&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/linear/DenseFieldMatrix.java
(original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/linear/DenseFieldMatrix.java
Sun May 24 23:27:03 2009
@@ -17,6 +17,8 @@
 
 package org.apache.commons.math.linear;
 
+import java.io.Serializable;
+
 import org.apache.commons.math.Field;
 import org.apache.commons.math.FieldElement;
 import org.apache.commons.math.MathRuntimeException;
@@ -61,7 +63,7 @@
  * @version $Revision$ $Date$
  * @since 2.0
  */
-public class DenseFieldMatrix<T extends FieldElement<T>> extends AbstractFieldMatrix<T>
{
+public class DenseFieldMatrix<T extends FieldElement<T>> extends AbstractFieldMatrix<T>
implements Serializable {
     
     /** Serializable version identifier */
     private static final long serialVersionUID = -4602336630143123183L;

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/linear/FieldMatrix.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/FieldMatrix.java?rev=778256&r1=778255&r2=778256&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/linear/FieldMatrix.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/linear/FieldMatrix.java Sun
May 24 23:27:03 2009
@@ -17,7 +17,6 @@
 
 package org.apache.commons.math.linear;
 
-import java.io.Serializable;
 
 import org.apache.commons.math.Field;
 import org.apache.commons.math.FieldElement;
@@ -32,7 +31,7 @@
  * @param <T> the type of the field elements
  * @version $Revision$ $Date$
  */
-public interface FieldMatrix<T extends FieldElement<T>> extends AnyMatrix, Serializable
{
+public interface FieldMatrix<T extends FieldElement<T>> extends AnyMatrix {
 
     /**
      * Get the type of field elements of the matrix.

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/linear/FieldMatrixImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/FieldMatrixImpl.java?rev=778256&r1=778255&r2=778256&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/linear/FieldMatrixImpl.java
(original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/linear/FieldMatrixImpl.java
Sun May 24 23:27:03 2009
@@ -17,6 +17,8 @@
 
 package org.apache.commons.math.linear;
 
+import java.io.Serializable;
+
 import org.apache.commons.math.Field;
 import org.apache.commons.math.FieldElement;
 import org.apache.commons.math.MathRuntimeException;
@@ -32,7 +34,7 @@
  * @param <T> the type of the field elements
  * @version $Revision$ $Date$
  */
-public class FieldMatrixImpl<T extends FieldElement<T>> extends AbstractFieldMatrix<T>
{
+public class FieldMatrixImpl<T extends FieldElement<T>> extends AbstractFieldMatrix<T>
implements Serializable {
     
     /** Serializable version identifier */
     private static final long serialVersionUID = 7260756672015356458L;

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/linear/FieldVector.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/FieldVector.java?rev=778256&r1=778255&r2=778256&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/linear/FieldVector.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/linear/FieldVector.java Sun
May 24 23:27:03 2009
@@ -16,8 +16,6 @@
  */
 package org.apache.commons.math.linear;
 
-import java.io.Serializable;
-
 import org.apache.commons.math.Field;
 import org.apache.commons.math.FieldElement;
 
@@ -45,7 +43,7 @@
  * @version $Revision$ $Date$
  * @since 2.0
  */
-public interface FieldVector<T extends FieldElement<T>> extends Serializable
{
+public interface FieldVector<T extends FieldElement<T>>  {
 
     /**
      * Get the type of field elements of the vector.

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/linear/FieldVectorImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/FieldVectorImpl.java?rev=778256&r1=778255&r2=778256&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/linear/FieldVectorImpl.java
(original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/linear/FieldVectorImpl.java
Sun May 24 23:27:03 2009
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.math.linear;
 
+import java.io.Serializable;
 import java.lang.reflect.Array;
 import java.util.Arrays;
 
@@ -29,7 +30,7 @@
  * @version $Revision$ $Date$
  * @since 2.0
  */
-public class FieldVectorImpl<T extends FieldElement<T>> implements FieldVector<T>
{
+public class FieldVectorImpl<T extends FieldElement<T>> implements FieldVector<T>,
Serializable {
 
     /** Serializable version identifier. */
     private static final long serialVersionUID = 7648186910365927050L;

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SparseFieldVector.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SparseFieldVector.java?rev=778256&r1=778255&r2=778256&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SparseFieldVector.java
(original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SparseFieldVector.java
Sun May 24 23:27:03 2009
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.math.linear;
 
+import java.io.Serializable;
 import java.lang.reflect.Array;
 
 import org.apache.commons.math.Field;
@@ -28,7 +29,7 @@
  * @version $Revision: 728186 $ $Date: 2009-04-25 12:39:38 -0700 (Sat, 25 Apr 2009) $
  * @since 2.0
 */
-public class SparseFieldVector<T extends FieldElement<T>> implements FieldVector<T>
{
+public class SparseFieldVector<T extends FieldElement<T>> implements FieldVector<T>,
Serializable {
     
     /**
      *  Serial version id

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/linear/DenseFieldMatrixTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/linear/DenseFieldMatrixTest.java?rev=778256&r1=778255&r2=778256&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/linear/DenseFieldMatrixTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/linear/DenseFieldMatrixTest.java
Sun May 24 23:27:03 2009
@@ -16,6 +16,12 @@
  */
 package org.apache.commons.math.linear;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
 import java.util.Arrays;
 import java.util.Random;
 
@@ -1245,7 +1251,28 @@
         }
 
     }
-    
+
+    @SuppressWarnings("unchecked")
+    public void testSerial()  {
+        try {
+            File test = File.createTempFile("DFM",".ser");
+            ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(test));
+            DenseFieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(testData);
+            out.writeObject(m);
+            out.close();
+            ObjectInputStream in = new ObjectInputStream(new FileInputStream(test));
+            DenseFieldMatrix<Fraction> nm = (DenseFieldMatrix<Fraction>)in.readObject();
+            in.close();
+            test.delete();
+            assertEquals(m,nm);
+            
+        } catch (IOException e) {
+            fail("IOException: "+e);
+        } catch (ClassNotFoundException e) {
+            fail("Can't happen: "+e);
+        }
+    }
+  
     private static class SetVisitor extends DefaultFieldMatrixChangingVisitor<Fraction>
{
         public SetVisitor() {
             super(Fraction.ZERO);

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/linear/FieldMatrixImplTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/linear/FieldMatrixImplTest.java?rev=778256&r1=778255&r2=778256&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/linear/FieldMatrixImplTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/linear/FieldMatrixImplTest.java
Sun May 24 23:27:03 2009
@@ -16,6 +16,13 @@
  */
 package org.apache.commons.math.linear;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
@@ -931,7 +938,28 @@
         }
 
     }
-    
+
+    @SuppressWarnings("unchecked")
+    public void testSerial()  {
+        try {
+            File test = File.createTempFile("FMI",".ser");
+            ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(test));
+            FieldMatrixImpl<Fraction> m = new FieldMatrixImpl<Fraction>(testData);
+            out.writeObject(m);
+            out.close();
+            ObjectInputStream in = new ObjectInputStream(new FileInputStream(test));
+            FieldMatrixImpl<Fraction> nm = (FieldMatrixImpl<Fraction>)in.readObject();
+            in.close();
+            test.delete();
+            assertEquals(m,nm);
+            
+        } catch (IOException e) {
+            fail("IOException: "+e);
+        } catch (ClassNotFoundException e) {
+            fail("Can't happen: "+e);
+        }
+    }
+  
     private static class SetVisitor extends DefaultFieldMatrixChangingVisitor<Fraction>
{
         public SetVisitor() {
             super(Fraction.ZERO);

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/linear/FieldVectorImplTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/linear/FieldVectorImplTest.java?rev=778256&r1=778255&r2=778256&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/linear/FieldVectorImplTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/linear/FieldVectorImplTest.java
Sun May 24 23:27:03 2009
@@ -16,6 +16,12 @@
  */
 package org.apache.commons.math.linear;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
 import java.io.Serializable;
 import java.lang.reflect.Array;
 
@@ -612,6 +618,27 @@
 
     }
 
+    @SuppressWarnings("unchecked")
+    public void testSerial()  {
+        try {
+            File test = File.createTempFile("FVI",".ser");
+            ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(test));
+            FieldVectorImpl<Fraction> v = new FieldVectorImpl<Fraction>(vec1);
+            out.writeObject(v);
+            out.close();
+            ObjectInputStream in = new ObjectInputStream(new FileInputStream(test));
+            FieldVectorImpl<Fraction> nv = (FieldVectorImpl<Fraction>)in.readObject();
+            in.close();
+            test.delete();
+            assertEquals(v,nv);
+            
+        } catch (IOException e) {
+            fail("IOException: "+e);
+        } catch (ClassNotFoundException e) {
+            fail("Can't happen: "+e);
+        }
+    }
+  
     /** verifies that two vectors are equals */
     protected void checkArray(String msg, Fraction[] m, Fraction[] n) {
         if (m.length != n.length) {



Mime
View raw message