/*
 * Copyright 2015 Dmitry Ustalov
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package mtsar;

import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.validation.Validator;
import javax.ws.rs.core.MultivaluedMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public final class ParamsUtils {
    @ParametersAreNonnullByDefault
    @Nonnull
    public final static List<String> extract(MultivaluedMap<String, String> params, String prefix) {
        final String regexp = "^" + Pattern.quote(prefix) + "(\\[\\d+\\]|)$";

        final List<String> values = params.entrySet().stream().
                filter(entries -> entries.getKey().matches(regexp) && entries.getValue() != null && !entries.getValue().isEmpty()).
                flatMap(entries -> entries.getValue().stream()).
                collect(Collectors.toList());

        return values;
    }

    public final static void validate(Validator validator, Object... objects) throws ConstraintViolationException {
        final Set<ConstraintViolation<Object>> violations = new HashSet<>();
        for (final Object object : objects) violations.addAll(validator.validate(object));
        if (!violations.isEmpty()) throw new ConstraintViolationException(violations);
    }
}

@@ -936,19 +936,109 @@
 va.util.
-Set
+Map;%0Aimport java.util.Set;%0Aimport java.util.function.Function;%0Aimport java.util.regex.Matcher
 ;%0Aimport
@@ -1100,16 +1100,47 @@
 ctors;%0A%0A
+@ParametersAreNonnullByDefault%0A
 public f
@@ -1173,37 +1173,744 @@
    @
-ParametersAreNonnullByDefault
+Nonnull%0A    public static Map%3CString, List%3CString%3E%3E nested(MultivaluedMap%3CString, String%3E params, String prefix) %7B%0A        final Pattern pattern = Pattern.compile(%22%5E(%22 + Pattern.quote(prefix) + %22%5C%5C%5B(%5C%5Cw+?)%5C%5C%5D)(%5C%5C%5B%5C%5Cd+%5C%5C%5D%7C)$%22);%0A%0A        final Map%3CString, Matcher%3E prefixes = params.keySet().stream().%0A                map(param -%3E pattern.matcher(param)).%0A                filter(Matcher::matches).%0A                collect(Collectors.toMap(matcher -%3E matcher.group(1), Function.identity(), (m1, m2) -%3E m1));%0A%0A        final Map%3CString, List%3CString%3E%3E values = prefixes.entrySet().stream().%0A                collect(Collectors.toMap(entry -%3E entry.getValue().group(2), entry -%3E extract(params, entry.getKey())));%0A%0A        return values;%0A    %7D%0A
 %0A   
@@ -1926,30 +1926,24 @@
 %0A    public 
-final 
 static List%3C

Add ParamsUtils.nested [ci skip]