jsr354-api
jsr354-api copied to clipboard
Code in class comments of MonetaryAmountFormat does not compile
The class comment of MonetaryAmountFormat has two code snippets. Both of them are full of compile errors
MonetaryAmountFormat f = MonetaryFormats.getInstance(loc);
f.setStyle(f.getStyle().toBuilder().setPattern("###.##;(###.##)").build());
- there are no
#setStyleand#getStylemethods - there is no
#getInstancemethod onMonetaryFormats, you probably mean#getAmountFormat
Locale[] locales = MonetaryFormats.getAvailableLocales();
MonetaryAmount amount = ...;
MonetaryAmountFormat form;
System.out.println("FORMAT");
for (int i = 0; i < locales.length; ++i) {
if (locales[i].getCountry().length() == 0) {
continue; // Skip language-only locales
}
System.out.print(locales[i].getDisplayName());
form = MonetaryFormats.getInstance(locales[i]);
System.out.print(": " + form.getStyle().getPattern());
String myAmount = form.format(amount);
System.out.print(" -> " + myAmount);
try {
System.out.println(" -> " + form.parse(form.format(myAmount)));
} catch (ParseException e) {}
}
}
- there is no
MonetaryFormats#getAvailableLocales(), you could useLocale#getAvailableLocales()but then you should probably also checkMonetaryFormats#isAvailable - while no a compile error an enhanced for loop over the locales would be nice
- again there is no
#getStylemethod - there is no
#getInstancemethod onMonetaryFormats #parsedoes not throwParseExceptionbutMonetaryParseException- the last } is too much
I ran into this as well, the documentation clearly shows an expectation of a MonetaryFormat.getInstance but it's not supported.
https://javamoney.github.io/apidocs/javax/money/format/MonetaryAmountFormat.html#print-java.lang.Appendable-javax.money.MonetaryAmount-