#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:
Oliver Gierke
2014-01-23 14:09:35 +01:00
parent c790a5d834
commit 9caa352470
5 changed files with 142 additions and 12 deletions

View File

@@ -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.
*