APIdia Launch Partner
Top Description Fields Constructors Methods
java.time.format

pack-priv final Class DateTimeParseContext

extends Object
Class Inheritance
Imports
java.time.ZoneId, java.time.chrono.Chronology, .IsoChronology, java.time.temporal.TemporalAccessor, .TemporalField, java.util.ArrayList, .Locale, .Objects, .Set, java.util.function.Consumer

Context 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 toUnresolved() is used to obtain the unresolved result data. The toResolved() is used to obtain the resolved result.

Implementation Specification

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

Since
1.8

Field Summary

Modifier and TypeField and Description
private boolean
caseSensitive

Whether to parse using case sensitively.

private ArrayList<Consumer<Chronology>>
chronoListeners

List of Consumers<Chronology> to be notified if the Chronology changes.

private DateTimeFormatter
formatter

The formatter, not null.

private final ArrayList<Parsed>
parsed

The list of parsed data.

private boolean
strict

Whether to parse using strict rules.

Constructor Summary

AccessConstructor and Description
pack-priv
DateTimeParseContext(DateTimeFormatter
the formatter controlling the parse, not null
formatter
)

Creates a new instance of the context.

Method Summary

Modifier and TypeMethod and Description
pack-priv void
addChronoChangedListener(Consumer<Chronology>
a Consumer<Chronology> to be called when Chronology changes
listener
)

Adds a Consumer<Chronology> to the list of listeners to be notified if the Chronology changes.

pack-priv boolean

Returns:

true if equal
charEquals
(char
the first character
ch1
,
char
the second character
ch2
)

Helper to compare two char.

pack-priv static boolean

Returns:

true if equal
charEqualsIgnoreCase
(char
the first
c1
,
char
the second
c2
)

Compares two characters ignoring case.

pack-priv DateTimeParseContext
copy()

Creates a copy of this context.

private Parsed

Returns:

the current temporal objects, not null
currentParsed
()

Gets the currently active temporal objects.

pack-priv void
endOptional(boolean
whether the optional segment was successfully parsed
successful
)

Ends the parsing of an optional segment of the input.

pack-priv DecimalStyle

Returns:

the DecimalStyle, not null
getDecimalStyle
()

Gets the DecimalStyle.

pack-priv Chronology

Returns:

the effective parsing chronology, not null
getEffectiveChronology
()

Gets the effective chronology during parsing.

pack-priv Locale

Returns:

the locale, not null
getLocale
()

Gets the locale.

pack-priv Long

Returns:

the value mapped to the specified field, null if field was not parsed
getParsed
(TemporalField
the field to query from the map, null returns null
field
)

Gets the first value that was parsed for the specified field.

pack-priv boolean

Returns:

true if parsing is case sensitive, false if case insensitive
isCaseSensitive
()

Checks if parsing is case sensitive.

pack-priv boolean

Returns:

true if parsing is strict, false if lenient
isStrict
()

Checks if parsing is strict.

pack-priv void
setCaseSensitive(boolean
changes the parsing to be case sensitive or not from now on
caseSensitive
)

Sets whether the parsing is case sensitive or not.

pack-priv void
setParsed(Chronology
the parsed chronology, not null
chrono
)

Stores the parsed chronology.

pack-priv void
setParsed(ZoneId
the parsed zone, not null
zone
)

Stores the parsed zone.

pack-priv void
setParsedDayPeriod(DateTimeFormatterBuilder.DayPeriod
the parsed day period
dayPeriod
)

Stores the parsed day period.

pack-priv int

Returns:

the new position
setParsedField
(TemporalField
the field to set in the field-value map, not null
field
,
long
the value to set in the field-value map
value
,
int
the position of the field being parsed
errorPos
,
int
the position after the field being parsed
successPos
)

Stores the parsed field.

pack-priv void
setParsedLeapSecond()

Stores the parsed leap second.

pack-priv void
setParsedZoneNameType(int
the parsed zone name type
type
)

Stores the parsed zone name type.

pack-priv void
setStrict(boolean
changes the parsing to be strict or lenient from now on
strict
)

Sets whether parsing is strict or lenient.

pack-priv void
startOptional()

Starts the parsing of an optional segment of the input.

pack-priv boolean

Returns:

true if equal
subSequenceEquals
(CharSequence
the first character sequence, not null
cs1
,
int
the offset into the first sequence, valid
offset1
,
CharSequence
the second character sequence, not null
cs2
,
int
the offset into the second sequence, valid
offset2
,
int
the length to check, valid
length
)

Helper to compare two CharSequence instances.

pack-priv TemporalAccessor

Returns:

the result of the parse, not null
toResolved
(ResolverStyle resolverStyle, Set<TemporalField> resolverFields)

Gets the resolved result of the parse.

public String

Returns:

a string representation of the context data, not null
toString
()

Overrides java.lang.Object.toString.

Returns a string version of the context for debugging.

pack-priv Parsed

Returns:

the result of the parse, not null
toUnresolved
()

Gets the unresolved result of the parse.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

caseSensitiveback to summary
private boolean caseSensitive

Whether to parse using case sensitively.

chronoListenersback to summary
private ArrayList<Consumer<Chronology>> chronoListeners

List of Consumers<Chronology> to be notified if the Chronology changes.

formatterback to summary
private DateTimeFormatter formatter

The formatter, not null.

parsedback to summary
private final ArrayList<Parsed> parsed

The list of parsed data.

