@Test public void testLeading() { assertEquals(LEADING_PADDED, Justify.right(UNPADDED, 10)); assertEquals(LEADING_PADDED, Justify.leading(UNPADDED, 10, ' ')); assertEquals(" ", Justify.leading(null, 10, ' ')); assertEquals(" ", Justify.leading("", 10, ' ')); assertEquals("ABCDEFGHIJ", Justify.right("ABCDEFGHIJKLM", 10)); }
public static String leading(String s, int size, char pad) { StringBuffer sb = new StringBuffer(); String input = s == null ? "" : s; if (input.length() < size) { for (int i = 0; i < size - input.length(); i++) { sb.append(pad); } sb.append(input); } else { sb.append(input); sb.setLength(size); } return sb.toString(); }
Justify { public static String leading(String s, int size, char pad) { StringBuffer sb = new StringBuffer(); String input = s == null ? "" : s; if (input.length() < size) { for (int i = 0; i < size - input.length(); i++) { sb.append(pad); } sb.append(input); } else { sb.append(input); sb.setLength(size); } return sb.toString(); } }
Justify { public static String leading(String s, int size, char pad) { StringBuffer sb = new StringBuffer(); String input = s == null ? "" : s; if (input.length() < size) { for (int i = 0; i < size - input.length(); i++) { sb.append(pad); } sb.append(input); } else { sb.append(input); sb.setLength(size); } return sb.toString(); } private  Justify(); }
Justify { public static String leading(String s, int size, char pad) { StringBuffer sb = new StringBuffer(); String input = s == null ? "" : s; if (input.length() < size) { for (int i = 0; i < size - input.length(); i++) { sb.append(pad); } sb.append(input); } else { sb.append(input); sb.setLength(size); } return sb.toString(); } private  Justify(); static String left(String s, int len); static String trailing(String s, int len, char pad); static String right(String input, int size); static String leading(String s, int size, char pad); }
Justify { public static String leading(String s, int size, char pad) { StringBuffer sb = new StringBuffer(); String input = s == null ? "" : s; if (input.length() < size) { for (int i = 0; i < size - input.length(); i++) { sb.append(pad); } sb.append(input); } else { sb.append(input); sb.setLength(size); } return sb.toString(); } private  Justify(); static String left(String s, int len); static String trailing(String s, int len, char pad); static String right(String input, int size); static String leading(String s, int size, char pad);  }