Class DateTimeParseContext
- java.lang.Object
-
- javax.time.calendar.format.DateTimeParseContext
-
public final class DateTimeParseContext extends java.lang.Object
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
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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
DateTimeParseContext.Parsed
Temporary store of parsed data.
-
Field Summary
Fields Modifier and Type Field Description private java.util.ArrayList<DateTimeParseContext.Parsed>
calendricals
The list of parsed data.private boolean
caseSensitive
Whether to parse using case sensitively.private boolean
strict
Whether to parse using strict rules.private DateTimeFormatSymbols
symbols
The date time format symbols, not null.
-
Constructor Summary
Constructors Constructor Description DateTimeParseContext(DateTimeFormatSymbols symbols)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private DateTimeParseContext.Parsed
currentCalendrical()
Gets the currently active calendrical.void
endOptional(boolean successful)
Ends the parsing of an optional segment of the input.java.util.Locale
getLocale()
Gets the locale to use for printing and parsing text.java.lang.Object
getParsed(CalendricalRule<?> rule)
Gets the parsed value for the specified rule.java.util.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, java.lang.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 aCalendricalMerger
that can be used to interpret the results of the parse.java.lang.String
toString()
Returns a string version of the context for debugging.
-
-
-
Field Detail
-
symbols
private final DateTimeFormatSymbols symbols
The date time format symbols, not null.
-
caseSensitive
private boolean caseSensitive
Whether to parse using case sensitively.
-
strict
private boolean strict
Whether to parse using strict rules.
-
calendricals
private final java.util.ArrayList<DateTimeParseContext.Parsed> calendricals
The list of parsed data.
-
-
Constructor Detail
-
DateTimeParseContext
public DateTimeParseContext(DateTimeFormatSymbols symbols)
Constructor.- Parameters:
symbols
- the symbols to use during parsing, not null
-
-
Method Detail
-
getLocale
public java.util.Locale getLocale()
Gets the locale to use for printing and parsing text.- Returns:
- the locale, never null
-
getSymbols
public DateTimeFormatSymbols getSymbols()
Gets the formatting symbols.- Returns:
- the formatting symbols, never null
-
isCaseSensitive
public boolean isCaseSensitive()
Checks if parsing is case sensitive.- Returns:
- true if parsing is case sensitive, false if case insensitive
-
setCaseSensitive
public 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
-
isStrict
public 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
public void setStrict(boolean strict)
Sets whether parsing is strict or lenient.- Parameters:
strict
- changes the parsing to be strict or lenient from now on
-
currentCalendrical
private DateTimeParseContext.Parsed currentCalendrical()
Gets the currently active calendrical.- Returns:
- the current calendrical, never null
-
getParsed
public java.lang.Object getParsed(CalendricalRule<?> rule)
Gets the parsed value for the specified 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.
- Parameters:
rule
- the rule to query from the map, not null- Returns:
- the value mapped to the specified rule, null if rule not in the map
-
getParsedRules
public java.util.Set<CalendricalRule<?>> getParsedRules()
Gets the set of parsed rules.The set can be read and have elements removed, but nothing can be added.
- Returns:
- the set of rules previously parsed, never null
-
setParsed
public void setParsed(CalendricalRule<?> rule, java.lang.Object value)
Sets the parsed value associated with the specified rule.The value stored may be out of range for the rule and of any type - no checks are performed.
- Parameters:
rule
- the rule to set in the rule-value map, not nullvalue
- the value to set in the rule-value map, not null
-
setParsed
public void setParsed(DateTimeFieldRule<?> rule, int value)
Sets the parsed value associated with the specified rule.The value stored may be out of range for the rule - no checks are performed.
- Parameters:
rule
- the rule to set in the rule-value map, not nullvalue
- the value to set in the rule-value map
-
startOptional
public void startOptional()
Starts the parsing of an optional segment of the input.
-
endOptional
public void endOptional(boolean successful)
Ends the parsing of an optional segment of the input.- Parameters:
successful
- whether the optional segment was successfully parsed
-
toCalendricalMerger
public CalendricalMerger toCalendricalMerger()
Returns aCalendricalMerger
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.- Returns:
- a new independent merger with the parsed rule-value map, never null
-
toString
public java.lang.String toString()
Returns a string version of the context for debugging.- Overrides:
toString
in classjava.lang.Object
- Returns:
- a string representation of the context date, never null
-
-