private Object readResolve() throws ObjectStreamException { // The old isoCode field used to determine the currency. return Currency.getInstance(isoCode); } }
@Override public void setCurrency(Currency currency) { com.ibm.icu.util.Currency icuCurrency = null; if (currency != null) { icuCurrency = com.ibm.icu.util.Currency.getInstance(currency.getCurrencyCode()); } fIcuDecfs.setCurrency(icuCurrency); }
@Override public Currency getCurrency() { java.util.Currency jdkCurrency = fJdkNfmt.getCurrency(); if (jdkCurrency == null) { return null; } return Currency.getInstance(jdkCurrency.getCurrencyCode()); }
/** * Returns a currency object for the default currency in the given * locale. * @param locale the locale * @return the currency object for this locale * @stable ICU 2.2 */ public static Currency getInstance(Locale locale) { return getInstance(ULocale.forLocale(locale)); }
@Override public void setCurrency(Currency currency) { if (currency == null) { fIcuDecfmt.setCurrency(null); } else { fIcuDecfmt.setCurrency(com.ibm.icu.util.Currency.getInstance(currency.getCurrencyCode())); } }
@Override public void setCurrency(Currency currency) { if (currency == null) { fIcuNfmt.setCurrency(null); } else { fIcuNfmt.setCurrency(com.ibm.icu.util.Currency.getInstance(currency.getCurrencyCode())); } }
private static Currency loadCurrency(String key) { String region; boolean isPreEuro; if (key.endsWith("-")) { region = key.substring(0, key.length() - 1); isPreEuro = true; } else { region = key; isPreEuro = false; } CurrencyMetaInfo info = CurrencyMetaInfo.getInstance(); List<String> list = info.currencies(CurrencyFilter.onRegion(region)); if (!list.isEmpty()) { String code = list.get(0); if (isPreEuro && EUR_STR.equals(code)) { if (list.size() < 2) { return null; } code = list.get(1); } return getInstance(code); } return null; }
/** * This function can be overridden by subclasses to use different heuristics * * @draft ICU 3.6 * @provisional This API might change or be removed in a future release. */ protected Currency guessCurrency() { return Currency.getInstance(new ULocale("und-" + getTerritory())); }
/** * Returns the currency in effect for this formatter. Subclasses should override this * method as needed. Unlike getCurrency(), this method should never return null. * * @internal * @deprecated This API is ICU internal only. */ @Deprecated @Override protected Currency getEffectiveCurrency() { Currency c = getCurrency(); if (c == null) { c = Currency.getInstance(symbols.getInternationalCurrencySymbol()); } return c; }
@Override public Number parseCurrencyAmount(String locale, String value, String currencyCode) throws ParseException { ULocale closestLocale = localeService.getClosestULocale(locale); Currency currency; if (StringUtils.isEmpty(currencyCode)) { currency = Currency.getInstance(new ULocale(locale)); } else { currency = Currency.getInstance(currencyCode); } NumberFormat nf = NumberFormat.getCurrencyInstance(closestLocale); nf.setCurrency(currency); return nf.parse(value); }
@Override public Number parseCurrencyAmount(String locale, String value, String currencyCode) throws ParseException { ULocale closestLocale = findClosestULocale(locale); Currency currency; if (StringUtils.isEmpty(currencyCode)) { currency = Currency.getInstance(new ULocale(locale)); } else { currency = Currency.getInstance(currencyCode); } NumberFormat nf = NumberFormat.getCurrencyInstance(closestLocale); nf.setCurrency(currency); return nf.parse(value); }
/** * Instantiate a currency from resource data. */ /* package */ static Currency createCurrency(ULocale loc) { String variant = loc.getVariant(); if ("EURO".equals(variant)) { return getInstance(EUR_STR); } // Cache the currency by region, and whether variant=PREEURO. // Minimizes the size of the cache compared with caching by ULocale. String key = ULocale.getRegionForSupplementalData(loc, false); if ("PREEURO".equals(variant)) { key = key + '-'; } return regionCurrencyCache.getInstance(key, null); }
/** * Returns the set of available currencies. The returned set of currencies contains all of the * available currencies, including obsolete ones. The result set can be modified without * affecting the available currencies in the runtime. * * @return The set of available currencies. The returned set could be empty if there is no * currency data available. * * @stable ICU 49 */ public static Set<Currency> getAvailableCurrencies() { CurrencyMetaInfo info = CurrencyMetaInfo.getInstance(); List<String> list = info.currencies(CurrencyFilter.all()); HashSet<Currency> resultSet = new HashSet<Currency>(list.size()); for (String code : list) { resultSet.add(getInstance(code)); } return resultSet; }
@Override public String formatCurrencyAmount(String locale, Number amount, String currencyCode) { ULocale closestLocale = findClosestULocale(locale); Currency currency; if (StringUtils.isEmpty(currencyCode)) { currency = Currency.getInstance(new ULocale(locale)); } else { currency = Currency.getInstance(currencyCode); } CurrencyAmount ca = new CurrencyAmount(amount, currency); NumberFormat nf = NumberFormat.getCurrencyInstance(closestLocale); nf.setCurrency(currency); return nf.format(ca); }
@Override public String formatCurrencyAmount(String locale, Number amount, String currencyCode) { ULocale closestLocale = localeService.getClosestULocale(locale); Currency currency; if (StringUtils.isEmpty(currencyCode)) { currency = Currency.getInstance(new ULocale(locale)); } else { currency = Currency.getInstance(currencyCode); } CurrencyAmount ca = new CurrencyAmount(amount, currency); NumberFormat nf = NumberFormat.getCurrencyInstance(closestLocale); nf.setCurrency(currency); return nf.format(ca); }
/** * Returns the currency in effect for this formatter. Subclasses * should override this method as needed. Unlike getCurrency(), * this method should never return null. * @return a non-null Currency * @internal * @deprecated This API is ICU internal only. */ @Deprecated protected Currency getEffectiveCurrency() { Currency c = getCurrency(); if (c == null) { ULocale uloc = getLocale(ULocale.VALID_LOCALE); if (uloc == null) { uloc = ULocale.getDefault(Category.FORMAT); } c = Currency.getInstance(uloc); } return c; }
/** * Returns a currency object for the default currency in the given * locale. * @stable ICU 3.2 */ public static Currency getInstance(ULocale locale) { String currency = locale.getKeywordValue("currency"); if (currency != null) { return getInstance(currency); } if (shim == null) { return createCurrency(locale); } return shim.createInstance(locale); }
NumberFormat createInstance(ULocale desiredLocale, int choice) { // use service cache // if (service.isDefault()) { // return NumberFormat.createInstance(desiredLocale, choice); // } ULocale[] actualLoc = new ULocale[1]; NumberFormat fmt = (NumberFormat)service.get(desiredLocale, choice, actualLoc); if (fmt == null) { throw new MissingResourceException("Unable to construct NumberFormat", "", ""); } fmt = (NumberFormat)fmt.clone(); // If we are creating a currency type formatter, then we may have to set the currency // explicitly, since the actualLoc may be different than the desiredLocale if ( choice == NumberFormat.CURRENCYSTYLE || choice == NumberFormat.ISOCURRENCYSTYLE || choice == NumberFormat.PLURALCURRENCYSTYLE) { fmt.setCurrency(Currency.getInstance(desiredLocale)); } ULocale uloc = actualLoc[0]; fmt.setLocale(uloc, uloc); // services make no distinction between actual & valid return fmt; }
/** Formats a double into a properly formatted currency string based on isoCode and Locale * @param price The price double to be formatted * @param isoCode the currency ISO code * @param locale The Locale used to format the number * @param maximumFractionDigits The maximum number of fraction digits used; if set to -1 than the default value for the locale is used * @return A String with the formatted price */ public static String formatCurrency(double price, String isoCode, Locale locale, int maximumFractionDigits) { com.ibm.icu.text.NumberFormat nf = com.ibm.icu.text.NumberFormat.getCurrencyInstance(locale); if (isoCode != null && isoCode.length() > 1) { nf.setCurrency(com.ibm.icu.util.Currency.getInstance(isoCode)); } else { if (Debug.verboseOn()) { Debug.logVerbose("No isoCode specified to format currency value:" + price, module); } } if (maximumFractionDigits >= 0) { nf.setMaximumFractionDigits(maximumFractionDigits); } return nf.format(price); }
/** * Update the currency object to match the symbols. This method is used only when the * caller has passed in a symbols object that may not be the default object for its * locale. */ private void setCurrencyForSymbols() { // Bug 4212072 Update the affix strings according to symbols in order to keep the // affix strings up to date. [Richard/GCL] // With the introduction of the Currency object, the currency symbols in the DFS // object are ignored. For backward compatibility, we check any explicitly set DFS // object. If it is a default symbols object for its locale, we change the // currency object to one for that locale. If it is custom, we set the currency to // null. DecimalFormatSymbols def = new DecimalFormatSymbols(symbols.getULocale()); if (symbols.getCurrencySymbol().equals(def.getCurrencySymbol()) && symbols.getInternationalCurrencySymbol() .equals(def.getInternationalCurrencySymbol())) { setCurrency(Currency.getInstance(symbols.getULocale())); } else { setCurrency(null); } }