public class CharacterFormatter extends CharacterFormatParser
STRING(value, format)
function
for characters.
Example:
CharacterFormatter formatter = new CharacterFormatter("String to format", "x(8)"); formatter.parse(); String formatted = formatter.getValue(); // "String t"
Modifier and Type | Class and Description |
---|---|
private static interface |
CharacterFormatter.Convert
Helper method for character testers.
|
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
format
The input format specification
|
private java.io.Reader |
in
Reader on the input formatted string
|
private java.lang.StringBuilder |
out
The collector for the output formatted value
|
Constructor and Description |
---|
CharacterFormatter(java.lang.String format,
java.lang.String value)
The constructor.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
format()
Do the formatting.
|
java.lang.String |
getValue()
Get the formatted value.
|
private void |
processCharacters(CharacterFormatter.Convert converter,
int repeatCount)
Process the action associated with a special formatting character.
|
private void |
processCharactersAsIs(int repeatCount)
Process characters with no conversion helper method.
|
protected void |
visitAlphanum(int repeatCount)
This method is called by
format() for each occurrence of
the 'n' (alphanumeric) special character in format string. |
protected void |
visitAnyChar(int repeatCount)
This method is called by
format() for each occurrence of
the 'x' (any character) special character in format string. |
protected void |
visitDigit(int repeatCount)
This method is called by
format() for each occurrence of
the '9' (the digit) special character in format string. |
protected void |
visitFillChar(char ch)
This method is called by
format() for each occurrence of
a non-special character in format string. |
protected void |
visitLetter(int repeatCount)
This method is called by
format() for each occurrence of
the 'a' (letter) special character in format string. |
protected void |
visitUpperLetter(int repeatCount)
This method is called by
format() for each occurrence of
the '!' (upcase) special character in format string. |
parse, visitEscape
protected final java.lang.String format
private final java.lang.StringBuilder out
private final java.io.Reader in
public CharacterFormatter(java.lang.String format, java.lang.String value)
format
- the format stringvalue
- the value to formatpublic java.lang.String getValue()
public java.lang.String format()
protected void visitFillChar(char ch)
format()
for each occurrence of
a non-special character in format string.visitFillChar
in class CharacterFormatParser
ch
- the format characterprotected void visitLetter(int repeatCount)
format()
for each occurrence of
the 'a' (letter) special character in format string.visitLetter
in class CharacterFormatParser
repeatCount
- the special character repeat countprotected void visitAlphanum(int repeatCount)
format()
for each occurrence of
the 'n' (alphanumeric) special character in format string.visitAlphanum
in class CharacterFormatParser
repeatCount
- the special character repeat countprotected void visitAnyChar(int repeatCount)
format()
for each occurrence of
the 'x' (any character) special character in format string.visitAnyChar
in class CharacterFormatParser
repeatCount
- the special character repeat countprotected void visitDigit(int repeatCount)
format()
for each occurrence of
the '9' (the digit) special character in format string.visitDigit
in class CharacterFormatParser
repeatCount
- the special character repeat countprotected void visitUpperLetter(int repeatCount)
format()
for each occurrence of
the '!' (upcase) special character in format string.visitUpperLetter
in class CharacterFormatParser
repeatCount
- the special character repeat countprivate final void processCharactersAsIs(int repeatCount)
repeatCount
- the character repeat countprivate final void processCharacters(CharacterFormatter.Convert converter, int repeatCount)
converter
- the character converterrepeatCount
- the number of times the operation should repeat