Пример #1
0
        /// <summary>
        /// Creates a DateFormat with the given time and/or date style in the given
        /// locale. </summary>
        /// <param name="timeStyle"> a value from 0 to 3 indicating the time format,
        /// ignored if flags is 2 </param>
        /// <param name="dateStyle"> a value from 0 to 3 indicating the time format,
        /// ignored if flags is 1 </param>
        /// <param name="flags"> either 1 for a time format, 2 for a date format,
        /// or 3 for a date/time format </param>
        /// <param name="loc"> the locale for the format </param>
        private static DateFormat Get(int timeStyle, int dateStyle, int flags, Locale loc)
        {
            if ((flags & 1) != 0)
            {
                if (timeStyle < 0 || timeStyle > 3)
                {
                    throw new IllegalArgumentException("Illegal time style " + timeStyle);
                }
            }
            else
            {
                timeStyle = -1;
            }
            if ((flags & 2) != 0)
            {
                if (dateStyle < 0 || dateStyle > 3)
                {
                    throw new IllegalArgumentException("Illegal date style " + dateStyle);
                }
            }
            else
            {
                dateStyle = -1;
            }

            LocaleProviderAdapter adapter    = LocaleProviderAdapter.getAdapter(typeof(DateFormatProvider), loc);
            DateFormat            dateFormat = Get(adapter, timeStyle, dateStyle, loc);

            if (dateFormat == null)
            {
                dateFormat = Get(LocaleProviderAdapter.forJRE(), timeStyle, dateStyle, loc);
            }
            return(dateFormat);
        }
Пример #2
0
        private static DateFormatSymbols GetProviderInstance(Locale locale)
        {
            LocaleProviderAdapter     adapter  = LocaleProviderAdapter.getAdapter(typeof(DateFormatSymbolsProvider), locale);
            DateFormatSymbolsProvider provider = adapter.DateFormatSymbolsProvider;
            DateFormatSymbols         dfsyms   = provider.GetInstance(locale);

            if (dfsyms == null)
            {
                provider = LocaleProviderAdapter.forJRE().DateFormatSymbolsProvider;
                dfsyms   = provider.GetInstance(locale);
            }
            return(dfsyms);
        }
Пример #3
0
        /// <summary>
        /// Gets the <code>DecimalFormatSymbols</code> instance for the specified
        /// locale.  This method provides access to <code>DecimalFormatSymbols</code>
        /// instances for locales supported by the Java runtime itself as well
        /// as for those supported by installed
        /// {@link java.text.spi.DecimalFormatSymbolsProvider
        /// DecimalFormatSymbolsProvider} implementations.
        /// If the specified locale contains the <seealso cref="java.util.Locale#UNICODE_LOCALE_EXTENSION"/>
        /// for the numbering system, the instance is initialized with the specified numbering
        /// system if the JRE implementation supports it. For example,
        /// <pre>
        /// NumberFormat.getNumberInstance(Locale.forLanguageTag("th-TH-u-nu-thai"))
        /// </pre>
        /// This may return a {@code NumberFormat} instance with the Thai numbering system,
        /// instead of the Latin numbering system.
        /// </summary>
        /// <param name="locale"> the desired locale. </param>
        /// <returns> a <code>DecimalFormatSymbols</code> instance. </returns>
        /// <exception cref="NullPointerException"> if <code>locale</code> is null
        /// @since 1.6 </exception>
        public static DecimalFormatSymbols GetInstance(Locale locale)
        {
            LocaleProviderAdapter adapter;

            adapter = LocaleProviderAdapter.getAdapter(typeof(DecimalFormatSymbolsProvider), locale);
            DecimalFormatSymbolsProvider provider = adapter.DecimalFormatSymbolsProvider;
            DecimalFormatSymbols         dfsyms   = provider.GetInstance(locale);

            if (dfsyms == null)
            {
                provider = LocaleProviderAdapter.forJRE().DecimalFormatSymbolsProvider;
                dfsyms   = provider.GetInstance(locale);
            }
            return(dfsyms);
        }
Пример #4
0
        /// <summary>
        /// Gets the Collator for the desired locale. </summary>
        /// <param name="desiredLocale"> the desired locale. </param>
        /// <returns> the Collator for the desired locale. </returns>
        /// <seealso cref= java.util.Locale </seealso>
        /// <seealso cref= java.util.ResourceBundle </seealso>
        public static Collator GetInstance(Locale desiredLocale)
        {
            SoftReference <Collator> @ref = Cache[desiredLocale];
            Collator result = (@ref != null) ? @ref.get() : null;

            if (result == null)
            {
                LocaleProviderAdapter adapter;
                adapter = LocaleProviderAdapter.getAdapter(typeof(CollatorProvider), desiredLocale);
                CollatorProvider provider = adapter.CollatorProvider;
                result = provider.GetInstance(desiredLocale);
                if (result == null)
                {
                    result = LocaleProviderAdapter.forJRE().CollatorProvider.getInstance(desiredLocale);
                }
                while (true)
                {
                    if (@ref != null)
                    {
                        // Remove the empty SoftReference if any
                        Cache.Remove(desiredLocale, @ref);
                    }
                    @ref = Cache.PutIfAbsent(desiredLocale, new SoftReference <>(result));
                    if (@ref == null)
                    {
                        break;
                    }
                    Collator cachedColl = @ref.get();
                    if (cachedColl != null)
                    {
                        result = cachedColl;
                        break;
                    }
                }
            }
            return((Collator)result.Clone());             // make the world safe
        }