harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From regi...@apache.org
Subject svn commit: r784683 - in /harmony/enhanced/classlib/trunk/modules/text/src: main/java/java/text/DateFormatSymbols.java main/java/java/text/SimpleDateFormat.java test/java/org/apache/harmony/text/tests/java/text/DateFormatSymbolsTest.java
Date Mon, 15 Jun 2009 08:17:37 GMT
Author: regisxu
Date: Mon Jun 15 08:17:36 2009
New Revision: 784683

URL: http://svn.apache.org/viewvc?rev=784683&view=rev
Log:
Apply patch for HARMONY-6095: [classlib][luni] Performance improvement patch for java.text.DateFormatSymbols.DateFormatSymbols(Locale)

Modified:
    harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/DateFormatSymbols.java
    harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/SimpleDateFormat.java
    harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatSymbolsTest.java

Modified: harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/DateFormatSymbols.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/DateFormatSymbols.java?rev=784683&r1=784682&r2=784683&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/DateFormatSymbols.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/DateFormatSymbols.java
Mon Jun 15 08:17:36 2009
@@ -17,6 +17,8 @@
 
 package java.text;
 
+import java.io.IOException;
+import java.io.ObjectOutputStream;
 import java.io.Serializable;
 import java.util.Arrays;
 import java.util.Locale;
@@ -68,6 +70,8 @@
 
     String[][] zoneStrings;
 
+    transient private com.ibm.icu.text.DateFormatSymbols icuSymbols;
+
     /**
      * Constructs a new {@code DateFormatSymbols} instance containing the
      * symbols for the default locale.
@@ -84,8 +88,7 @@
      *            the locale.
      */
     public DateFormatSymbols(Locale locale) {
-        com.ibm.icu.text.DateFormatSymbols icuSymbols = new com.ibm.icu.text.DateFormatSymbols(locale);
-        
+        icuSymbols = new com.ibm.icu.text.DateFormatSymbols(locale);
         localPatternChars = icuSymbols.getLocalPatternChars();
         ampms = icuSymbols.getAmPmStrings();
         eras = icuSymbols.getEras();
@@ -93,11 +96,20 @@
         shortMonths = icuSymbols.getShortMonths();
         shortWeekdays = icuSymbols.getShortWeekdays();
         weekdays = icuSymbols.getWeekdays();
-        zoneStrings = icuSymbols.getZoneStrings();
+    }
+
+    private void writeObject(ObjectOutputStream oos) throws IOException {
+        if (zoneStrings == null) {
+            zoneStrings = icuSymbols.getZoneStrings();
+        }
+        oos.defaultWriteObject();
     }
 
     @Override
     public Object clone() {
+        if (zoneStrings == null) {
+            zoneStrings = icuSymbols.getZoneStrings();
+        }
         try {
             DateFormatSymbols symbols = (DateFormatSymbols) super.clone();
             symbols.ampms = ampms.clone();
@@ -135,7 +147,15 @@
         if (!(object instanceof DateFormatSymbols)) {
             return false;
         }
+        if (zoneStrings == null) {
+            zoneStrings = icuSymbols.getZoneStrings();
+        }
+
         DateFormatSymbols obj = (DateFormatSymbols) object;
+
+        if (obj.zoneStrings == null) {
+            obj.zoneStrings = obj.icuSymbols.getZoneStrings();
+        }
         if (!localPatternChars.equals(obj.localPatternChars)) {
             return false;
         }
@@ -260,6 +280,9 @@
      * @return a two-dimensional array of strings.
      */
     public String[][] getZoneStrings() {
+        if (zoneStrings == null) {
+            zoneStrings = icuSymbols.getZoneStrings();
+        }
         String[][] clone = new String[zoneStrings.length][];
         for (int i = zoneStrings.length; --i >= 0;) {
             clone[i] = zoneStrings[i].clone();
@@ -269,6 +292,9 @@
 
     @Override
     public int hashCode() {
+        if (zoneStrings == null) {
+            zoneStrings = icuSymbols.getZoneStrings();
+        }
         int hashCode;
         hashCode = localPatternChars.hashCode();
         for (String element : ampms) {

Modified: harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/SimpleDateFormat.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/SimpleDateFormat.java?rev=784683&r1=784682&r2=784683&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/SimpleDateFormat.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/SimpleDateFormat.java
Mon Jun 15 08:17:36 2009
@@ -879,7 +879,7 @@
 
         if (generalTimezone) {
             String id = calendar.getTimeZone().getID();
-            String[][] zones = formatData.zoneStrings;
+            String[][] zones = formatData.getZoneStrings();
             String[] zone = null;
             for (String[] element : zones) {
                 if (id.equals(element[0])) {

Modified: harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatSymbolsTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatSymbolsTest.java?rev=784683&r1=784682&r2=784683&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatSymbolsTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatSymbolsTest.java
Mon Jun 15 08:17:36 2009
@@ -16,6 +16,10 @@
  */
 package org.apache.harmony.text.tests.java.text;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
 import java.text.DateFormatSymbols;
 import java.util.Arrays;
 import java.util.Locale;
@@ -339,4 +343,27 @@
      */
     protected void tearDown() {
     }
+
+    // Test serialization mechanism of DateFormatSymbols
+    public void test_serialization() throws Exception {
+        DateFormatSymbols symbols = new DateFormatSymbols(Locale.FRANCE);
+        String[][] zoneStrings = symbols.getZoneStrings();
+        assertNotNull(zoneStrings);
+
+        // serialize
+        ByteArrayOutputStream byteOStream = new ByteArrayOutputStream();
+        ObjectOutputStream objectOStream = new ObjectOutputStream(byteOStream);
+        objectOStream.writeObject(symbols);
+
+        // and deserialize
+        ObjectInputStream objectIStream = new ObjectInputStream(
+                new ByteArrayInputStream(byteOStream.toByteArray()));
+        DateFormatSymbols symbolsD = (DateFormatSymbols) objectIStream
+                .readObject();
+
+        // The associated currency will not persist
+        String[][] zoneStringsD = symbolsD.getZoneStrings();
+        assertNotNull(zoneStringsD);
+        assertEquals(symbols, symbolsD);
+    }
 }



Mime
View raw message