commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From billbar...@apache.org
Subject svn commit: r786936 - in /commons/proper/math/trunk/src: java/org/apache/commons/math/analysis/polynomials/ test/org/apache/commons/math/analysis/ test/org/apache/commons/math/analysis/polynomials/
Date Sun, 21 Jun 2009 01:12:23 GMT
Author: billbarker
Date: Sun Jun 21 01:12:22 2009
New Revision: 786936

URL: http://svn.apache.org/viewvc?rev=786936&view=rev
Log:
Restore Serializable to PolynomialFunction

Modified:
    commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/polynomials/PolynomialFunction.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/SinFunction.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/polynomials/PolynomialFunctionTest.java

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/polynomials/PolynomialFunction.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/polynomials/PolynomialFunction.java?rev=786936&r1=786935&r2=786936&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/polynomials/PolynomialFunction.java
(original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/polynomials/PolynomialFunction.java
Sun Jun 21 01:12:22 2009
@@ -16,6 +16,9 @@
  */
 package org.apache.commons.math.analysis.polynomials;
 
+import java.io.Serializable;
+import java.util.Arrays;
+
 import org.apache.commons.math.MathRuntimeException;
 import org.apache.commons.math.analysis.DifferentiableUnivariateRealFunction;
 import org.apache.commons.math.analysis.UnivariateRealFunction;
@@ -28,9 +31,14 @@
  *
  * @version $Revision$ $Date$
  */
-public class PolynomialFunction implements DifferentiableUnivariateRealFunction {
+public class PolynomialFunction implements DifferentiableUnivariateRealFunction, Serializable
{
 
     /**
+     * Serializtion identifier
+     */
+    private static final long serialVersionUID = -7726511984200295583L;
+    
+    /**
      * The coefficients of the polynomial, ordered by degree -- i.e.,  
      * coefficients[0] is the constant term and coefficients[n] is the 
      * coefficient of x^n where n is the degree of the polynomial.
@@ -315,4 +323,28 @@
 
      }
 
+    /** {@inheritDoc} */
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + Arrays.hashCode(coefficients);
+        return result;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (!(obj instanceof PolynomialFunction))
+            return false;
+        PolynomialFunction other = (PolynomialFunction) obj;
+        if (!Arrays.equals(coefficients, other.coefficients))
+            return false;
+        return true;
+    }
+
 }

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/SinFunction.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/SinFunction.java?rev=786936&r1=786935&r2=786936&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/SinFunction.java (original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/SinFunction.java Sun
Jun 21 01:12:22 2009
@@ -16,8 +16,6 @@
  */
 package org.apache.commons.math.analysis;
 
-import java.io.Serializable;
-
 import org.apache.commons.math.FunctionEvaluationException;
 
 /**

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/polynomials/PolynomialFunctionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/polynomials/PolynomialFunctionTest.java?rev=786936&r1=786935&r2=786936&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/polynomials/PolynomialFunctionTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/polynomials/PolynomialFunctionTest.java
Sun Jun 21 01:12:22 2009
@@ -18,7 +18,7 @@
 
 // commons-math
 import org.apache.commons.math.MathException;
-
+import org.apache.commons.math.TestUtils;
 // junit
 import junit.framework.TestCase;
 
@@ -226,6 +226,11 @@
 
     }
 
+    public void testSerial() {
+        PolynomialFunction p2 = new PolynomialFunction(new double[] { 3.0, 2.0, 1.0 });
+        assertEquals(p2, TestUtils.serializeAndRecover(p2));
+    }
+    
     public void checkPolynomial(PolynomialFunction p, String reference) {
         assertEquals(reference, p.toString());
     }



Mime
View raw message