StringAlign extends Format { @Override public StringBuffer format( Object input, StringBuffer where, FieldPosition ignore) { String s = input.toString(); String wanted = s.substring(0, Math.min(s.length(), maxChars)); switch (just) { case RIGHT: pad(where, maxChars - wanted.length()); where.append(wanted); break; case CENTER: int toAdd = maxChars - wanted.length(); pad(where, toAdd/2); where.append(wanted); pad(where, toAdd - toAdd/2); break; case LEFT: where.append(wanted); pad(where, maxChars - wanted.length()); break; } return where; } StringAlign(int maxChars, Justify just); @Override StringBuffer format(
		Object input, StringBuffer where, FieldPosition ignore); Object parseObject(String source, ParsePosition pos);  }
@Test public void testNullString() { assertEquals(" ", new StringAlign(5, StringAlign.Justify.RIGHT).format("")); }
@Test public void testIntRight() { assertEquals(" 42", new StringAlign(5, StringAlign.Justify.RIGHT).format(42)); }
@Test public void testObjCentred() { assertEquals(" " + ONCE + " ", new StringAlign(15, StringAlign.Justify.CENTER).format(o)); }