public class MaskFormat extends Format implements FormatProvider
MaskFormat is used to format and parse strings by the mean of a mask. Underscore '_' is used as default place holder for the next message character. The other characters within the mask are inserted between the message symbols. The backslash '\' is escape symbol. Combination of '\?' will include '?' in the human-readable message, where '?' can be any character including underscore '_' and backslash '\'. Hash '#' can be used to skip (delete) a character from the original message.
| Input | Mask | Output |
|---|---|---|
| 313378444416 | _ _____ _____ _ | 3 13378 44441 6 |
| A58818501 | _-__-_____/_ | A-58-81850/1 |
| A/5881850 1 | _# __ _____#-_ | A 58 81850-1 |
Format.Field| Constructor and Description |
|---|
MaskFormat() |
MaskFormat(String mask) |
MaskFormat(String mask,
char placeholder) |
| Modifier and Type | Method and Description |
|---|---|
static FormatFactory |
factory() |
StringBuffer |
format(Object obj,
StringBuffer toAppendTo,
FieldPosition pos) |
String |
format(String str) |
static String |
format(String mask,
String str) |
static String |
format(String mask,
String str,
char placeholder) |
FormatFactory |
getFactory()
Gets the format factory.
|
String |
getFormatName()
Gets the format name that will be registered.
|
String |
getMask() |
char |
getPlaceholder() |
String |
parse(String source) |
String |
parse(String source,
ParsePosition pos) |
static String |
parse(String mask,
String source) |
static String |
parse(String mask,
String source,
char placeholder) |
Object |
parseObject(String source) |
Object |
parseObject(String source,
ParsePosition pos) |
void |
setMask(String mask) |
void |
setPlaceholder(char placeholder) |
clone, format, formatToCharacterIteratorpublic MaskFormat()
public MaskFormat(String mask)
public MaskFormat(String mask, char placeholder)
public static FormatFactory factory()
public static String parse(String mask, String source) throws ParseException
ParseExceptionpublic static String parse(String mask, String source, char placeholder) throws ParseException
ParseExceptionpublic StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos)
public FormatFactory getFactory()
FormatProvidergetFactory in interface FormatProviderFormatFactory instancepublic String getFormatName()
FormatProvidergetFormatName in interface FormatProviderpublic String getMask()
public char getPlaceholder()
public String parse(String source) throws ParseException
ParseExceptionpublic String parse(String source, ParsePosition pos) throws ParseException
ParseExceptionpublic Object parseObject(String source) throws ParseException
parseObject in class FormatParseExceptionpublic Object parseObject(String source, ParsePosition pos)
parseObject in class Formatpublic void setMask(String mask)
public void setPlaceholder(char placeholder)
Copyright © 2015. All Rights Reserved.