Class PeriodFormatterBuilder
- java.lang.Object
-
- org.joda.time.format.PeriodFormatterBuilder
-
public class PeriodFormatterBuilder extends java.lang.ObjectFactory that creates complex instances of PeriodFormatter via method calls.Period formatting is performed by the
PeriodFormatterclass. Three classes provide factory methods to create formatters, and this is one. The others arePeriodFormatandISOPeriodFormat.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 ") .printZeroRarelyLast() .appendMonths() .appendSuffix(" month", " months") .toFormatter();PeriodFormatterBuilder itself is mutable and not thread-safe, but the formatters that it builds are thread-safe and immutable.
- Since:
- 1.0
- See Also:
PeriodFormat
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classPeriodFormatterBuilder.CompositeComposite implementation that merges other fields to create a full pattern.(package private) static classPeriodFormatterBuilder.CompositeAffixBuilds a composite affix by merging two other affix implementations.(package private) static classPeriodFormatterBuilder.FieldFormatterFormats the numeric value of a field, potentially with prefix/suffix.(package private) static classPeriodFormatterBuilder.IgnorableAffixAn affix that can be ignored.(package private) static classPeriodFormatterBuilder.LiteralHandles a simple literal piece of text.(package private) static interfacePeriodFormatterBuilder.PeriodFieldAffixDefines a formatted field's prefix or suffix text.(package private) static classPeriodFormatterBuilder.PluralAffixImplements an affix where the text varies by the amount of the field.(package private) static classPeriodFormatterBuilder.RegExAffixImplements an affix where the text varies by the amount of the field.(package private) static classPeriodFormatterBuilder.SeparatorHandles a separator, that splits the fields into multiple parts.(package private) static classPeriodFormatterBuilder.SimpleAffixImplements an affix where the text does not vary by the amount.
-
Field Summary
Fields Modifier and Type Field Description private static intDAYSprivate static intHOURSprivate java.util.List<java.lang.Object>iElementPairsprivate PeriodFormatterBuilder.FieldFormatter[]iFieldFormattersprivate intiMaxParsedDigitsprivate intiMinPrintedDigitsprivate booleaniNotParserSet to true if the formatter is not a parser.private booleaniNotPrinterSet to true if the formatter is not a printer.private PeriodFormatterBuilder.PeriodFieldAffixiPrefixprivate intiPrintZeroSettingprivate booleaniRejectSignedValuesprivate static intMAX_FIELDprivate static intMILLISprivate static intMINUTESprivate static intMONTHSprivate static java.util.concurrent.ConcurrentMap<java.lang.String,java.util.regex.Pattern>PATTERNSprivate static intPRINT_ZERO_ALWAYSprivate static intPRINT_ZERO_IF_SUPPORTEDprivate static intPRINT_ZERO_NEVERprivate static intPRINT_ZERO_RARELY_FIRSTprivate static intPRINT_ZERO_RARELY_LASTprivate static intSECONDSprivate static intSECONDS_MILLISprivate static intSECONDS_OPTIONAL_MILLISprivate static intWEEKSprivate static intYEARS
-
Constructor Summary
Constructors Constructor Description PeriodFormatterBuilder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description PeriodFormatterBuilderappend(PeriodFormatter formatter)Appends another formatter.PeriodFormatterBuilderappend(PeriodPrinter printer, PeriodParser parser)Appends a printer parser pair.private PeriodFormatterBuilderappend0(PeriodPrinter printer, PeriodParser parser)PeriodFormatterBuilderappendDays()Instruct the printer to emit an integer days field, if supported.private voidappendField(int type)private voidappendField(int type, int minPrinted)PeriodFormatterBuilderappendHours()Instruct the printer to emit an integer hours field, if supported.PeriodFormatterBuilderappendLiteral(java.lang.String text)Instructs the printer to emit specific text, and the parser to expect it.PeriodFormatterBuilderappendMillis()Instruct the printer to emit an integer millis field, if supported.PeriodFormatterBuilderappendMillis3Digit()Instruct the printer to emit an integer millis field, if supported.PeriodFormatterBuilderappendMinutes()Instruct the printer to emit an integer minutes field, if supported.PeriodFormatterBuilderappendMonths()Instruct the printer to emit an integer months field, if supported.PeriodFormatterBuilderappendPrefix(java.lang.String text)Append a field prefix which applies only to the next appended field.PeriodFormatterBuilderappendPrefix(java.lang.String[] regularExpressions, java.lang.String[] prefixes)Append a field prefix which applies only to the next appended field.PeriodFormatterBuilderappendPrefix(java.lang.String singularText, java.lang.String pluralText)Append a field prefix which applies only to the next appended field.private PeriodFormatterBuilderappendPrefix(PeriodFormatterBuilder.PeriodFieldAffix prefix)Append a field prefix which applies only to the next appended field.PeriodFormatterBuilderappendSeconds()Instruct the printer to emit an integer seconds field, if supported.PeriodFormatterBuilderappendSecondsWithMillis()Instruct the printer to emit a combined seconds and millis field, if supported.PeriodFormatterBuilderappendSecondsWithOptionalMillis()Instruct the printer to emit a combined seconds and millis field, if supported.PeriodFormatterBuilderappendSeparator(java.lang.String text)Append a separator, which is output if fields are printed both before and after the separator.PeriodFormatterBuilderappendSeparator(java.lang.String text, java.lang.String finalText)Append a separator, which is output if fields are printed both before and after the separator.PeriodFormatterBuilderappendSeparator(java.lang.String text, java.lang.String finalText, java.lang.String[] variants)Append a separator, which is output if fields are printed both before and after the separator.private PeriodFormatterBuilderappendSeparator(java.lang.String text, java.lang.String finalText, java.lang.String[] variants, boolean useBefore, boolean useAfter)PeriodFormatterBuilderappendSeparatorIfFieldsAfter(java.lang.String text)Append a separator, which is output only if fields are printed after the separator.PeriodFormatterBuilderappendSeparatorIfFieldsBefore(java.lang.String text)Append a separator, which is output only if fields are printed before the separator.PeriodFormatterBuilderappendSuffix(java.lang.String text)Append a field suffix which applies only to the last appended field.PeriodFormatterBuilderappendSuffix(java.lang.String[] regularExpressions, java.lang.String[] suffixes)Append a field suffix which applies only to the last appended field.PeriodFormatterBuilderappendSuffix(java.lang.String singularText, java.lang.String pluralText)Append a field suffix which applies only to the last appended field.private PeriodFormatterBuilderappendSuffix(PeriodFormatterBuilder.PeriodFieldAffix suffix)Append a field suffix which applies only to the last appended field.PeriodFormatterBuilderappendWeeks()Instruct the printer to emit an integer weeks field, if supported.PeriodFormatterBuilderappendYears()Instruct the printer to emit an integer years field, if supported.voidclear()Clears out all the appended elements, allowing this builder to be reused.private voidclearPrefix()private static java.lang.Object[]createComposite(java.util.List<java.lang.Object> elementPairs)PeriodFormatterBuildermaximumParsedDigits(int maxDigits)Set the maximum digits parsed for the next and following appended fields.PeriodFormatterBuilderminimumPrintedDigits(int minDigits)Set the minimum digits printed for the next and following appended fields.PeriodFormatterBuilderprintZeroAlways()Always print zero values for the next and following appended fields, even if the period doesn't support it.PeriodFormatterBuilderprintZeroIfSupported()Print zero values for the next and following appended fields only if the period supports it.PeriodFormatterBuilderprintZeroNever()Never print zero values for the next and following appended fields, unless no fields would be printed.PeriodFormatterBuilderprintZeroRarelyFirst()Never print zero values for the next and following appended fields, unless no fields would be printed.PeriodFormatterBuilderprintZeroRarelyLast()Never print zero values for the next and following appended fields, unless no fields would be printed.PeriodFormatterBuilderrejectSignedValues(boolean v)Reject signed values when parsing the next and following appended fields.PeriodFormattertoFormatter()Constructs a PeriodFormatter using all the appended elements.private static PeriodFormattertoFormatter(java.util.List<java.lang.Object> elementPairs, boolean notPrinter, boolean notParser)PeriodParsertoParser()Internal method to create a PeriodParser instance using all the appended elements.PeriodPrintertoPrinter()Internal method to create a PeriodPrinter instance using all the appended elements.
-
-
-
Field Detail
-
PRINT_ZERO_RARELY_FIRST
private static final int PRINT_ZERO_RARELY_FIRST
- See Also:
- Constant Field Values
-
PRINT_ZERO_RARELY_LAST
private static final int PRINT_ZERO_RARELY_LAST
- See Also:
- Constant Field Values
-
PRINT_ZERO_IF_SUPPORTED
private static final int PRINT_ZERO_IF_SUPPORTED
- See Also:
- Constant Field Values
-
PRINT_ZERO_ALWAYS
private static final int PRINT_ZERO_ALWAYS
- See Also:
- Constant Field Values
-
PRINT_ZERO_NEVER
private static final int PRINT_ZERO_NEVER
- See Also:
- Constant Field Values
-
YEARS
private static final int YEARS
- See Also:
- Constant Field Values
-
MONTHS
private static final int MONTHS
- See Also:
- Constant Field Values
-
WEEKS
private static final int WEEKS
- See Also:
- Constant Field Values
-
DAYS
private static final int DAYS
- See Also:
- Constant Field Values
-
HOURS
private static final int HOURS
- See Also:
- Constant Field Values
-
MINUTES
private static final int MINUTES
- See Also:
- Constant Field Values
-
SECONDS
private static final int SECONDS
- See Also:
- Constant Field Values
-
MILLIS
private static final int MILLIS
- See Also:
- Constant Field Values
-
SECONDS_MILLIS
private static final int SECONDS_MILLIS
- See Also:
- Constant Field Values
-
SECONDS_OPTIONAL_MILLIS
private static final int SECONDS_OPTIONAL_MILLIS
- See Also:
- Constant Field Values
-
MAX_FIELD
private static final int MAX_FIELD
- See Also:
- Constant Field Values
-
PATTERNS
private static final java.util.concurrent.ConcurrentMap<java.lang.String,java.util.regex.Pattern> PATTERNS
-
iMinPrintedDigits
private int iMinPrintedDigits
-
iPrintZeroSetting
private int iPrintZeroSetting
-
iMaxParsedDigits
private int iMaxParsedDigits
-
iRejectSignedValues
private boolean iRejectSignedValues
-
iPrefix
private PeriodFormatterBuilder.PeriodFieldAffix iPrefix
-
iElementPairs
private java.util.List<java.lang.Object> iElementPairs
-
iNotPrinter
private boolean iNotPrinter
Set to true if the formatter is not a printer.
-
iNotParser
private boolean iNotParser
Set to true if the formatter is not a parser.
-
iFieldFormatters
private PeriodFormatterBuilder.FieldFormatter[] iFieldFormatters
-
-
Method Detail
-
toFormatter
public PeriodFormatter toFormatter()
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.
Once this method has been called, the builder is in an invalid state.
The returned formatter may not support both printing and parsing. The methods
PeriodFormatter.isPrinter()andPeriodFormatter.isParser()will help you determine the state of the formatter.- Returns:
- the newly created formatter
- Throws:
java.lang.IllegalStateException- if the builder can produce neither a printer nor a parser
-
toPrinter
public PeriodPrinter toPrinter()
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.
- Returns:
- the newly created printer, null if builder cannot create a printer
-
toParser
public PeriodParser toParser()
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.
- Returns:
- the newly created parser, null if builder cannot create a parser
-
clear
public void clear()
Clears out all the appended elements, allowing this builder to be reused.
-
append
public PeriodFormatterBuilder append(PeriodFormatter formatter)
Appends another formatter.- Returns:
- this PeriodFormatterBuilder
-
append
public PeriodFormatterBuilder append(PeriodPrinter printer, PeriodParser parser)
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 respectively.
- Parameters:
printer- appends a printer to the builder, null if printing is not supportedparser- appends a parser to the builder, null if parsing is not supported- Returns:
- this PeriodFormatterBuilder
- Throws:
java.lang.IllegalArgumentException- if both the printer and parser are null
-
appendLiteral
public PeriodFormatterBuilder appendLiteral(java.lang.String text)
Instructs the printer to emit specific text, and the parser to expect it. The parser is case-insensitive.- Returns:
- this PeriodFormatterBuilder
- Throws:
java.lang.IllegalArgumentException- if text is null
-
minimumPrintedDigits
public PeriodFormatterBuilder minimumPrintedDigits(int minDigits)
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.- Returns:
- this PeriodFormatterBuilder
-
maximumParsedDigits
public PeriodFormatterBuilder maximumParsedDigits(int maxDigits)
Set the maximum digits parsed for the next and following appended fields. By default, the maximum digits parsed is ten.- Returns:
- this PeriodFormatterBuilder
-
rejectSignedValues
public PeriodFormatterBuilder rejectSignedValues(boolean v)
Reject signed values when parsing the next and following appended fields.- Returns:
- this PeriodFormatterBuilder
-
printZeroRarelyLast
public PeriodFormatterBuilder printZeroRarelyLast()
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.
- Returns:
- this PeriodFormatterBuilder
-
printZeroRarelyFirst
public PeriodFormatterBuilder printZeroRarelyFirst()
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.- Returns:
- this PeriodFormatterBuilder
-
printZeroIfSupported
public PeriodFormatterBuilder printZeroIfSupported()
Print zero values for the next and following appended fields only if the period supports it.- Returns:
- this PeriodFormatterBuilder
-
printZeroAlways
public PeriodFormatterBuilder printZeroAlways()
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.- Returns:
- this PeriodFormatterBuilder
-
printZeroNever
public PeriodFormatterBuilder printZeroNever()
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.
- Returns:
- this PeriodFormatterBuilder
-
appendPrefix
public PeriodFormatterBuilder appendPrefix(java.lang.String text)
Append a field prefix which applies only to the next appended field. If the field is not printed, neither is the prefix.- Parameters:
text- text to print before field only if field is printed- Returns:
- this PeriodFormatterBuilder
- See Also:
appendSuffix(java.lang.String)
-
appendPrefix
public PeriodFormatterBuilder appendPrefix(java.lang.String singularText, java.lang.String pluralText)
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.
- Parameters:
singularText- text to print if field value is onepluralText- text to print if field value is not one- Returns:
- this PeriodFormatterBuilder
- See Also:
appendSuffix(java.lang.String)
-
appendPrefix
public PeriodFormatterBuilder appendPrefix(java.lang.String[] regularExpressions, java.lang.String[] prefixes)
Append a field prefix which applies only to the next appended field. If the field is not printed, neither is the prefix.The value is converted to String. During parsing, the prefix is selected based on the match with the regular expression. The index of the first regular expression that matches value converted to String nominates the prefix. If none of the regular expressions match the value converted to String then the last prefix is selected.
An example usage for English might look like this:
appendPrefix(new String[] { "ˆ1$", ".*" }, new String[] { " year", " years" })Please note that for languages with simple mapping (singular and plural prefix only - like the one above) the
appendPrefix(String, String)method will produce in a slightly faster formatter and thatappendPrefix(String[], String[])method should be only used when the mapping between values and prefixes is more complicated than the difference between singular and plural.- Parameters:
regularExpressions- an array of regular expressions, at least one element, length has to match the length of prefixes parameterprefixes- an array of prefixes, at least one element, length has to match the length of regularExpressions parameter- Returns:
- this PeriodFormatterBuilder
- Throws:
java.lang.IllegalStateException- if no field exists to append to- Since:
- 2.5
- See Also:
appendPrefix(java.lang.String)
-
appendPrefix
private PeriodFormatterBuilder appendPrefix(PeriodFormatterBuilder.PeriodFieldAffix prefix)
Append a field prefix which applies only to the next appended field. If the field is not printed, neither is the prefix.- Parameters:
prefix- custom prefix- Returns:
- this PeriodFormatterBuilder
- See Also:
appendSuffix(java.lang.String)
-
appendYears
public PeriodFormatterBuilder appendYears()
Instruct the printer to emit an integer years field, if supported.The number of printed and parsed digits can be controlled using
minimumPrintedDigits(int)andmaximumParsedDigits(int).- Returns:
- this PeriodFormatterBuilder
-
appendMonths
public PeriodFormatterBuilder appendMonths()
Instruct the printer to emit an integer months field, if supported.The number of printed and parsed digits can be controlled using
minimumPrintedDigits(int)andmaximumParsedDigits(int).- Returns:
- this PeriodFormatterBuilder
-
appendWeeks
public PeriodFormatterBuilder appendWeeks()
Instruct the printer to emit an integer weeks field, if supported.The number of printed and parsed digits can be controlled using
minimumPrintedDigits(int)andmaximumParsedDigits(int).- Returns:
- this PeriodFormatterBuilder
-
appendDays
public PeriodFormatterBuilder appendDays()
Instruct the printer to emit an integer days field, if supported.The number of printed and parsed digits can be controlled using
minimumPrintedDigits(int)andmaximumParsedDigits(int).- Returns:
- this PeriodFormatterBuilder
-
appendHours
public PeriodFormatterBuilder appendHours()
Instruct the printer to emit an integer hours field, if supported.The number of printed and parsed digits can be controlled using
minimumPrintedDigits(int)andmaximumParsedDigits(int).- Returns:
- this PeriodFormatterBuilder
-
appendMinutes
public PeriodFormatterBuilder appendMinutes()
Instruct the printer to emit an integer minutes field, if supported.The number of printed and parsed digits can be controlled using
minimumPrintedDigits(int)andmaximumParsedDigits(int).- Returns:
- this PeriodFormatterBuilder
-
appendSeconds
public PeriodFormatterBuilder appendSeconds()
Instruct the printer to emit an integer seconds field, if supported.The number of printed and parsed digits can be controlled using
minimumPrintedDigits(int)andmaximumParsedDigits(int).- Returns:
- this PeriodFormatterBuilder
-
appendSecondsWithMillis
public PeriodFormatterBuilder appendSecondsWithMillis()
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.- Returns:
- this PeriodFormatterBuilder
-
appendSecondsWithOptionalMillis
public PeriodFormatterBuilder appendSecondsWithOptionalMillis()
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.- Returns:
- this PeriodFormatterBuilder
-
appendMillis
public PeriodFormatterBuilder appendMillis()
Instruct the printer to emit an integer millis field, if supported.The number of printed and parsed digits can be controlled using
minimumPrintedDigits(int)andmaximumParsedDigits(int).- Returns:
- this PeriodFormatterBuilder
-
appendMillis3Digit
public PeriodFormatterBuilder appendMillis3Digit()
Instruct the printer to emit an integer millis field, if supported.The number of arsed digits can be controlled using
maximumParsedDigits(int).- Returns:
- this PeriodFormatterBuilder
-
appendField
private void appendField(int type)
-
appendField
private void appendField(int type, int minPrinted)
-
appendSuffix
public PeriodFormatterBuilder appendSuffix(java.lang.String text)
Append a field suffix which applies only to the last appended field. If the field is not printed, neither is the suffix.- Parameters:
text- text to print after field only if field is printed- Returns:
- this PeriodFormatterBuilder
- Throws:
java.lang.IllegalStateException- if no field exists to append to- See Also:
appendPrefix(java.lang.String)
-
appendSuffix
public PeriodFormatterBuilder appendSuffix(java.lang.String singularText, java.lang.String pluralText)
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.
- Parameters:
singularText- text to print if field value is onepluralText- text to print if field value is not one- Returns:
- this PeriodFormatterBuilder
- Throws:
java.lang.IllegalStateException- if no field exists to append to- See Also:
appendPrefix(java.lang.String)
-
appendSuffix
public PeriodFormatterBuilder appendSuffix(java.lang.String[] regularExpressions, java.lang.String[] suffixes)
Append a field suffix which applies only to the last appended field. If the field is not printed, neither is the suffix.The value is converted to String. During parsing, the suffix is selected based on the match with the regular expression. The index of the first regular expression that matches value converted to String nominates the suffix. If none of the regular expressions match the value converted to String then the last suffix is selected.
An example usage for English might look like this:
appendSuffix(new String[] { "ˆ1$", ".*" }, new String[] { " year", " years" })Please note that for languages with simple mapping (singular and plural suffix only - like the one above) the
appendSuffix(String, String)method will result in a slightly faster formatter and thatappendSuffix(String[], String[])method should be only used when the mapping between values and prefixes is more complicated than the difference between singular and plural.- Parameters:
regularExpressions- an array of regular expressions, at least one element, length has to match the length of suffixes parametersuffixes- an array of suffixes, at least one element, length has to match the length of regularExpressions parameter- Returns:
- this PeriodFormatterBuilder
- Throws:
java.lang.IllegalStateException- if no field exists to append to- Since:
- 2.5
- See Also:
appendPrefix(java.lang.String)
-
appendSuffix
private PeriodFormatterBuilder appendSuffix(PeriodFormatterBuilder.PeriodFieldAffix suffix)
Append a field suffix which applies only to the last appended field. If the field is not printed, neither is the suffix.- Parameters:
suffix- custom suffix- Returns:
- this PeriodFormatterBuilder
- Throws:
java.lang.IllegalStateException- if no field exists to append to- See Also:
appendPrefix(java.lang.String)
-
appendSeparator
public PeriodFormatterBuilder appendSeparator(java.lang.String text)
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.
- Parameters:
text- the text to use as a separator- Returns:
- this PeriodFormatterBuilder
- Throws:
java.lang.IllegalStateException- if this separator follows a previous one
-
appendSeparatorIfFieldsAfter
public PeriodFormatterBuilder appendSeparatorIfFieldsAfter(java.lang.String text)
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.
- Parameters:
text- the text to use as a separator- Returns:
- this PeriodFormatterBuilder
- Throws:
java.lang.IllegalStateException- if this separator follows a previous one
-
appendSeparatorIfFieldsBefore
public PeriodFormatterBuilder appendSeparatorIfFieldsBefore(java.lang.String text)
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.
- Parameters:
text- the text to use as a separator- Returns:
- this PeriodFormatterBuilder
- Throws:
java.lang.IllegalStateException- if this separator follows a previous one
-
appendSeparator
public PeriodFormatterBuilder appendSeparator(java.lang.String text, java.lang.String finalText)
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.
- Parameters:
text- the text to use as a separatorfinalText- the text used used if this is the final separator to be printed- Returns:
- this PeriodFormatterBuilder
- Throws:
java.lang.IllegalStateException- if this separator follows a previous one
-
appendSeparator
public PeriodFormatterBuilder appendSeparator(java.lang.String text, java.lang.String finalText, java.lang.String[] variants)
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.
- Parameters:
text- the text to use as a separatorfinalText- the text used used if this is the final separator to be printedvariants- set of text values which are also acceptable when parsed- Returns:
- this PeriodFormatterBuilder
- Throws:
java.lang.IllegalStateException- if this separator follows a previous one
-
appendSeparator
private PeriodFormatterBuilder appendSeparator(java.lang.String text, java.lang.String finalText, java.lang.String[] variants, boolean useBefore, boolean useAfter)
-
clearPrefix
private void clearPrefix() throws java.lang.IllegalStateException- Throws:
java.lang.IllegalStateException
-
append0
private PeriodFormatterBuilder append0(PeriodPrinter printer, PeriodParser parser)
-
toFormatter
private static PeriodFormatter toFormatter(java.util.List<java.lang.Object> elementPairs, boolean notPrinter, boolean notParser)
-
createComposite
private static java.lang.Object[] createComposite(java.util.List<java.lang.Object> elementPairs)
-
-