Class InstantPatternDynamicFormatter.PatternSequence

    • Field Detail

      • pattern

        final java.lang.String pattern
      • precision

        final java.time.temporal.ChronoUnit precision
    • Constructor Detail

      • PatternSequence

        PatternSequence​(java.lang.String pattern,
                        java.time.temporal.ChronoUnit precision)
        Creates a PatternSequence from a DateTimeFormatter pattern and its precision.

        Quoting invariant: every literal in pattern must be enclosed in single quotes. To include a lone apostrophe as a literal, use "''''" (open quote, escaped apostrophe '', close quote). Never use a bare "''": while syntactically valid, it becomes ambiguous at concatenation boundaries. This contract lets us merge adjacent quoted blocks in a purely context-free way (drop the left closing quote and the right opening quote).

        Examples:

        
         "yyyy-MM-dd 'at' HH:mm"    // OK: 'at' is a quoted literal
         "HH 'o''clock'"            // OK: apostrophe inside a quoted block is escaped as ''
         "yyyy''''MM"               // OK: emits a literal apostrophe between year and month
         
        Parameters:
        pattern - a DateTimeFormatter pattern with all literals fully quoted
        precision - the largest ChronoUnit interval over which the formatted output remains constant for this pattern
        Throws:
        java.lang.NullPointerException - if pattern or precision is null
        java.lang.IllegalArgumentException - if pattern is not a valid DateTimeFormatter pattern
    • Method Detail

      • createFormatter

        abstract InstantPatternFormatter createFormatter​(java.util.Locale locale,
                                                         java.util.TimeZone timeZone)
      • tryMerge

        abstract @Nullable InstantPatternDynamicFormatter.PatternSequence tryMerge​(InstantPatternDynamicFormatter.PatternSequence other,
                                                                                   java.time.temporal.ChronoUnit thresholdPrecision)
        Tries to merge two pattern sequences.

        If not {@link null}, the pattern sequence returned by this method must:

        1. Have a precision, which is the minimum of the precisions of the two merged sequences.
        2. Create formatters that are equivalent to the concatenation of the formatters produced by the two merged sequences.

        The returned pattern sequence should try to achieve these two goals:

        1. Create formatters which are faster than the concatenation of the formatters produced by the two merged sequences.
        2. It should be {@link null} if one of the pattern sequences is effectively constant over thresholdPrecision, but the other one is not.
        Parameters:
        other - A pattern sequence.
        thresholdPrecision - A precision threshold to determine effectively constant sequences. This prevents merging effectively constant and dynamic pattern sequences.
        Returns:
        A merged formatter factory or null if merging is not possible.
      • isConstantForDurationOf

        boolean isConstantForDurationOf​(java.time.temporal.ChronoUnit thresholdPrecision)
      • escapeLiteral

        static java.lang.String escapeLiteral​(java.lang.String literal)
      • mergePatterns

        static java.lang.String mergePatterns​(java.lang.String left,
                                              java.lang.String right)
        Concatenates two DateTimeFormatter pattern fragments.

        Precondition (enforced by the caller): every literal is fully quoted. Even a lone apostrophe is emitted as the quoted literal block "''''" (open quote, escaped apostrophe, and close quote). We never use a bare "''".

      • equals

        public boolean equals​(java.lang.Object object)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object