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 java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description PatternSequence(java.lang.String pattern, java.time.temporal.ChronoUnit precision)Creates aPatternSequencefrom aDateTimeFormatterpattern and its precision.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description (package private) abstract InstantPatternFormattercreateFormatter(java.util.Locale locale, java.util.TimeZone timeZone)booleanequals(java.lang.Object object)(package private) static java.lang.StringescapeLiteral(java.lang.String literal)inthashCode()(package private) booleanisConstantForDurationOf(java.time.temporal.ChronoUnit thresholdPrecision)(package private) static java.lang.StringmergePatterns(java.lang.String left, java.lang.String right)Concatenates two DateTimeFormatter pattern fragments.java.lang.StringtoString()(package private) abstract @Nullable InstantPatternDynamicFormatter.PatternSequencetryMerge(InstantPatternDynamicFormatter.PatternSequence other, java.time.temporal.ChronoUnit thresholdPrecision)Tries to merge two pattern sequences.
-
-
-
Constructor Detail
-
PatternSequence
PatternSequence(java.lang.String pattern, java.time.temporal.ChronoUnit precision)Creates aPatternSequencefrom aDateTimeFormatterpattern and its precision.Quoting invariant: every literal in
patternmust 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 quotedprecision- the largestChronoUnitinterval over which the formatted output remains constant for this pattern- Throws:
java.lang.NullPointerException- ifpatternorprecisionisnulljava.lang.IllegalArgumentException- ifpatternis not a validDateTimeFormatterpattern
-
-
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:
- Have a
precision, which is the minimum of the precisions of the two merged sequences. - 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:
- Create formatters which are faster than the concatenation of the formatters produced by the two merged sequences.
-
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
nullif merging is not possible.
- Have a
-
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:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-