Class DateTimeParseContext
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 #toBuilder() is typically used
to obtain a builder that can combine the separate parsed fields into meaningful values.
Specification for implementors
This class is a mutable context intended for use from a single thread. Usage of the class is thread-safe within standard parsing as a new instance of this class is automatically created for each parse and parsing is single-threaded-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) final classTemporary store of parsed data. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanWhether to parse using case sensitively.private LocaleThe locale, not null.private ChronologyThe override chronology.private ZoneIdThe override zone.private final ArrayList<DateTimeParseContext.Parsed>The list of parsed data.private booleanWhether to parse using strict rules.private DecimalStyleThe symbols, not null. -
Constructor Summary
ConstructorsConstructorDescriptionDateTimeParseContext(Locale locale, DecimalStyle symbols, Chronology chronology) DateTimeParseContext(DateTimeFormatter formatter) Creates a new instance of the context. -
Method Summary
Modifier and TypeMethodDescription(package private) voidaddChronologyChangedParser(DateTimeFormatterBuilder.ReducedPrinterParser reducedPrinterParser, long value, int errorPos, int successPos) (package private) booleancharEquals(char ch1, char ch2) Helper to compare twochar.(package private) static booleancharEqualsIgnoreCase(char c1, char c2) Compares two characters ignoring case.(package private) DateTimeParseContextcopy()Creates a copy of this context.private DateTimeParseContext.ParsedGets the currently active temporal objects.(package private) voidendOptional(boolean successful) Ends the parsing of an optional segment of the input.(package private) ChronologyGets the effective chronology during parsing.(package private) LocaleGets the locale.(package private) LonggetParsed(TemporalField field) Gets the first value that was parsed for the specified field.(package private) DecimalStyleGets the formatting symbols.(package private) booleanChecks if parsing is case sensitive.(package private) booleanisStrict()Checks if parsing is strict.(package private) voidsetCaseSensitive(boolean caseSensitive) Sets whether the parsing is case sensitive or not.(package private) voidSets the locale.(package private) voidsetParsed(Chronology chrono) Stores the parsed chronology.(package private) voidStores the parsed zone.(package private) intsetParsedField(TemporalField field, long value, int errorPos, int successPos) Stores the parsed field.(package private) voidStores the leap second.(package private) voidsetStrict(boolean strict) Sets whether parsing is strict or lenient.(package private) voidStarts the parsing of an optional segment of the input.(package private) booleansubSequenceEquals(CharSequence cs1, int offset1, CharSequence cs2, int offset2, int length) Helper to compare twoCharSequenceinstances.(package private) DateTimeParseContext.ParsedtoParsed()Returns aTemporalAccessorthat can be used to interpret the results of the parse.toString()Returns a string version of the context for debugging.
-
Field Details
-
locale
The locale, not null. -
symbols
The symbols, not null. -
overrideChronology
The override chronology. -
overrideZone
The override zone. -
caseSensitive
private boolean caseSensitiveWhether to parse using case sensitively. -
strict
private boolean strictWhether to parse using strict rules. -
parsed
The list of parsed data.
-
-
Constructor Details
-
DateTimeParseContext
DateTimeParseContext(DateTimeFormatter formatter) Creates a new instance of the context.- Parameters:
formatter- the formatter controlling the parse, not null
-
DateTimeParseContext
DateTimeParseContext(Locale locale, DecimalStyle symbols, Chronology chronology) -
DateTimeParseContext
DateTimeParseContext(DateTimeParseContext other)
-
-
Method Details
-
copy
DateTimeParseContext copy()Creates a copy of this context. -
getLocale
Locale getLocale()Gets the locale.This locale is used to control localization in the parse except where localization is controlled by the symbols.
- Returns:
- the locale, not null
-
getSymbols
DecimalStyle getSymbols()Gets the formatting symbols.The symbols control the localization of numeric parsing.
- Returns:
- the formatting symbols, not null
-
getEffectiveChronology
Chronology getEffectiveChronology()Gets the effective chronology during parsing.- Returns:
- the effective parsing chronology, not null
-
isCaseSensitive
boolean isCaseSensitive()Checks if parsing is case sensitive.- Returns:
- true if parsing is case sensitive, false if case insensitive
-
setCaseSensitive
void setCaseSensitive(boolean caseSensitive) Sets whether the parsing is case sensitive or not.- Parameters:
caseSensitive- changes the parsing to be case sensitive or not from now on
-
subSequenceEquals
Helper to compare twoCharSequenceinstances. This usesisCaseSensitive().- Parameters:
cs1- the first character sequence, not nulloffset1- the offset into the first sequence, validcs2- the second character sequence, not nulloffset2- the offset into the second sequence, validlength- the length to check, valid- Returns:
- true if equal
-
charEquals
boolean charEquals(char ch1, char ch2) Helper to compare twochar. This usesisCaseSensitive().- Parameters:
ch1- the first characterch2- the second character- Returns:
- true if equal
-
charEqualsIgnoreCase
static boolean charEqualsIgnoreCase(char c1, char c2) Compares two characters ignoring case.- Parameters:
c1- the firstc2- the second- Returns:
- true if equal
-
isStrict
boolean isStrict()Checks if parsing is strict.Strict parsing requires exact matching of the text and sign styles.
- Returns:
- true if parsing is strict, false if lenient
-
setStrict
void setStrict(boolean strict) Sets whether parsing is strict or lenient.- Parameters:
strict- changes the parsing to be strict or lenient from now on
-
startOptional
void startOptional()Starts the parsing of an optional segment of the input. -
endOptional
void endOptional(boolean successful) Ends the parsing of an optional segment of the input.- Parameters:
successful- whether the optional segment was successfully parsed
-
currentParsed
Gets the currently active temporal objects.- Returns:
- the current temporal objects, not null
-
getParsed
Gets the first value that was parsed for the specified field.This searches the results of the parse, returning the first value found for the specified field. No attempt is made to derive a value. The field may have an out of range value. For example, the day-of-month might be set to 50, or the hour to 1000.
- Parameters:
field- the field to query from the map, null returns null- Returns:
- the value mapped to the specified field, null if field was not parsed
-
setParsedField
Stores the parsed field.This stores a field-value pair that has been parsed. The value stored may be out of range for the field - no checks are performed.
- Parameters:
field- the field to set in the field-value map, not nullvalue- the value to set in the field-value maperrorPos- the position of the field being parsedsuccessPos- the position after the field being parsed- Returns:
- the new position
-
setParsed
Stores the parsed chronology.This stores the chronology that has been parsed. No validation is performed other than ensuring it is not null.
- Parameters:
chrono- the parsed chronology, not null
-
addChronologyChangedParser
void addChronologyChangedParser(DateTimeFormatterBuilder.ReducedPrinterParser reducedPrinterParser, long value, int errorPos, int successPos) -
setParsed
Stores the parsed zone.This stores the zone that has been parsed. No validation is performed other than ensuring it is not null.
- Parameters:
zone- the parsed zone, not null
-
setParsedLeapSecond
void setParsedLeapSecond()Stores the leap second. -
toParsed
DateTimeParseContext.Parsed toParsed()Returns aTemporalAccessorthat can be used to interpret the results of the parse.- Returns:
- an accessor with the results of the parse, not null
-
toString
Returns a string version of the context for debugging. -
setLocale
Sets the locale.This locale is used to control localization in the print output except where localization is controlled by the symbols.
- Parameters:
locale- the locale, not null
-