This is the mail archive of the java-patches@sources.redhat.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Patch: Serialization mods


Here are some more serialization changes.  Enjoy!
--warrenl



2000-10-10  Warren Levy  <warrenl@cygnus.com>

	* gnu/gcj/text/LocaleData_en.java (monetarySeparator): Added.
	* java/sql/Date.java (serialVersionUID): New field.
	* java/sql/Time.java (serialVersionUID): New field.
	* java/sql/Timestamp.java (serialVersionUID): New field.
	* java/text/ChoiceFormat.java (serialVersionUID): New field.
	* java/text/DateFormat.java (getDateTimeInstance (int)): Removed.
	* java/text/DateFormatSymbols.java (serialVersionUID): New field.
	* java/text/DecimalFormat.java (serialVersionOnStream): New field.
	(readObject): New serialization method.
	* java/text/DecimalFormatSymbols.java (monetarySeparator): New field.
	(serialVersionOnStream): New field.
	(readObject): New serialization method.
	(getMonetaryDecimalSeparator): New method.
	(setMonetaryDecimalSeparator): New method.
	* java/text/NumberFormat.java (maxFractionDigits): New field.
	(maxIntegerDigits): New field.
	(minFractionDigits): New field.
	(minIntegerDigits): New field.
	(serialVersionOnStream): New field.
	(serialVersionUID): New field.
	(readObject): New serialization method.
	(writeObject): New serialization method.
	* java/text/SimpleDateFormat.java (defaultCenturyStart): Initialized.
	(serialVersionOnStream): New field.
	(serialVersionUID): New field.
	(readObject): New serialization method.

Index: gnu/gcj/text/LocaleData_en.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/gnu/gcj/text/LocaleData_en.java,v
retrieving revision 1.5
diff -u -p -r1.5 LocaleData_en.java
--- LocaleData_en.java	2000/03/07 19:55:25	1.5
+++ LocaleData_en.java	2000/10/10 22:33:23
@@ -1,6 +1,6 @@
 // Generic English locale data for java.text.
 
-/* Copyright (C) 1999  Free Software Foundation
+/* Copyright (C) 1999, 2000  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -48,6 +48,7 @@ public final class LocaleData_en extends
     { "groupingSeparator", "," },
     { "infinity", "\u221e" },
     { "minusSign", "-" },
+    { "monetarySeparator", "." },
     { "NaN", "\ufffd" },
     { "patternSeparator", ";" },
     { "percent", "%" },
Index: java/sql/Date.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/sql/Date.java,v
retrieving revision 1.1
diff -u -p -r1.1 Date.java
--- Date.java	2000/04/11 09:21:53	1.1
+++ Date.java	2000/10/10 22:33:25
@@ -1,5 +1,5 @@
 /* Date.java -- Wrapper around java.util.Date
-   Copyright (C) 1999 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2000 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -35,7 +35,7 @@ import java.text.SimpleDateFormat;
   *
   * @author Aaron M. Renn (arenn@urbanophile.com)
   */
