#137 - Improved TemplateVariables to combine variables.
Request parameters variables {?…} and continued ones {&…} are now combined by TemplateVariables. Improved detection of the base URI and adapted the rendering logic accordingly. UriTemplates can now be augmented with additional TemplateVariables.
Added equals(…) and hashCode() methods for TempalteVariables.
This commit is contained in:
@@ -15,6 +15,9 @@
|
||||
*/
|
||||
package org.springframework.hateoas;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -109,8 +112,8 @@ public final class TemplateVariable {
|
||||
* @param variable must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
boolean isOfSameTypeAs(TemplateVariable variable) {
|
||||
return this.type.equals(variable.type);
|
||||
boolean isCombinable(TemplateVariable variable) {
|
||||
return this.type.canBeCombinedWith(variable.type);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -171,6 +174,8 @@ public final class TemplateVariable {
|
||||
SEGMENT("/", true), //
|
||||
FRAGMENT("#", true);
|
||||
|
||||
private static final List<VariableType> combinableTypes = Arrays.asList(REQUEST_PARAM, REQUEST_PARAM_CONTINUED);
|
||||
|
||||
private final String key;
|
||||
private final boolean optional;
|
||||
|
||||
@@ -188,6 +193,10 @@ public final class TemplateVariable {
|
||||
return optional;
|
||||
}
|
||||
|
||||
public boolean canBeCombinedWith(VariableType type) {
|
||||
return this.equals(type) || combinableTypes.contains(this) && combinableTypes.contains(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link VariableType} for the given variable key.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user