Class SignedPrinterParser

java.lang.Object
org.joda.money.format.SignedPrinterParser
All Implemented Interfaces:
Serializable, MoneyParser, MoneyPrinter

final class SignedPrinterParser extends Object implements MoneyPrinter, MoneyParser, Serializable
Prints and parses using delegated formatters, one for positive and one for megative.

This class is immutable and thread-safe.

  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      Serialization version.
      See Also:
    • whenPositive

      private final MoneyFormatter whenPositive
      The formatter to use when positive.
    • whenZero

      private final MoneyFormatter whenZero
      The formatter to use when zero.
    • whenNegative

      private final MoneyFormatter whenNegative
      The formatter to use when negative.
  • Constructor Details

    • SignedPrinterParser

      SignedPrinterParser(MoneyFormatter whenPositive, MoneyFormatter whenZero, MoneyFormatter whenNegative)
      Constructor.
      Parameters:
      whenPositive - the formatter to use when the amount is positive
      whenZero - the formatter to use when the amount is zero
      whenNegative - the formatter to use when the amount is positive
  • Method Details

    • print

      public void print(MoneyPrintContext context, Appendable appendable, BigMoney money) throws IOException
      Description copied from interface: MoneyPrinter
      Prints part of a monetary value to the output appendable.

      The implementation determines what to append, which may be some or all of the data held in the BigMoney.

      The context is not a thread-safe object and a new instance will be created for each print. The context must not be stored in an instance variable or shared with any other threads.

      Specified by:
      print in interface MoneyPrinter
      Parameters:
      context - the context being used, not null
      appendable - the appendable to add to, not null
      money - the money to print, not null
      Throws:
      IOException - if an IO exception occurs
    • parse

      public void parse(MoneyParseContext context)
      Description copied from interface: MoneyParser
      Parses monetary information using a textual representation.

      The text and parse index are stored in the context. The parsed data and updated index is also stored in the context.

      Implementations should avoid throwing exceptions and use the error index in the context instead to record the problem. The context can be assumed to not be in error on entry to this method.

      The context is not a thread-safe object and a new instance will be created for each parse. The context must not be stored in an instance variable or shared with any other threads.

      Specified by:
      parse in interface MoneyParser
      Parameters:
      context - the context to use and parse into, not null
    • toString

      public String toString()
      Overrides:
      toString in class Object