StringUtils { @Deprecated public static <T> T fromString(Class<T> returnType, String... strings) { Class<?> componentType = returnType.getComponentType(); if (componentType != null) { if (strings == null) { return null; } else { int length = strings.length; Object typed = Array.newInstance(componentType, length); for (int i = 0; i < length; i++) { Array.set(typed, i, fromString(componentType, strings[i])); } return (T) typed; } } else { String string = strings == null || strings.length == 0 ? null : strings[0]; if (String.class == returnType) { return (T) string; } else if (string == null && !returnType.isPrimitive()) { return null; } else if (boolean.class == returnType || Boolean.class.isAssignableFrom(returnType)) { return (T) Boolean.valueOf(string); } else if (byte.class == returnType || Byte.class.isAssignableFrom(returnType)) { return (T) Byte.valueOf(string); } else if (short.class == returnType || Short.class.isAssignableFrom(returnType)) { return (T) Short.valueOf(string); } else if (int.class == returnType || Integer.class.isAssignableFrom(returnType)) { return (T) Integer.valueOf(string); } else if (long.class == returnType || Long.class.isAssignableFrom(returnType)) { return (T) Long.valueOf(string); } else if (float.class == returnType || Float.class.isAssignableFrom(returnType)) { return (T) Float.valueOf(string); } else if (double.class == returnType || Double.class.isAssignableFrom(returnType)) { return (T) Double.valueOf(string); } else if (char.class == returnType || Character.class.isAssignableFrom(returnType)) { if (string.length() == 1) { return (T) Character.valueOf(string.charAt(0)); } } else if (Date.class.isAssignableFrom(returnType)) { return (T) DateUtils.fromString(string); } throw new IllegalArgumentException(String.format( "Cannot convert [%s] string to [%s] type!", string, returnType.getName() )); } }  @Deprecated static T fromString(Class<T> returnType, String... strings); static String toDelimited(String string, String delimiter); static String toHyphenated(String string); static String toUnderscored(String string); static String toPascalCase(String string); static String toCamelCase(String string); static String toLabel(String string); static String toNormalized(CharSequence string); static String[] fromCsv(String string); static String toCsv(String... strings); static String escapeHtmlAndBreak(String string, int maxWordLength); static String escapeHtmlAndBreak(String string); static String hex(byte[] bytes); static byte[] hash(String algorithm, String string); static byte[] md5(String string); static byte[] sha1(String string); static byte[] sha512(String string); static byte[] hmac(String algorithm, String key, String string); static byte[] hmacSha1(String key, String string); static String encodeUri(String string); static String decodeUri(String string); static String addQueryParameters(String uri, Object... parameters); static String getQueryParameterValue(String uri, String name); static List<String> getQueryParameterValues(String uri, String name); static Map<String, List<String>> getQueryParameterMap(String url); @Deprecated static String transformUri(String uri, Object... parameters); @Deprecated static String getParameter(String uri, String name); @Deprecated static String[] getParameterValues(String uri, String name); static Pattern getPattern(String pattern); static Matcher getMatcher(CharSequence string, String pattern); static MatchResult getMatcherResult(CharSequence string, String pattern); static boolean matches(CharSequence string, String pattern); static boolean matchAll(CharSequence string, String... patterns); static boolean matchAny(CharSequence string, String... patterns); static int matchCount(CharSequence string, String... patterns); static String replaceAll(CharSequence string, String pattern, String replacement); static String replaceAll(CharSequence string, String pattern, String replacement, String... more); static String removeAll(CharSequence string, CharSequence pattern); static String[] split(CharSequence string, String pattern, int limit); static String[] split(CharSequence string, String pattern); static String escapeCsv(String string); static String escapeHtml(String string); static String escapeJava(String string); static String escapeJavaScript(String string); static String escapeQuotes(String string); static String escapeSql(String string); static String escapeXml(String string); static String unescapeCsv(String string); static String unescapeHtml(String string); static String unescapeJava(String string); static String unescapeJavaScript(String string); static String unescapeXml(String string); static String join(List<String> strings, String delimiter); static String join(String[] strings, String delimiter); static boolean isEmpty(String string); static boolean isBlank(String string); static boolean equals(String str1, String str2); static boolean equalsIgnoreCase(String str1, String str2); static String stripHtml(CharSequence sequence); static String ensureStart(String string, String delimiter); static String ensureEnd(String string, String delimiter); static String ensureSurrounding(String string, String delimiter); static String removeStart(String string, String delimiter); static String removeEnd(String string, String delimiter); static String removeSurrounding(String string, String delimiter); static String getPathInfo(String path, String servletPath); static String toLowerCaseAscii(String string); static String trimAndCollapseWhitespaces(String string); static String getFileName(String filePath); @Deprecated
    static final Charset US_ASCII; @Deprecated
    static final Charset ISO_8859_1; @Deprecated
    static final Charset UTF_8; @Deprecated
    static final Charset UTF_16BE; @Deprecated
    static final Charset UTF_16LE; @Deprecated
    static final Charset UTF_16; }
