@Test public void testFormat() { assertEquals("abcXXXxyz", TextUtil.format("abc{}xyz", "XXX")); assertEquals("abcXXXxyz", TextUtil.format("abc{}xyz", "XXX", "YYY", "ZZZ")); assertEquals("AAAabcBBBxyzCCC", TextUtil.format("{}abc{}xyz{}", "AAA", "BBB", "CCC")); assertEquals("AAAabcBBBxyzCCC", TextUtil.format("{}abc{}xyz{}", "AAA", "BBB", "CCC")); assertEquals("abc\\{}xyz", TextUtil.format("abc\\{}xyz", "XXX")); assertEquals("abc[[NULL]]xyz", TextUtil.format("abc{}xyz", (String)null)); assertEquals("abc[[NULL]]xyz", TextUtil.format("abc{}xyz", null, null, null)); assertEquals("abcXXXdef[[NULL]]xyz", TextUtil.format("abc{}def{}xyz", "XXX", null, null)); }
public static String format(String pattern, Object... args) { String padded = PAD + pattern + PAD; String[] tokens = padded.split("(?<!\\\\)(\\{})"); if (tokens.length > 1) { StringBuilder sb = new StringBuilder(); sb.append(tokens[0]); for (int i = 1; i < tokens.length; i++) { if (args != null && args[i - 1] != null) { sb.append(args[i - 1]); } else { sb.append(NULL_PRINT); } sb.append(tokens[i]); } return sb.substring(11, sb.length() - 11); } else { return pattern; } }
TextUtil { public static String format(String pattern, Object... args) { String padded = PAD + pattern + PAD; String[] tokens = padded.split("(?<!\\\\)(\\{})"); if (tokens.length > 1) { StringBuilder sb = new StringBuilder(); sb.append(tokens[0]); for (int i = 1; i < tokens.length; i++) { if (args != null && args[i - 1] != null) { sb.append(args[i - 1]); } else { sb.append(NULL_PRINT); } sb.append(tokens[i]); } return sb.substring(11, sb.length() - 11); } else { return pattern; } } }
TextUtil { public static String format(String pattern, Object... args) { String padded = PAD + pattern + PAD; String[] tokens = padded.split("(?<!\\\\)(\\{})"); if (tokens.length > 1) { StringBuilder sb = new StringBuilder(); sb.append(tokens[0]); for (int i = 1; i < tokens.length; i++) { if (args != null && args[i - 1] != null) { sb.append(args[i - 1]); } else { sb.append(NULL_PRINT); } sb.append(tokens[i]); } return sb.substring(11, sb.length() - 11); } else { return pattern; } }  }
TextUtil { public static String format(String pattern, Object... args) { String padded = PAD + pattern + PAD; String[] tokens = padded.split("(?<!\\\\)(\\{})"); if (tokens.length > 1) { StringBuilder sb = new StringBuilder(); sb.append(tokens[0]); for (int i = 1; i < tokens.length; i++) { if (args != null && args[i - 1] != null) { sb.append(args[i - 1]); } else { sb.append(NULL_PRINT); } sb.append(tokens[i]); } return sb.substring(11, sb.length() - 11); } else { return pattern; } }  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 format(String pattern, Object... args) { String padded = PAD + pattern + PAD; String[] tokens = padded.split("(?<!\\\\)(\\{})"); if (tokens.length > 1) { StringBuilder sb = new StringBuilder(); sb.append(tokens[0]); for (int i = 1; i < tokens.length; i++) { if (args != null && args[i - 1] != null) { sb.append(args[i - 1]); } else { sb.append(NULL_PRINT); } sb.append(tokens[i]); } return sb.substring(11, sb.length() - 11); } else { return pattern; } }  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; }