-public class Date extends java.util.Date implements java.io.Serializable
+public class Date extends java.util.Date
 {
 
 /*
@@ -46,6 +46,11 @@ public class Date extends java.util.Date
   * Used for parsing and formatting this date.
   */
 private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+
+/**
+  * This is the serialization UID for this class.
+  */
+private static final long serialVersionUID = 1511598038487230103L;
 
 /*************************************************************************/
 
Index: java/sql/Time.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/sql/Time.java,v
retrieving revision 1.1
diff -u -p -r1.1 Time.java
--- Time.java	2000/04/11 09:21:53	1.1
+++ Time.java	2000/10/10 22:33:25
@@ -1,5 +1,5 @@
 /* Time.java -- Wrapper around java.util.Date
-   Copyright (C) 1999 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2000 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -35,7 +35,7 @@ import java.text.SimpleDateFormat;
   *
   * @author Aaron M. Renn (arenn@urbanophile.com)
   */
-public class Time extends java.util.Date implements java.io.Serializable
+public class Time extends java.util.Date
 {
 
 /*
@@ -46,6 +46,11 @@ public class Time extends java.util.Date
   * Used for parsing and formatting this date.
   */
 private static SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
+
+/**
+  * This is the serialization UID for this class.
+  */
+private static final long serialVersionUID = 8397324403548013681L;
 
 /*************************************************************************/
 
Index: java/sql/Timestamp.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/sql/Timestamp.java,v
retrieving revision 1.1
diff -u -p -r1.1 Timestamp.java
--- Timestamp.java	2000/04/11 09:21:53	1.1
+++ Timestamp.java	2000/10/10 22:33:25
@@ -1,5 +1,5 @@
 /* Time.java -- Wrapper around java.util.Date
-   Copyright (C) 1999 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2000 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -39,7 +39,7 @@ import java.text.SimpleDateFormat;
   *
   * @author Aaron M. Renn (arenn@urbanophile.com)
   */
-public class Timestamp extends java.util.Date implements java.io.Serializable
+public class Timestamp extends java.util.Date
 {
 
 /*
@@ -55,6 +55,11 @@ private static SimpleDateFormat parse_sd
 
 private static SimpleDateFormat format_sdf =
   new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
+/**
+  * This is the serialization UID for this class.
+  */
+private static final long serialVersionUID = 3581463369166924961L;
 
 /*************************************************************************/
 
Index: java/text/ChoiceFormat.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/text/ChoiceFormat.java,v
retrieving revision 1.6
diff -u -p -r1.6 ChoiceFormat.java
--- ChoiceFormat.java	2000/06/27 05:10:03	1.6
+++ ChoiceFormat.java	2000/10/10 22:33:25
@@ -307,4 +307,6 @@ public class ChoiceFormat extends Number
   private static final int mantissaBits = 52;
   // Number of exponent bits in a double.
   private static final int exponentBits = 11;
+
+  private static final long serialVersionUID = 1795184449645032964L;
 }
Index: java/text/DateFormat.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/text/DateFormat.java,v
retrieving revision 1.5
diff -u -p -r1.5 DateFormat.java
--- DateFormat.java	2000/03/07 19:55:27	1.5
+++ DateFormat.java	2000/10/10 22:33:25
@@ -219,11 +219,6 @@ public abstract class DateFormat extends
     return getDateTimeInstance (DEFAULT, DEFAULT, Locale.getDefault());
   }
 
-  public static final DateFormat getDateTimeInstance (int style)
-  {
-    return getDateTimeInstance (style, style, Locale.getDefault());
-  }
-
   public static final DateFormat getDateTimeInstance (int dateStyle, 
 						      int timeStyle)
   {
Index: java/text/DateFormatSymbols.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/text/DateFormatSymbols.java,v
retrieving revision 1.4
diff -u -p -r1.4 DateFormatSymbols.java
--- DateFormatSymbols.java	2000/03/07 19:55:27	1.4
+++ DateFormatSymbols.java	2000/10/10 22:33:26
@@ -33,6 +33,8 @@ public class DateFormatSymbols extends O
   private String[] weekdays;
   private String[][] zoneStrings;
 
+  private static final long serialVersionUID = -5987973545549424702L;
+
   private static final String[] ampmsDefault = {"AM", "PM" };
   private static final String[] erasDefault = {"BC", "AD" };
   // localPatternCharsDefault is used by SimpleDateFormat.
Index: java/text/DecimalFormat.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/text/DecimalFormat.java,v
retrieving revision 1.4
diff -u -p -r1.4 DecimalFormat.java
--- DecimalFormat.java	2000/03/07 19:55:27	1.4
+++ DecimalFormat.java	2000/10/10 22:33:26
@@ -1,6 +1,6 @@
 // DecimalFormat.java - Localized number formatting.
 
-/* Copyright (C) 1999  Free Software Foundation
+/* Copyright (C) 1999, 2000  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -13,6 +13,8 @@ package java.text;
 import java.util.Locale;
 import java.util.MissingResourceException;
 import java.util.ResourceBundle;
+import java.io.ObjectInputStream;
+import java.io.IOException;
 
 /**
  * @author Tom Tromey <tromey@cygnus.com>
@@ -20,7 +22,7 @@ import java.util.ResourceBundle;
  */
 /* Written using "Java Class Libraries", 2nd edition, plus online
  * API docs for JDK 1.2 from http://www.javasoft.com.
- * Status:  Believed complete and correct to 1.2, except serialization.
+ * Status:  Believed complete and correct to 1.2.
  * Note however that the docs are very unclear about how format parsing
  * should work.  No doubt there are problems here.
  */
@@ -976,8 +978,21 @@ public class DecimalFormat extends Numbe
   private String negativeSuffix;
   private String positivePrefix;
   private String positiveSuffix;
+  private int serialVersionOnStream = 1;
   private DecimalFormatSymbols symbols;
   private boolean useExponentialNotation;
+  private static final long serialVersionUID = 864413376551465018L;
+
+  private void readObject(ObjectInputStream stream)
+    throws IOException, ClassNotFoundException
+  {
+    stream.defaultReadObject();
+    if (serialVersionOnStream < 1)
+      {
+        useExponentialNotation = false;
+	serialVersionOnStream = 1;
+      }
+  }
 
   // The locale-independent pattern symbols happen to be the same as
   // the US symbols.
Index: java/text/DecimalFormatSymbols.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/text/DecimalFormatSymbols.java,v
retrieving revision 1.3
diff -u -p -r1.3 DecimalFormatSymbols.java
--- DecimalFormatSymbols.java	2000/03/07 19:55:27	1.3
+++ DecimalFormatSymbols.java	2000/10/10 22:33:26
@@ -1,6 +1,6 @@
 // DecimalFormatSymbols.java - Symbols used to format numbers.
 
-/* Copyright (C) 1999  Free Software Foundation
+/* Copyright (C) 1999, 2000  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -14,6 +14,8 @@ import java.io.Serializable;
 import java.util.Locale;
 import java.util.MissingResourceException;
 import java.util.ResourceBundle;
+import java.io.ObjectInputStream;
+import java.io.IOException;
 
 /**
  * @author Tom Tromey <tromey@cygnus.com>
@@ -21,7 +23,7 @@ import java.util.ResourceBundle;
  */
 /* Written using "Java Class Libraries", 2nd edition, plus online
  * API docs for JDK 1.2 from http://www.javasoft.com.
- * Status:  Believed complete and correct to 1.2, except serialization.
+ * Status:  Believed complete and correct to 1.2.
  */
 
 public final class DecimalFormatSymbols implements Cloneable, Serializable
@@ -40,6 +42,7 @@ public final class DecimalFormatSymbols 
       this.groupingSeparator = orig.groupingSeparator;
       this.infinity = orig.infinity;
       this.intlCurrencySymbol = orig.intlCurrencySymbol;
+      this.monetarySeparator = orig.monetarySeparator;
       this.minusSign = orig.minusSign;
       this.NaN = orig.NaN;
       this.patternSeparator = orig.patternSeparator;
@@ -107,6 +110,14 @@ public final class DecimalFormatSymbols 
       infinity = safeGetString (res, "infinity", "\u221e");
       // FIXME: default?
       intlCurrencySymbol = safeGetString (res, "intlCurrencySymbol", "$");
+      try
+        {
+	  monetarySeparator = safeGetChar (res, "monetarySeparator", '.');
+	}
+      catch (MissingResourceException x)
+        {
+	  monetarySeparator = decimalSeparator;
+	}
       minusSign = safeGetChar (res, "minusSign", '-');
       NaN = safeGetString (res, "NaN", "\ufffd");
       patternSeparator = safeGetChar (res, "patternSeparator", ';');
@@ -128,6 +139,7 @@ public final class DecimalFormatSymbols 
 	      && infinity.equals(dfs.infinity)
 	      && intlCurrencySymbol.equals(dfs.intlCurrencySymbol)
 	      && minusSign == dfs.minusSign
+	      && monetarySeparator == dfs.monetarySeparator
 	      && NaN.equals(dfs.NaN)
 	      && patternSeparator == dfs.patternSeparator
 	      && percent == dfs.percent
@@ -176,6 +188,11 @@ public final class DecimalFormatSymbols 
       return minusSign;
     }
 
+  public char getMonetaryDecimalSeparator ()
+    {
+      return monetarySeparator;
+    }
+
   public String getNaN ()
     {
       return NaN;
@@ -250,6 +267,11 @@ public final class DecimalFormatSymbols 
       this.minusSign = minusSign;
     }
 
+  public void setMonetaryDecimalSeparator (char decimalSep)
+    {
+      monetarySeparator = decimalSep;
+    }
+
   public void setNaN (String nan)
     {
       NaN = nan;
@@ -285,9 +307,24 @@ public final class DecimalFormatSymbols 
   private String infinity;
   private String intlCurrencySymbol;
   private char minusSign;
+  private char monetarySeparator;
   private String NaN;
   private char patternSeparator;
   private char percent;
   private char perMill;
+  private int serialVersionOnStream = 1;
   private char zeroDigit;
+  private static final long serialVersionUID = 5772796243397350300L;
+
+  private void readObject(ObjectInputStream stream)
+    throws IOException, ClassNotFoundException
+  {
+    stream.defaultReadObject();
+    if (serialVersionOnStream < 1)
+      {
+        monetarySeparator = decimalSeparator;
+	exponential = 'E';
+	serialVersionOnStream = 1;
+      }
+  }
 }
Index: java/text/NumberFormat.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/text/NumberFormat.java,v
retrieving revision 1.5
diff -u -p -r1.5 NumberFormat.java
--- NumberFormat.java	2000/03/07 19:55:27	1.5
+++ NumberFormat.java	2000/10/10 22:33:26
@@ -11,6 +11,9 @@ package java.text;
 import java.util.Locale;
 import java.util.ResourceBundle;
 import java.util.MissingResourceException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.IOException;
 
 /**
  * @author Tom Tromey <tromey@cygnus.com>
@@ -18,8 +21,7 @@ import java.util.MissingResourceExceptio
  */
 /* Written using "Java Class Libraries", 2nd edition, plus online
  * API docs for JDK 1.2 from http://www.javasoft.com.
- * Status:  Believed complete and correct to 1.2, except serialization
- *          and getAvailableLocales.
+ * Status:  Believed complete and correct to 1.2, except getAvailableLocales.
  */
 
 public abstract class NumberFormat extends Format implements Cloneable
@@ -249,13 +251,44 @@ public abstract class NumberFormat exten
     }
 
   // These field names are fixed by the serialization spec.
