summaryrefslogtreecommitdiffstats
path: root/libjava/java/text/DecimalFormatSymbols.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/java/text/DecimalFormatSymbols.java')
-rw-r--r--libjava/java/text/DecimalFormatSymbols.java75
1 files changed, 75 insertions, 0 deletions
diff --git a/libjava/java/text/DecimalFormatSymbols.java b/libjava/java/text/DecimalFormatSymbols.java
index 110e45f1200..b72f144546b 100644
--- a/libjava/java/text/DecimalFormatSymbols.java
+++ b/libjava/java/text/DecimalFormatSymbols.java
@@ -38,13 +38,19 @@ exception statement from your version. */
package java.text;
+import gnu.java.locale.LocaleHelper;
+
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
+
+import java.text.spi.DecimalFormatSymbolsProvider;
+
import java.util.Currency;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
+import java.util.ServiceLoader;
/**
* This class is a container for the symbols used by
@@ -77,6 +83,11 @@ public final class DecimalFormatSymbols implements Cloneable, Serializable
/**
* This method initializes a new instance of
* <code>DecimalFormatSymbols</code> for the default locale.
+ * This constructor only obtains instances using the runtime's resources;
+ * to also include {@link java.text.spi.DateFormatSymbolsProvider} instances,
+ * call {@link #getInstance()} instead.
+ *
+ * @see #getInstance()
*/
public DecimalFormatSymbols ()
{
@@ -664,4 +675,68 @@ public final class DecimalFormatSymbols implements Cloneable, Serializable
serialVersionOnStream = 2;
}
+
+ /**
+ * Returns a {@link DecimalFormatSymbols} instance for the
+ * default locale obtained from either the runtime itself
+ * or one of the installed
+ * {@link java.text.spi.DecimalFormatSymbolsProvider} instances.
+ * This is equivalent to calling
+ * <code>getInstance(Locale.getDefault())</code>.
+ *
+ * @return a {@link DecimalFormatSymbols} instance for the default
+ * locale.
+ * @since 1.6
+ */
+ public static final DecimalFormatSymbols getInstance()
+ {
+ return getInstance(Locale.getDefault());
+ }
+
+ /**
+ * Returns a {@link DecimalFormatSymbols} instance for the
+ * specified locale obtained from either the runtime itself
+ * or one of the installed
+ * {@link java.text.spi.DecimalFormatSymbolsProvider} instances.
+ *
+ * @param locale the locale for which an instance should be
+ * returned.
+ * @return a {@link DecimalFormatSymbols} instance for the specified
+ * locale.
+ * @throws NullPointerException if <code>locale</code> is
+ * <code>null</code>.
+ * @since 1.6
+ */
+ public static final DecimalFormatSymbols getInstance(Locale locale)
+ {
+ try
+ {
+ if (!locale.equals(Locale.ROOT))
+ ResourceBundle.getBundle("gnu.java.locale.LocaleInformation",
+ locale,
+ ClassLoader.getSystemClassLoader());
+ return new DecimalFormatSymbols(locale);
+ }
+ catch (MissingResourceException x)
+ {
+ /* This means runtime support for the locale
+ * is not available, so we check providers. */
+ }
+ for (DecimalFormatSymbolsProvider p :
+ ServiceLoader.load(DecimalFormatSymbolsProvider.class))
+ {
+ for (Locale loc : p.getAvailableLocales())
+ {
+ if (loc.equals(locale))
+ {
+ DecimalFormatSymbols syms = p.getInstance(locale);
+ if (syms != null)
+ return syms;
+ break;
+ }
+ }
+ }
+ return getInstance(LocaleHelper.getFallbackLocale(locale));
+ }
+
}
OpenPOWER on IntegriCloud