harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hinde...@apache.org
Subject svn commit: r785606 [4/4] - in /harmony/enhanced/classlib/branches/java6: ./ make/ modules/archive/src/main/java/java/util/jar/ modules/archive/src/main/java/java/util/zip/ modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/ m...
Date Wed, 17 Jun 2009 14:00:28 GMT
Modified: harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/DateFormatSymbols.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/DateFormatSymbols.java?rev=785606&r1=785605&r2=785606&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/DateFormatSymbols.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/DateFormatSymbols.java
Wed Jun 17 14:00:24 2009
@@ -17,6 +17,8 @@
 
 package java.text;
 
+import java.io.IOException;
+import java.io.ObjectOutputStream;
 import java.io.Serializable;
 import java.text.spi.DateFormatSymbolsProvider;
 import java.util.Arrays;
@@ -80,6 +82,8 @@
 
     private static final String PROVIDER_CONFIGURATION_FILE_NAME = "META-INF/services/java.text.spi.DateFormatSymbolsProvider";
//$NON-NLS-1$
 
+    transient private com.ibm.icu.text.DateFormatSymbols icuSymbols;
+
     /**
      * Constructs a new {@code DateFormatSymbols} instance containing the
      * symbols for the default locale.
@@ -96,9 +100,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();
@@ -106,7 +108,6 @@
         shortMonths = icuSymbols.getShortMonths();
         shortWeekdays = icuSymbols.getShortWeekdays();
         weekdays = icuSymbols.getWeekdays();
-        zoneStrings = icuSymbols.getZoneStrings();
     }
 
     /**
@@ -200,8 +201,18 @@
 
     }
 
+    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();
@@ -239,7 +250,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;
         }
@@ -364,6 +383,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();
@@ -373,6 +395,9 @@
 
     @Override
     public int hashCode() {
+        if (zoneStrings == null) {
+            zoneStrings = icuSymbols.getZoneStrings();
+        }
         int hashCode;
         hashCode = localPatternChars.hashCode();
         for (String element : ampms) {

Modified: harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/SimpleDateFormat.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/SimpleDateFormat.java?rev=785606&r1=785605&r2=785606&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/SimpleDateFormat.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/SimpleDateFormat.java
Wed Jun 17 14:00:24 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])) {
@@ -1081,6 +1081,7 @@
             tzId = id;
             icuFormat.setTimeZone(com.ibm.icu.util.TimeZone.getTimeZone(tzId));
         }
+        icuFormat.setLenient(calendar.isLenient());
         return icuFormat.parse(string,position);
     }
 

Modified: harmony/enhanced/classlib/branches/java6/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatSymbolsTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatSymbolsTest.java?rev=785606&r1=785605&r2=785606&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatSymbolsTest.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatSymbolsTest.java
Wed Jun 17 14:00:24 2009
@@ -18,6 +18,10 @@
 
 import java.io.File;
 import java.net.URL;
+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;
@@ -509,4 +513,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);
+    }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatTest.java?rev=785606&r1=785605&r2=785606&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatTest.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatTest.java
Wed Jun 17 14:00:24 2009
@@ -459,4 +459,17 @@
 			assertNotNull(e.getMessage());
 		}
 	}
+
+    /**
+     * @tests java.text.DateFormat#setLenient(boolean)
+     */
+    public void test_setLenient() {
+	Date d = null;
+	DateFormat output = new SimpleDateFormat("MM/dd/yy");
+	output.setLenient(false);
+	try {
+	    d = output.parse("01/01/-1");
+	    fail("Should throw ParseException here.");
+	} catch (ParseException e) {}
+    }
 }



Mime
View raw message