下面列出了java.text.NumberFormat#getAvailableLocales ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Provides a list of example formats for the <code>Decimal</code> data type.
*
* @return
*/
private static List<String> listDecimalFormats(){
List<String> result = new ArrayList<String>();
result.add("0.###");
result.add("0.00");
result.add("#,##0.###");
result.add("#,##0.00");
result.add("#,##0");
result.add("#,##0%");
// Create list of common patterns
Set<String> set = new HashSet<String>();
set.addAll(result);
for (Locale locale: NumberFormat.getAvailableLocales()) {
for (NumberFormat format : new NumberFormat[] { NumberFormat.getNumberInstance(locale),
NumberFormat.getIntegerInstance(locale),
NumberFormat.getCurrencyInstance(locale),
NumberFormat.getPercentInstance(locale) }) {
// Add pattern
if (format instanceof DecimalFormat) {
String pattern = ((DecimalFormat)format).toPattern();
if (!set.contains(pattern)) {
set.add(pattern);
result.add(pattern);
}
}
}
}
return result;
}
/**
* Test the built in number formats.
*/
@Test
public void testBuiltInNumberFormat() {
final Object[] args = new Object[] {Double.valueOf("6543.21")};
final Locale[] availableLocales = NumberFormat.getAvailableLocales();
checkBuiltInFormat("1: {0,number}", args, availableLocales);
checkBuiltInFormat("2: {0,number,integer}", args, availableLocales);
checkBuiltInFormat("3: {0,number,currency}", args, availableLocales);
checkBuiltInFormat("4: {0,number,percent}", args, availableLocales);
checkBuiltInFormat("5: {0,number,00000.000}", args, availableLocales);
}
/**
* Return an array of all locales for which the getInstance() method of this class can
* return localized instances. See {@link NumberFormat#getAvailableLocales()}
*/
public static Locale[] getAvailableLocales() {
return NumberFormat.getAvailableLocales();
}
/**
* Get the set of locales for which complex formats are available.
* <p>This is the same set as the {@link NumberFormat} set.</p>
* @return available complex format locales.
*/
public static Locale[] getAvailableLocales() {
return NumberFormat.getAvailableLocales();
}
/**
* Get the set of locales for which 3D vectors formats are available.
* <p>This is the same set as the {@link NumberFormat} set.</p>
* @return available 3D vector format locales.
*/
public static Locale[] getAvailableLocales() {
return NumberFormat.getAvailableLocales();
}
/**
* Get the set of locales for which real vectors formats are available.
* <p>This is the same set as the {@link NumberFormat} set.</p>
* @return available real vector format locales.
*/
public static Locale[] getAvailableLocales() {
return NumberFormat.getAvailableLocales();
}
/**
* Get the set of locales for which complex formats are available. This
* is the same set as the {@link NumberFormat} set.
* @return available complex format locales.
*/
public static Locale[] getAvailableLocales() {
return NumberFormat.getAvailableLocales();
}
/**
* Get the set of locales for which 3D vectors formats are available.
* <p>This is the same set as the {@link NumberFormat} set.</p>
* @return available 3D vector format locales.
*/
public static Locale[] getAvailableLocales() {
return NumberFormat.getAvailableLocales();
}
/**
* Get the set of locales for which complex formats are available. This
* is the same set as the {@link NumberFormat} set.
* @return available complex format locales.
*/
public static Locale[] getAvailableLocales() {
return NumberFormat.getAvailableLocales();
}
/**
* Get the set of locales for which real vectors formats are available.
* <p>This is the same set as the {@link NumberFormat} set.</p>
* @return available real vector format locales.
*/
public static Locale[] getAvailableLocales() {
return NumberFormat.getAvailableLocales();
}
/**
* Get the set of locales for which complex formats are available.
* <p>This is the same set as the {@link NumberFormat} set.</p>
* @return available complex format locales.
*/
public static Locale[] getAvailableLocales() {
return NumberFormat.getAvailableLocales();
}
/**
* Get the set of locales for which complex formats are available. This
* is the same set as the {@link NumberFormat} set.
* @return available complex format locales.
*/
public static Locale[] getAvailableLocales() {
return NumberFormat.getAvailableLocales();
}
/**
* Get the set of locales for which complex formats are available. This
* is the same set as the {@link NumberFormat} set.
* @return available complex format locales.
*/
public static Locale[] getAvailableLocales() {
return NumberFormat.getAvailableLocales();
}
/**
* Get the set of locales for which complex formats are available. This
* is the same set as the {@link NumberFormat} set.
* @return available complex format locales.
*/
public static Locale[] getAvailableLocales() {
return NumberFormat.getAvailableLocales();
}
/**
* Get the set of locales for which complex formats are available. This
* is the same set as the {@link NumberFormat} set.
* @return available complex format locales.
*/
public static Locale[] getAvailableLocales() {
return NumberFormat.getAvailableLocales();
}
/**
* Get the set of locales for which real vectors formats are available.
* <p>This is the same set as the {@link NumberFormat} set.</p>
* @return available real vector format locales.
*/
public static Locale[] getAvailableLocales() {
return NumberFormat.getAvailableLocales();
}
/**
* Get the set of locales for which point/vector formats are available.
* <p>This is the same set as the {@link NumberFormat} set.</p>
* @return available point/vector format locales.
*/
public static Locale[] getAvailableLocales() {
return NumberFormat.getAvailableLocales();
}
/**
* Get the set of locales for which real vectors formats are available.
* <p>This is the same set as the {@link NumberFormat} set.</p>
* @return available real vector format locales.
*/
public static Locale[] getAvailableLocales() {
return NumberFormat.getAvailableLocales();
}
/**
* Get the set of locales for which point/vector formats are available.
* <p>This is the same set as the {@link NumberFormat} set.</p>
* @return available point/vector format locales.
*/
public static Locale[] getAvailableLocales() {
return NumberFormat.getAvailableLocales();
}
/**
* Get the set of locales for which complex formats are available.
* <p>This is the same set as the {@link NumberFormat} set.</p>
* @return available complex format locales.
*/
public static Locale[] getAvailableLocales() {
return NumberFormat.getAvailableLocales();
}