Top Description Inners Fields Constructors Methods
org.joda.money.format

public final Class MoneyFormatterBuilder

extends Object
Class Inheritance
Imports
java.io.IOException, java.util.ArrayList, .List, .Locale, org.joda.money.BigMoney, .CurrencyUnit, .IllegalCurrencyException

Provides the ability to build a formatter for monetary values.

This class is mutable and intended for use by a single thread. A new instance should be created for each use. The formatters produced by the builder are immutable and thread-safe.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static enum
MoneyFormatterBuilder.SingletonPrinters

Handles the singleton outputs.

private static enum
MoneyFormatterBuilder.Singletons

Handles the singleton outputs.

Field Summary

Modifier and TypeField and Description
private final List<MoneyParser>
parsers

The parsers.

private final List<MoneyPrinter>
printers

The printers.

Constructor Summary

AccessConstructor and Description
public
MoneyFormatterBuilder()

Constructor, creating a new empty builder.

Method Summary

Modifier and TypeMethod and Description
public MoneyFormatterBuilder

Returns:

this for chaining, never null
append
(MoneyFormatter
the formatter to append, not null
formatter
)

Appends the printers and parsers from the specified formatter to this builder.

public MoneyFormatterBuilder

Returns:

this for chaining, never null
append
(MoneyPrinter
the printer to append, null makes the formatter unable to print
printer
,
MoneyParser
the parser to append, null makes the formatter unable to parse
parser
)

Appends the specified printer and parser to this builder.

public MoneyFormatterBuilder

Returns:

this, for chaining, never null
appendAmount
()

Appends the amount to the builder using a standard format.

public MoneyFormatterBuilder

Returns:

this, for chaining, never null
appendAmount
(MoneyAmountStyle
the style to use, not null
style
)

Appends the amount to the builder using the specified amount style.

public MoneyFormatterBuilder

Returns:

this, for chaining, never null
appendAmountLocalized
()

Appends the amount to the builder using a grouped localized format.

public MoneyFormatterBuilder

Returns:

this, for chaining, never null
appendCurrencyCode
()

Appends the currency code to the builder.

public MoneyFormatterBuilder

Returns:

this, for chaining, never null
appendCurrencyNumeric3Code
()

Appends the currency code to the builder.

public MoneyFormatterBuilder

Returns:

this, for chaining, never null
appendCurrencyNumericCode
()

Appends the currency code to the builder.

public MoneyFormatterBuilder

Returns:

this, for chaining, never null
appendCurrencySymbolLocalized
()

Appends the localized currency symbol to the builder.

private MoneyFormatterBuilder

Returns:

this for chaining, never null
appendInternal
(MoneyPrinter
the printer to append, null makes the formatter unable to print
printer
,
MoneyParser
the parser to append, null makes the formatter unable to parse
parser
)

Appends the specified printer and parser to this builder.

public MoneyFormatterBuilder

Returns:

this, for chaining, never null
appendLiteral
(CharSequence
the literal to append, null or empty ignored
literal
)

Appends a literal to the builder.

public MoneyFormatterBuilder

Returns:

this for chaining, never null
appendSigned
(MoneyFormatter
the formatter to use when the amount is positive or zero
whenPositiveOrZero
,
MoneyFormatter
the formatter to use when the amount is negative
whenNegative
)

Appends the specified formatters, one used when the amount is positive, and one when the amount is negative.

public MoneyFormatterBuilder

Returns:

this for chaining, never null
appendSigned
(MoneyFormatter
the formatter to use when the amount is positive
whenPositive
,
MoneyFormatter
the formatter to use when the amount is zero
whenZero
,
MoneyFormatter
the formatter to use when the amount is negative
whenNegative
)

Appends the specified formatters, one used when the amount is positive, one when the amount is zero and one when the amount is negative.

public MoneyFormatter

Returns:

the formatter built from this builder, never null
toFormatter
()

Builds the formatter from the builder using the default locale.

