java.lang.Object | |
↳ | org.joda.time.format.PeriodFormatterBuilder |
Factory that creates complex instances of PeriodFormatter via method calls.
Period formatting is performed by the PeriodFormatter
class.
Three classes provide factory methods to create formatters, and this is one.
The others are PeriodFormat
and ISOPeriodFormat
.
PeriodFormatterBuilder is used for constructing formatters which are then used to print or parse. The formatters are built by appending specific fields or other formatters to an instance of this builder.
For example, a formatter that prints years and months, like "15 years and 8 months", can be constructed as follows:
PeriodFormatter yearsAndMonths = new PeriodFormatterBuilder() .printZeroAlways() .appendYears() .appendSuffix(" year", " years") .appendSeparator(" and ") .printZeroRarely() .appendMonths() .appendSuffix(" month", " months") .toFormatter();
PeriodFormatterBuilder itself is mutable and not thread-safe, but the formatters that it builds are thread-safe and immutable.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Appends another formatter.
| |||||||||||
Appends a printer parser pair.
| |||||||||||
Instruct the printer to emit an integer days field, if supported.
| |||||||||||
Instruct the printer to emit an integer hours field, if supported.
| |||||||||||
Instructs the printer to emit specific text, and the parser to expect it.
| |||||||||||
Instruct the printer to emit an integer millis field, if supported.
| |||||||||||
Instruct the printer to emit an integer millis field, if supported.
| |||||||||||
Instruct the printer to emit an integer minutes field, if supported.
| |||||||||||
Instruct the printer to emit an integer months field, if supported.
| |||||||||||
Append a field prefix which applies only to the next appended field.
| |||||||||||
Append a field prefix which applies only to the next appended field.
| |||||||||||
Instruct the printer to emit an integer seconds field, if supported.
| |||||||||||
Instruct the printer to emit a combined seconds and millis field, if supported.
| |||||||||||
Instruct the printer to emit a combined seconds and millis field, if supported.
| |||||||||||
Append a separator, which is output if fields are printed both before
and after the separator.
| |||||||||||
Append a separator, which is output if fields are printed both before
and after the separator.
| |||||||||||
Append a separator, which is output if fields are printed both before
and after the separator.
| |||||||||||
Append a separator, which is output only if fields are printed after the separator.
| |||||||||||
Append a separator, which is output only if fields are printed before the separator.
| |||||||||||
Append a field suffix which applies only to the last appended field.
| |||||||||||
Append a field suffix which applies only to the last appended field.
| |||||||||||
Instruct the printer to emit an integer weeks field, if supported.
| |||||||||||
Instruct the printer to emit an integer years field, if supported.
| |||||||||||
Clears out all the appended elements, allowing this builder to be reused.
| |||||||||||
Set the maximum digits parsed for the next and following appended
fields.
| |||||||||||
Set the minimum digits printed for the next and following appended
fields.
| |||||||||||
Always print zero values for the next and following appended fields,
even if the period doesn't support it.
| |||||||||||
Print zero values for the next and following appened fields only if the
period supports it.
| |||||||||||
Never print zero values for the next and following appended fields,
unless no fields would be printed.
| |||||||||||
Never print zero values for the next and following appended fields,
unless no fields would be printed.
| |||||||||||
Never print zero values for the next and following appended fields,
unless no fields would be printed.
| |||||||||||
Reject signed values when parsing the next and following appended fields.
| |||||||||||
Constructs a PeriodFormatter using all the appended elements.
| |||||||||||
Internal method to create a PeriodParser instance using all the
appended elements.
| |||||||||||
Internal method to create a PeriodPrinter instance using all the
appended elements.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Appends another formatter.
Appends a printer parser pair.
Either the printer or the parser may be null, in which case the builder will be unable to produce a parser or printer repectively.
printer | appends a printer to the builder, null if printing is not supported |
---|---|
parser | appends a parser to the builder, null if parsing is not supported |
IllegalArgumentException | if both the printer and parser are null |
---|
Instruct the printer to emit an integer days field, if supported.
The number of printed and parsed digits can be controlled using
minimumPrintedDigits(int)
and maximumParsedDigits(int)
.
Instruct the printer to emit an integer hours field, if supported.
The number of printed and parsed digits can be controlled using
minimumPrintedDigits(int)
and maximumParsedDigits(int)
.
Instructs the printer to emit specific text, and the parser to expect it. The parser is case-insensitive.
IllegalArgumentException | if text is null |
---|
Instruct the printer to emit an integer millis field, if supported.
The number of printed and parsed digits can be controlled using
minimumPrintedDigits(int)
and maximumParsedDigits(int)
.
Instruct the printer to emit an integer millis field, if supported.
The number of arsed digits can be controlled using maximumParsedDigits(int)
.
Instruct the printer to emit an integer minutes field, if supported.
The number of printed and parsed digits can be controlled using
minimumPrintedDigits(int)
and maximumParsedDigits(int)
.
Instruct the printer to emit an integer months field, if supported.
The number of printed and parsed digits can be controlled using
minimumPrintedDigits(int)
and maximumParsedDigits(int)
.
Append a field prefix which applies only to the next appended field. If the field is not printed, neither is the prefix.
During parsing, the singular and plural versions are accepted whether or not the actual value matches plurality.
singularText | text to print if field value is one |
---|---|
pluralText | text to print if field value is not one |
Append a field prefix which applies only to the next appended field. If the field is not printed, neither is the prefix.
text | text to print before field only if field is printed |
---|
Instruct the printer to emit an integer seconds field, if supported.
The number of printed and parsed digits can be controlled using
minimumPrintedDigits(int)
and maximumParsedDigits(int)
.
Instruct the printer to emit a combined seconds and millis field, if supported. The millis will overflow into the seconds if necessary. The millis are always output.
Instruct the printer to emit a combined seconds and millis field, if supported. The millis will overflow into the seconds if necessary. The millis are only output if non-zero.
Append a separator, which is output if fields are printed both before and after the separator.
This method changes the separator depending on whether it is the last separator to be output.
For example, builder.appendDays().appendSeparator(",", "&").appendHours().appendSeparator(",", "&").appendMinutes()
will output '1,2&3' if all three fields are output, '1&2' if two fields are output
and '1' if just one field is output.
The text will be parsed case-insensitively.
Note: appending a separator discontinues any further work on the latest appended field.
text | the text to use as a separator |
---|---|
finalText | the text used used if this is the final separator to be printed |
IllegalStateException | if this separator follows a previous one |
---|
Append a separator, which is output if fields are printed both before and after the separator.
This method changes the separator depending on whether it is the last separator to be output.
For example, builder.appendDays().appendSeparator(",", "&").appendHours().appendSeparator(",", "&").appendMinutes()
will output '1,2&3' if all three fields are output, '1&2' if two fields are output
and '1' if just one field is output.
The text will be parsed case-insensitively.
Note: appending a separator discontinues any further work on the latest appended field.
text | the text to use as a separator |
---|---|
finalText | the text used used if this is the final separator to be printed |
variants | set of text values which are also acceptable when parsed |
IllegalStateException | if this separator follows a previous one |
---|
Append a separator, which is output if fields are printed both before and after the separator.
For example, builder.appendDays().appendSeparator(",").appendHours()
will only output the comma if both the days and hours fields are output.
The text will be parsed case-insensitively.
Note: appending a separator discontinues any further work on the latest appended field.
text | the text to use as a separator |
---|
IllegalStateException | if this separator follows a previous one |
---|
Append a separator, which is output only if fields are printed after the separator.
For example,
builder.appendDays().appendSeparatorIfFieldsAfter(",").appendHours()
will only output the comma if the hours fields is output.
The text will be parsed case-insensitively.
Note: appending a separator discontinues any further work on the latest appended field.
text | the text to use as a separator |
---|
IllegalStateException | if this separator follows a previous one |
---|
Append a separator, which is output only if fields are printed before the separator.
For example,
builder.appendDays().appendSeparatorIfFieldsBefore(",").appendHours()
will only output the comma if the days fields is output.
The text will be parsed case-insensitively.
Note: appending a separator discontinues any further work on the latest appended field.
text | the text to use as a separator |
---|
IllegalStateException | if this separator follows a previous one |
---|
Append a field suffix which applies only to the last appended field. If the field is not printed, neither is the suffix.
text | text to print after field only if field is printed |
---|
IllegalStateException | if no field exists to append to |
---|
Append a field suffix which applies only to the last appended field. If the field is not printed, neither is the suffix.
During parsing, the singular and plural versions are accepted whether or not the actual value matches plurality.
singularText | text to print if field value is one |
---|---|
pluralText | text to print if field value is not one |
IllegalStateException | if no field exists to append to |
---|
Instruct the printer to emit an integer weeks field, if supported.
The number of printed and parsed digits can be controlled using
minimumPrintedDigits(int)
and maximumParsedDigits(int)
.
Instruct the printer to emit an integer years field, if supported.
The number of printed and parsed digits can be controlled using
minimumPrintedDigits(int)
and maximumParsedDigits(int)
.
Clears out all the appended elements, allowing this builder to be reused.
Set the maximum digits parsed for the next and following appended fields. By default, the maximum digits parsed is ten.
Set the minimum digits printed for the next and following appended fields. By default, the minimum digits printed is one. If the field value is zero, it is not printed unless a printZero rule is applied.
Always print zero values for the next and following appended fields, even if the period doesn't support it. The parser requires values for fields that always print zero.
Print zero values for the next and following appened fields only if the period supports it.
Never print zero values for the next and following appended fields, unless no fields would be printed. If no fields are printed, the printer forces the last "printZeroRarely" field to print a zero.
This field setting is the default.
Never print zero values for the next and following appended fields, unless no fields would be printed. If no fields are printed, the printer forces the first "printZeroRarely" field to print a zero.
Never print zero values for the next and following appended fields, unless no fields would be printed. If no fields are printed, the printer forces the last "printZeroRarely" field to print a zero.
This field setting is the default.
Reject signed values when parsing the next and following appended fields.
Constructs a PeriodFormatter using all the appended elements.
This is the main method used by applications at the end of the build process to create a usable formatter.
Subsequent changes to this builder do not affect the returned formatter.
The returned formatter may not support both printing and parsing.
The methods isPrinter()
and
isParser()
will help you determine the state
of the formatter.
IllegalStateException | if the builder can produce neither a printer nor a parser |
---|
Internal method to create a PeriodParser instance using all the appended elements.
Most applications will not use this method.
If you want a printer in an application, call toFormatter()
and just use the printing API.
Subsequent changes to this builder do not affect the returned parser.
Internal method to create a PeriodPrinter instance using all the appended elements.
Most applications will not use this method.
If you want a printer in an application, call toFormatter()
and just use the printing API.
Subsequent changes to this builder do not affect the returned printer.