Package javax.time.calendar.format
Class CompositePrinterParser
java.lang.Object
javax.time.calendar.format.CompositePrinterParser
- All Implemented Interfaces:
DateTimeParser
,DateTimePrinter
Composite printer and parser.
CompositePrinterParser is immutable and thread-safe.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final boolean
Whether the print and parse are optional.private final DateTimeParser[]
The list of parsers that will be used, treated as immutable.private final DateTimePrinter[]
The list of printers that will be used, treated as immutable. -
Constructor Summary
ConstructorsConstructorDescriptionCompositePrinterParser
(List<DateTimePrinter> printers, List<DateTimeParser> parsers, boolean optional) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
isPrintDataAvailable
(Calendrical calendrical) Checks if the calendrical contains the data necessary to be printed.boolean
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.toString()
withOptional
(boolean optional) Returns a copy of this printer-parser with the optional flag changed.
-
Field Details
-
printers
The list of printers that will be used, treated as immutable. -
parsers
The list of parsers that will be used, treated as immutable. -
optional
private final boolean optionalWhether the print and parse are optional.
-
-
Constructor Details
-
CompositePrinterParser
CompositePrinterParser(List<DateTimePrinter> printers, List<DateTimeParser> parsers, boolean optional) Constructor.- Parameters:
printers
- the printers, may be null in which case print() must not be calledparsers
- the parsers, may be null in which case parse() must not be calledoptional
- whether the print/parse is optional
-
-
Method Details
-
withOptional
Returns a copy of this printer-parser with the optional flag changed.- Parameters:
optional
- the optional flag to set in the copy- Returns:
- the new printer-parser, never null
-
isPrintSupported
public boolean isPrintSupported() -
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
-
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
-
isParseSupported
public boolean isParseSupported() -
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
-
toString
-