spring-hateoas-ext/src/main/java/de/escalon/hypermedia/affordance/PartialUriTemplate.java
private PartialUriTemplateComponents getUriTemplateComponents(Map<String, ?> parameters, List<String>
            requiredArgs) {
        Assert.notNull(parameters, "Parameters must not be null!");

        final StringBuilder baseUrl = new StringBuilder(urlComponents.get(0));
        final StringBuilder queryHead = new StringBuilder();
        final StringBuilder queryTail = new StringBuilder();
        final StringBuilder fragmentIdentifier = new StringBuilder();
        for (int i = 1; i < urlComponents.size(); i++) {
            final String part = urlComponents.get(i);
            final List<Integer> variablesInPart = variableIndices.get(i);
            if (variablesInPart.isEmpty()) {
                if (part.startsWith("?") || part.startsWith("&")) {
                    queryHead.append(part);
                } else if (part.startsWith("#")) {
                    fragmentIdentifier.append(part);
                } else {
                    baseUrl.append(part);
                }
            } else {
                for (Integer variableInPart : variablesInPart) {
                    final TemplateVariable variable = variables.get(variableInPart);
                    final Object value = parameters.get(variable.getName());
                    if (value == null) {
                        switch (variable.getType()) {
                            case REQUEST_PARAM:
                            case REQUEST_PARAM_CONTINUED:
                                if (requiredArgs.isEmpty() || requiredArgs.contains(variable.getName())) {
                                    // query vars without value always go last (query tail)
                                    if (queryTail.length() > 0) {
                                        queryTail.append(',');
                                    }
                                    queryTail.append(variable.getName());
                                }
                                break;
                            case FRAGMENT:
                                fragmentIdentifier.append(variable.toString());
                                break;
                            case PATH_VARIABLE:
                                if (queryHead.length() != 0) {
                                    // level 1 variable in query
                                    queryHead.append(variable.toString());
                                } else {
                                    baseUrl.append(variable.toString());
                                }
                                break;
                            case SEGMENT:
                                baseUrl.append(variable.toString());
                        }
                    } else {
                        switch (variable.getType()) {
                            case REQUEST_PARAM:
                            case REQUEST_PARAM_CONTINUED:
                                if (queryHead.length() == 0) {
                                    queryHead.append('?');
                                } else {
                                    queryHead.append('&');
                                }
                                queryHead.append(variable.getName())
                                        .append('=')
                                        .append(urlEncode(value.toString()));
                                break;
                            case SEGMENT:
                                baseUrl.append('/');
                                // fall through
                            case PATH_VARIABLE:
                                if (queryHead.length() != 0) {
                                    // level 1 variable in query
                                    queryHead.append(urlEncode(value.toString()));
                                } else {
                                    baseUrl.append(urlEncode(value.toString()));
                                }
                                break;
                            case FRAGMENT:
                                fragmentIdentifier.append('#');
                                fragmentIdentifier.append(urlEncode(value.toString()));
                                break;
                        }
                    }
                }
            }
        }

        return new PartialUriTemplateComponents(baseUrl.toString(), queryHead.toString(), queryTail.toString(),
                fragmentIdentifier.toString(), variableNames);
    }
private PartialUriTemplateComponents getUriTemplateComponents(Map<String, ?> parameters, List<String>
            requiredArgs) {
        Assert.notNull(parameters, "Parameters must not be null!");

        final StringBuilder baseUrl = new StringBuilder(urlComponents.get(0));
        final StringBuilder queryHead = new StringBuilder();
        final StringBuilder queryTail = new StringBuilder();
        final StringBuilder fragmentIdentifier = new StringBuilder();
        for (int i = 1; i < urlComponents.size(); i++) {
            final String part = urlComponents.get(i);
            final List<Integer> variablesInPart = variableIndices.get(i);
            if (variablesInPart.isEmpty()) {
                if (part.startsWith("?") || part.startsWith("&")) {
                    queryHead.append(part);
                } else if (part.startsWith("#")) {
                    fragmentIdentifier.append(part);
                } else {
                    baseUrl.append(part);
                }
            } else {
                for (Integer variableInPart : variablesInPart) {
                    final TemplateVariable variable = variables.get(variableInPart);
                    final Object value = parameters.get(variable.getName());
                    if (value == null) {
                        switch (variable.getType()) {
                            case REQUEST_PARAM:
                            case REQUEST_PARAM_CONTINUED:
                                if (requiredArgs.isEmpty() || requiredArgs.contains(variable.getName())) {
                                    // query vars without value always go last (query tail)
                                    if (queryTail.length() > 0) {
                                        queryTail.append(',');
                                    }
                                    queryTail.append(variable.getName());
                                }
                                break;
                            case FRAGMENT:
                                fragmentIdentifier.append(variable.toString());
                                break;
                            case PATH_VARIABLE:
                                if (queryHead.length() != 0) {
                                    // level 1 variable in query
                                    queryHead.append(variable.toString());
                                } else {
                                    baseUrl.append(variable.toString());
                                }
                                break;
                            case SEGMENT:
                                baseUrl.append(variable.toString());
                        }
                    } else {
                        switch (variable.getType()) {
                            case REQUEST_PARAM:
                            case REQUEST_PARAM_CONTINUED:
                                if (queryHead.length() == 0) {
                                    queryHead.append('?');
                                } else {
                                    queryHead.append('&');
                                }
                                queryHead.append(variable.getName())
                                        .append('=')
                                        .append(urlEncode(value.toString()));
                                break;
                            case SEGMENT:
                                baseUrl.append('/');
                                // fall through
                            case PATH_VARIABLE:
                                if (queryHead.length() != 0) {
                                    // level 1 variable in query
                                    queryHead.append(urlEncode(value.toString()));
                                } else {
                                    baseUrl.append(urlEncode(value.toString()));
                                }
                                break;
                            case FRAGMENT:
                                fragmentIdentifier.append('#');
                                fragmentIdentifier.append(urlEncode(value.toString()));
                                break;
                        }
                    }
                }
            }
        }

        return new PartialUriTemplateComponents(baseUrl.toString(), queryHead.toString(), queryTail.toString(),
                fragmentIdentifier.toString(), variableNames);
    }
Applies parameters to template variables.

@param parameters
to apply to variables
@param requiredArgs
if not empty, retains given requiredArgs
@return uri components