@Test public void testGetSingleValue() throws Exception { assertEquals("a", HttpUtil.getSingleValue("a")); assertEquals("a", HttpUtil.getSingleValue(new String [] {"a", "b", "c"} )); assertEquals("a", HttpUtil.getSingleValue(new ArrayList<String>() {{ add("a"); add("b"); add("c"); }} )); assertEquals("a", HttpUtil.getSingleValue(new HashSet<String>() {{ add("a"); }} )); assertNull(HttpUtil.getSingleValue(Collections.emptyList())); assertNull(HttpUtil.getSingleValue(new String [0] )); }
public static String getSingleValue(final Object param) { if (param instanceof String) { return (String) param; } else if (param instanceof Collection) { if (!((Collection) param).isEmpty()) { if (param instanceof List) { return ((List) param).get(0).toString(); } return ((Collection) param).iterator().next().toString(); } } else if (param instanceof String[]) { if (((String[]) param).length > 0) { return ((String[]) param)[0]; } } return null; }
HttpUtil { public static String getSingleValue(final Object param) { if (param instanceof String) { return (String) param; } else if (param instanceof Collection) { if (!((Collection) param).isEmpty()) { if (param instanceof List) { return ((List) param).get(0).toString(); } return ((Collection) param).iterator().next().toString(); } } else if (param instanceof String[]) { if (((String[]) param).length > 0) { return ((String[]) param)[0]; } } return null; } }
HttpUtil { public static String getSingleValue(final Object param) { if (param instanceof String) { return (String) param; } else if (param instanceof Collection) { if (!((Collection) param).isEmpty()) { if (param instanceof List) { return ((List) param).get(0).toString(); } return ((Collection) param).iterator().next().toString(); } } else if (param instanceof String[]) { if (((String[]) param).length > 0) { return ((String[]) param)[0]; } } return null; }  }
HttpUtil { public static String getSingleValue(final Object param) { if (param instanceof String) { return (String) param; } else if (param instanceof Collection) { if (!((Collection) param).isEmpty()) { if (param instanceof List) { return ((List) param).get(0).toString(); } return ((Collection) param).iterator().next().toString(); } } else if (param instanceof String[]) { if (((String[]) param).length > 0) { return ((String[]) param)[0]; } } return null; }  static String dumpRequest(final HttpServletRequest request); static String decodeUtf8UriParam(final String value); static String encodeUtf8UriParam(final String value); static Map<String, List<String>> getParameters(final String requestURL,
                                                          final Set<String> pathVariables); static Map<String, List<String>> getParameters(final String requestURL,
                                                          final Set<String> pathVariables,
                                                          final boolean removeDuplicates); static Map<String, List<String>> getParameters(final HttpServletRequest request,
                                                          final Set<String> pathVariables); static Map<String, List<String>> getParameters(final HttpServletRequest request,
                                                          final Set<String> pathVariables,
                                                          final boolean removeDuplicates); static Map<String, List<String>> allParameters(final HttpServletRequest request,
                                                          final Set<String> pathVariables); static Map<String, List<String>> allParameters(final HttpServletRequest request,
                                                          final Set<String> pathVariables,
                                                          final boolean removeDuplicates); static String getSingleValue(final Object param); static String escapeForHTML(final String raw); static String escapeForHTMLAttribute(final String raw); }
HttpUtil { public static String getSingleValue(final Object param) { if (param instanceof String) { return (String) param; } else if (param instanceof Collection) { if (!((Collection) param).isEmpty()) { if (param instanceof List) { return ((List) param).get(0).toString(); } return ((Collection) param).iterator().next().toString(); } } else if (param instanceof String[]) { if (((String[]) param).length > 0) { return ((String[]) param)[0]; } } return null; }  static String dumpRequest(final HttpServletRequest request); static String decodeUtf8UriParam(final String value); static String encodeUtf8UriParam(final String value); static Map<String, List<String>> getParameters(final String requestURL,
                                                          final Set<String> pathVariables); static Map<String, List<String>> getParameters(final String requestURL,
                                                          final Set<String> pathVariables,
                                                          final boolean removeDuplicates); static Map<String, List<String>> getParameters(final HttpServletRequest request,
                                                          final Set<String> pathVariables); static Map<String, List<String>> getParameters(final HttpServletRequest request,
                                                          final Set<String> pathVariables,
                                                          final boolean removeDuplicates); static Map<String, List<String>> allParameters(final HttpServletRequest request,
                                                          final Set<String> pathVariables); static Map<String, List<String>> allParameters(final HttpServletRequest request,
                                                          final Set<String> pathVariables,
                                                          final boolean removeDuplicates); static String getSingleValue(final Object param); static String escapeForHTML(final String raw); static String escapeForHTMLAttribute(final String raw);  }