Restore Serializable to PolynomialFunction

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@786936 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
William Barker 2009-06-21 01:12:22 +00:00
parent 828c863a00
commit b3c7fd661c
3 changed files with 39 additions and 4 deletions

View File

@ -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,7 +31,12 @@ import org.apache.commons.math.analysis.UnivariateRealFunction;
*
* @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.,
@ -315,4 +323,28 @@ public class PolynomialFunction implements DifferentiableUnivariateRealFunction
}
/** {@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;
}
}

View File

@ -16,8 +16,6 @@
*/
package org.apache.commons.math.analysis;
import java.io.Serializable;
import org.apache.commons.math.FunctionEvaluationException;
/**

View File

@ -18,7 +18,7 @@ package org.apache.commons.math.analysis.polynomials;
// commons-math
import org.apache.commons.math.MathException;
import org.apache.commons.math.TestUtils;
// junit
import junit.framework.TestCase;
@ -226,6 +226,11 @@ public final class PolynomialFunctionTest extends TestCase {
}
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());
}