-  // FIXME: serialization spec also mentions `byte' versions of the
-  // min/max fields.  We have no use for those, so for now they are
-  // omitted.
   protected boolean groupingUsed;
   protected int maximumFractionDigits;
+  private byte maxFractionDigits;
   protected int maximumIntegerDigits;
+  private byte maxIntegerDigits;
   protected int minimumFractionDigits;
+  private byte minFractionDigits;
   protected int minimumIntegerDigits;
+  private byte minIntegerDigits;
   protected boolean parseIntegerOnly;
+  private int serialVersionOnStream;
+  private static final long serialVersionUID = -2308460125733713944L;
+
+  private void readObject(ObjectInputStream stream)
+    throws IOException, ClassNotFoundException
+  {
+    stream.defaultReadObject();
+    if (serialVersionOnStream < 1)
+      {
+        maximumFractionDigits = maxFractionDigits;
+	maximumIntegerDigits = maxIntegerDigits;
+	minimumFractionDigits = minFractionDigits;
+	minimumIntegerDigits = minIntegerDigits;
+	serialVersionOnStream = 1;
+      }
+  }
+
+  private void writeObject(ObjectOutputStream stream) throws IOException
+  {
+    maxFractionDigits = maximumFractionDigits < Byte.MAX_VALUE ?
+      (byte) maximumFractionDigits : Byte.MAX_VALUE;
+    maxIntegerDigits = maximumIntegerDigits < Byte.MAX_VALUE ?
+      (byte) maximumIntegerDigits : Byte.MAX_VALUE;
+    minFractionDigits = minimumFractionDigits < Byte.MAX_VALUE ?
+      (byte) minimumFractionDigits : Byte.MAX_VALUE;
+    minIntegerDigits = minimumIntegerDigits < Byte.MAX_VALUE ?
+      (byte) minimumIntegerDigits : Byte.MAX_VALUE;
+    serialVersionOnStream = 1;
+    stream.defaultWriteObject();
+  }
 }
