Class MessageFmt.ChoiceArgumentSegment
- Enclosing class:
- MessageFmt
MessageFmt.ArgumentSegment that formats its argument using a ChoiceFormat.
When a MessageFormat executes a nested ChoiceFormat, if the resulting string contains a '{'
then the string is recursively interpreted again as a MessageFormat pattern. Therefore, the semantics
of a ChoiceFormat differ when treated standalone vs. nested in a MessageFormat.
This class models the latter scenario. Each option of the choice is modeled as a new, nested MessageFormat
(see MessageFmt.ChoiceArgumentSegment.Option) regardless of whether '{' appeared in the original pattern for the
choice. This simplifies the model but also means that if the original choice pattern didn't contain '{', then
the MessageFormat modeling that choice will have escaping applied to its format string,
preserving the net effect.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents one option in aMessageFmt.ChoiceArgumentSegment. -
Constructor Summary
ConstructorsConstructorDescriptionChoiceArgumentSegment(int argumentNumber, ChoiceFormat format) Create an instance modeling the givenChoiceFormat.ChoiceArgumentSegment(int argumentNumber, MessageFmt.ChoiceArgumentSegment.Option... options) Create an instance from explicitly givenMessageFmt.ChoiceArgumentSegment.Options. -
Method Summary
Modifier and TypeMethodDescriptionbooleanprotected StringGet theMessageFormatpattern string argument suffix, if any.@NotNull @Size(min=1) @Valid List<@NotNull MessageFmt.ChoiceArgumentSegment.Option>Get the possible options.inthashCode()voidBuild theChoiceFormatrepresented by this instance.toString()voidvisit(MessageFmt.SegmentSwitch target) Visit the method of the given switch corresponding to this instance's concrete type.Methods inherited from class org.dellroad.stuff.text.MessageFmt.FormatArgumentSegment
ofMethods inherited from class org.dellroad.stuff.text.MessageFmt.ArgumentSegment
getArgumentNumber, setArgumentNumber, toPattern
-
Constructor Details
-
ChoiceArgumentSegment
public ChoiceArgumentSegment() -
ChoiceArgumentSegment
public ChoiceArgumentSegment(int argumentNumber, MessageFmt.ChoiceArgumentSegment.Option... options) Create an instance from explicitly givenMessageFmt.ChoiceArgumentSegment.Options.- Parameters:
argumentNumber- the index of the argument formatted by this segmentoptions- choice options- Throws:
IllegalArgumentException- ifoptionsor any element thereof is null
-
ChoiceArgumentSegment
Create an instance modeling the givenChoiceFormat.- Parameters:
argumentNumber- argument numberformat- source format- Throws:
IllegalArgumentException- ifformatis null- See Also:
-
-
Method Details
-
getOptions
@NotNull @Size(min=1) @Valid public @NotNull @Size(min=1) @Valid List<@NotNull MessageFmt.ChoiceArgumentSegment.Option> getOptions()Get the possible options.- Returns:
- options for choice
-
setOptions
-
toChoiceFormat
Build theChoiceFormatrepresented by this instance.- Returns:
- an equivalent
ChoiceFormat
-
getArgumentSuffix
Description copied from class:MessageFmt.ArgumentSegmentGet theMessageFormatpattern string argument suffix, if any.If present, this suffix follows the argument number and a comma, and precedes the closing curly brace.
- Specified by:
getArgumentSuffixin classMessageFmt.ArgumentSegment- Returns:
- pattern string argument suffix, or null if none needed
-
visit
Description copied from class:MessageFmt.SegmentVisit the method of the given switch corresponding to this instance's concrete type.- Specified by:
visitin classMessageFmt.Segment- Parameters:
target- visitor pattern target
-
equals
- Overrides:
equalsin classMessageFmt.ArgumentSegment
-
hashCode
public int hashCode()- Overrides:
hashCodein classMessageFmt.ArgumentSegment
-
toString
- Overrides:
toStringin classMessageFmt.ArgumentSegment
-