streamlined deserialization of DerivativeStructure

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1403648 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2012-10-30 09:52:09 +00:00
parent ea8e5c488d
commit d4b31ce8ff
2 changed files with 10 additions and 3 deletions

View File

@ -887,9 +887,7 @@ public class DerivativeStructure implements FieldElement<DerivativeStructure>, S
* @return replacement {@link DerivativeStructure}
*/
private Object readResolve() {
final DerivativeStructure ds = new DerivativeStructure(variables, order);
System.arraycopy(data, 0, ds.data, 0, ds.data.length);
return ds;
return new DerivativeStructure(variables, order, data);
}
}

View File

@ -1128,6 +1128,15 @@ public class DerivativeStructureTest {
TestUtils.assertEquals(derivatives, xRef.add(yRef.subtract(zRef)).getAllDerivatives(), 1.0e-15);
}
@Test
public void testSerialization() {
DerivativeStructure a = new DerivativeStructure(3, 2, 0, 1.3);
DerivativeStructure b = (DerivativeStructure) TestUtils.serializeAndRecover(a);
Assert.assertEquals(a.getFreeParameters(), b.getFreeParameters());
Assert.assertEquals(a.getOrder(), b.getOrder());
checkEquals(a, b, 1.0e-15);
}
private void checkF0F1(DerivativeStructure ds, double value, double...derivatives) {
// check dimension