public MoneyFormatter

Returns:

the formatter built from this builder, never null
toFormatter
(Locale
the initial locale for the formatter, not null
locale
)

Builds the formatter from the builder setting the locale.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

parsersback to summary
private final List<MoneyParser> parsers

The parsers.

printersback to summary
private final List<MoneyPrinter> printers

The printers.

Constructor Detail

MoneyFormatterBuilderback to summary
public MoneyFormatterBuilder()

Constructor, creating a new empty builder.

Method Detail

appendback to summary
public MoneyFormatterBuilder append(MoneyFormatter formatter)

Appends the printers and parsers from the specified formatter to this builder.

If the specified formatter cannot print, then the the output of this builder will be unable to print. If the specified formatter cannot parse, then the output of this builder will be unable to parse.

Parameters
formatter:MoneyFormatter

the formatter to append, not null

Returns:MoneyFormatterBuilder

this for chaining, never null

appendback to summary
public MoneyFormatterBuilder append(MoneyPrinter printer, MoneyParser parser)

Appends the specified printer and parser to this builder.

If null is specified then the formatter will be unable to print/parse.

Parameters
printer:MoneyPrinter

the printer to append, null makes the formatter unable to print

parser:MoneyParser

the parser to append, null makes the formatter unable to parse

Returns:MoneyFormatterBuilder

this for chaining, never null

appendAmountback to summary
public MoneyFormatterBuilder appendAmount()

Appends the amount to the builder using a standard format.

The format used is MoneyAmountStyle#ASCII_DECIMAL_POINT_GROUP3_COMMA. The amount is the value itself, such as '12.34'.

Returns:MoneyFormatterBuilder

this, for chaining, never null

appendAmountback to summary
public MoneyFormatterBuilder appendAmount(MoneyAmountStyle style)

Appends the amount to the builder using the specified amount style.

The amount is the value itself, such as '12.34'.

The amount style allows the formatting of the number to be controlled in detail. This includes the characters for positive, negative, decimal, grouping and whether to output the absolute or signed amount. See MoneyAmountStyle for more details.

Parameters
style:MoneyAmountStyle

the style to use, not null

Returns:MoneyFormatterBuilder

this, for chaining, never null

appendAmountLocalizedback to summary
public MoneyFormatterBuilder appendAmountLocalized()

Appends the amount to the builder using a grouped localized format.

The format used is MoneyAmountStyle#LOCALIZED_GROUPING. The amount is the value itself, such as '12.34'.

Returns:MoneyFormatterBuilder

this, for chaining, never null

appendCurrencyCodeback to summary
public MoneyFormatterBuilder appendCurrencyCode()

Appends the currency code to the builder.

The currency code is the three letter ISO code, such as 'GBP'.

Returns:MoneyFormatterBuilder

this, for chaining, never null

appendCurrencyNumeric3Codeback to summary
public MoneyFormatterBuilder appendCurrencyNumeric3Code()

Appends the currency code to the builder.

The numeric code is the ISO numeric code, such as '826' and is zero padded to three digits.

Returns:MoneyFormatterBuilder

this, for chaining, never null

appendCurrencyNumericCodeback to summary
public MoneyFormatterBuilder appendCurrencyNumericCode()

Appends the currency code to the builder.

The numeric code is the ISO numeric code, such as '826'.

Returns:MoneyFormatterBuilder

this, for chaining, never null

appendCurrencySymbolLocalizedback to summary
public MoneyFormatterBuilder appendCurrencySymbolLocalized()

Appends the localized currency symbol to the builder.

The localized currency symbol is the symbol as chosen by the locale of the formatter.

Symbols cannot be parsed.

Returns:MoneyFormatterBuilder

this, for chaining, never null

appendInternalback to summary
private MoneyFormatterBuilder appendInternal(MoneyPrinter printer, MoneyParser parser)

Appends the specified printer and parser to this builder.

Either the printer or parser must be non-null.