strictback to summary
private boolean strict

Whether to parse using strict rules.

Constructor Detail

DateTimeParseContextback to summary
pack-priv DateTimeParseContext(DateTimeFormatter formatter)

Creates a new instance of the context.

Parameters
formatter:DateTimeFormatter

the formatter controlling the parse, not null

Method Detail

addChronoChangedListenerback to summary
pack-priv void addChronoChangedListener(Consumer<Chronology> listener)

Adds a Consumer<Chronology> to the list of listeners to be notified if the Chronology changes.

Parameters
listener:Consumer<Chronology>

a Consumer<Chronology> to be called when Chronology changes

charEqualsback to summary
pack-priv boolean charEquals(char ch1, char ch2)

Helper to compare two char. This uses isCaseSensitive().

Parameters
ch1:char

the first character

ch2:char

the second character

Returns:boolean

true if equal

charEqualsIgnoreCaseback to summary
pack-priv static boolean charEqualsIgnoreCase(char c1, char c2)

Compares two characters ignoring case.

Parameters
c1:char

the first

c2:char

the second

Returns:boolean

true if equal

copyback to summary
pack-priv DateTimeParseContext copy()

Creates a copy of this context. This retains the case sensitive and strict flags.

currentParsedback to summary
private Parsed currentParsed()

Gets the currently active temporal objects.

Returns:Parsed

the current temporal objects, not null

endOptionalback to summary
pack-priv void endOptional(boolean successful)

Ends the parsing of an optional segment of the input.

Parameters
successful:boolean

whether the optional segment was successfully parsed

getDecimalStyleback to summary
pack-priv DecimalStyle getDecimalStyle()

Gets the DecimalStyle.

The DecimalStyle controls the numeric parsing.

Returns:DecimalStyle

the DecimalStyle, not null

getEffectiveChronologyback to summary
pack-priv Chronology getEffectiveChronology()

Gets the effective chronology during parsing.

Returns:Chronology

the effective parsing chronology, not null

getLocaleback to summary
pack-priv Locale getLocale()

Gets the locale.

This locale is used to control localization in the parse except where localization is controlled by the DecimalStyle.

Returns:Locale

the locale, not null

getParsedback to summary
pack-priv 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:TemporalField

the field to query from the map, null returns null

Returns:Long

the value mapped to the specified field, null if field was not parsed

isCaseSensitiveback to summary
pack-priv boolean isCaseSensitive()

Checks if parsing is case sensitive.

Returns:boolean

true if parsing is case sensitive, false if case insensitive

isStrictback to summary
pack-priv boolean isStrict()

Checks if parsing is strict.

Strict parsing requires exact matching of the text and sign styles.

Returns:boolean

true if parsing is strict, false if lenient

setCaseSensitiveback to summary
pack-priv void setCaseSensitive(boolean caseSensitive)

Sets whether the parsing is case sensitive or not.

Parameters
caseSensitive:boolean

changes the parsing to be case sensitive or not from now on

setParsedback to summary
pack-priv 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.

The list of listeners is copied and cleared so that each listener is called only once. A listener can add itself again if it needs to be notified of future changes.

Parameters
chrono:Chronology

the parsed chronology, not null

setParsedback to summary
pack-priv 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:ZoneId

the parsed zone, not null

setParsedDayPeriodback to summary
pack-priv void setParsedDayPeriod(DateTimeFormatterBuilder.DayPeriod dayPeriod)

Stores the parsed day period.

Parameters
dayPeriod:DateTimeFormatterBuilder.DayPeriod

the parsed day period

setParsedFieldback to summary
pack-priv 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:TemporalField

the field to set in the field-value map, not null

value:long

the value to set in the field-value map

errorPos:int

the position of the field being parsed

successPos:int

the position after the field being parsed

Returns:int

the new position

setParsedLeapSecondback to summary
pack-priv void setParsedLeapSecond()

Stores the parsed leap second.

setParsedZoneNameTypeback to summary
pack-priv void setParsedZoneNameType(int type)

Stores the parsed zone name type.

This stores the zone name type that has been parsed. The parsed type should either be;

Parameters
type:int

the parsed zone name type

setStrictback to summary
pack-priv void setStrict(boolean strict)

Sets whether parsing is strict or lenient.

Parameters
strict:boolean

changes the parsing to be strict or lenient from now on

startOptionalback to summary
pack-priv void startOptional()

Starts the parsing of an optional segment of the input.

subSequenceEqualsback to summary
pack-priv boolean subSequenceEquals(CharSequence cs1, int offset1, CharSequence cs2, int offset2, int length)

Helper to compare two CharSequence instances. This uses isCaseSensitive().

Parameters
cs1:CharSequence

the first character sequence, not null

offset1:int

the offset into the first sequence, valid

cs2:CharSequence

the second character sequence, not null

offset2:int

the offset into the second sequence, valid

length:int

the length to check, valid

Returns:boolean

true if equal

toResolvedback to summary
pack-priv TemporalAccessor toResolved(ResolverStyle resolverStyle, Set<TemporalField> resolverFields)

Gets the resolved result of the parse.

Returns:TemporalAccessor

the result of the parse, not null

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string version of the context for debugging.

Returns:String

a string representation of the context data, not null

Annotations
@Override
toUnresolvedback to summary
pack-priv Parsed toUnresolved()

Gets the unresolved result of the parse.

Returns:Parsed

the result of the parse, not null