Fix and document CompositeUriComponentsContributor#hasContributors()

Prior to this commit, the hasContributors() method incorrectly returned
false if contributors had been configured.

This commit fixes the logic in hasContributors() and documents it.

Closes #27271
This commit is contained in:
Sam Brannen
2021-08-18 17:33:50 +02:00
parent 6177f00a63
commit 6770e4b3cc
2 changed files with 26 additions and 18 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 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.
@@ -31,8 +31,8 @@ import org.springframework.web.util.UriComponentsBuilder;
/**
* A {@link UriComponentsContributor} containing a list of other contributors
* to delegate and also encapsulating a specific {@link ConversionService} to
* use for formatting method argument values to Strings.
* to delegate to and also encapsulating a specific {@link ConversionService} to
* use for formatting method argument values as Strings.
*
* @author Rossen Stoyanchev
* @author Juergen Hoeller
@@ -52,7 +52,7 @@ public class CompositeUriComponentsContributor implements UriComponentsContribut
* {@code HandlerMethodArgumentResolvers} in {@code RequestMappingHandlerAdapter}
* and provide that to this constructor.
* @param contributors a collection of {@link UriComponentsContributor}
* or {@link HandlerMethodArgumentResolver HandlerMethodArgumentResolvers}.
* or {@link HandlerMethodArgumentResolver HandlerMethodArgumentResolvers}
*/
public CompositeUriComponentsContributor(UriComponentsContributor... contributors) {
this.contributors = Arrays.asList((Object[]) contributors);
@@ -66,7 +66,7 @@ public class CompositeUriComponentsContributor implements UriComponentsContribut
* {@code HandlerMethodArgumentResolvers} in {@code RequestMappingHandlerAdapter}
* and provide that to this constructor.
* @param contributors a collection of {@link UriComponentsContributor}
* or {@link HandlerMethodArgumentResolver HandlerMethodArgumentResolvers}.
* or {@link HandlerMethodArgumentResolver HandlerMethodArgumentResolvers}
*/
public CompositeUriComponentsContributor(Collection<?> contributors) {
this(contributors, null);
@@ -82,7 +82,7 @@ public class CompositeUriComponentsContributor implements UriComponentsContribut
* {@link org.springframework.format.support.DefaultFormattingConversionService}
* will be used by default.
* @param contributors a collection of {@link UriComponentsContributor}
* or {@link HandlerMethodArgumentResolver HandlerMethodArgumentResolvers}.
* or {@link HandlerMethodArgumentResolver HandlerMethodArgumentResolvers}
* @param cs a ConversionService to use when method argument values
* need to be formatted as Strings before being added to the URI
*/
@@ -91,9 +91,14 @@ public class CompositeUriComponentsContributor implements UriComponentsContribut
this.conversionService = (cs != null ? cs : new DefaultFormattingConversionService());
}
/**
* Determine if this {@code CompositeUriComponentsContributor} has any
* contributors.
* @return {@code true} if this {@code CompositeUriComponentsContributor}
* was created with contributors to delegate to
*/
public boolean hasContributors() {
return this.contributors.isEmpty();
return !this.contributors.isEmpty();
}
@Override
@@ -139,7 +144,7 @@ public class CompositeUriComponentsContributor implements UriComponentsContribut
public void contributeMethodArgument(MethodParameter parameter, Object value, UriComponentsBuilder builder,
Map<String, Object> uriVariables) {
this.contributeMethodArgument(parameter, value, builder, uriVariables, this.conversionService);
contributeMethodArgument(parameter, value, builder, uriVariables, this.conversionService);
}
}