Parsing numbers safely and locale

Java's NumberFormat is 1) non thread-safe (which can be worked around with a ThreadLocal ); 2) inconvenient to use correctly for the simplest use case when I know whether the string should contain int, long, or double, and want an API like:

int parseInt(String str, Locale locale) throws ParseException; 
int parseInt(String str, int defaultValue, Locale locale);
long parseLong(String str, Locale locale) throws ParseException;
long parseLong(String str, long defaultValue, Locale locale);
double parseDouble(String str, Locale locale) throws ParseException;
double parseDouble(String str, double defaultValue, Locale locale);

where the exception is thrown when the string isn't completely parsed. Obviously, such a wrapper is easy to write, but I couldn't find one in Guava or Apache Commons Lang. Did I just miss it? Or is there another more-or-less standard solution for this?


我找到的一个选项是Apache Commons Validator(仍然不是线程安全的)。

链接地址: http://www.djcxy.com/p/11004.html

上一篇: 为什么.PHONY:目标而不是目标:.PHONY?

下一篇: 安全解析数字和语言环境