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
Modifier and TypeClassDescriptionstatic class
Represents one option in aMessageFmt.ChoiceArgumentSegment
. -
Constructor Summary
ConstructorDescriptionChoiceArgumentSegment
(int argumentNumber, ChoiceFormat format) Create an instance modeling the givenChoiceFormat
.ChoiceArgumentSegment
(int argumentNumber, MessageFmt.ChoiceArgumentSegment.Option... options) Create an instance from explicitly givenMessageFmt.ChoiceArgumentSegment.Option
s. -
Method Summary
Modifier and TypeMethodDescriptionboolean
protected String
Get theMessageFormat
pattern string argument suffix, if any.@NotNull @Size(min=1) @Valid List<@NotNull MessageFmt.ChoiceArgumentSegment.Option>
Get the possible options.int
hashCode()
void
Build theChoiceFormat
represented by this instance.toString()
void
visit
(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
of
Methods 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.Option
s.- Parameters:
argumentNumber
- the index of the argument formatted by this segmentoptions
- choice options- Throws:
IllegalArgumentException
- ifoptions
or any element thereof is null
-
ChoiceArgumentSegment
Create an instance modeling the givenChoiceFormat
.- Parameters:
argumentNumber
- argument numberformat
- source format- Throws:
IllegalArgumentException
- ifformat
is 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 theChoiceFormat
represented by this instance.- Returns:
- an equivalent
ChoiceFormat
-
getArgumentSuffix
Description copied from class:MessageFmt.ArgumentSegment
Get theMessageFormat
pattern string argument suffix, if any.If present, this suffix follows the argument number and a comma, and precedes the closing curly brace.
- Specified by:
getArgumentSuffix
in classMessageFmt.ArgumentSegment
- Returns:
- pattern string argument suffix, or null if none needed
-
visit
Description copied from class:MessageFmt.Segment
Visit the method of the given switch corresponding to this instance's concrete type.- Specified by:
visit
in classMessageFmt.Segment
- Parameters:
target
- visitor pattern target
-
equals
- Overrides:
equals
in classMessageFmt.ArgumentSegment
-
hashCode
public int hashCode()- Overrides:
hashCode
in classMessageFmt.ArgumentSegment
-
toString
- Overrides:
toString
in classMessageFmt.ArgumentSegment
-