@Test public void testPadRight() { assertEquals("abcXX", TextUtil.padRight("abc", "X", 5)); assertEquals("abc", TextUtil.padRight("abc", "X", 2)); assertEquals("abc", TextUtil.padRight("abc", "X", -99)); assertEquals("abcAB", TextUtil.padRight("abc", "ABCDEFG", 5)); assertEquals("abc ", TextUtil.padRight("abc", null, 5)); assertNull(TextUtil.padRight(null, "ABCDEFG", 5)); }
public static String padRight(String base, String repeatString, int totalLength) { if (base == null) return null; if (base.length() < totalLength) { if (repeatString == null) repeatString = " "; StringBuilder sb = new StringBuilder(base); while (sb.length() < totalLength) { sb.append(repeatString); } return sb.substring(0, totalLength); } else { return base; } }
TextUtil { public static String padRight(String base, String repeatString, int totalLength) { if (base == null) return null; if (base.length() < totalLength) { if (repeatString == null) repeatString = " "; StringBuilder sb = new StringBuilder(base); while (sb.length() < totalLength) { sb.append(repeatString); } return sb.substring(0, totalLength); } else { return base; } } }
TextUtil { public static String padRight(String base, String repeatString, int totalLength) { if (base == null) return null; if (base.length() < totalLength) { if (repeatString == null) repeatString = " "; StringBuilder sb = new StringBuilder(base); while (sb.length() < totalLength) { sb.append(repeatString); } return sb.substring(0, totalLength); } else { return base; } }  }
TextUtil { public static String padRight(String base, String repeatString, int totalLength) { if (base == null) return null; if (base.length() < totalLength) { if (repeatString == null) repeatString = " "; StringBuilder sb = new StringBuilder(base); while (sb.length() < totalLength) { sb.append(repeatString); } return sb.substring(0, totalLength); } else { return base; } }  static void println(PrintStream out, String pattern, Object... args); static void println(PrintStream out, int maxLineLength, String linePrefix, String pattern, Object... args); static void println(PrintStream out, int maxLineLength, String linePrefix, String content); static String format(String pattern, Object... args); static String repeat(String base, int repeat); static String padRight(String base, String repeatString, int totalLength); static String trimToNull(String source); static String nullToEmpty(String source); static String trimToEmpty(String source); static boolean toBoolean(String value); static List<String> wrap(String in, int length, String prefix, String wrappedLineIndent); static List<String> wrap(String in, int length); static int findFirstInstanceOf(String toBeSearched, int searchFrom, String... toBeFound); static int findLastInstanceOf(String toBeSearched, int searchFrom, String... toBeFound); static String escapeXml(String text); }
TextUtil { public static String padRight(String base, String repeatString, int totalLength) { if (base == null) return null; if (base.length() < totalLength) { if (repeatString == null) repeatString = " "; StringBuilder sb = new StringBuilder(base); while (sb.length() < totalLength) { sb.append(repeatString); } return sb.substring(0, totalLength); } else { return base; } }  static void println(PrintStream out, String pattern, Object... args); static void println(PrintStream out, int maxLineLength, String linePrefix, String pattern, Object... args); static void println(PrintStream out, int maxLineLength, String linePrefix, String content); static String format(String pattern, Object... args); static String repeat(String base, int repeat); static String padRight(String base, String repeatString, int totalLength); static String trimToNull(String source); static String nullToEmpty(String source); static String trimToEmpty(String source); static boolean toBoolean(String value); static List<String> wrap(String in, int length, String prefix, String wrappedLineIndent); static List<String> wrap(String in, int length); static int findFirstInstanceOf(String toBeSearched, int searchFrom, String... toBeFound); static int findLastInstanceOf(String toBeSearched, int searchFrom, String... toBeFound); static String escapeXml(String text); static final String[] EMPTY_STRING_ARRAY; static final List<String> EMPTY_STRING_LIST; static final String NULL_PRINT; static final String SECOND_LINE_INDENT; }