com.jamonapi.utils
Class LocaleContext
java.lang.Object
com.jamonapi.utils.LocaleContext
public final class LocaleContext
- extends java.lang.Object
Provides a context for localized parameters, mainly formatters, in thread local scope.
Note normally the Formatting classes are not thread safe.
This class uses ThreadLocal to return a unique object to each thread, so the getFloatingPointFormatter
returns the same object in one thread, and getIntegerFormatter returns another one in the same thread.
By using only LocaleContext to get Format objects instead of constructing Format objects
otherwise, thread-safety is ensured. This class is tuned for performance: constructing a Format
object is rather expensive, this class only creates them when really needed.
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
getFloatingPointFormatter
public static java.text.DecimalFormat getFloatingPointFormatter()
- Returns:
- the thread local storage for the fixed-point number formatting specific for the locale
getIntegerFormatter
public static java.text.DecimalFormat getIntegerFormatter()
- Returns:
- the thread local storage for the integral number formatting specific for the locale
getPercentFormatter
public static java.text.DecimalFormat getPercentFormatter()
- Returns:
- the thread local storage for the percent number formatting specific for the locale
getCurrencyFormatter
public static java.text.DecimalFormat getCurrencyFormatter()
- Returns:
- the thread local storage for the currency formatting specific for the locale
getDecimalGroupSeparator
public static char getDecimalGroupSeparator()
- Returns:
- the thread local storage for the number formatting decimal grouping separator
specific for the locale
getDateFormatter
public static java.text.DateFormat getDateFormatter()
- Returns:
- the locale specific date time formatter
setLocale
public static void setLocale(java.util.Locale locale)
- Sets the locale to apply for formatting.
- Parameters:
locale
- the locale to apply for formatting.