public static String namedFormat(String str, Object... nameValuePairs) { if (nameValuePairs.length % 2 != 0) { throw new InvalidParameterException("You must include one value for each parameter"); } final HashMap<String, String> map = new HashMap<String, String>(nameValuePairs.length / 2); for (int i = 0; i < nameValuePairs.length; i += 2) { map.put(Strings.toString(nameValuePairs[i]), Strings.toString(nameValuePairs[i + 1])); } return namedFormat(str, map); }
public static String toString(final Object o, final String def) { return o == null ? def : o instanceof InputStream ? toString((InputStream) o) : o instanceof Reader ? toString((Reader) o) : o instanceof Object[] ? Strings.join(", ", (Object[]) o) : o instanceof Collection ? Strings.join(", ", (Collection<?>) o) : o.toString(); }
public static <T> String join(final String delimiter, final Collection<T> objs) { if (objs == null || objs.isEmpty()) { return ""; } final Iterator<T> iter = objs.iterator(); final StringBuilder buffer = new StringBuilder(Strings.toString(iter.next())); while (iter.hasNext()) { final T obj = iter.next(); if (notEmpty(obj)) { buffer.append(delimiter).append(Strings.toString(obj)); } } return buffer.toString(); }
public static boolean equalsIgnoreCase(Object a, Object b) { return Strings.toString(a).toLowerCase().equals(Strings.toString(b).toLowerCase()); }
public static boolean equals(Object a, Object b) { return Strings.toString(a).equals(Strings.toString(b)); }
public static String capitalize(String s) { final String c = Strings.toString(s); return c.length() >= 2 ? c.substring(0, 1).toUpperCase() + c.substring(1) : c.length() >= 1 ? c.toUpperCase() : c; }