Author: billbarker Date: Sat Jun 20 03:00:18 2009 New Revision: 786751 URL: http://svn.apache.org/viewvc?rev=786751&view=rev Log: Change Complex to use readResolve instead of introspection
Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/complex/Complex.java Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/complex/Complex.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/complex/Complex.java?rev=786751&r1=786750&r2=786751&view=diff ============================================================================== --- commons/proper/math/trunk/src/java/org/apache/commons/math/complex/Complex.java (original) +++ commons/proper/math/trunk/src/java/org/apache/commons/math/complex/Complex.java Sat Jun 20 03:00:18 2009 @@ -17,8 +17,6 @@ package org.apache.commons.math.complex; -import java.io.IOException; -import java.io.ObjectInputStream; import java.io.Serializable; import java.util.ArrayList; import java.util.List; @@ -973,33 +971,15 @@ } /** - * Deserialize a Complex Object. - * @param ois The stream to deserialize from. - * @throws IOException If there is an error reading the stream. - * @throws ClassNotFoundException If this class cannot be found. - */ - private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException { - ois.defaultReadObject(); - - try { - final java.lang.reflect.Field fNaN = getClass().getDeclaredField("isNaN"); - fNaN.setAccessible(true); - fNaN.set(this, Double.isNaN(real) || Double.isNaN(imaginary)); - final java.lang.reflect.Field fInf = getClass().getDeclaredField("isInfinite"); - fInf.setAccessible(true); - fInf.set(this, !isNaN && (Double.isInfinite(real) || Double.isInfinite(imaginary))); - } catch (IllegalAccessException iae) { - IOException ioe = new IOException(); - ioe.initCause(iae); - throw ioe; - } catch (NoSuchFieldException nsfe) { - IOException ioe = new IOException(); - ioe.initCause(nsfe); - throw ioe; - } - + * <p>Resolve the transient fields in a deserialized Complex Object.</p> + * <p>Subclasses will need to override {...@link #createComplex} to deserialize properly</p> + * @return A Complex instance with all fields resolved. + * @since 2.0 + */ + private final Object readResolve() { + return createComplex(real, imaginary); } - + /** {...@inheritdoc} */ public ComplexField getField() { return ComplexField.getInstance();