Polishing

This commit is contained in:
Juergen Hoeller
2018-06-28 14:51:31 +02:00
parent b68e692854
commit 40efcc933c
107 changed files with 510 additions and 624 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -129,7 +129,9 @@ public class PathMatchConfigurer {
* @since 5.1
*/
public PathMatchConfigurer addPathPrefix(String prefix, Predicate<Class<?>> predicate) {
this.pathPrefixes = this.pathPrefixes == null ? new LinkedHashMap<>() : this.pathPrefixes;
if (this.pathPrefixes == null) {
this.pathPrefixes = new LinkedHashMap<>();
}
this.pathPrefixes.put(prefix, predicate);
return this;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -74,15 +74,15 @@ abstract class AbstractMediaTypeExpression implements MediaTypeExpression, Compa
}
@Override
public boolean equals(@Nullable Object obj) {
if (this == obj) {
public boolean equals(@Nullable Object other) {
if (this == other) {
return true;
}
if (obj != null && getClass() == obj.getClass()) {
AbstractMediaTypeExpression other = (AbstractMediaTypeExpression) obj;
return (this.mediaType.equals(other.mediaType) && this.isNegated == other.isNegated);
if (other == null || getClass() != other.getClass()) {
return false;
}
return false;
AbstractMediaTypeExpression otherExpr = (AbstractMediaTypeExpression) other;
return (this.mediaType.equals(otherExpr.mediaType) && this.isNegated == otherExpr.isNegated);
}
@Override

View File

@@ -19,6 +19,7 @@ package org.springframework.web.servlet.mvc.condition;
import javax.servlet.http.HttpServletRequest;
import org.springframework.lang.Nullable;
import org.springframework.util.ObjectUtils;
/**
* Supports "name=value" style expressions as described in:
@@ -93,19 +94,16 @@ abstract class AbstractNameValueExpression<T> implements NameValueExpression<T>
@Override
public boolean equals(Object obj) {
if (this == obj) {
public boolean equals(@Nullable Object other) {
if (this == other) {
return true;
}
if (obj instanceof AbstractNameValueExpression) {
AbstractNameValueExpression<?> other = (AbstractNameValueExpression<?>) obj;
String thisName = (isCaseSensitiveName() ? this.name : this.name.toLowerCase());
String otherName = (isCaseSensitiveName() ? other.name : other.name.toLowerCase());
return (thisName.equalsIgnoreCase(otherName) &&
(this.value != null ? this.value.equals(other.value) : other.value == null) &&
this.isNegated == other.isNegated);
if (other == null || getClass() != other.getClass()) {
return false;
}
return false;
AbstractNameValueExpression<?> that = (AbstractNameValueExpression<?>) other;
return ((isCaseSensitiveName() ? this.name.equals(that.name) : this.name.equalsIgnoreCase(that.name)) &&
ObjectUtils.nullSafeEquals(this.value, that.value) && this.isNegated == that.isNegated);
}
@Override

View File

@@ -57,15 +57,14 @@ public abstract class AbstractRequestCondition<T extends AbstractRequestConditio
@Override
public boolean equals(@Nullable Object obj) {
if (this == obj) {
public boolean equals(@Nullable Object other) {
if (this == other) {
return true;
}
if (obj != null && getClass() == obj.getClass()) {
AbstractRequestCondition<?> other = (AbstractRequestCondition<?>) obj;
return getContent().equals(other.getContent());
if (other == null || getClass() != other.getClass()) {
return false;
}
return false;
return getContent().equals(((AbstractRequestCondition<?>) other).getContent());
}
@Override

View File

@@ -92,7 +92,7 @@ public class CompositeRequestCondition extends AbstractRequestCondition<Composit
@Override
protected Collection<?> getContent() {
return (isEmpty()) ? Collections.emptyList() : getConditions();
return (!isEmpty() ? getConditions() : Collections.emptyList());
}
@Override

View File

@@ -146,7 +146,7 @@ public final class ConsumesRequestCondition extends AbstractRequestCondition<Con
*/
@Override
public ConsumesRequestCondition combine(ConsumesRequestCondition other) {
return !other.expressions.isEmpty() ? other : this;
return (!other.expressions.isEmpty() ? other : this);
}
/**

View File

@@ -175,8 +175,8 @@ public final class PatternsRequestCondition extends AbstractRequestCondition<Pat
else {
result.add("");
}
return new PatternsRequestCondition(result, this.pathHelper, this.pathMatcher, this.useSuffixPatternMatch,
this.useTrailingSlashMatch, this.fileExtensions);
return new PatternsRequestCondition(result, this.pathHelper, this.pathMatcher,
this.useSuffixPatternMatch, this.useTrailingSlashMatch, this.fileExtensions);
}
/**
@@ -198,17 +198,14 @@ public final class PatternsRequestCondition extends AbstractRequestCondition<Pat
@Override
@Nullable
public PatternsRequestCondition getMatchingCondition(HttpServletRequest request) {
if (this.patterns.isEmpty()) {
return this;
}
String lookupPath = this.pathHelper.getLookupPathForRequest(request);
List<String> matches = getMatchingPatterns(lookupPath);
return matches.isEmpty() ? null :
new PatternsRequestCondition(matches, this.pathHelper, this.pathMatcher, this.useSuffixPatternMatch,
this.useTrailingSlashMatch, this.fileExtensions);
return (!matches.isEmpty() ?
new PatternsRequestCondition(matches, this.pathHelper, this.pathMatcher,
this.useSuffixPatternMatch, this.useTrailingSlashMatch, this.fileExtensions) : null);
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -86,7 +86,7 @@ public abstract class AbstractVersionStrategy implements VersionStrategy {
private final String prefix;
public PrefixVersionPathStrategy(String version) {
Assert.hasText(version, "'version' must not be empty");
Assert.hasText(version, "Version must not be empty");
this.prefix = version;
}

View File

@@ -82,18 +82,15 @@ public class CachingResourceResolver extends AbstractResourceResolver {
/**
* Configure the supported content codings from the
* {@literal "Accept-Encoding"} header for which to cache resource variations.
*
* <p>The codings configured here are generally expected to match those
* configured on {@link EncodedResourceResolver#setContentCodings(List)}.
*
* <p>By default this property is set to {@literal ["br", "gzip"]} based on
* the value of {@link EncodedResourceResolver#DEFAULT_CODINGS}.
*
* @param codings one or more supported content codings
* @since 5.1
*/
public void setContentCodings(List<String> codings) {
Assert.notEmpty(codings, "At least one content coding expected.");
Assert.notEmpty(codings, "At least one content coding expected");
this.contentCodings.clear();
this.contentCodings.addAll(codings);
}

View File

@@ -229,19 +229,19 @@ public class CssLinkResourceTransformer extends ResourceTransformerSupport {
@Override
public int compareTo(ContentChunkInfo other) {
return (this.start < other.start ? -1 : (this.start == other.start ? 0 : 1));
return Integer.compare(this.start, other.start);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (obj instanceof ContentChunkInfo) {
ContentChunkInfo other = (ContentChunkInfo) obj;
return (this.start == other.start && this.end == other.end);
if (!(other instanceof ContentChunkInfo)) {
return false;
}
return false;
ContentChunkInfo otherCci = (ContentChunkInfo) other;
return (this.start == otherCci.start && this.end == otherCci.end);
}
@Override

View File

@@ -75,27 +75,22 @@ public class EncodedResourceResolver extends AbstractResourceResolver {
* coding that is present in the {@literal "Accept-Encoding"} header for a
* given request, and that has a file present with the associated extension,
* is used.
*
* <p><strong>Note:</strong> Each coding must be associated with a file
* extension via {@link #registerExtension} or {@link #setExtensions}. Also
* customizations to the list of codings here should be matched by
* customizations to the same list in {@link CachingResourceResolver} to
* ensure encoded variants of a resource are cached under separate keys.
*
* <p>By default this property is set to {@literal ["br", "gzip"]}.
*
* @param codings one or more supported content codings
* @since 5.1
*/
public void setContentCodings(List<String> codings) {
Assert.notEmpty(codings, "At least one content coding expected.");
Assert.notEmpty(codings, "At least one content coding expected");
this.contentCodings.clear();
this.contentCodings.addAll(codings);
}
/**
* Return a read-only list with the supported content codings.
* @since 5.1
*/
public List<String> getContentCodings() {
return Collections.unmodifiableList(this.contentCodings);
@@ -107,31 +102,28 @@ public class EncodedResourceResolver extends AbstractResourceResolver {
* <p>By default this is configured with {@literal ["br" -> ".br"]} and
* {@literal ["gzip" -> ".gz"]}.
* @param extensions the extensions to use.
* @since 5.1
* @see #registerExtension(String, String)
*/
public void setExtensions(Map<String, String> extensions) {
extensions.forEach(this::registerExtension);
}
/**
* Java config friendly alternative to {@link #setExtensions(Map)}.
* @param coding the content coding
* @param extension the associated file extension
* @since 5.1
*/
public void registerExtension(String coding, String extension) {
this.extensions.put(coding, extension.startsWith(".") ? extension : "." + extension);
}
/**
* Return a read-only map with coding-to-extension mappings.
* @since 5.1
*/
public Map<String, String> getExtensions() {
return Collections.unmodifiableMap(this.extensions);
}
/**
* Java config friendly alternative to {@link #setExtensions(Map)}.
* @param coding the content coding
* @param extension the associated file extension
*/
public void registerExtension(String coding, String extension) {
this.extensions.put(coding, (extension.startsWith(".") ? extension : "." + extension));
}
@Override
protected Resource resolveResourceInternal(@Nullable HttpServletRequest request, String requestPath,
@@ -168,12 +160,12 @@ public class EncodedResourceResolver extends AbstractResourceResolver {
@Nullable
private String getAcceptEncoding(HttpServletRequest request) {
String header = request.getHeader(HttpHeaders.ACCEPT_ENCODING);
return header != null ? header.toLowerCase() : null;
return (header != null ? header.toLowerCase() : null);
}
private String getExtension(String coding) {
String extension = this.extensions.get(coding);
Assert.notNull(extension, "No file extension associated with content coding " + coding);
Assert.state(extension != null, () -> "No file extension associated with content coding " + coding);
return extension;
}

View File

@@ -225,7 +225,7 @@ public class ScriptTemplateView extends AbstractUrlBasedView {
}
if (this.resourceLoaderPaths == null) {
String resourceLoaderPath = viewConfig.getResourceLoaderPath();
setResourceLoaderPath(resourceLoaderPath == null ? DEFAULT_RESOURCE_LOADER_PATH : resourceLoaderPath);
setResourceLoaderPath(resourceLoaderPath != null ? resourceLoaderPath : DEFAULT_RESOURCE_LOADER_PATH);
}
if (this.sharedEngine == null && viewConfig.isSharedEngine() != null) {
this.sharedEngine = viewConfig.isSharedEngine();