### Question:
FilenameFormatter implements Serializable { public void applyPattern(final String pattern) throws IllegalArgumentException { int last = 0; RuntimeException cause = null; for (int fieldNumber=0; ;fieldNumber++) { final String field; switch (fieldNumber) { case 0: field = "{level:"; break; case 1: field = "{column:"; break; case 2: field = "{row:"; break; default: { suffix = pattern.substring(last); return; } } int i = pattern.indexOf(field, last); if (i < 0) { break; } final String separator = pattern.substring(last, i); i += field.length(); last = pattern.indexOf('}', i); if (last < 0) { break; } final int n; try { n = Integer.parseInt(pattern.substring(i, last)); } catch (NumberFormatException e) { cause = e; break; } last++; switch (fieldNumber) { case 0: prefix = separator; levelFieldSize = n; break; case 1: levelSeparator = separator; columnFieldSize = n; break; case 2: locationSeparator = separator; rowFieldSize = n; break; } } throw new IllegalArgumentException(Errors.format( ErrorKeys.ILLEGAL_ARGUMENT_$2, "pattern", pattern), cause); } FilenameFormatter(); void initialize(final ImageReaderSpi tileReaderSpi); void computeLevelFieldSize(final int n); void computeFieldSizes(final Rectangle imageBounds, final Rectangle tileBounds); void ensurePrefixSet(final Object input); String generateFilename(final int level, final int column, final int row); String guessPattern(final int level, final int column, final int row, final String filename); void applyPattern(final String pattern); @Override String toString();  }### Answer:
@Test public void testApplyPattern() { final FilenameFormatter formatter = new FilenameFormatter(); formatter.applyPattern("L{level:2}_{column:2}{row:2}.png"); assertEquals("L{level:2}_{column:2}{row:2}.png", formatter.toString()); assertEquals("L01_AA01.png", formatter.generateFilename(0, 0, 0)); assertEquals("L13_AD15.png", formatter.generateFilename(12, 3, 14)); formatter.applyPattern("L{level:1}_{column:2}{row:3}.png"); assertEquals("L{level:1}_{column:2}{row:3}.png", formatter.toString()); assertEquals("L1_AA001.png", formatter.generateFilename(0, 0, 0)); assertEquals("L3_AD015.png", formatter.generateFilename(2, 3, 14)); }