20
20
import java .nio .charset .Charset ;
21
21
import java .nio .charset .StandardCharsets ;
22
22
import java .util .ArrayList ;
23
- import java .util .Arrays ;
24
23
import java .util .Collection ;
25
- import java .util .Collections ;
26
24
import java .util .HashMap ;
27
25
import java .util .LinkedList ;
28
26
import java .util .List ;
34
32
import org .springframework .http .HttpRequest ;
35
33
import org .springframework .lang .Nullable ;
36
34
import org .springframework .util .Assert ;
37
- import org .springframework .util .CollectionUtils ;
38
35
import org .springframework .util .LinkedMultiValueMap ;
39
36
import org .springframework .util .MultiValueMap ;
40
37
import org .springframework .util .ObjectUtils ;
@@ -104,6 +101,8 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable {
104
101
105
102
private static final Pattern FORWARDED_PROTO_PATTERN = Pattern .compile ("proto=\" ?([^;,\" ]+)\" ?" );
106
103
104
+ private static final Object [] EMPTY_VALUES = new Object [0 ];
105
+
107
106
108
107
@ Nullable
109
108
private String scheme ;
@@ -700,11 +699,22 @@ public UriComponentsBuilder replaceQuery(@Nullable String query) {
700
699
* @param name the query parameter name
701
700
* @param values the query parameter values
702
701
* @return this UriComponentsBuilder
703
- * @see #queryParams (String, Collection)
702
+ * @see #queryParam (String, Collection)
704
703
*/
705
704
@ Override
706
705
public UriComponentsBuilder queryParam (String name , Object ... values ) {
707
- return queryParams (name , (!ObjectUtils .isEmpty (values ) ? Arrays .asList (values ) : Collections .emptyList ()));
706
+ Assert .notNull (name , "Name must not be null" );
707
+ if (!ObjectUtils .isEmpty (values )) {
708
+ for (Object value : values ) {
709
+ String valueAsString = (value != null ? value .toString () : null );
710
+ this .queryParams .add (name , valueAsString );
711
+ }
712
+ }
713
+ else {
714
+ this .queryParams .add (name , null );
715
+ }
716
+ resetSchemeSpecificPart ();
717
+ return this ;
708
718
}
709
719
710
720
/**
@@ -719,19 +729,8 @@ public UriComponentsBuilder queryParam(String name, Object... values) {
719
729
* @see #queryParam(String, Object...)
720
730
*/
721
731
@ Override
722
- public UriComponentsBuilder queryParams (String name , @ Nullable Collection <?> values ) {
723
- Assert .notNull (name , "Name must not be null" );
724
- if (!CollectionUtils .isEmpty (values )) {
725
- for (Object value : values ) {
726
- String valueAsString = (value != null ? value .toString () : null );
727
- this .queryParams .add (name , valueAsString );
728
- }
729
- }
730
- else {
731
- this .queryParams .add (name , null );
732
- }
733
- resetSchemeSpecificPart ();
734
- return this ;
732
+ public UriComponentsBuilder queryParam (String name , @ Nullable Collection <?> values ) {
733
+ return queryParam (name , values != null ? values .toArray () : EMPTY_VALUES );
735
734
}
736
735
737
736
/**
@@ -754,11 +753,17 @@ public UriComponentsBuilder queryParams(@Nullable MultiValueMap<String, String>
754
753
* @param name the query parameter name
755
754
* @param values the query parameter values
756
755
* @return this UriComponentsBuilder
757
- * @see #replaceQueryParams (String, Collection)
756
+ * @see #replaceQueryParam (String, Collection)
758
757
*/
759
758
@ Override
760
759
public UriComponentsBuilder replaceQueryParam (String name , Object ... values ) {
761
- return replaceQueryParams (name , (!ObjectUtils .isEmpty (values ) ? Arrays .asList (values ) : Collections .emptyList ()));
760
+ Assert .notNull (name , "Name must not be null" );
761
+ this .queryParams .remove (name );
762
+ if (!ObjectUtils .isEmpty (values )) {
763
+ queryParam (name , values );
764
+ }
765
+ resetSchemeSpecificPart ();
766
+ return this ;
762
767
}
763
768
764
769
/**
@@ -771,14 +776,8 @@ public UriComponentsBuilder replaceQueryParam(String name, Object... values) {
771
776
* @since 5.2.0
772
777
*/
773
778
@ Override
774
- public UriComponentsBuilder replaceQueryParams (String name , @ Nullable Collection <?> values ) {
775
- Assert .notNull (name , "Name must not be null" );
776
- this .queryParams .remove (name );
777
- if (!CollectionUtils .isEmpty (values )) {
778
- queryParams (name , values );
779
- }
780
- resetSchemeSpecificPart ();
781
- return this ;
779
+ public UriComponentsBuilder replaceQueryParam (String name , @ Nullable Collection <?> values ) {
780
+ return replaceQueryParam (name , values != null ? values .toArray () : EMPTY_VALUES );
782
781
}
783
782
784
783
/**
0 commit comments