org.springframework.format.number.money

Class MonetaryAmountFormatter

  • java.lang.Object
    • org.springframework.format.number.money.MonetaryAmountFormatter
  • All Implemented Interfaces:
    Formatter<javax.money.MonetaryAmount>, Parser<javax.money.MonetaryAmount>, Printer<javax.money.MonetaryAmount>


    public class MonetaryAmountFormatter
    extends java.lang.Object
    implements Formatter<javax.money.MonetaryAmount>
    Formatter for JSR-354 MonetaryAmount values, delegating to MonetaryAmountFormat.format(javax.money.MonetaryAmount) and MonetaryAmountFormat.parse(java.lang.CharSequence).
    Since:
    4.2
    Author:
    Juergen Hoeller
    See Also:
    getMonetaryAmountFormat(java.util.Locale)
    • Constructor Summary

      Constructors 
      Constructor and Description
      MonetaryAmountFormatter()
      Create a locale-driven MonetaryAmountFormatter.
      MonetaryAmountFormatter(java.lang.String formatName)
      Create a new MonetaryAmountFormatter for the given format name.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      protected javax.money.format.MonetaryAmountFormat getMonetaryAmountFormat(java.util.Locale locale)
      Obtain a MonetaryAmountFormat for the given locale.
      javax.money.MonetaryAmount parse(java.lang.String text, java.util.Locale locale)
      Parse a text String to produce a T.
      java.lang.String print(javax.money.MonetaryAmount object, java.util.Locale locale)
      Print the object of type T for display.
      void setFormatName(java.lang.String formatName)
      Specify the format name, to be resolved by the JSR-354 provider at runtime.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MonetaryAmountFormatter

        public MonetaryAmountFormatter()
        Create a locale-driven MonetaryAmountFormatter.
      • MonetaryAmountFormatter

        public MonetaryAmountFormatter(java.lang.String formatName)
        Create a new MonetaryAmountFormatter for the given format name.
        Parameters:
        formatName - the format name, to be resolved by the JSR-354 provider at runtime
    • Method Detail

      • setFormatName

        public void setFormatName(java.lang.String formatName)
        Specify the format name, to be resolved by the JSR-354 provider at runtime.

        Default is none, obtaining a MonetaryAmountFormat based on the current locale.

      • print

        public java.lang.String print(javax.money.MonetaryAmount object,
                                      java.util.Locale locale)
        Description copied from interface: Printer
        Print the object of type T for display.
        Specified by:
        print in interface Printer<javax.money.MonetaryAmount>
        Parameters:
        object - the instance to print
        locale - the current user locale
        Returns:
        the printed text string
      • parse

        public javax.money.MonetaryAmount parse(java.lang.String text,
                                                java.util.Locale locale)
        Description copied from interface: Parser
        Parse a text String to produce a T.
        Specified by:
        parse in interface Parser<javax.money.MonetaryAmount>
        Parameters:
        text - the text string
        locale - the current user locale
        Returns:
        an instance of T
      • getMonetaryAmountFormat

        protected javax.money.format.MonetaryAmountFormat getMonetaryAmountFormat(java.util.Locale locale)
        Obtain a MonetaryAmountFormat for the given locale.

        The default implementation simply calls MonetaryFormats.getAmountFormat(java.util.Locale, java.lang.String...) with either the configured format name or the given locale.

        Parameters:
        locale - the current locale
        Returns:
        the MonetaryAmountFormat (never null)
        See Also:
        setFormatName(java.lang.String)