MaskFormat extends Format implements FormatProvider { public static String parse(String mask, String source) throws ParseException { return parse(mask, source, DEFAULT_PLACEHOLDER); } MaskFormat();  MaskFormat(String mask);  MaskFormat(String mask, char placeholder); static FormatFactory factory(); static String format(String mask, String str); static String format(String mask, String str, char placeholder); static String parse(String mask, String source); static String parse(String mask, String source, char placeholder); StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos); String format(String str); @Override FormatFactory getFactory(); @Override String getFormatName(); String getMask(); char getPlaceholder(); String parse(String source); String parse(String source, ParsePosition pos); Object parseObject(String source); Object parseObject(String source, ParsePosition pos); void setMask(String mask); void setPlaceholder(char placeholder);  }
@Test public void maskParseTest() throws ParseException { Assert.assertEquals(MaskFormat.parse("", "hi"), "hi"); Assert.assertEquals(MaskFormat.parse((String) null, (String) null), null); Assert.assertEquals(MaskFormat.parse("____ ____ __", "1234 5678 90"), "1234567890"); Assert.assertEquals(MaskFormat.parse("____-__-__", "2008-11-28"), "20081128"); Assert.assertEquals(MaskFormat.parse("__\\___", "10_10"), "1010"); Assert.assertEquals(MaskFormat.parse("$$_$$", "10_10", '$'), "1010"); Assert.assertEquals(MaskFormat.parse("1bla_bla__bla bla bla 12", "1bla0bla10bla bla bla 12"), "010"); try { MaskFormat.parse("helo", "123"); Assert.fail(); } catch (ParseException ex) { } }