StringUtils { public static Map<String, String> parseParameters(String rawParameters) { Matcher matcher = PARAMETERS_PATTERN.matcher(rawParameters); if (!matcher.matches()) { return Collections.emptyMap(); } String pairs = matcher.group(1); String[] pairArr = pairs.split("\\s*,\\s*"); Map<String, String> parameters = new HashMap<>(); for (String pair : pairArr) { Matcher pairMatcher = PAIR_PARAMETERS_PATTERN.matcher(pair); if (pairMatcher.matches()) { parameters.put(pairMatcher.group(1), pairMatcher.group(2)); } } return parameters; } private  StringUtils(); static int length(final CharSequence cs); static String repeat(final String str, final int repeat); static String repeat(final String str, final String separator, final int repeat); static String removeEnd(final String str, final String remove); static String repeat(final char ch, final int repeat); static String stripEnd(final String str, final String stripChars); static String replace(final String text, final String searchString, final String replacement); static String replace(final String text, final String searchString, final String replacement, int max); static boolean isBlank(CharSequence cs); static boolean isEmpty(String str); static boolean isNoneEmpty(final String... ss); static boolean isAnyEmpty(final String... ss); static boolean isNotEmpty(String str); static boolean isEquals(String s1, String s2); static boolean isInteger(String str); static int parseInteger(String str); static boolean isJavaIdentifier(String s); static boolean isContains(String values, String value); static boolean isContains(String str, char ch); static boolean isNotContains(String str, char ch); static boolean isContains(String[] values, String value); static boolean isNumeric(String str, boolean allowDot); static String toString(Throwable e); static String toString(String msg, Throwable e); static String translate(String src, String from, String to); static String[] split(String str, char ch); static List<String> splitToList(String str, char ch); static Set<String> splitToSet(String value, char separatorChar); static Set<String> splitToSet(String value, char separatorChar, boolean trimElements); static String join(String[] array); static String join(String[] array, char split); static String join(String[] array, String split); static String join(Collection<String> coll, String split); static String getQueryStringValue(String qs, String key); static Map<String, String> parseQueryString(String qs); static String getServiceKey(Map<String, String> ps); static String toQueryString(Map<String, String> ps); static String camelToSplitName(String camelName, String split); static String toArgumentString(Object[] args); static String trim(String str); static String toURLKey(String key); static String toOSStyleKey(String key); static boolean isAllUpperCase(String str); static String[] delimitedListToStringArray(String str, String delimiter); static String[] delimitedListToStringArray(String str, String delimiter, String charsToDelete); static String arrayToDelimitedString(Object[] arr, String delim); static String deleteAny(String inString, String charsToDelete); static String[] toStringArray(Collection<String> collection); static String nullSafeToString(Object obj); static Map<String, String> parseParameters(String rawParameters); static int decodeHexNibble(final char c); static byte decodeHexByte(CharSequence s, int pos); static String toCommaDelimitedString(String one, String... others); static final String EMPTY_STRING; static final int INDEX_NOT_FOUND; static final String[] EMPTY_STRING_ARRAY; static final char EQUAL_CHAR; static final String EQUAL; static final char AND_CHAR; static final String AND; static final char SEMICOLON_CHAR; static final String SEMICOLON; static final char QUESTION_MASK_CHAR; static final String QUESTION_MASK; static final char SLASH_CHAR; static final String SLASH; static final char HYPHEN_CHAR; static final String HYPHEN; }
@Test public void testParseParameters() { String legalStr = "[{key1:value1},{key2:value2}]"; Map<String, String> legalMap = StringUtils.parseParameters(legalStr); assertEquals(2, legalMap.size()); assertEquals("value2", legalMap.get("key2")); String legalSpaceStr = "[{key1: value1}, {key2 :value2}]"; Map<String, String> legalSpaceMap = StringUtils.parseParameters(legalSpaceStr); assertEquals(2, legalSpaceMap.size()); assertEquals("value2", legalSpaceMap.get("key2")); String legalSpecialStr = "[{key-1: value*.1}, {key.2 :value*.-_2}]"; Map<String, String> legalSpecialMap = StringUtils.parseParameters(legalSpecialStr); assertEquals(2, legalSpecialMap.size()); assertEquals("value*.1", legalSpecialMap.get("key-1")); assertEquals("value*.-_2", legalSpecialMap.get("key.2")); String illegalStr = "[{key=value},{aa:bb}]"; Map<String, String> illegalMap = StringUtils.parseParameters(illegalStr); assertEquals(0, illegalMap.size()); }