/** * Creates a new {@link UriTemplate} with the current {@link TemplateVariable}s augmented with the given ones. * * @param variables can be {@literal null}. * @return will never be {@literal null}. */ public UriTemplate with(TemplateVariables variables) { if (variables == null) { return this; } UriComponents components = UriComponentsBuilder.fromUriString(baseUri).build(); List<TemplateVariable> result = new ArrayList<>(); for (TemplateVariable variable : variables) { boolean isRequestParam = variable.isRequestParameterVariable(); boolean alreadyPresent = components.getQueryParams().containsKey(variable.getName()); if (isRequestParam && alreadyPresent) { continue; } if (variable.isFragment() && StringUtils.hasText(components.getFragment())) { continue; } result.add(variable); } return new UriTemplate(baseUri, this.variables.concat(result)); }
/** * Creates a new {@link UriTemplate} with the current {@link TemplateVariable}s augmented with the given ones. * * @param variables can be {@literal null}. * @return will never be {@literal null}. */ public UriTemplate with(TemplateVariables variables) { if (variables == null) { return this; } UriComponents components = UriComponentsBuilder.fromUriString(baseUri).build(); List<TemplateVariable> result = new ArrayList<TemplateVariable>(); for (TemplateVariable variable : variables) { boolean isRequestParam = variable.isRequestParameterVariable(); boolean alreadyPresent = components.getQueryParams().containsKey(variable.getName()); if (isRequestParam && alreadyPresent) { continue; } if (variable.isFragment() && StringUtils.hasText(components.getFragment())) { continue; } result.add(variable); } return new UriTemplate(baseUri, this.variables.concat(result)); }