Class InstantPatternDynamicFormatter.PatternSequence
- Direct Known Subclasses:
InstantPatternDynamicFormatter.DynamicPatternSequence,InstantPatternDynamicFormatter.SecondPatternSequence,InstantPatternDynamicFormatter.StaticPatternSequence
- Enclosing class:
InstantPatternDynamicFormatter
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) final String(package private) final ChronoUnit -
Constructor Summary
ConstructorsConstructorDescriptionPatternSequence(String pattern, ChronoUnit precision) Creates aPatternSequencefrom aDateTimeFormatterpattern and its precision. -
Method Summary
Modifier and TypeMethodDescription(package private) abstract InstantPatternFormattercreateFormatter(Locale locale, TimeZone timeZone) boolean(package private) static StringescapeLiteral(String literal) inthashCode()(package private) booleanisConstantForDurationOf(ChronoUnit thresholdPrecision) (package private) static StringmergePatterns(String left, String right) Concatenates two DateTimeFormatter pattern fragments.toString()(package private) abstract @Nullable InstantPatternDynamicFormatter.PatternSequencetryMerge(InstantPatternDynamicFormatter.PatternSequence other, ChronoUnit thresholdPrecision) Tries to merge two pattern sequences.
-
Field Details
-
pattern
-
precision
-
-
Constructor Details
-
PatternSequence
PatternSequence(String pattern, 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:
NullPointerException- ifpatternorprecisionisnullIllegalArgumentException- ifpatternis not a validDateTimeFormatterpattern
-
-
Method Details
-
createFormatter
-
tryMerge
abstract @Nullable InstantPatternDynamicFormatter.PatternSequence tryMerge(InstantPatternDynamicFormatter.PatternSequence other, ChronoUnit thresholdPrecision) Tries to merge two pattern sequences.If not
}, the pattern sequence returned by this method must:invalid @link
{@link null- 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
} if one of the pattern sequences is effectively constant over
invalid @link
{@link nullthresholdPrecision, 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
-
escapeLiteral
-
mergePatterns
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
-
hashCode
public int hashCode() -
toString
-