Parameters
printer:MoneyPrinter

the printer to append, null makes the formatter unable to print

parser:MoneyParser

the parser to append, null makes the formatter unable to parse

Returns:MoneyFormatterBuilder

this for chaining, never null

appendLiteralback to summary
public MoneyFormatterBuilder appendLiteral(CharSequence literal)

Appends a literal to the builder.

The localized currency symbol is the symbol as chosen by the locale of the formatter.

Parameters
literal:CharSequence

the literal to append, null or empty ignored

Returns:MoneyFormatterBuilder

this, for chaining, never null

appendSignedback to summary
public MoneyFormatterBuilder appendSigned(MoneyFormatter whenPositiveOrZero, MoneyFormatter whenNegative)

Appends the specified formatters, one used when the amount is positive, and one when the amount is negative.

When printing, the amount is queried and the appropriate formatter is used.

When parsing, each formatter is tried, with the longest successful match, or the first match if multiple are successful. If the negative parser is matched, the amount returned will be negative no matter what amount is parsed.

A typical use case for this would be to produce a format like '($123)' for negative amounts and '$123' for positive amounts.

In order to use this method, it may be necessary to output an unsigned amount. This can be achieved using appendAmount(MoneyAmountStyle) and MoneyAmountStyle#withAbsValue(boolean).

Parameters
whenPositiveOrZero:MoneyFormatter

the formatter to use when the amount is positive or zero

whenNegative:MoneyFormatter

the formatter to use when the amount is negative

Returns:MoneyFormatterBuilder

this for chaining, never null

appendSignedback to summary
public MoneyFormatterBuilder appendSigned(MoneyFormatter whenPositive, MoneyFormatter whenZero, MoneyFormatter whenNegative)

Appends the specified formatters, one used when the amount is positive, one when the amount is zero and one when the amount is negative.

When printing, the amount is queried and the appropriate formatter is used.

When parsing, each formatter is tried, with the longest successful match, or the first match if multiple are successful. If the zero parser is matched, the amount returned will be zero no matter what amount is parsed. If the negative parser is matched, the amount returned will be negative no matter what amount is parsed.

A typical use case for this would be to produce a format like '($123)' for negative amounts and '$123' for positive amounts.

In order to use this method, it may be necessary to output an unsigned amount. This can be achieved using appendAmount(MoneyAmountStyle) and MoneyAmountStyle#withAbsValue(boolean).

Parameters
whenPositive:MoneyFormatter

the formatter to use when the amount is positive

whenZero:MoneyFormatter

the formatter to use when the amount is zero

whenNegative:MoneyFormatter

the formatter to use when the amount is negative

Returns:MoneyFormatterBuilder

this for chaining, never null

toFormatterback to summary
public MoneyFormatter toFormatter()

Builds the formatter from the builder using the default locale.

Once the builder is in the correct state it must be converted to a MoneyFormatter to be used. Calling this method does not change the state of this instance, so it can still be used.

This method uses the default locale within the returned formatter. It can be changed by calling MoneyFormatter#withLocale(Locale).

Returns:MoneyFormatter

the formatter built from this builder, never null

toFormatterback to summary
public MoneyFormatter toFormatter(Locale locale)

Builds the formatter from the builder setting the locale.

Once the builder is in the correct state it must be converted to a MoneyFormatter to be used. Calling this method does not change the state of this instance, so it can still be used.

This method uses the specified locale within the returned formatter. It can be changed by calling MoneyFormatter#withLocale(Locale).

Parameters
locale:Locale

the initial locale for the formatter, not null

Returns:MoneyFormatter

the formatter built from this builder, never null

Annotations
@SuppressWarnings:cast
org.joda.money.format back to summary

private final Enum MoneyFormatterBuilder.SingletonPrinters

extends Enum<MoneyFormatterBuilder.SingletonPrinters>
implements MoneyPrinter
Class Inheritance
All Implemented Interfaces
org.joda.money.format.MoneyPrinter

