class StringExt {

    public static <A> Map<String, A> parseKeyValueList(String text, Pattern entrySeparator, Pattern pairSeparator,
                                                       BiFunction<A, String, A> accumulator) {
        String trimmed = safeTrim(text);
        if (isEmpty(trimmed)) {
            return Collections.emptyMap();
        }
        List<String> keyValuePairs = asList(entrySeparator.split(trimmed));
        if (keyValuePairs.isEmpty()) {
            return Collections.emptyMap();
        }
        Map<String, A> result = new HashMap<>();
        for (String keyValuePair : keyValuePairs) {
            int idx = indexOf(pairSeparator, keyValuePair);
            String key;
            String value;
            if (idx == -1) {
                key = keyValuePair;
                value = "";
            } else if (idx == keyValuePair.length() - 1) {
                key = keyValuePair.substring(0, idx);
                value = "";
            } else {
                key = keyValuePair.substring(0, idx);
                value = keyValuePair.substring(idx + 1);
            }

            result.put(key, accumulator.apply(result.get(key), value));
        }
        return result;
    }

    private  StringExt();

}