@Test public void fromString_primitive_boolean() { assertEquals(Boolean.class, StringUtils.fromString(boolean.class, "true").getClass()); assertEquals(new Boolean(true), StringUtils.fromString(boolean.class, "true")); }
@Test (expected=IllegalArgumentException.class) public void fromString_other() { class MyClass {} StringUtils.fromString(MyClass.class, "c"); }
@Test public void fromString_array() { assertEquals(char[].class, StringUtils.fromString(char[].class, "c","d").getClass()); assertArrayEquals(new char[] {'c','d'}, StringUtils.fromString(char[].class, "c","d")); }
@Test public void fromString_array_empty() { assertEquals(char[].class, StringUtils.fromString(char[].class).getClass()); assertArrayEquals(new char[] {}, StringUtils.fromString(char[].class)); }
@Test public void fromString_array_null() { assertEquals(char[].class, StringUtils.fromString(char[].class).getClass()); assertArrayEquals(new char[] {}, StringUtils.fromString(char[].class)); }
@Test (expected=NullPointerException.class) public void fromString_array_null_null() { assertEquals(null, StringUtils.fromString(char[].class, null, null)); }
@Test (expected=IllegalArgumentException.class) public void fromString_array_invalid() { StringUtils.fromString(int[].class, "1","a"); }
@Test public void fromString_primitive_multiple() { assertEquals(Integer.class, StringUtils.fromString(int.class, "1","2").getClass()); assertEquals(new Integer(1), StringUtils.fromString(int.class, "1","2")); }
@Test (expected=NumberFormatException.class) public void fromString_missing_value() { StringUtils.fromString(int.class); }
@Test (expected=NumberFormatException.class) public void fromString_null_value() { StringUtils.fromString(int.class, (String)null); }
@Test (expected=NumberFormatException.class) public void fromString_invalid_value() { StringUtils.fromString(int.class, "a"); }
@Test public void fromString_primitive_byte() { assertEquals(Byte.class, StringUtils.fromString(byte.class, "1").getClass()); assertEquals(new Byte((byte)1), StringUtils.fromString(byte.class, "1")); }
@Test (expected=NumberFormatException.class) public void fromString_invalid_value_after() { StringUtils.fromString(int.class, "2a"); }
@Test (expected=NumberFormatException.class) public void fromString_invalid_value_before() { StringUtils.fromString(int.class, "a2"); }
@Test public void fromString_primitive_short() { assertEquals(Short.class, StringUtils.fromString(short.class, "7").getClass()); assertEquals(new Short((short)7), StringUtils.fromString(short.class, "7")); }
@Test public void fromString_primitive_int() { assertEquals(Integer.class, StringUtils.fromString(int.class, "1234").getClass()); assertEquals(new Integer(1234), StringUtils.fromString(int.class, "1234")); }
@Test public void fromString_primitive_long() { assertEquals(Long.class, StringUtils.fromString(long.class, "1234").getClass()); assertEquals(new Long(1234L), StringUtils.fromString(long.class, "1234")); }
@Test public void fromString_primitive_float() { assertEquals(Float.class, StringUtils.fromString(float.class, "12.34").getClass()); assertEquals(new Float(12.34), StringUtils.fromString(float.class, "12.34")); }
@Test public void fromString_primitive_double() { assertEquals(Double.class, StringUtils.fromString(double.class, "23.5").getClass()); assertEquals(new Double(23.5), StringUtils.fromString(double.class, "23.5")); }
@Test public void fromString_primitive_char() { assertEquals(Character.class, StringUtils.fromString(char.class, "c").getClass()); assertEquals(new Character('c'), StringUtils.fromString(char.class, "c")); }
@Test public void fromString_string() { assertEquals(String.class, StringUtils.fromString(String.class, "value").getClass()); assertEquals(new String("value"), StringUtils.fromString(String.class, "value")); }
@Test public void fromString_date() throws ParseException { String dateStr = "2011-10-15 14:15:00"; Date expect = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateStr); assertEquals(Date.class, StringUtils.fromString(Date.class, dateStr).getClass()); assertEquals(expect, StringUtils.fromString(Date.class, dateStr)); }