Use Set.of instead of HashSet with Arrays.asList

This commit is contained in:
Juergen Hoeller
2022-05-06 16:19:27 +02:00
parent 12357fdf44
commit 2b65f274dc
10 changed files with 36 additions and 47 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 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.
@@ -24,7 +24,6 @@ import java.time.Instant;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
@@ -73,6 +72,7 @@ public abstract class RequestPredicates {
private static final Log logger = LogFactory.getLog(RequestPredicates.class);
/**
* Return a {@code RequestPredicate} that always matches.
* @return a predicate that always matches
@@ -535,7 +535,6 @@ public abstract class RequestPredicates {
public String toString() {
return this.pattern.getPatternString();
}
}
@@ -564,12 +563,13 @@ public abstract class RequestPredicates {
}
}
private static class ContentTypePredicate extends HeadersPredicate {
private final Set<MediaType> mediaTypes;
public ContentTypePredicate(MediaType... mediaTypes) {
this(new HashSet<>(Arrays.asList(mediaTypes)));
this(Set.of(mediaTypes));
}
private ContentTypePredicate(Set<MediaType> mediaTypes) {
@@ -601,12 +601,13 @@ public abstract class RequestPredicates {
}
}
private static class AcceptPredicate extends HeadersPredicate {
private final Set<MediaType> mediaTypes;
public AcceptPredicate(MediaType... mediaTypes) {
this(new HashSet<>(Arrays.asList(mediaTypes)));
this(Set.of(mediaTypes));
}
private AcceptPredicate(Set<MediaType> mediaTypes) {
@@ -696,7 +697,6 @@ public abstract class RequestPredicates {
this.extension :
this.extensionPredicate);
}
}
@@ -807,6 +807,7 @@ public abstract class RequestPredicates {
}
}
/**
* {@link RequestPredicate} that negates a delegate predicate.
*/
@@ -849,6 +850,7 @@ public abstract class RequestPredicates {
}
}
/**
* {@link RequestPredicate} where either {@code left} or {@code right} predicates
* may match.
@@ -1053,8 +1055,6 @@ public abstract class RequestPredicates {
return this.request.session();
}
@Override
public Optional<Principal> principal() {
return this.request.principal();
@@ -1084,7 +1084,6 @@ public abstract class RequestPredicates {
public String toString() {
return method() + " " + path();
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 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.
@@ -19,7 +19,6 @@ package org.springframework.web.servlet.mvc.method.annotation;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
@@ -77,19 +76,19 @@ public abstract class AbstractMessageConverterMethodProcessor extends AbstractMe
implements HandlerMethodReturnValueHandler {
/* Extensions associated with the built-in message converters */
private static final Set<String> SAFE_EXTENSIONS = new HashSet<>(Arrays.asList(
private static final Set<String> SAFE_EXTENSIONS = Set.of(
"txt", "text", "yml", "properties", "csv",
"json", "xml", "atom", "rss",
"png", "jpe", "jpeg", "jpg", "gif", "wbmp", "bmp"));
"png", "jpe", "jpeg", "jpg", "gif", "wbmp", "bmp");
private static final Set<String> SAFE_MEDIA_BASE_TYPES = new HashSet<>(
Arrays.asList("audio", "image", "video"));
private static final Set<String> SAFE_MEDIA_BASE_TYPES =
Set.of("audio", "image", "video");
private static final List<MediaType> ALL_APPLICATION_MEDIA_TYPES =
Arrays.asList(MediaType.ALL, new MediaType("application"));
List.of(MediaType.ALL, new MediaType("application"));
private static final Type RESOURCE_REGION_LIST_TYPE =
new ParameterizedTypeReference<List<ResourceRegion>>() { }.getType();
new ParameterizedTypeReference<List<ResourceRegion>>() {}.getType();
private final ContentNegotiationManager contentNegotiationManager;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2022 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.
@@ -18,9 +18,7 @@ package org.springframework.web.servlet.view;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
@@ -273,7 +271,7 @@ public abstract class AbstractView extends WebApplicationObjectSupport implement
* flag on but do not list specific bean names for this property.
*/
public void setExposedContextBeanNames(String... exposedContextBeanNames) {
this.exposedContextBeanNames = new HashSet<>(Arrays.asList(exposedContextBeanNames));
this.exposedContextBeanNames = Set.of(exposedContextBeanNames);
}
/**