|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.joda.money.format.MoneyFormatter
public final class MoneyFormatter
Formats instances of money to and from a String.
Instances of MoneyFormatter
can be created by
MoneyFormatterBuilder
.
This class is immutable and thread-safe.
Method Summary | |
---|---|
Locale |
getLocale()
Gets the locale to use. |
boolean |
isParser()
Checks whether this formatter can parse. |
boolean |
isPrinter()
Checks whether this formatter can print. |
MoneyParseContext |
parse(CharSequence text,
int startIndex)
Parses the text extracting monetary information. |
BigMoney |
parseBigMoney(CharSequence text)
Fully parses the text into a BigMoney . |
Money |
parseMoney(CharSequence text)
Fully parses the text into a Money requiring that the parsed
amount has the correct number of decimal places. |
void |
print(Appendable appendable,
BigMoneyProvider moneyProvider)
Prints a monetary value to an Appendable converting
any IOException to a MoneyFormatException . |
String |
print(BigMoneyProvider moneyProvider)
Prints a monetary value to a String . |
void |
printIO(Appendable appendable,
BigMoneyProvider moneyProvider)
Prints a monetary value to an Appendable potentially
throwing an IOException . |
String |
toString()
Gets a string summary of the formatter. |
MoneyFormatter |
withLocale(Locale locale)
Returns a copy of this instance with the specified locale. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Method Detail |
---|
public Locale getLocale()
public MoneyFormatter withLocale(Locale locale)
Changing the locale may change the style of output depending on how the formatter has been configured.
locale
- the locale, not null
public boolean isPrinter()
If the formatter cannot print, an UnsupportedOperationException will be thrown from the print methods.
public boolean isParser()
If the formatter cannot parse, an UnsupportedOperationException will be thrown from the print methods.
public String print(BigMoneyProvider moneyProvider)
String
.
moneyProvider
- the money to print, not null
UnsupportedOperationException
- if the formatter is unable to print
MoneyFormatException
- if there is a problem while printingpublic void print(Appendable appendable, BigMoneyProvider moneyProvider)
Appendable
converting
any IOException
to a MoneyFormatException
.
Example implementations of Appendable
are StringBuilder
,
StringBuffer
or Writer
. Note that StringBuilder
and StringBuffer
never throw an IOException
.
appendable
- the appendable to add to, not nullmoneyProvider
- the money to print, not null
UnsupportedOperationException
- if the formatter is unable to print
MoneyFormatException
- if there is a problem while printingpublic void printIO(Appendable appendable, BigMoneyProvider moneyProvider) throws IOException
Appendable
potentially
throwing an IOException
.
Example implementations of Appendable
are StringBuilder
,
StringBuffer
or Writer
. Note that StringBuilder
and StringBuffer
never throw an IOException
.
appendable
- the appendable to add to, not nullmoneyProvider
- the money to print, not null
UnsupportedOperationException
- if the formatter is unable to print
MoneyFormatException
- if there is a problem while printing
IOException
- if an IO error occurspublic BigMoney parseBigMoney(CharSequence text)
BigMoney
.
The parse must complete normally and parse the entire text (currency and amount). If the parse completes without reading the entire length of the text, an exception is thrown. If any other problem occurs during parsing, an exception is thrown.
text
- the text to parse, not null
UnsupportedOperationException
- if the formatter is unable to parse
MoneyFormatException
- if there is a problem while parsingpublic Money parseMoney(CharSequence text)
Money
requiring that the parsed
amount has the correct number of decimal places.
The parse must complete normally and parse the entire text (currency and amount). If the parse completes without reading the entire length of the text, an exception is thrown. If any other problem occurs during parsing, an exception is thrown.
text
- the text to parse, not null
UnsupportedOperationException
- if the formatter is unable to parse
MoneyFormatException
- if there is a problem while parsing
ArithmeticException
- if the scale of the parsed money exceeds the scale of the currencypublic MoneyParseContext parse(CharSequence text, int startIndex)
This method parses the input providing low-level access to the parsing state. The resulting context contains the parsed text, indicator of error, position following the parse and the parsed currency and amount. Together, these provide enough information for higher level APIs to use.
text
- the text to parse, not nullstartIndex
- the start index to parse from
IndexOutOfBoundsException
- if the start index is invalid
UnsupportedOperationException
- if this formatter cannot parsepublic String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |