#1172 - Provide static helpers to build TemplateVariable instance.

We now expose static factory methods to make code setting up a UriTemplate with TemplateVariable instances.

Original pull request: #1192.
This commit is contained in:
Greg Turnquist
2020-02-05 20:38:51 -06:00
committed by Oliver Drotbohm
parent f297bb28e5
commit f1bc790a23
2 changed files with 82 additions and 2 deletions

View File

@@ -71,6 +71,66 @@ public final class TemplateVariable implements Serializable {
this.description = description;
}
/**
* Static helper to fashion {@link VariableType#PATH_VARIABLE} variables.
*
* @param pathVariable
* @return
*/
public static TemplateVariable pathVariable(String pathVariable) {
return new TemplateVariable(pathVariable, VariableType.PATH_VARIABLE);
}
/**
* Static helper to fashion {@link VariableType#REQUEST_PARAM} variables.
*
* @param requestParam
* @return
*/
public static TemplateVariable requestParam(String requestParam) {
return new TemplateVariable(requestParam, VariableType.REQUEST_PARAM);
}
/**
* Static helper to fashion {@link VariableType#REQUEST_PARAM_CONTINUED} variables.
*
* @param requestParam
* @return
*/
public static TemplateVariable requestParamContinued(String requestParam) {
return new TemplateVariable(requestParam, VariableType.REQUEST_PARAM_CONTINUED);
}
/**
* Static helper to fashion {@link VariableType#SEGMENT} variables.
*
* @param segment
* @return
*/
public static TemplateVariable segment(String segment) {
return new TemplateVariable(segment, VariableType.SEGMENT);
}
/**
* Static helper to fashion {@link VariableType#FRAGMENT} variables.
*
* @param fragment
* @return
*/
public static TemplateVariable fragment(String fragment) {
return new TemplateVariable(fragment, VariableType.FRAGMENT);
}
/**
* Static helper to fashion {@link VariableType#COMPOSITE_PARAM} variables.
*
* @param compositeParam
* @return
*/
public static TemplateVariable compositeParam(String compositeParam) {
return new TemplateVariable(compositeParam, VariableType.COMPOSITE_PARAM);
}
/**
* Returns whether the variable has a description.
*
@@ -192,7 +252,7 @@ public final class TemplateVariable implements Serializable {
.orElseThrow(() -> new IllegalArgumentException("Unsupported variable type " + key + "!"));
}
/*
/*
* (non-Javadoc)
* @see java.lang.Enum#toString()
*/