public interface FormatToken
T
to a String
or an Appendable
.
Instances of FormatToken
can be added to a ItemFormatBuilder
to assemble a complex input/output ItemFormat
using a programmatic
fluent API. Hereby each FormatToken
instance represent a part of the
overall formatted String. Similarly when parsing an input by calling
ItemFormat#parse(CharSequence, Locale)
each FormatToken
can
read and forward the current ParseContext
, or through an error, if
the input does not provide a parseable input for the given
FormatToken
.
Classes implementing this interface are required to be thread-safe and immutable.
Modifier and Type | Method and Description |
---|---|
void |
parse(ParseContext context)
Parses an item from the given
ParseContext . |
void |
print(Appendable appendable,
javax.money.MonetaryAmount amount)
Prints an item value to an
Appendable . |
void print(Appendable appendable, javax.money.MonetaryAmount amount) throws IOException
Appendable
.
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 nullitem
- the item to print, not nulllocale
- the Locale
to be used, not null.UnsupportedOperationException
- if the formatter is unable to printIOException
- if an IO error occursvoid parse(ParseContext context) throws ParseException
ParseContext
. Any parsed item can
be added to the ParseContext
using
ParseContext#addParseResult(Object, Object)
as results. At the
end of the parsing process an instance of ItemFactory
is
transferring the results parsed into the target item to be parsed.context
- the parse contextlocale
- the Locale
to be used, not null.style
- the LocalizationStyle
to be used.ParseException
- thrown, if parsing fails.Copyright © 2012–2013 JSR 354 - Expert Group. All rights reserved.