class UriComponent {

    public static MultivaluedMap<String, String> parseQueryString(String rawQuery, boolean decode) {
        MultivaluedMap<String, String> result = new MultivaluedMapImpl();
        if (!(rawQuery == null || rawQuery.isEmpty())) {
            int p = 0;
            int n = 0;
            while (n < rawQuery.length()) {
                n = rawQuery.indexOf('&', p);
                if (n < 0) {
                    n = rawQuery.length();
                }

                String pair = rawQuery.substring(p, n);
                if (!pair.isEmpty()) {
                    String name;
                    String value;
                    int eq = pair.indexOf('=');
                    if (eq < 0) {
                        // no value
                        name = pair;
                        value = "";
                    } else {
                        name = pair.substring(0, eq);
                        value = pair.substring(eq + 1);
                    }

                    result.add(decode ? decode(name, QUERY) : name, decode ? decode(value, QUERY) : value);
                }
                p = n + 1;
            }
        }
        return result;
    }

    private  UriComponent();

}