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:
parent
828c863a00
commit
b3c7fd661c
|
@ -16,6 +16,9 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.math.analysis.polynomials;
|
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.MathRuntimeException;
|
||||||
import org.apache.commons.math.analysis.DifferentiableUnivariateRealFunction;
|
import org.apache.commons.math.analysis.DifferentiableUnivariateRealFunction;
|
||||||
import org.apache.commons.math.analysis.UnivariateRealFunction;
|
import org.apache.commons.math.analysis.UnivariateRealFunction;
|
||||||
|
@ -28,8 +31,13 @@ import org.apache.commons.math.analysis.UnivariateRealFunction;
|
||||||
*
|
*
|
||||||
* @version $Revision$ $Date$
|
* @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.,
|
* The coefficients of the polynomial, ordered by degree -- i.e.,
|
||||||
* coefficients[0] is the constant term and coefficients[n] is the
|
* coefficients[0] is the constant term and coefficients[n] is the
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,6 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.math.analysis;
|
package org.apache.commons.math.analysis;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
import org.apache.commons.math.FunctionEvaluationException;
|
import org.apache.commons.math.FunctionEvaluationException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -18,7 +18,7 @@ package org.apache.commons.math.analysis.polynomials;
|
||||||
|
|
||||||
// commons-math
|
// commons-math
|
||||||
import org.apache.commons.math.MathException;
|
import org.apache.commons.math.MathException;
|
||||||
|
import org.apache.commons.math.TestUtils;
|
||||||
// junit
|
// junit
|
||||||
import junit.framework.TestCase;
|
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) {
|
public void checkPolynomial(PolynomialFunction p, String reference) {
|
||||||
assertEquals(reference, p.toString());
|
assertEquals(reference, p.toString());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue