Revision: 8521
Author: [email protected]
Date: Wed Aug 11 12:24:47 2010
Log: Lazily generate LocaleInfoImpl (rebase from superdevmode)

Review at http://gwt-code-reviews.appspot.com/619807

Review by: [email protected]
http://code.google.com/p/google-web-toolkit/source/detail?r=8521

Modified:
 /trunk/user/src/com/google/gwt/i18n/client/LocaleInfo.java

=======================================
--- /trunk/user/src/com/google/gwt/i18n/client/LocaleInfo.java Mon Jun 14 12:28:42 2010 +++ /trunk/user/src/com/google/gwt/i18n/client/LocaleInfo.java Wed Aug 11 12:24:47 2010
@@ -33,9 +33,7 @@
* is a static. In the future, we would need a hash map from locale names
    * to LocaleInfo instances.
    */
-  private static LocaleInfo instance  = new LocaleInfo(
-      (LocaleInfoImpl) GWT.create(LocaleInfoImpl.class),
-      (CldrImpl) GWT.create(CldrImpl.class));
+  private static LocaleInfo instance  = new LocaleInfo();

   /**
    * @return an array of available locale names
@@ -52,7 +50,7 @@
* you might want to get the list of available locales in order to create
      * instances of each of them.
      */
-    return instance.infoImpl.getAvailableLocaleNames();
+    return LocaleInfoImplHolder.infoImpl.getAvailableLocaleNames();
   }

   /**
@@ -84,19 +82,23 @@
     /*
      * See the comment from getAvailableLocaleNames() above.
      */
-    return instance.infoImpl.getLocaleNativeDisplayName(localeName);
-  }
+ return LocaleInfoImplHolder.infoImpl.getLocaleNativeDisplayName(localeName);
+  }
+
+   private static class LocaleInfoImplHolder {
+ static final LocaleInfoImpl infoImpl = GWT.create(LocaleInfoImpl.class);
+   }
+
+   private static class CldrImplHolder {
+     static final CldrImpl cldrImpl = GWT.create(CldrImpl.class);
+   }

   /**
    * @return true if any locale supported by this build of the app is RTL.
    */
   public static boolean hasAnyRTL() {
-    return instance.infoImpl.hasAnyRTL();
-  }
-
-  private final LocaleInfoImpl infoImpl;
-
-  private final CldrImpl cldrImpl;
+    return LocaleInfoImplHolder.infoImpl.hasAnyRTL();
+  }

   private DateTimeConstants dateTimeConstants;

@@ -109,19 +111,6 @@
    * Any such subclass should override all methods.
    */
   protected LocaleInfo() {
-    infoImpl = null;
-    cldrImpl = null;
-  }
-
-  /**
-   * Create a LocaleInfo instance, passing in the implementation classes.
-   *
-   * @param impl LocaleInfoImpl instance to use
-   * @param cldr CldrImpl instance to use
-   */
-  private LocaleInfo(LocaleInfoImpl impl, CldrImpl cldr) {
-    this.infoImpl = impl;
-    this.cldrImpl = cldr;
   }

   /**
@@ -144,7 +133,7 @@
    * @return the name of this locale, such as "default, "en_US", etc
    */
   public final String getLocaleName() {
-    return infoImpl.getLocaleName();
+    return LocaleInfoImplHolder.infoImpl.getLocaleName();
   }

   /**
@@ -159,7 +148,7 @@
    * @return true if this locale is right-to-left instead of left-to-right
    */
   public final boolean isRTL() {
-    return cldrImpl.isRTL();
+    return CldrImplHolder.cldrImpl.isRTL();
   }

   private void ensureDateTimeConstants() {
@@ -171,13 +160,13 @@

   private void ensureDateTimeFormatInfo() {
     if (dateTimeFormatInfo == null) {
-      dateTimeFormatInfo = infoImpl.getDateTimeFormatInfo();
+ dateTimeFormatInfo = LocaleInfoImplHolder.infoImpl.getDateTimeFormatInfo();
     }
   }

   private void ensureNumberConstants() {
     if (numberConstants == null) {
-      numberConstants = infoImpl.getNumberConstants();
+      numberConstants = LocaleInfoImplHolder.infoImpl.getNumberConstants();
     }
   }
 }

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to