Factory methods throw exceptions for syntax errors and for too few or too many arguments/placeholders.
SimpleFormatter objects are immutable and can be safely cached like strings.
Example:
SimpleFormatter fmt = SimpleFormatter.compile("{1} '{born}' in {0}");
// Output: "paul {born} in england"
System.out.println(fmt.format("england", "paul"));
MessageFormat, MessagePattern.ApostropheMode
| Modifier and Type | Field and Description |
|---|---|
| private final String | compiledPattern
Binary representation of the compiled pattern. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static SimpleFormatter | Returns: The new SimpleFormatter object.The pattern string. pattern)Creates a formatter from the pattern string. |
| public static SimpleFormatter | Returns: The new SimpleFormatter object.The pattern string. pattern, int The pattern must have at least this many arguments. min, int The pattern must have at most this many arguments. max)Creates a formatter from the pattern string. |
| public String | |
| public StringBuilder | Returns: appendToGets the formatted pattern and values appended. appendTo, int[] offsets[i] receives the offset of where
values[i] replaced pattern argument {i}.
Can be null, or can be shorter or longer than values.
If there is no {i} in the pattern, then offsets[i] is set to -1. offsets, CharSequence... The argument values.
An argument value must not be the same object as appendTo.
values.length must be at least getArgumentLimit().
Can be null if getArgumentLimit()==0. values)Formats the given values, appending to the appendTo builder. |
| public StringBuilder | Returns: resultGets its contents replaced by the formatted pattern and values. result, int[] offsets[i] receives the offset of where
values[i] replaced pattern argument {i}.
Can be null, or can be shorter or longer than values.
If there is no {i} in the pattern, then offsets[i] is set to -1. offsets, CharSequence... The argument values.
An argument value may be the same object as result.
values.length must be at least getArgumentLimit(). values)Formats the given values, replacing the contents of the result builder. |
| public int | |
| public String | |
| public String | toString()
Overrides java. |
| compiledPattern | back to summary |
|---|---|
| private final String compiledPattern Binary representation of the compiled pattern.
| |
| SimpleFormatter | back to summary |
|---|---|
| private SimpleFormatter(String compiledPattern) | |
| compile | back to summary |
|---|---|
| public static SimpleFormatter compile(CharSequence pattern) Creates a formatter from the pattern string.
| |
| compileMinMaxArguments | back to summary |
|---|---|
| public static SimpleFormatter compileMinMaxArguments(CharSequence pattern, int min, int max) Creates a formatter from the pattern string. The number of arguments checked against the given limits is the highest argument number plus one, not the number of occurrences of arguments.
| |
| format | back to summary |
|---|---|
| public String format(CharSequence... values) Formats the given values.
| |
| formatAndAppend | back to summary |
|---|---|
| public StringBuilder formatAndAppend(StringBuilder appendTo, int[] offsets, CharSequence... values) Formats the given values, appending to the appendTo builder.
| |
| formatAndReplace | back to summary |
|---|---|
| public StringBuilder formatAndReplace(StringBuilder result, int[] offsets, CharSequence... values) Formats the given values, replacing the contents of the result builder. May optimize by actually appending to the result if it is the same object as the value corresponding to the initial argument in the pattern.
| |
| getArgumentLimit | back to summary |
|---|---|
public int getArgumentLimit()
| |
| getTextWithNoArguments | back to summary |
|---|---|
| public String getTextWithNoArguments() Returns the pattern text with none of the arguments. Like formatting with all-empty string values.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Returns a string similar to the original pattern, only for debugging.
| |