Class DateTimeParseContext


  • 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 #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
    • 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.
    • 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)
    • Method Detail

      • 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 two CharSequence instances. This uses isCaseSensitive().
        Parameters:
        cs1 - the first character sequence, not null
        offset1 - the offset into the first sequence, valid
        cs2 - the second character sequence, not null
        offset2 - the offset into the second sequence, valid
        length - the length to check, valid
        Returns:
        true if equal
      • charEquals

        boolean charEquals​(char ch1,
                           char ch2)
        Helper to compare two char. This uses isCaseSensitive().
        Parameters:
        ch1 - the first character
        ch2 - the second character
        Returns:
        true if equal
      • charEqualsIgnoreCase

        static boolean charEqualsIgnoreCase​(char c1,
                                            char c2)
        Compares two characters ignoring case.
        Parameters:
        c1 - the first
        c2 - 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 null
        value - the value to set in the field-value map
        errorPos - the position of the field being parsed
        successPos - 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
      • 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 a TemporalAccessor that 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:
        toString in class java.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