Package javax.time.calendar.format
Class NumberPrinterParser
java.lang.Object
javax.time.calendar.format.NumberPrinterParser
- All Implemented Interfaces:
DateTimeParser
,DateTimePrinter
- Direct Known Subclasses:
ReducedPrinterParser
Prints and parses a numeric date-time field with optional padding.
NumberPrinterParser is immutable and thread-safe.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final int[]
Array of 10 to the power of n.private final int
The maximum width allowed, from 1 to 10.(package private) final int
The minimum width allowed, zero padding is used up to this width, from 1 to 10.(package private) final DateTimeFieldRule
<?> The rule to output, not null.private final DateTimeFormatterBuilder.SignStyle
The positive/negative sign style, not null.private final int
The subsequent width of fixed width non-negative number fields, 0 or greater. -
Constructor Summary
ConstructorsModifierConstructorDescription(package private)
NumberPrinterParser
(DateTimeFieldRule<?> rule, int minWidth, int maxWidth, DateTimeFormatterBuilder.SignStyle signStyle) Constructor.private
NumberPrinterParser
(DateTimeFieldRule<?> rule, int minWidth, int maxWidth, DateTimeFormatterBuilder.SignStyle signStyle, int subsequentWidth) Constructor. -
Method Summary
Modifier and TypeMethodDescription(package private) int
getValue
(Calendrical calendrical) Gets the value to output.boolean
isPrintDataAvailable
(Calendrical calendrical) Checks if the calendrical contains the data necessary to be printed.int
parse
(DateTimeParseContext context, String parseText, int position) Parses from the supplied text and position into the calendrical.void
print
(Calendrical calendrical, Appendable appendable, DateTimeFormatSymbols symbols) Prints the calendrical object to the appendable.(package private) void
setValue
(DateTimeParseContext context, long value) Stores the value.toString()
(package private) NumberPrinterParser
withSubsequentWidth
(int subsequentWidth) Returns a new instance with an updated subsequent width.
-
Field Details
-
EXCEED_POINTS
static final int[] EXCEED_POINTSArray of 10 to the power of n. -
rule
The rule to output, not null. -
minWidth
final int minWidthThe minimum width allowed, zero padding is used up to this width, from 1 to 10. -
maxWidth
private final int maxWidthThe maximum width allowed, from 1 to 10. -
signStyle
The positive/negative sign style, not null. -
subsequentWidth
private final int subsequentWidthThe subsequent width of fixed width non-negative number fields, 0 or greater.
-
-
Constructor Details
-
NumberPrinterParser
NumberPrinterParser(DateTimeFieldRule<?> rule, int minWidth, int maxWidth, DateTimeFormatterBuilder.SignStyle signStyle) Constructor.- Parameters:
rule
- the rule of the field to print, not nullminWidth
- the minimum field width, from 1 to 10maxWidth
- the maximum field width, from minWidth to 10signStyle
- the positive/negative sign style, not null
-
NumberPrinterParser
private NumberPrinterParser(DateTimeFieldRule<?> rule, int minWidth, int maxWidth, DateTimeFormatterBuilder.SignStyle signStyle, int subsequentWidth) Constructor.- Parameters:
rule
- the rule of the field to print, not nullminWidth
- the minimum field width, from 1 to 10maxWidth
- the maximum field width, from minWidth to 10signStyle
- the positive/negative sign style, not nullsubsequentWidth
- the width of subsequent non-negative numbers, 0 or greater
-
-
Method Details
-
withSubsequentWidth
Returns a new instance with an updated subsequent width.- Parameters:
subsequentWidth
- the width of subsequent non-negative numbers, 0 or greater- Returns:
- a new updated printer-parser, never null
-
print
public void print(Calendrical calendrical, Appendable appendable, DateTimeFormatSymbols symbols) throws IOException Prints the calendrical object to the appendable.- Specified by:
print
in interfaceDateTimePrinter
- Parameters:
calendrical
- the calendrical to print, not nullappendable
- the appendable to add to, not nullsymbols
- the formatting symbols to use, not null- Throws:
IOException
- if the append throws an exception
-
getValue
Gets the value to output.- Parameters:
calendrical
- the calendrical, not null- Returns:
- the value
-
isPrintDataAvailable
Checks if the calendrical contains the data necessary to be printed.The implementation should not check the validity of the data, just whether there is sufficient data to attempt a print.
- Specified by:
isPrintDataAvailable
in interfaceDateTimePrinter
- Parameters:
calendrical
- the calendrical to check, not null- Returns:
- true if the calendrical can be printed, false if not
-
parse
Parses from the supplied text and position into the calendrical.- Specified by:
parse
in interfaceDateTimeParser
- Parameters:
context
- the context to use and parse into, not nullparseText
- the input text to parse, not nullposition
- the position to start parsing at, from 0 to the text length- Returns:
- the new parse position, where negative means an error with the error position encoded using the complement ~ operator
-
setValue
Stores the value.- Parameters:
context
- the context to store into, not nullvalue
- the value
-
toString
-