Skip to content

Commit ff46cec

Browse files
committed
Polishing
1 parent e1a0c50 commit ff46cec

File tree

4 files changed

+110
-111
lines changed

4 files changed

+110
-111
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/PatternsRequestCondition.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -103,8 +103,8 @@ private PatternsRequestCondition(Collection<String> patterns, UrlPathHelper urlP
103103
List<String> fileExtensions) {
104104

105105
this.patterns = Collections.unmodifiableSet(prependLeadingSlash(patterns));
106-
this.pathHelper = urlPathHelper != null ? urlPathHelper : new UrlPathHelper();
107-
this.pathMatcher = pathMatcher != null ? pathMatcher : new AntPathMatcher();
106+
this.pathHelper = (urlPathHelper != null ? urlPathHelper : new UrlPathHelper());
107+
this.pathMatcher = (pathMatcher != null ? pathMatcher : new AntPathMatcher());
108108
this.useSuffixPatternMatch = useSuffixPatternMatch;
109109
this.useTrailingSlashMatch = useTrailingSlashMatch;
110110
if (fileExtensions != null) {
@@ -220,7 +220,6 @@ public PatternsRequestCondition getMatchingCondition(HttpServletRequest request)
220220
* {@link #getMatchingCondition(javax.servlet.http.HttpServletRequest)}.
221221
* This method is provided as an alternative to be used if no request is available
222222
* (e.g. introspection, tooling, etc).
223-
*
224223
* @param lookupPath the lookup path to match to existing patterns
225224
* @return a collection of matching patterns sorted with the closest match at the top
226225
*/

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfo.java

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.springframework.web.servlet.mvc.method;
1818

1919
import java.util.List;
20-
2120
import javax.servlet.http.HttpServletRequest;
2221

2322
import org.springframework.http.HttpHeaders;
@@ -39,13 +38,13 @@
3938
/**
4039
* Encapsulates the following request mapping conditions:
4140
* <ol>
42-
* <li>{@link PatternsRequestCondition}
43-
* <li>{@link RequestMethodsRequestCondition}
44-
* <li>{@link ParamsRequestCondition}
45-
* <li>{@link HeadersRequestCondition}
46-
* <li>{@link ConsumesRequestCondition}
47-
* <li>{@link ProducesRequestCondition}
48-
* <li>{@code RequestCondition} (optional, custom request condition)
41+
* <li>{@link PatternsRequestCondition}
42+
* <li>{@link RequestMethodsRequestCondition}
43+
* <li>{@link ParamsRequestCondition}
44+
* <li>{@link HeadersRequestCondition}
45+
* <li>{@link ConsumesRequestCondition}
46+
* <li>{@link ProducesRequestCondition}
47+
* <li>{@code RequestCondition} (optional, custom request condition)
4948
* </ol>
5049
*
5150
* @author Arjen Poutsma
@@ -297,21 +296,21 @@ public int compareTo(RequestMappingInfo other, HttpServletRequest request) {
297296
}
298297

299298
@Override
300-
public boolean equals(Object obj) {
301-
if (this == obj) {
299+
public boolean equals(Object other) {
300+
if (this == other) {
302301
return true;
303302
}
304-
if (obj != null && obj instanceof RequestMappingInfo) {
305-
RequestMappingInfo other = (RequestMappingInfo) obj;
306-
return (this.patternsCondition.equals(other.patternsCondition) &&
307-
this.methodsCondition.equals(other.methodsCondition) &&
308-
this.paramsCondition.equals(other.paramsCondition) &&
309-
this.headersCondition.equals(other.headersCondition) &&
310-
this.consumesCondition.equals(other.consumesCondition) &&
311-
this.producesCondition.equals(other.producesCondition) &&
312-
this.customConditionHolder.equals(other.customConditionHolder));
313-
}
314-
return false;
303+
if (!(other instanceof RequestMappingInfo)) {
304+
return false;
305+
}
306+
RequestMappingInfo otherInfo = (RequestMappingInfo) other;
307+
return (this.patternsCondition.equals(otherInfo.patternsCondition) &&
308+
this.methodsCondition.equals(otherInfo.methodsCondition) &&
309+
this.paramsCondition.equals(otherInfo.paramsCondition) &&
310+
this.headersCondition.equals(otherInfo.headersCondition) &&
311+
this.consumesCondition.equals(otherInfo.consumesCondition) &&
312+
this.producesCondition.equals(otherInfo.producesCondition) &&
313+
this.customConditionHolder.equals(otherInfo.customConditionHolder));
315314
}
316315

317316
@Override
@@ -348,6 +347,7 @@ public String toString() {
348347
return builder.toString();
349348
}
350349

350+
351351
/**
352352
* Create a new {@code RequestMappingInfo.Builder} with the given paths.
353353
* @param paths the paths to use
@@ -416,6 +416,7 @@ public interface Builder {
416416
RequestMappingInfo build();
417417
}
418418

419+
419420
private static class DefaultBuilder implements Builder {
420421

421422
private String[] paths;
@@ -436,12 +437,10 @@ private static class DefaultBuilder implements Builder {
436437

437438
private BuilderConfiguration options = new BuilderConfiguration();
438439

439-
440440
public DefaultBuilder(String... paths) {
441441
this.paths = paths;
442442
}
443443

444-
445444
@Override
446445
public Builder paths(String... paths) {
447446
this.paths = paths;
@@ -498,7 +497,6 @@ public Builder options(BuilderConfiguration options) {
498497

499498
@Override
500499
public RequestMappingInfo build() {
501-
502500
ContentNegotiationManager manager = this.options.getContentNegotiationManager();
503501

504502
PatternsRequestCondition patternsCondition = new PatternsRequestCondition(
@@ -516,13 +514,13 @@ public RequestMappingInfo build() {
516514
}
517515
}
518516

517+
519518
/**
520519
* Container for configuration options used for request mapping purposes.
521520
* Such configuration is required to create RequestMappingInfo instances but
522521
* is typically used across all RequestMappingInfo instances.
523-
*
524-
* @see Builder#options
525522
* @since 4.2
523+
* @see Builder#options
526524
*/
527525
public static class BuilderConfiguration {
528526

@@ -538,7 +536,6 @@ public static class BuilderConfiguration {
538536

539537
private ContentNegotiationManager contentNegotiationManager;
540538

541-
542539
/**
543540
* Set a custom UrlPathHelper to use for the PatternsRequestCondition.
544541
* <p>By default this is not set.

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMapping.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ public void setEmbeddedValueResolver(StringValueResolver resolver) {
122122

123123
@Override
124124
public void afterPropertiesSet() {
125-
126125
this.config = new RequestMappingInfo.BuilderConfiguration();
127126
this.config.setPathHelper(getUrlPathHelper());
128127
this.config.setPathMatcher(getPathMatcher());
@@ -204,15 +203,13 @@ protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handler
204203
* Delegates to {@link #createRequestMappingInfo(RequestMapping, RequestCondition)},
205204
* supplying the appropriate custom {@link RequestCondition} depending on whether
206205
* the supplied {@code annotatedElement} is a class or method.
207-
*
208206
* @see #getCustomTypeCondition(Class)
209207
* @see #getCustomMethodCondition(Method)
210208
*/
211209
private RequestMappingInfo createRequestMappingInfo(AnnotatedElement element) {
212210
RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(element, RequestMapping.class);
213211
RequestCondition<?> condition = (element instanceof Class<?> ?
214-
getCustomTypeCondition((Class<?>) element) :
215-
getCustomMethodCondition((Method) element));
212+
getCustomTypeCondition((Class<?>) element) : getCustomMethodCondition((Method) element));
216213
return (requestMapping != null ? createRequestMappingInfo(requestMapping, condition) : null);
217214
}
218215

@@ -252,8 +249,8 @@ protected RequestCondition<?> getCustomMethodCondition(Method method) {
252249
* a directly declared annotation, a meta-annotation, or the synthesized
253250
* result of merging annotation attributes within an annotation hierarchy.
254251
*/
255-
protected RequestMappingInfo createRequestMappingInfo(RequestMapping requestMapping,
256-
RequestCondition<?> customCondition) {
252+
protected RequestMappingInfo createRequestMappingInfo(
253+
RequestMapping requestMapping, RequestCondition<?> customCondition) {
257254

258255
return RequestMappingInfo
259256
.paths(resolveEmbeddedValuesInPatterns(requestMapping.path()))
@@ -348,7 +345,7 @@ else if (!allowCredentials.isEmpty()) {
348345
+ "or an empty string (\"\"); current value is [" + allowCredentials + "].");
349346
}
350347

351-
if ((annotation.maxAge() >= 0) && (config.getMaxAge() == null)) {
348+
if (annotation.maxAge() >= 0 && config.getMaxAge() == null) {
352349
config.setMaxAge(annotation.maxAge());
353350
}
354351
}

0 commit comments

Comments
 (0)