Here you can find the source of getNumberFormatFromCache(Locale locale, Currency currency)
Parameter | Description |
---|---|
locale | the Locale |
currency | the Currency |
public static NumberFormat getNumberFormatFromCache(Locale locale, Currency currency)
//package com.java2s; /*//from ww w . j av a2 s . co m * #%L * BroadleafCommerce Common Libraries * %% * Copyright (C) 2009 - 2013 Broadleaf Commerce * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * #L% */ import java.text.NumberFormat; import java.util.Currency; import java.util.Locale; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; public class Main { protected static final Map<String, NumberFormat> FORMAT_CACHE = new ConcurrentHashMap<String, NumberFormat>(); /** * Provides a cached approach for creating NumberFormat instances. More performant * than creating a new one each time. * * @param locale the Locale * @param currency the Currency * @return either a new NumberFormat instance, or one taken from the cache */ public static NumberFormat getNumberFormatFromCache(Locale locale, Currency currency) { String key = locale.toString() + currency.getCurrencyCode(); if (!FORMAT_CACHE.containsKey(key)) { NumberFormat format = NumberFormat.getCurrencyInstance(locale); format.setCurrency(currency); FORMAT_CACHE.put(key, format); } return FORMAT_CACHE.get(key); } }