@Test public final void testReplace() { assertThat(KeyValue.replace(null)).isEqualTo(null); assertThat(KeyValue.replace("")).isEqualTo(""); assertThat(KeyValue.replace("abc")).isEqualTo("abc"); assertThat(KeyValue.replace("${a}abc")).isEqualTo("${a}abc"); assertThat(KeyValue.replace("abc${d}")).isEqualTo("abc${d}"); assertThat(KeyValue.replace("a${b}c")).isEqualTo("a${b}c"); assertThat(KeyValue.replace("${a}abc", new KeyValue("a", "x"))).isEqualTo("xabc"); assertThat(KeyValue.replace("abc${d}", new KeyValue("d", "x"))).isEqualTo("abcx"); assertThat(KeyValue.replace("a${b}c", new KeyValue("b", "x"))).isEqualTo("axc"); }
@SuppressWarnings("unchecked") public static String replace(final String message, final KeyValue... keyValue) { if (keyValue == null) { return message; } final Map<String, String> map = new HashMap<String, String>(); for (final KeyValue kv : keyValue) { if (kv.getValue() instanceof Collection) { final StringBuffer sb = new StringBuffer(); final Collection coll = (Collection) kv.getValue(); int count = 0; for (final Object entry : coll) { if (count > 0) { sb.append(", "); } sb.append(entry.toString()); count++; } map.put(kv.getKey(), sb.toString()); } else { map.put(kv.getKey(), kv.getValue().toString()); } } return replaceVars(message, map); }
KeyValue { @SuppressWarnings("unchecked") public static String replace(final String message, final KeyValue... keyValue) { if (keyValue == null) { return message; } final Map<String, String> map = new HashMap<String, String>(); for (final KeyValue kv : keyValue) { if (kv.getValue() instanceof Collection) { final StringBuffer sb = new StringBuffer(); final Collection coll = (Collection) kv.getValue(); int count = 0; for (final Object entry : coll) { if (count > 0) { sb.append(", "); } sb.append(entry.toString()); count++; } map.put(kv.getKey(), sb.toString()); } else { map.put(kv.getKey(), kv.getValue().toString()); } } return replaceVars(message, map); } }
KeyValue { @SuppressWarnings("unchecked") public static String replace(final String message, final KeyValue... keyValue) { if (keyValue == null) { return message; } final Map<String, String> map = new HashMap<String, String>(); for (final KeyValue kv : keyValue) { if (kv.getValue() instanceof Collection) { final StringBuffer sb = new StringBuffer(); final Collection coll = (Collection) kv.getValue(); int count = 0; for (final Object entry : coll) { if (count > 0) { sb.append(", "); } sb.append(entry.toString()); count++; } map.put(kv.getKey(), sb.toString()); } else { map.put(kv.getKey(), kv.getValue().toString()); } } return replaceVars(message, map); } KeyValue(final String key, final Object value); }
KeyValue { @SuppressWarnings("unchecked") public static String replace(final String message, final KeyValue... keyValue) { if (keyValue == null) { return message; } final Map<String, String> map = new HashMap<String, String>(); for (final KeyValue kv : keyValue) { if (kv.getValue() instanceof Collection) { final StringBuffer sb = new StringBuffer(); final Collection coll = (Collection) kv.getValue(); int count = 0; for (final Object entry : coll) { if (count > 0) { sb.append(", "); } sb.append(entry.toString()); count++; } map.put(kv.getKey(), sb.toString()); } else { map.put(kv.getKey(), kv.getValue().toString()); } } return replaceVars(message, map); } KeyValue(final String key, final Object value); final String getKey(); final Object getValue(); @SuppressWarnings("unchecked") static String replace(final String message, final KeyValue... keyValue); static String replaceVars(final String str, final Map vars); }
KeyValue { @SuppressWarnings("unchecked") public static String replace(final String message, final KeyValue... keyValue) { if (keyValue == null) { return message; } final Map<String, String> map = new HashMap<String, String>(); for (final KeyValue kv : keyValue) { if (kv.getValue() instanceof Collection) { final StringBuffer sb = new StringBuffer(); final Collection coll = (Collection) kv.getValue(); int count = 0; for (final Object entry : coll) { if (count > 0) { sb.append(", "); } sb.append(entry.toString()); count++; } map.put(kv.getKey(), sb.toString()); } else { map.put(kv.getKey(), kv.getValue().toString()); } } return replaceVars(message, map); } KeyValue(final String key, final Object value); final String getKey(); final Object getValue(); @SuppressWarnings("unchecked") static String replace(final String message, final KeyValue... keyValue); static String replaceVars(final String str, final Map vars);  }