Handles the singleton outputs.

Field Summary

Modifier and TypeField and Description
public static final MoneyFormatterBuilder.SingletonPrinters

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
print(MoneyPrintContext
the context being used, not null
context
,
Appendable
the appendable to add to, not null
appendable
,
BigMoney
the money to print, not null
money
)

Implements org.joda.money.format.MoneyPrinter.print.

Prints part of a monetary value to the output appendable.

public String
toString()

Overrides java.lang.Enum.toString.

Returns the name of this enum constant, as contained in the declaration.

public static MoneyFormatterBuilder.SingletonPrinters
public static MoneyFormatterBuilder.SingletonPrinters[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinalvalueOf

Field Detail

LOCALIZED_SYMBOLback to summary
public static final MoneyFormatterBuilder.SingletonPrinters LOCALIZED_SYMBOL

Constructor Detail

SingletonPrintersback to summary
private SingletonPrinters()

Method Detail

printback to summary
public void print(MoneyPrintContext context, Appendable appendable, BigMoney money) throws IOException

Implements org.joda.money.format.MoneyPrinter.print.

Doc from org.joda.money.format.MoneyPrinter.print.

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.

Parameters
context:MoneyPrintContext

the context being used, not null

appendable:Appendable

the appendable to add to, not null

money:BigMoney

the money to print, not null

Annotations
@Override
Exceptions
IOException:
if an IO exception occurs
toStringback to summary
public String toString()

Overrides java.lang.Enum.toString.

Doc from java.lang.Enum.toString.

Returns the name of this enum constant, as contained in the declaration. This method may be overridden, though it typically isn't necessary or desirable. An enum class should override this method when a more "programmer-friendly" string form exists.

Returns:String

the name of this enum constant

Annotations
@Override
valueOfback to summary
public static MoneyFormatterBuilder.SingletonPrinters valueOf(String name)
valuesback to summary
public static MoneyFormatterBuilder.SingletonPrinters[] values()
org.joda.money.format back to summary

private sealed Enum MoneyFormatterBuilder.Singletons

extends Enum<MoneyFormatterBuilder.Singletons>
implements MoneyPrinter, MoneyParser
Class Inheritance
All Implemented Interfaces
org.joda.money.format.MoneyParser, org.joda.money.format.MoneyPrinter

Handles the singleton outputs.

Field Summary

Modifier and TypeField and Description
public static final MoneyFormatterBuilder.Singletons
public static final MoneyFormatterBuilder.Singletons
public static final MoneyFormatterBuilder.Singletons
private final String

Constructor Summary

AccessConstructor and Description
private
Singletons(String toString)

Method Summary

Modifier and TypeMethod and Description
public String
toString()

Overrides java.lang.Enum.toString.

Returns the name of this enum constant, as contained in the declaration.

public static MoneyFormatterBuilder.Singletons
public static MoneyFormatterBuilder.Singletons[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinalvalueOf

Field Detail

CODEback to summary
public static final MoneyFormatterBuilder.Singletons CODE
NUMERIC_3_CODEback to summary
public static final MoneyFormatterBuilder.Singletons NUMERIC_3_CODE
NUMERIC_CODEback to summary
public static final MoneyFormatterBuilder.Singletons NUMERIC_CODE
toStringback to summary
private final String toString

Constructor Detail

Singletonsback to summary
private Singletons(String toString)

Method Detail

toStringback to summary
public String toString()

Overrides java.lang.Enum.toString.

Doc from java.lang.Enum.toString.

Returns the name of this enum constant, as contained in the declaration. This method may be overridden, though it typically isn't necessary or desirable. An enum class should override this method when a more "programmer-friendly" string form exists.

Returns:String

the name of this enum constant

Annotations
@Override
valueOfback to summary
public static MoneyFormatterBuilder.Singletons valueOf(String name)
valuesback to summary
public static MoneyFormatterBuilder.Singletons[] values()