You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2009/07/20 18:51:09 UTC

svn commit: r795912 - in /commons/proper/math/trunk/src: java/org/apache/commons/math/util/BigRealField.java test/org/apache/commons/math/util/BigRealFieldTest.java

Author: luc
Date: Mon Jul 20 16:51:09 2009
New Revision: 795912

URL: http://svn.apache.org/viewvc?rev=795912&view=rev
Log:
handle serialization of BigRealField (which is a singleton) properly and test it

Added:
    commons/proper/math/trunk/src/test/org/apache/commons/math/util/BigRealFieldTest.java   (with props)
Modified:
    commons/proper/math/trunk/src/java/org/apache/commons/math/util/BigRealField.java

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/util/BigRealField.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/util/BigRealField.java?rev=795912&r1=795911&r2=795912&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/util/BigRealField.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/util/BigRealField.java Mon Jul 20 16:51:09 2009
@@ -31,8 +31,6 @@
  * @since 2.0
  */
 public class BigRealField implements Field<BigReal>, Serializable  {
-    // TODO: Add Serializable documentation
-    // TODO: Check Serializable implementation
 
     /** Serializable version identifier */
     private static final long serialVersionUID = 4756431066541037559L;
@@ -67,4 +65,12 @@
         private static final BigRealField INSTANCE = new BigRealField();
     }
 
+    /** Handle deserialization of the singleton.
+     * @return the singleton instance
+     */
+    private Object readResolve() {
+        // return the singleton instance
+        return LazyHolder.INSTANCE; 
+    }
+
 }

Added: commons/proper/math/trunk/src/test/org/apache/commons/math/util/BigRealFieldTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/util/BigRealFieldTest.java?rev=795912&view=auto
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/util/BigRealFieldTest.java (added)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/util/BigRealFieldTest.java Mon Jul 20 16:51:09 2009
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.math.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.commons.math.TestUtils;
+import org.junit.Test;
+
+public class BigRealFieldTest {
+
+    @Test
+    public void testZero() {
+        assertEquals(BigReal.ZERO, BigRealField.getInstance().getZero());
+    }
+
+    @Test
+    public void testOne() {
+        assertEquals(BigReal.ONE, BigRealField.getInstance().getOne());
+    }
+
+    @Test
+    public void testSerial() {
+        // deserializing the singleton should give the singleton itself back
+        BigRealField field = BigRealField.getInstance();
+        assertTrue(field == TestUtils.serializeAndRecover(field));
+    }
+
+}

Propchange: commons/proper/math/trunk/src/test/org/apache/commons/math/util/BigRealFieldTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/math/trunk/src/test/org/apache/commons/math/util/BigRealFieldTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision