public final class DateTimeParseContext extends Object
This class represents the current state of the parse. It has the ability to store and retrieve the parsed values and manage optional segments. It also provides key information to the parsing methods.
Once parsing is complete, the toCalendricalMerger()
is typically used
to obtain a merger that will merge the separate parsed fields into meaningful values.
This class is mutable and thus not thread-safe. Usage of the class is thread-safe within the Time Framework for Java as the framework creates a new instance of the class for each parse.
Constructor and Description |
---|
DateTimeParseContext(DateTimeFormatSymbols symbols)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
endOptional(boolean successful)
Ends the parsing of an optional segment of the input.
|
Locale |
getLocale()
Gets the locale to use for printing and parsing text.
|
Object |
getParsed(CalendricalRule<?> rule)
Gets the parsed value for the specified rule.
|
Set<CalendricalRule<?>> |
getParsedRules()
Gets the set of parsed rules.
|
DateTimeFormatSymbols |
getSymbols()
Gets the formatting symbols.
|
boolean |
isCaseSensitive()
Checks if parsing is case sensitive.
|
boolean |
isStrict()
Checks if parsing is strict.
|
void |
setCaseSensitive(boolean caseSensitive)
Sets whether the parsing is case sensitive or not.
|
void |
setParsed(CalendricalRule<?> rule,
Object value)
Sets the parsed value associated with the specified rule.
|
void |
setParsed(DateTimeFieldRule<?> rule,
int value)
Sets the parsed value associated with the specified rule.
|
void |
setStrict(boolean strict)
Sets whether parsing is strict or lenient.
|
void |
startOptional()
Starts the parsing of an optional segment of the input.
|
CalendricalMerger |
toCalendricalMerger()
Returns a
CalendricalMerger that can be used to interpret
the results of the parse. |
String |
toString()
Returns a string version of the context for debugging.
|
public DateTimeParseContext(DateTimeFormatSymbols symbols)
symbols
- the symbols to use during parsing, not nullpublic Locale getLocale()
public DateTimeFormatSymbols getSymbols()
public boolean isCaseSensitive()
public void setCaseSensitive(boolean caseSensitive)
caseSensitive
- changes the parsing to be case sensitive or not from now onpublic boolean isStrict()
Strict parsing requires exact matching of the text and sign styles.
public void setStrict(boolean strict)
strict
- changes the parsing to be strict or lenient from now onpublic Object getParsed(CalendricalRule<?> rule)
The value returned is directly obtained from the stored map of values. It may be of any type and any value. For example, the day-of-month might be set to 50, or the hour to 1000.
rule
- the rule to query from the map, not nullpublic Set<CalendricalRule<?>> getParsedRules()
The set can be read and have elements removed, but nothing can be added.
public void setParsed(CalendricalRule<?> rule, Object value)
The value stored may be out of range for the rule and of any type - no checks are performed.
rule
- the rule to set in the rule-value map, not nullvalue
- the value to set in the rule-value map, not nullpublic void setParsed(DateTimeFieldRule<?> rule, int value)
The value stored may be out of range for the rule - no checks are performed.
rule
- the rule to set in the rule-value map, not nullvalue
- the value to set in the rule-value mappublic void startOptional()
public void endOptional(boolean successful)
successful
- whether the optional segment was successfully parsedpublic CalendricalMerger toCalendricalMerger()
CalendricalMerger
that can be used to interpret
the results of the parse.
This method is typically used once parsing is complete to obtain the parsed data.
Parsing will typically result in separate fields, such as year, month and day.
The returned merger can be used to combine the parsed data into meaningful
objects such as LocalDate
, potentially applying complex processing
to handle invalid parsed data.
Copyright © 2014. All rights reserved.