Skip to content

Code in class comments of MonetaryAmountFormat does not compile #115

Open
@marschall

Description

@marschall

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions