Package javax.time.calendar.format
Class NumberPrinterParser
- java.lang.Object
-
- javax.time.calendar.format.NumberPrinterParser
-
- All Implemented Interfaces:
DateTimeParser
,DateTimePrinter
- Direct Known Subclasses:
ReducedPrinterParser
class NumberPrinterParser extends java.lang.Object implements DateTimePrinter, DateTimeParser
Prints and parses a numeric date-time field with optional padding.NumberPrinterParser is immutable and thread-safe.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static int[]
EXCEED_POINTS
Array of 10 to the power of n.private int
maxWidth
The maximum width allowed, from 1 to 10.(package private) int
minWidth
The minimum width allowed, zero padding is used up to this width, from 1 to 10.(package private) DateTimeFieldRule<?>
rule
The rule to output, not null.private DateTimeFormatterBuilder.SignStyle
signStyle
The positive/negative sign style, not null.private int
subsequentWidth
The subsequent width of fixed width non-negative number fields, 0 or greater.
-
Constructor Summary
Constructors Modifier Constructor Description (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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (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, java.lang.String parseText, int position)
Parses from the supplied text and position into the calendrical.void
print(Calendrical calendrical, java.lang.Appendable appendable, DateTimeFormatSymbols symbols)
Prints the calendrical object to the appendable.(package private) void
setValue(DateTimeParseContext context, long value)
Stores the value.java.lang.String
toString()
(package private) NumberPrinterParser
withSubsequentWidth(int subsequentWidth)
Returns a new instance with an updated subsequent width.
-
-
-
Field Detail
-
EXCEED_POINTS
static final int[] EXCEED_POINTS
Array of 10 to the power of n.
-
rule
final DateTimeFieldRule<?> rule
The rule to output, not null.
-
minWidth
final int minWidth
The minimum width allowed, zero padding is used up to this width, from 1 to 10.
-
maxWidth
private final int maxWidth
The maximum width allowed, from 1 to 10.
-
signStyle
private final DateTimeFormatterBuilder.SignStyle signStyle
The positive/negative sign style, not null.
-
subsequentWidth
private final int subsequentWidth
The subsequent width of fixed width non-negative number fields, 0 or greater.
-
-
Constructor Detail
-
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 Detail
-
withSubsequentWidth
NumberPrinterParser withSubsequentWidth(int subsequentWidth)
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, java.lang.Appendable appendable, DateTimeFormatSymbols symbols) throws java.io.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:
java.io.IOException
- if the append throws an exception
-
getValue
int getValue(Calendrical calendrical)
Gets the value to output.- Parameters:
calendrical
- the calendrical, not null- Returns:
- the value
-
isPrintDataAvailable
public boolean isPrintDataAvailable(Calendrical calendrical)
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
public int parse(DateTimeParseContext context, java.lang.String parseText, int position)
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
void setValue(DateTimeParseContext context, long value)
Stores the value.- Parameters:
context
- the context to store into, not nullvalue
- the value
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-