Class InstantPatternDynamicFormatter.PatternSequence

java.lang.Object
org.apache.logging.log4j.core.util.internal.instant.InstantPatternDynamicFormatter.PatternSequence
Direct Known Subclasses:
InstantPatternDynamicFormatter.DynamicPatternSequence, InstantPatternDynamicFormatter.SecondPatternSequence, InstantPatternDynamicFormatter.StaticPatternSequence
Enclosing class:
InstantPatternDynamicFormatter

abstract static class InstantPatternDynamicFormatter.PatternSequence extends Object
  • Field Details

  • Constructor Details

    • PatternSequence

      PatternSequence(String pattern, 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:
      NullPointerException - if pattern or precision is null
      IllegalArgumentException - if pattern is not a valid DateTimeFormatter pattern
  • Method Details

    • createFormatter

      abstract InstantPatternFormatter createFormatter(Locale locale, TimeZone timeZone)
    • tryMerge

      Tries to merge two pattern sequences.

      If not

      invalid @link
      {@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
        invalid @link
        {@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(ChronoUnit thresholdPrecision)
    • escapeLiteral

      static String escapeLiteral(String literal)
    • mergePatterns

      static String mergePatterns(String left, 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 "''". invalid input: '<'/

    • equals

      public boolean equals(Object object)
      Overrides:
      equals in class Object
    • hashCode

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

      public String toString()
      Overrides:
      toString in class Object