Skip to content

Commit d1c1fbb

Browse files
committed
#1172 - Polishing.
A bit of Javadoc on the factory methods. Avoiding abbreviations in method names, shorter parameter names. More trailing whitespace removal. Reformatting of method invocation in test cases. Original pull request: #1192.
1 parent f1bc790 commit d1c1fbb

File tree

2 files changed

+71
-44
lines changed

2 files changed

+71
-44
lines changed

src/main/java/org/springframework/hateoas/TemplateVariable.java

+34-28
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
/**
3131
* A single template variable.
32-
*
32+
*
3333
* @author Oliver Gierke
3434
* @author JamesE Richardson
3535
*/
@@ -45,7 +45,7 @@ public final class TemplateVariable implements Serializable {
4545

4646
/**
4747
* Creates a new {@link TemplateVariable} with the given name and type.
48-
*
48+
*
4949
* @param name must not be {@literal null} or empty.
5050
* @param type must not be {@literal null}.
5151
*/
@@ -55,7 +55,7 @@ public TemplateVariable(String name, TemplateVariable.VariableType type) {
5555

5656
/**
5757
* Creates a new {@link TemplateVariable} with the given name, type and description.
58-
*
58+
*
5959
* @param name must not be {@literal null} or empty.
6060
* @param type must not be {@literal null}.
6161
* @param description must not be {@literal null}.
@@ -74,38 +74,42 @@ public TemplateVariable(String name, TemplateVariable.VariableType type, String
7474
/**
7575
* Static helper to fashion {@link VariableType#PATH_VARIABLE} variables.
7676
*
77-
* @param pathVariable
77+
* @param variable must not be {@literal null} or empty.
7878
* @return
79+
* @since 1.1
7980
*/
80-
public static TemplateVariable pathVariable(String pathVariable) {
81-
return new TemplateVariable(pathVariable, VariableType.PATH_VARIABLE);
81+
public static TemplateVariable pathVariable(String variable) {
82+
return new TemplateVariable(variable, VariableType.PATH_VARIABLE);
8283
}
8384

8485
/**
8586
* Static helper to fashion {@link VariableType#REQUEST_PARAM} variables.
8687
*
87-
* @param requestParam
88+
* @param parameter must not be {@literal null} or empty.
8889
* @return
90+
* @since 1.1
8991
*/
90-
public static TemplateVariable requestParam(String requestParam) {
91-
return new TemplateVariable(requestParam, VariableType.REQUEST_PARAM);
92+
public static TemplateVariable requestParameter(String parameter) {
93+
return new TemplateVariable(parameter, VariableType.REQUEST_PARAM);
9294
}
9395

9496
/**
9597
* Static helper to fashion {@link VariableType#REQUEST_PARAM_CONTINUED} variables.
9698
*
97-
* @param requestParam
99+
* @param parameter must not be {@literal null} or empty.
98100
* @return
101+
* @since 1.1
99102
*/
100-
public static TemplateVariable requestParamContinued(String requestParam) {
101-
return new TemplateVariable(requestParam, VariableType.REQUEST_PARAM_CONTINUED);
103+
public static TemplateVariable requestParameterContinued(String parameter) {
104+
return new TemplateVariable(parameter, VariableType.REQUEST_PARAM_CONTINUED);
102105
}
103106

104107
/**
105108
* Static helper to fashion {@link VariableType#SEGMENT} variables.
106109
*
107-
* @param segment
110+
* @param segment must not be {@literal null} or empty.
108111
* @return
112+
* @since 1.1
109113
*/
110114
public static TemplateVariable segment(String segment) {
111115
return new TemplateVariable(segment, VariableType.SEGMENT);
@@ -114,8 +118,9 @@ public static TemplateVariable segment(String segment) {
114118
/**
115119
* Static helper to fashion {@link VariableType#FRAGMENT} variables.
116120
*
117-
* @param fragment
121+
* @param fragment must not be {@literal null} or empty.
118122
* @return
123+
* @since 1.1
119124
*/
120125
public static TemplateVariable fragment(String fragment) {
121126
return new TemplateVariable(fragment, VariableType.FRAGMENT);
@@ -124,16 +129,17 @@ public static TemplateVariable fragment(String fragment) {
124129
/**
125130
* Static helper to fashion {@link VariableType#COMPOSITE_PARAM} variables.
126131
*
127-
* @param compositeParam
132+
* @param parameter must not be {@literal null} or empty.
128133
* @return
134+
* @since 1.1
129135
*/
130-
public static TemplateVariable compositeParam(String compositeParam) {
131-
return new TemplateVariable(compositeParam, VariableType.COMPOSITE_PARAM);
136+
public static TemplateVariable compositeParameter(String parameter) {
137+
return new TemplateVariable(parameter, VariableType.COMPOSITE_PARAM);
132138
}
133-
139+
134140
/**
135141
* Returns whether the variable has a description.
136-
*
142+
*
137143
* @return
138144
*/
139145
public boolean hasDescription() {
@@ -143,7 +149,7 @@ public boolean hasDescription() {
143149
/**
144150
* Returns whether the template variable is optional, which means the template can be expanded to a URI without a
145151
* value given for that variable.
146-
*
152+
*
147153
* @return
148154
*/
149155
boolean isRequired() {
@@ -152,7 +158,7 @@ boolean isRequired() {
152158

153159
/**
154160
* Returns whether the given {@link TemplateVariable} is of the same type as the current one.
155-
*
161+
*
156162
* @param variable must not be {@literal null}.
157163
* @return
158164
*/
@@ -163,7 +169,7 @@ boolean isCombinable(TemplateVariable variable) {
163169
/**
164170
* Returns whether the given {@link TemplateVariable} is logically equivalent to the given one. This considers request
165171
* parameter variables equivalent independently from whether they're continued or not.
166-
*
172+
*
167173
* @param variable
168174
* @return
169175
*/
@@ -173,7 +179,7 @@ boolean isEquivalent(TemplateVariable variable) {
173179

174180
/**
175181
* Returns whether the current {@link TemplateVariable} is representing a request parameter.
176-
*
182+
*
177183
* @return
178184
*/
179185
boolean isRequestParameterVariable() {
@@ -182,14 +188,14 @@ boolean isRequestParameterVariable() {
182188

183189
/**
184190
* Returns whether the variable is a fragment one.
185-
*
191+
*
186192
* @return
187193
*/
188194
boolean isFragment() {
189195
return type.equals(FRAGMENT);
190196
}
191197

192-
/*
198+
/*
193199
* (non-Javadoc)
194200
* @see java.lang.Object#toString()
195201
*/
@@ -202,7 +208,7 @@ public String toString() {
202208

203209
/**
204210
* An enumeration for all supported variable types.
205-
*
211+
*
206212
* @author Oliver Gierke
207213
*/
208214
public enum VariableType {
@@ -227,7 +233,7 @@ public enum VariableType {
227233

228234
/**
229235
* Returns whether the variable of this type is optional.
230-
*
236+
*
231237
* @return
232238
*/
233239
public boolean isOptional() {
@@ -240,7 +246,7 @@ public boolean canBeCombinedWith(VariableType type) {
240246

241247
/**
242248
* Returns the {@link VariableType} for the given variable key.
243-
*
249+
*
244250
* @param key must not be {@literal null}.
245251
* @return
246252
*/

src/test/java/org/springframework/hateoas/UriTemplateUnitTest.java

+37-16
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
import org.junit.jupiter.api.Test;
4040
import org.junit.jupiter.params.ParameterizedTest;
4141
import org.junit.jupiter.params.provider.MethodSource;
42-
import org.springframework.hateoas.TemplateVariable.*;
42+
import org.springframework.hateoas.TemplateVariable.VariableType;
4343

4444
/**
4545
* Unit tests for {@link UriTemplate}.
@@ -301,23 +301,44 @@ void expandsTemplateWithAddedVariable() {
301301
assertThat(template.expand("value").toString()).isEqualTo("/foo?bar=value");
302302
}
303303

304-
@Test // 1172
304+
@Test // #1172
305305
void useHelperMethodsToBuildUriTemplates() {
306306

307-
assertThat(UriTemplate.of("/foo").with(pathVariable("var")).getVariableNames()).containsExactly("var");
308-
309-
assertThat(UriTemplate.of("/foo").with(requestParam("var")).with(requestParamContinued("var2")).toString())
310-
.isEqualTo("/foo{?var,var2}");
311-
assertThat(UriTemplate.of("/foo").with(requestParam("var")).with(requestParam("var2")).toString())
312-
.isEqualTo("/foo{?var,var2}");
313-
314-
assertThat(UriTemplate.of("/foo").with(requestParamContinued("var2")).toString()).isEqualTo("/foo{&var2}");
315-
316-
assertThat(UriTemplate.of("/foo").with(segment("var")).toString()).isEqualTo("/foo{/var}");
317-
318-
assertThat(UriTemplate.of("/foo").with(fragment("var")).toString()).isEqualTo("/foo{#var}");
319-
320-
assertThat(UriTemplate.of("/foo").with(compositeParam("var")).toString()).isEqualTo("/foo{*var}");
307+
assertThat(UriTemplate.of("/foo") //
308+
.with(pathVariable("var")) //
309+
.getVariableNames()) //
310+
.containsExactly("var");
311+
312+
assertThat(UriTemplate.of("/foo") //
313+
.with(requestParameter("var")) //
314+
.with(requestParameterContinued("var2")) //
315+
.toString()) //
316+
.isEqualTo("/foo{?var,var2}");
317+
318+
assertThat(UriTemplate.of("/foo") //
319+
.with(requestParameter("var")) //
320+
.with(requestParameter("var2")) //
321+
.toString()) //
322+
.isEqualTo("/foo{?var,var2}");
323+
324+
assertThat(UriTemplate.of("/foo") //
325+
.with(requestParameterContinued("var2")) //
326+
.toString()).isEqualTo("/foo{&var2}");
327+
328+
assertThat(UriTemplate.of("/foo") //
329+
.with(segment("var")) //
330+
.toString()) //
331+
.isEqualTo("/foo{/var}");
332+
333+
assertThat(UriTemplate.of("/foo") //
334+
.with(fragment("var")) //
335+
.toString()) //
336+
.isEqualTo("/foo{#var}");
337+
338+
assertThat(UriTemplate.of("/foo") //
339+
.with(compositeParameter("var")) //
340+
.toString()) //
341+
.isEqualTo("/foo{*var}");
321342
}
322343

323344
private static void assertVariables(UriTemplate template, TemplateVariable... variables) {

0 commit comments

Comments
 (0)