Class DateTimeParseContext

java.lang.Object
javax.time.calendar.format.DateTimeParseContext

public final class DateTimeParseContext extends 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.

  • Field Details

    • 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 ArrayList<DateTimeParseContext.Parsed> calendricals
      The list of parsed data.
  • Constructor Details

    • DateTimeParseContext

      public DateTimeParseContext(DateTimeFormatSymbols symbols)
      Constructor.
      Parameters:
      symbols - the symbols to use during parsing, not null
  • Method Details

    • getLocale

      public 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 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 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, 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 null
      value - 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 null
      value - 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 a 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.

      Returns:
      a new independent merger with the parsed rule-value map, never null
    • toString

      public String toString()
      Returns a string version of the context for debugging.
      Overrides:
      toString in class Object
      Returns:
      a string representation of the context date, never null