Package org.joda.time.format
Class PeriodFormatterBuilder.FieldFormatter
- java.lang.Object
-
- org.joda.time.format.PeriodFormatterBuilder.FieldFormatter
-
- All Implemented Interfaces:
PeriodParser
,PeriodPrinter
- Enclosing class:
- PeriodFormatterBuilder
static class PeriodFormatterBuilder.FieldFormatter extends java.lang.Object implements PeriodPrinter, PeriodParser
Formats the numeric value of a field, potentially with prefix/suffix.
-
-
Field Summary
Fields Modifier and Type Field Description private PeriodFormatterBuilder.FieldFormatter[]
iFieldFormatters
The array of the latest formatter added for each type.private int
iFieldType
The index of the field type, 0=year, etc.private int
iMaxParsedDigits
private int
iMinPrintedDigits
private PeriodFormatterBuilder.PeriodFieldAffix
iPrefix
private int
iPrintZeroSetting
private boolean
iRejectSignedValues
private PeriodFormatterBuilder.PeriodFieldAffix
iSuffix
-
Constructor Summary
Constructors Constructor Description FieldFormatter(int minPrintedDigits, int printZeroSetting, int maxParsedDigits, boolean rejectSignedValues, int fieldType, PeriodFormatterBuilder.FieldFormatter[] fieldFormatters, PeriodFormatterBuilder.PeriodFieldAffix prefix, PeriodFormatterBuilder.PeriodFieldAffix suffix)
FieldFormatter(PeriodFormatterBuilder.FieldFormatter field, PeriodFormatterBuilder.PeriodFieldAffix suffix)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
calculatePrintedLength(ReadablePeriod period, java.util.Locale locale)
Returns the exact number of characters produced for the given period.int
countFieldsToPrint(ReadablePeriod period, int stopAt, java.util.Locale locale)
Returns the amount of fields from the given period that this printer will print.void
finish(PeriodFormatterBuilder.FieldFormatter[] fieldFormatters)
(package private) int
getFieldType()
(package private) long
getFieldValue(ReadablePeriod period)
(package private) boolean
isSupported(PeriodType type, int field)
(package private) boolean
isZero(ReadablePeriod period)
private int
parseInt(java.lang.String text, int position, int length)
int
parseInto(ReadWritablePeriod period, java.lang.String text, int position, java.util.Locale locale)
Parses a period from the given text, at the given position, saving the result into the fields of the given ReadWritablePeriod.void
printTo(java.io.Writer out, ReadablePeriod period, java.util.Locale locale)
Prints a ReadablePeriod to a Writer.void
printTo(java.lang.StringBuffer buf, ReadablePeriod period, java.util.Locale locale)
Prints a ReadablePeriod to a StringBuffer.(package private) void
setFieldValue(ReadWritablePeriod period, int field, int value)
-
-
-
Field Detail
-
iMinPrintedDigits
private final int iMinPrintedDigits
-
iPrintZeroSetting
private final int iPrintZeroSetting
-
iMaxParsedDigits
private final int iMaxParsedDigits
-
iRejectSignedValues
private final boolean iRejectSignedValues
-
iFieldType
private final int iFieldType
The index of the field type, 0=year, etc.
-
iFieldFormatters
private final PeriodFormatterBuilder.FieldFormatter[] iFieldFormatters
The array of the latest formatter added for each type. This is shared between all the field formatters in a formatter.
-
iPrefix
private final PeriodFormatterBuilder.PeriodFieldAffix iPrefix
-
iSuffix
private final PeriodFormatterBuilder.PeriodFieldAffix iSuffix
-
-
Constructor Detail
-
FieldFormatter
FieldFormatter(int minPrintedDigits, int printZeroSetting, int maxParsedDigits, boolean rejectSignedValues, int fieldType, PeriodFormatterBuilder.FieldFormatter[] fieldFormatters, PeriodFormatterBuilder.PeriodFieldAffix prefix, PeriodFormatterBuilder.PeriodFieldAffix suffix)
-
FieldFormatter
FieldFormatter(PeriodFormatterBuilder.FieldFormatter field, PeriodFormatterBuilder.PeriodFieldAffix suffix)
-
-
Method Detail
-
finish
public void finish(PeriodFormatterBuilder.FieldFormatter[] fieldFormatters)
-
countFieldsToPrint
public int countFieldsToPrint(ReadablePeriod period, int stopAt, java.util.Locale locale)
Description copied from interface:PeriodPrinter
Returns the amount of fields from the given period that this printer will print.- Specified by:
countFieldsToPrint
in interfacePeriodPrinter
- Parameters:
period
- the period to usestopAt
- stop counting at this value, enter a number ≥ 256 to count alllocale
- the locale to use- Returns:
- amount of fields printed
-
calculatePrintedLength
public int calculatePrintedLength(ReadablePeriod period, java.util.Locale locale)
Description copied from interface:PeriodPrinter
Returns the exact number of characters produced for the given period.- Specified by:
calculatePrintedLength
in interfacePeriodPrinter
- Parameters:
period
- the period to uselocale
- the locale to use- Returns:
- the estimated length
-
printTo
public void printTo(java.lang.StringBuffer buf, ReadablePeriod period, java.util.Locale locale)
Description copied from interface:PeriodPrinter
Prints a ReadablePeriod to a StringBuffer.- Specified by:
printTo
in interfacePeriodPrinter
- Parameters:
buf
- the formatted period is appended to this bufferperiod
- the period to formatlocale
- the locale to use
-
printTo
public void printTo(java.io.Writer out, ReadablePeriod period, java.util.Locale locale) throws java.io.IOException
Description copied from interface:PeriodPrinter
Prints a ReadablePeriod to a Writer.- Specified by:
printTo
in interfacePeriodPrinter
- Parameters:
out
- the formatted period is written outperiod
- the period to formatlocale
- the locale to use- Throws:
java.io.IOException
-
parseInto
public int parseInto(ReadWritablePeriod period, java.lang.String text, int position, java.util.Locale locale)
Description copied from interface:PeriodParser
Parses a period from the given text, at the given position, saving the result into the fields of the given ReadWritablePeriod. If the parse succeeds, the return value is the new text position. Note that the parse may succeed without fully reading the text.If it fails, the return value is negative, but the period may still be modified. To determine the position where the parse failed, apply the one's complement operator (~) on the return value.
- Specified by:
parseInto
in interfacePeriodParser
- Parameters:
period
- a period that will be modifiedtext
- text to parseposition
- position to start parsing fromlocale
- the locale to use for parsing- Returns:
- new position, if negative, parse failed. Apply complement operator (~) to get position of failure
-
parseInt
private int parseInt(java.lang.String text, int position, int length)
- Parameters:
text
- text to parseposition
- position in textlength
- exact count of characters to parse- Returns:
- parsed int value
-
getFieldValue
long getFieldValue(ReadablePeriod period)
- Returns:
- Long.MAX_VALUE if nothing to print, otherwise value
-
isZero
boolean isZero(ReadablePeriod period)
-
isSupported
boolean isSupported(PeriodType type, int field)
-
setFieldValue
void setFieldValue(ReadWritablePeriod period, int field, int value)
-
getFieldType
int getFieldType()
-
-