Polishing (collapsed if checks, consistent downcasts, refined javadoc)

This commit is contained in:
Juergen Hoeller
2018-03-08 18:11:57 +01:00
parent 0f7485b01d
commit 139dc1d373
50 changed files with 336 additions and 435 deletions

View File

@@ -144,17 +144,15 @@ public class ResourceHttpMessageWriter implements HttpMessageWriter<Resource> {
private static Optional<Mono<Void>> zeroCopy(Resource resource, @Nullable ResourceRegion region,
ReactiveHttpOutputMessage message) {
if (message instanceof ZeroCopyHttpOutputMessage) {
if (resource.isFile()) {
try {
File file = resource.getFile();
long pos = region != null ? region.getPosition() : 0;
long count = region != null ? region.getCount() : file.length();
return Optional.of(((ZeroCopyHttpOutputMessage) message).writeWith(file, pos, count));
}
catch (IOException ex) {
// should not happen
}
if (message instanceof ZeroCopyHttpOutputMessage && resource.isFile()) {
try {
File file = resource.getFile();
long pos = region != null ? region.getPosition() : 0;
long count = region != null ? region.getCount() : file.length();
return Optional.of(((ZeroCopyHttpOutputMessage) message).writeWith(file, pos, count));
}
catch (IOException ex) {
// should not happen
}
}
return Optional.empty();

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.
@@ -51,12 +51,8 @@ public class RequestParamMapMethodArgumentResolver implements HandlerMethodArgum
@Override
public boolean supportsParameter(MethodParameter parameter) {
RequestParam requestParam = parameter.getParameterAnnotation(RequestParam.class);
if (requestParam != null) {
if (Map.class.isAssignableFrom(parameter.getParameterType())) {
return !StringUtils.hasText(requestParam.name());
}
}
return false;
return (requestParam != null && Map.class.isAssignableFrom(parameter.getParameterType()) &&
!StringUtils.hasText(requestParam.name()));
}
@Override

View File

@@ -220,10 +220,9 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod
Assert.state(name != null, "Unresolvable parameter name");
if (value == null) {
if (requestParam != null) {
if (!requestParam.required() || !requestParam.defaultValue().equals(ValueConstants.DEFAULT_NONE)) {
return;
}
if (requestParam != null &&
(!requestParam.required() || !requestParam.defaultValue().equals(ValueConstants.DEFAULT_NONE))) {
return;
}
builder.queryParam(name);
}

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.
@@ -98,15 +98,14 @@ public class CompositeUriComponentsContributor implements UriComponentsContribut
@Override
public boolean supportsParameter(MethodParameter parameter) {
for (Object c : this.contributors) {
if (c instanceof UriComponentsContributor) {
UriComponentsContributor contributor = (UriComponentsContributor) c;
if (contributor.supportsParameter(parameter)) {
for (Object contributor : this.contributors) {
if (contributor instanceof UriComponentsContributor) {
if (((UriComponentsContributor) contributor).supportsParameter(parameter)) {
return true;
}
}
else if (c instanceof HandlerMethodArgumentResolver) {
if (((HandlerMethodArgumentResolver) c).supportsParameter(parameter)) {
else if (contributor instanceof HandlerMethodArgumentResolver) {
if (((HandlerMethodArgumentResolver) contributor).supportsParameter(parameter)) {
return false;
}
}

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.
@@ -98,10 +98,9 @@ public class HandlerMethodReturnValueHandlerComposite implements HandlerMethodRe
private boolean isAsyncReturnValue(@Nullable Object value, MethodParameter returnType) {
for (HandlerMethodReturnValueHandler handler : this.returnValueHandlers) {
if (handler instanceof AsyncHandlerMethodReturnValueHandler) {
if (((AsyncHandlerMethodReturnValueHandler) handler).isAsyncReturnValue(value, returnType)) {
return true;
}
if (handler instanceof AsyncHandlerMethodReturnValueHandler &&
((AsyncHandlerMethodReturnValueHandler) handler).isAsyncReturnValue(value, returnType)) {
return true;
}
}
return false;
@@ -122,9 +121,7 @@ public class HandlerMethodReturnValueHandlerComposite implements HandlerMethodRe
@Nullable List<? extends HandlerMethodReturnValueHandler> handlers) {
if (handlers != null) {
for (HandlerMethodReturnValueHandler handler : handlers) {
this.returnValueHandlers.add(handler);
}
this.returnValueHandlers.addAll(handlers);
}
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.
@@ -157,10 +157,8 @@ class InternalPathPatternParser {
}
}
else if (ch == '*') {
if (this.insideVariableCapture) {
if (this.variableCaptureStart == pos - 1) {
this.isCaptureTheRestVariable = true;
}
if (this.insideVariableCapture && this.variableCaptureStart == this.pos - 1) {
this.isCaptureTheRestVariable = true;
}
this.wildcard = true;
}