Class DateTimeParseContext
- java.lang.Object
-
- org.threeten.bp.format.DateTimeParseContext
-
final class DateTimeParseContext extends java.lang.ObjectContext object used during date and time parsing.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 Classes Modifier and Type Class Description (package private) classDateTimeParseContext.ParsedTemporary store of parsed data.
-
Field Summary
Fields Modifier and Type Field Description private booleancaseSensitiveWhether to parse using case sensitively.private java.util.LocalelocaleThe locale, not null.private ChronologyoverrideChronologyThe override chronology.private ZoneIdoverrideZoneThe override zone.private java.util.ArrayList<DateTimeParseContext.Parsed>parsedThe list of parsed data.private booleanstrictWhether to parse using strict rules.private DecimalStylesymbolsThe symbols, not null.
-
Constructor Summary
Constructors Constructor Description DateTimeParseContext(java.util.Locale locale, DecimalStyle symbols, Chronology chronology)DateTimeParseContext(DateTimeFormatter formatter)Creates a new instance of the context.DateTimeParseContext(DateTimeParseContext other)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (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.ParsedcurrentParsed()Gets the currently active temporal objects.(package private) voidendOptional(boolean successful)Ends the parsing of an optional segment of the input.(package private) ChronologygetEffectiveChronology()Gets the effective chronology during parsing.(package private) java.util.LocalegetLocale()Gets the locale.(package private) java.lang.LonggetParsed(TemporalField field)Gets the first value that was parsed for the specified field.(package private) DecimalStylegetSymbols()Gets the formatting symbols.(package private) booleanisCaseSensitive()Checks 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) voidsetLocale(java.util.Locale locale)Sets the locale.(package private) voidsetParsed(Chronology chrono)Stores the parsed chronology.(package private) voidsetParsed(ZoneId zone)Stores the parsed zone.(package private) intsetParsedField(TemporalField field, long value, int errorPos, int successPos)Stores the parsed field.(package private) voidsetParsedLeapSecond()Stores the leap second.(package private) voidsetStrict(boolean strict)Sets whether parsing is strict or lenient.(package private) voidstartOptional()Starts the parsing of an optional segment of the input.(package private) booleansubSequenceEquals(java.lang.CharSequence cs1, int offset1, java.lang.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.java.lang.StringtoString()Returns a string version of the context for debugging.
-
-
-
Field Detail
-
locale
private java.util.Locale locale
The locale, not null.
-
symbols
private DecimalStyle symbols
The symbols, not null.
-
overrideChronology
private Chronology overrideChronology
The override chronology.
-
overrideZone
private ZoneId overrideZone
The override zone.
-
caseSensitive
private boolean caseSensitive
Whether to parse using case sensitively.
-
strict
private boolean strict
Whether to parse using strict rules.
-
parsed
private final java.util.ArrayList<DateTimeParseContext.Parsed> parsed
The list of parsed data.
-
-
Constructor Detail
-
DateTimeParseContext
DateTimeParseContext(DateTimeFormatter formatter)
Creates a new instance of the context.- Parameters:
formatter- the formatter controlling the parse, not null
-
DateTimeParseContext
DateTimeParseContext(java.util.Locale locale, DecimalStyle symbols, Chronology chronology)
-
DateTimeParseContext
DateTimeParseContext(DateTimeParseContext other)
-
-
Method Detail
-
copy
DateTimeParseContext copy()
Creates a copy of this context.
-
getLocale
java.util.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
boolean subSequenceEquals(java.lang.CharSequence cs1, int offset1, java.lang.CharSequence cs2, int offset2, int length)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
private DateTimeParseContext.Parsed currentParsed()
Gets the currently active temporal objects.- Returns:
- the current temporal objects, not null
-
getParsed
java.lang.Long getParsed(TemporalField field)
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
int setParsedField(TemporalField field, long value, int errorPos, int successPos)
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
void setParsed(Chronology chrono)
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
void setParsed(ZoneId zone)
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
public java.lang.String toString()
Returns a string version of the context for debugging.- Overrides:
toStringin classjava.lang.Object- Returns:
- a string representation of the context data, not null
-
setLocale
void setLocale(java.util.Locale locale)
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
-
-