Index: java/text/SimpleDateFormat.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/text/SimpleDateFormat.java,v
retrieving revision 1.4
diff -u -p -r1.4 SimpleDateFormat.java
--- SimpleDateFormat.java	2000/03/07 19:55:27	1.4
+++ SimpleDateFormat.java	2000/10/10 22:33:27
@@ -9,6 +9,8 @@ details.  */
 package java.text;
 
 import java.util.*;
+import java.io.ObjectInputStream;
+import java.io.IOException;
 
 /**
  * @author Per Bothner <bothner@cygnus.com>
@@ -16,14 +18,29 @@ import java.util.*;
  */
 /* Written using "Java Class Libraries", 2nd edition, plus online
  * API docs for JDK 1.2 beta from http://www.javasoft.com.
- * Status:  parse is not implemented.
+ * Status:  Believed complete and correct to 1.2.
  */
 
 public class SimpleDateFormat extends DateFormat
 {
-  private Date defaultCenturyStart;
+  // Serialization fields.
+  private Date defaultCenturyStart = new Date();
   private DateFormatSymbols formatData;
   private String pattern;
+  private int serialVersionOnStream = 1;
+  private static final long serialVersionUID = 4774881970558875024L;
+
+  // Serialization method.
+  private void readObject(ObjectInputStream stream)
+    throws IOException, ClassNotFoundException
+  {
+    stream.defaultReadObject();
+    if (serialVersionOnStream < 1)
+      {
+        defaultCenturyStart = new Date();
+	serialVersionOnStream = 1;
+      }
+  }
 
   public SimpleDateFormat ()
   {

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]