Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code in class comments of MonetaryAmountFormat does not compile #115

Open
marschall opened this issue Jan 6, 2019 · 1 comment
Open

Comments

@marschall
Copy link
Member

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 #setStyle and #getStyle methods
  • there is no #getInstance method on MonetaryFormats, 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 use Locale#getAvailableLocales() but then you should probably also check MonetaryFormats#isAvailable
  • while no a compile error an enhanced for loop over the locales would be nice
  • again there is no #getStyle method
  • there is no #getInstance method on MonetaryFormats
  • #parse does not throw ParseException but MonetaryParseException
  • the last } is too much
@keilw keilw added the analysis label Jan 6, 2019
@retinaburn
Copy link

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-

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants