From 01c5bc04e83ef0ce2bda79d7e7f41f46fa9f4070 Mon Sep 17 00:00:00 2001 From: Ievgen Degtiarenko Date: Thu, 10 Mar 2022 10:27:46 +0100 Subject: [PATCH] replace `.collect(toUnmodifiableList())` with `.toList()` (#84760) Replace collect with a simipler toList call that also creates immutable collection. --- .../elasticsearch/tools/launchers/JvmOption.java | 4 ++-- .../tools/launchers/JvmOptionsParser.java | 4 +--- .../common/ssl/CompositeTrustConfig.java | 5 +---- .../org/elasticsearch/common/ssl/KeyStoreUtil.java | 6 +----- .../elasticsearch/common/ssl/PemTrustConfig.java | 3 +-- .../elasticsearch/common/ssl/StoreKeyConfig.java | 5 ++--- .../elasticsearch/common/ssl/StoreTrustConfig.java | 3 +-- .../elasticsearch/kibana/KibanaPluginTests.java | 7 +------ .../action/search/SearchProgressListener.java | 7 ++----- .../cluster/node/DiscoveryNodeRole.java | 2 +- .../index/seqno/ReplicationTracker.java | 5 +---- .../indices/AssociatedIndexDescriptor.java | 3 +-- .../indices/SystemDataStreamDescriptor.java | 3 +-- .../indices/SystemIndexDescriptor.java | 3 +-- .../org/elasticsearch/indices/SystemIndices.java | 9 ++++----- .../java/org/elasticsearch/tasks/TaskManager.java | 2 +- .../timeseries/support/TimeSeriesMetrics.java | 3 +-- .../org/elasticsearch/common/util/MapsTests.java | 13 +++---------- .../common/util/iterable/IterablesTests.java | 3 +-- .../java/org/elasticsearch/test/ESTestCase.java | 8 ++------ .../java/org/elasticsearch/test/NodeRoles.java | 9 +++------ .../elasticsearch/test/rest/ESRestTestCase.java | 4 +--- .../AutoscalingCountTestDeciderService.java | 3 +-- .../AutoscalingSyncTestDeciderService.java | 3 +-- .../capacity/FixedAutoscalingDeciderService.java | 3 +-- .../org/elasticsearch/xpack/ccr/AutoFollowIT.java | 3 +-- .../org/elasticsearch/license/LicenseService.java | 4 ++-- .../xpack/core/action/XPackUsageResponse.java | 3 +-- .../results/ClassificationInferenceResults.java | 2 +- .../results/RegressionInferenceResults.java | 2 +- .../GetServiceAccountCredentialsNodesResponse.java | 5 ++--- .../GetServiceAccountCredentialsResponse.java | 4 +--- .../action/user/GetUserPrivilegesResponse.java | 2 +- .../authz/accesscontrol/IndicesAccessControl.java | 6 +----- .../authz/permission/DocumentPermissions.java | 5 ++--- .../authz/privilege/ClusterPrivilegeResolver.java | 3 +-- .../security/authz/privilege/IndexPrivilege.java | 7 +------ .../elasticsearch/xpack/core/ssl/SSLService.java | 8 ++------ .../elasticsearch/license/LicenseServiceTests.java | 5 ++--- .../xpack/core/LocalStateCompositeXPackPlugin.java | 2 +- .../GetServiceAccountCredentialsResponseTests.java | 6 ++---- .../idp/saml/sp/SamlServiceProviderDocument.java | 5 ++--- .../saml/sp/SamlServiceProviderDocumentTests.java | 5 +---- .../xpack/logstash/LogstashPluginTests.java | 7 +------ .../xpack/ml/dataframe/stats/ProgressTracker.java | 5 +---- .../org/elasticsearch/xpack/ql/type/DataTypes.java | 3 +-- .../security/operator/OperatorPrivilegesIT.java | 5 +---- .../xpack/security/QueryApiKeyIT.java | 14 +++++++------- .../enrollment/TransportNodeEnrollmentAction.java | 2 +- .../xpack/security/authc/ApiKeyService.java | 2 +- .../elasticsearch/xpack/security/authc/Realms.java | 4 ++-- .../authc/ldap/ActiveDirectoryGroupsResolver.java | 2 +- .../security/authc/ldap/SearchGroupsResolver.java | 5 +---- .../authc/ldap/UserAttributeGroupsResolver.java | 3 +-- .../xpack/security/authc/saml/SamlAttributes.java | 9 ++------- .../xpack/security/authc/saml/SamlRealm.java | 2 +- .../service/FileServiceAccountTokenStore.java | 3 +-- .../enrollment/BaseEnrollmentTokenGenerator.java | 4 ++-- .../apikey/TransportQueryApiKeyActionTests.java | 5 +---- .../authc/service/ServiceAccountServiceTests.java | 3 +-- .../support/ApiKeyBoolQueryBuilderTests.java | 3 +-- .../elasticsearch/xpack/sql/type/SqlDataTypes.java | 3 +-- .../xpack/stack/StackTemplateRegistry.java | 3 +-- 63 files changed, 90 insertions(+), 194 deletions(-) diff --git a/distribution/tools/launchers/src/main/java/org/elasticsearch/tools/launchers/JvmOption.java b/distribution/tools/launchers/src/main/java/org/elasticsearch/tools/launchers/JvmOption.java index 38df43c274a8..5c62fbcd0262 100644 --- a/distribution/tools/launchers/src/main/java/org/elasticsearch/tools/launchers/JvmOption.java +++ b/distribution/tools/launchers/src/main/java/org/elasticsearch/tools/launchers/JvmOption.java @@ -98,7 +98,7 @@ class JvmOption { Stream.of("-Xshare:off"), Stream.of("-XX:+PrintFlagsFinal"), Stream.of("-version") - ).reduce(Stream::concat).get().collect(Collectors.toUnmodifiableList()); + ).reduce(Stream::concat).get().toList(); final Process process = new ProcessBuilder().command(command).start(); final List output = readLinesFromInputStream(process.getInputStream()); final List error = readLinesFromInputStream(process.getErrorStream()); @@ -119,7 +119,7 @@ class JvmOption { private static List readLinesFromInputStream(final InputStream is) throws IOException { try (InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8); BufferedReader br = new BufferedReader(isr)) { - return br.lines().collect(Collectors.toUnmodifiableList()); + return br.lines().toList(); } } } diff --git a/distribution/tools/launchers/src/main/java/org/elasticsearch/tools/launchers/JvmOptionsParser.java b/distribution/tools/launchers/src/main/java/org/elasticsearch/tools/launchers/JvmOptionsParser.java index 4f33a1ba5b02..96e75b4bcf5b 100644 --- a/distribution/tools/launchers/src/main/java/org/elasticsearch/tools/launchers/JvmOptionsParser.java +++ b/distribution/tools/launchers/src/main/java/org/elasticsearch/tools/launchers/JvmOptionsParser.java @@ -125,9 +125,7 @@ final class JvmOptionsParser { final List jvmOptions = readJvmOptionsFiles(config); if (esJavaOpts != null) { - jvmOptions.addAll( - Arrays.stream(esJavaOpts.split("\\s+")).filter(Predicate.not(String::isBlank)).collect(Collectors.toUnmodifiableList()) - ); + jvmOptions.addAll(Arrays.stream(esJavaOpts.split("\\s+")).filter(Predicate.not(String::isBlank)).toList()); } final List substitutedJvmOptions = substitutePlaceholders(jvmOptions, Collections.unmodifiableMap(substitutions)); diff --git a/libs/ssl-config/src/main/java/org/elasticsearch/common/ssl/CompositeTrustConfig.java b/libs/ssl-config/src/main/java/org/elasticsearch/common/ssl/CompositeTrustConfig.java index 54c6057daa82..98c71a988897 100644 --- a/libs/ssl-config/src/main/java/org/elasticsearch/common/ssl/CompositeTrustConfig.java +++ b/libs/ssl-config/src/main/java/org/elasticsearch/common/ssl/CompositeTrustConfig.java @@ -63,10 +63,7 @@ public class CompositeTrustConfig implements SslTrustConfig { @Override public Collection getConfiguredCertificates() { - return configs.stream() - .map(SslTrustConfig::getConfiguredCertificates) - .flatMap(Collection::stream) - .collect(Collectors.toUnmodifiableList()); + return configs.stream().map(SslTrustConfig::getConfiguredCertificates).flatMap(Collection::stream).toList(); } @Override diff --git a/libs/ssl-config/src/main/java/org/elasticsearch/common/ssl/KeyStoreUtil.java b/libs/ssl-config/src/main/java/org/elasticsearch/common/ssl/KeyStoreUtil.java index b235ec986c74..aebee89297a8 100644 --- a/libs/ssl-config/src/main/java/org/elasticsearch/common/ssl/KeyStoreUtil.java +++ b/libs/ssl-config/src/main/java/org/elasticsearch/common/ssl/KeyStoreUtil.java @@ -28,7 +28,6 @@ import java.util.List; import java.util.Locale; import java.util.function.Function; import java.util.function.Predicate; -import java.util.stream.Collectors; import java.util.stream.Stream; import javax.net.ssl.KeyManager; @@ -281,10 +280,7 @@ public final class KeyStoreUtil { if (certificates == null || certificates.length == 0) { return List.of(); } - return Stream.of(certificates) - .filter(c -> c instanceof X509Certificate) - .map(X509Certificate.class::cast) - .collect(Collectors.toUnmodifiableList()); + return Stream.of(certificates).filter(c -> c instanceof X509Certificate).map(X509Certificate.class::cast).toList(); } catch (KeyStoreException e) { throw exceptionHandler.apply(e); } diff --git a/libs/ssl-config/src/main/java/org/elasticsearch/common/ssl/PemTrustConfig.java b/libs/ssl-config/src/main/java/org/elasticsearch/common/ssl/PemTrustConfig.java index c89a2aafee8e..f1d7a7b6f412 100644 --- a/libs/ssl-config/src/main/java/org/elasticsearch/common/ssl/PemTrustConfig.java +++ b/libs/ssl-config/src/main/java/org/elasticsearch/common/ssl/PemTrustConfig.java @@ -21,7 +21,6 @@ import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Objects; -import java.util.stream.Collectors; import javax.net.ssl.TrustManagerFactory; import javax.net.ssl.X509ExtendedTrustManager; @@ -87,7 +86,7 @@ public final class PemTrustConfig implements SslTrustConfig { } private List resolveFiles() { - return this.certificateAuthorities.stream().map(this::resolveFile).collect(Collectors.toUnmodifiableList()); + return this.certificateAuthorities.stream().map(this::resolveFile).toList(); } private Path resolveFile(String other) { diff --git a/libs/ssl-config/src/main/java/org/elasticsearch/common/ssl/StoreKeyConfig.java b/libs/ssl-config/src/main/java/org/elasticsearch/common/ssl/StoreKeyConfig.java index e8429b92b830..8c07def7a5a6 100644 --- a/libs/ssl-config/src/main/java/org/elasticsearch/common/ssl/StoreKeyConfig.java +++ b/libs/ssl-config/src/main/java/org/elasticsearch/common/ssl/StoreKeyConfig.java @@ -27,7 +27,6 @@ import java.util.Enumeration; import java.util.List; import java.util.Objects; import java.util.function.Function; -import java.util.stream.Collectors; import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.TrustManagerFactory; @@ -121,7 +120,7 @@ public class StoreKeyConfig implements SslKeyConfig { return null; }) .filter(Objects::nonNull) - .collect(Collectors.toUnmodifiableList()); + .toList(); } @Override @@ -136,7 +135,7 @@ public class StoreKeyConfig implements SslKeyConfig { firstElement = false; } return certificates.stream(); - }).collect(Collectors.toUnmodifiableList()); + }).toList(); } @Override diff --git a/libs/ssl-config/src/main/java/org/elasticsearch/common/ssl/StoreTrustConfig.java b/libs/ssl-config/src/main/java/org/elasticsearch/common/ssl/StoreTrustConfig.java index 9245730c6f65..f03f5ec577f4 100644 --- a/libs/ssl-config/src/main/java/org/elasticsearch/common/ssl/StoreTrustConfig.java +++ b/libs/ssl-config/src/main/java/org/elasticsearch/common/ssl/StoreTrustConfig.java @@ -19,7 +19,6 @@ import java.util.Collection; import java.util.Enumeration; import java.util.List; import java.util.Objects; -import java.util.stream.Collectors; import javax.net.ssl.X509ExtendedTrustManager; @@ -73,7 +72,7 @@ public final class StoreTrustConfig implements SslTrustConfig { } else { return null; } - }).filter(Objects::nonNull).collect(Collectors.toUnmodifiableList()); + }).filter(Objects::nonNull).toList(); } @Override diff --git a/modules/kibana/src/test/java/org/elasticsearch/kibana/KibanaPluginTests.java b/modules/kibana/src/test/java/org/elasticsearch/kibana/KibanaPluginTests.java index cd9f9de3a644..6d9c4c39ad48 100644 --- a/modules/kibana/src/test/java/org/elasticsearch/kibana/KibanaPluginTests.java +++ b/modules/kibana/src/test/java/org/elasticsearch/kibana/KibanaPluginTests.java @@ -12,18 +12,13 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.indices.SystemIndexDescriptor; import org.elasticsearch.test.ESTestCase; -import java.util.stream.Collectors; - import static org.hamcrest.Matchers.contains; public class KibanaPluginTests extends ESTestCase { public void testKibanaIndexNames() { assertThat( - new KibanaPlugin().getSystemIndexDescriptors(Settings.EMPTY) - .stream() - .map(SystemIndexDescriptor::getIndexPattern) - .collect(Collectors.toUnmodifiableList()), + new KibanaPlugin().getSystemIndexDescriptors(Settings.EMPTY).stream().map(SystemIndexDescriptor::getIndexPattern).toList(), contains(".kibana_*", ".reporting-*", ".apm-agent-configuration*", ".apm-custom-link*") ); } diff --git a/server/src/main/java/org/elasticsearch/action/search/SearchProgressListener.java b/server/src/main/java/org/elasticsearch/action/search/SearchProgressListener.java index cb1b70931933..2699a609ff71 100644 --- a/server/src/main/java/org/elasticsearch/action/search/SearchProgressListener.java +++ b/server/src/main/java/org/elasticsearch/action/search/SearchProgressListener.java @@ -20,7 +20,6 @@ import org.elasticsearch.search.aggregations.InternalAggregations; import java.util.List; import java.util.Objects; -import java.util.stream.Collectors; import java.util.stream.StreamSupport; /** @@ -171,12 +170,10 @@ public abstract class SearchProgressListener { .filter(Objects::nonNull) .map(SearchPhaseResult::getSearchShardTarget) .map(e -> new SearchShard(e.getClusterAlias(), e.getShardId())) - .collect(Collectors.toUnmodifiableList()); + .toList(); } static List buildSearchShards(GroupShardsIterator its) { - return StreamSupport.stream(its.spliterator(), false) - .map(e -> new SearchShard(e.getClusterAlias(), e.shardId())) - .collect(Collectors.toUnmodifiableList()); + return StreamSupport.stream(its.spliterator(), false).map(e -> new SearchShard(e.getClusterAlias(), e.shardId())).toList(); } } diff --git a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodeRole.java b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodeRole.java index 805de6f2c47e..a5671bcdda4e 100644 --- a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodeRole.java +++ b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodeRole.java @@ -275,7 +275,7 @@ public class DiscoveryNodeRole implements Comparable { static { final List roleFields = Arrays.stream(DiscoveryNodeRole.class.getFields()) .filter(f -> f.getType().equals(DiscoveryNodeRole.class)) - .collect(Collectors.toUnmodifiableList()); + .toList(); // this will detect duplicate role names final Map roleMap = roleFields.stream().map(f -> { try { diff --git a/server/src/main/java/org/elasticsearch/index/seqno/ReplicationTracker.java b/server/src/main/java/org/elasticsearch/index/seqno/ReplicationTracker.java index 27db5189d338..7245359cf5e8 100644 --- a/server/src/main/java/org/elasticsearch/index/seqno/ReplicationTracker.java +++ b/server/src/main/java/org/elasticsearch/index/seqno/ReplicationTracker.java @@ -562,10 +562,7 @@ public class ReplicationTracker extends AbstractIndexShardComponent implements L * Returns a list of peer recovery retention leases installed in this replication group */ public List getPeerRecoveryRetentionLeases() { - return getRetentionLeases().leases() - .stream() - .filter(lease -> PEER_RECOVERY_RETENTION_LEASE_SOURCE.equals(lease.source())) - .collect(Collectors.toUnmodifiableList()); + return getRetentionLeases().leases().stream().filter(lease -> PEER_RECOVERY_RETENTION_LEASE_SOURCE.equals(lease.source())).toList(); } /** diff --git a/server/src/main/java/org/elasticsearch/indices/AssociatedIndexDescriptor.java b/server/src/main/java/org/elasticsearch/indices/AssociatedIndexDescriptor.java index 2a5b84eae88a..f123b61aa482 100644 --- a/server/src/main/java/org/elasticsearch/indices/AssociatedIndexDescriptor.java +++ b/server/src/main/java/org/elasticsearch/indices/AssociatedIndexDescriptor.java @@ -15,7 +15,6 @@ import org.elasticsearch.cluster.metadata.Metadata; import java.util.List; import java.util.Objects; -import java.util.stream.Collectors; /** * An "associated index" is an index that is related to or derived from a system @@ -106,7 +105,7 @@ public class AssociatedIndexDescriptor implements IndexPatternMatcher { */ @Override public List getMatchingIndices(Metadata metadata) { - return metadata.indices().keySet().stream().filter(this::matchesIndexPattern).collect(Collectors.toUnmodifiableList()); + return metadata.indices().keySet().stream().filter(this::matchesIndexPattern).toList(); } /** diff --git a/server/src/main/java/org/elasticsearch/indices/SystemDataStreamDescriptor.java b/server/src/main/java/org/elasticsearch/indices/SystemDataStreamDescriptor.java index 54072b6280b0..4c792a3d4614 100644 --- a/server/src/main/java/org/elasticsearch/indices/SystemDataStreamDescriptor.java +++ b/server/src/main/java/org/elasticsearch/indices/SystemDataStreamDescriptor.java @@ -17,7 +17,6 @@ import org.elasticsearch.cluster.metadata.Metadata; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.stream.Collectors; import static org.elasticsearch.indices.AssociatedIndexDescriptor.buildAutomaton; @@ -91,7 +90,7 @@ public class SystemDataStreamDescriptor { * @return List of names of backing indices */ public List getBackingIndexNames(Metadata metadata) { - return metadata.indices().keySet().stream().filter(this.characterRunAutomaton::run).collect(Collectors.toUnmodifiableList()); + return metadata.indices().keySet().stream().filter(this.characterRunAutomaton::run).toList(); } public String getDescription() { diff --git a/server/src/main/java/org/elasticsearch/indices/SystemIndexDescriptor.java b/server/src/main/java/org/elasticsearch/indices/SystemIndexDescriptor.java index 4d9c4589f86c..df925267f042 100644 --- a/server/src/main/java/org/elasticsearch/indices/SystemIndexDescriptor.java +++ b/server/src/main/java/org/elasticsearch/indices/SystemIndexDescriptor.java @@ -31,7 +31,6 @@ import java.util.Locale; import java.util.Map; import java.util.Objects; import java.util.Set; -import java.util.stream.Collectors; /** * A system index descriptor describes one or more system indices. It can match a number of indices using @@ -400,7 +399,7 @@ public class SystemIndexDescriptor implements IndexPatternMatcher, Comparable getMatchingIndices(Metadata metadata) { - return metadata.indices().keySet().stream().filter(this::matchesIndexPattern).collect(Collectors.toUnmodifiableList()); + return metadata.indices().keySet().stream().filter(this::matchesIndexPattern).toList(); } /** diff --git a/server/src/main/java/org/elasticsearch/indices/SystemIndices.java b/server/src/main/java/org/elasticsearch/indices/SystemIndices.java index 53cfe1e2ef4d..4495c816c5f4 100644 --- a/server/src/main/java/org/elasticsearch/indices/SystemIndices.java +++ b/server/src/main/java/org/elasticsearch/indices/SystemIndices.java @@ -50,7 +50,6 @@ import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.stream.Stream; -import static java.util.stream.Collectors.toUnmodifiableList; import static org.elasticsearch.tasks.TaskResultsService.TASKS_DESCRIPTOR; import static org.elasticsearch.tasks.TaskResultsService.TASKS_FEATURE_NAME; @@ -513,7 +512,7 @@ public class SystemIndices { .stream() .flatMap(entry -> entry.getValue().getIndexDescriptors().stream().map(descriptor -> new Tuple<>(entry.getKey(), descriptor))) .sorted(Comparator.comparing(d -> d.v1() + ":" + d.v2().getIndexPattern())) // Consistent ordering -> consistent error message - .collect(Collectors.toUnmodifiableList()); + .toList(); List> sourceDataStreamDescriptorPair = sourceToFeature.entrySet() .stream() .filter(entry -> entry.getValue().getDataStreamDescriptors().isEmpty() == false) @@ -521,7 +520,7 @@ public class SystemIndices { entry -> entry.getValue().getDataStreamDescriptors().stream().map(descriptor -> new Tuple<>(entry.getKey(), descriptor)) ) .sorted(Comparator.comparing(d -> d.v1() + ":" + d.v2().getDataStreamName())) // Consistent ordering -> consistent error message - .collect(Collectors.toUnmodifiableList()); + .toList(); // This is O(n^2) with the number of system index descriptors, and each check is quadratic with the number of states in the // automaton, but the absolute number of system index descriptors should be quite small (~10s at most), and the number of states @@ -533,7 +532,7 @@ public class SystemIndices { d -> overlaps(descriptorToCheck.v2(), d.v2()) || (d.v2().getAliasName() != null && descriptorToCheck.v2().matchesIndexPattern(d.v2().getAliasName())) ) - .collect(toUnmodifiableList()); + .toList(); if (descriptorsMatchingThisPattern.isEmpty() == false) { throw new IllegalStateException( "a system index descriptor [" @@ -552,7 +551,7 @@ public class SystemIndices { dsTuple -> descriptorToCheck.v2().matchesIndexPattern(dsTuple.v2().getDataStreamName()) || overlaps(descriptorToCheck.v2().getIndexPattern(), dsTuple.v2().getBackingIndexPattern()) ) - .collect(toUnmodifiableList()); + .toList(); if (dataStreamsMatching.isEmpty() == false) { throw new IllegalStateException( "a system index descriptor [" diff --git a/server/src/main/java/org/elasticsearch/tasks/TaskManager.java b/server/src/main/java/org/elasticsearch/tasks/TaskManager.java index b299448574d9..deecd29b743d 100644 --- a/server/src/main/java/org/elasticsearch/tasks/TaskManager.java +++ b/server/src/main/java/org/elasticsearch/tasks/TaskManager.java @@ -404,7 +404,7 @@ public class TaskManager implements ClusterStateApplier { ban.registerChannel(DIRECT_CHANNEL_TRACKER); } } - return cancellableTasks.getByParent(parentTaskId).map(t -> t.task).collect(Collectors.toUnmodifiableList()); + return cancellableTasks.getByParent(parentTaskId).map(t -> t.task).toList(); } /** diff --git a/server/src/main/java/org/elasticsearch/timeseries/support/TimeSeriesMetrics.java b/server/src/main/java/org/elasticsearch/timeseries/support/TimeSeriesMetrics.java index 96f682392123..45f39ba663c7 100644 --- a/server/src/main/java/org/elasticsearch/timeseries/support/TimeSeriesMetrics.java +++ b/server/src/main/java/org/elasticsearch/timeseries/support/TimeSeriesMetrics.java @@ -52,7 +52,6 @@ import java.util.Map; import java.util.Objects; import java.util.function.Predicate; import java.util.regex.Pattern; -import java.util.stream.Collectors; import java.util.stream.Stream; import static java.util.stream.Collectors.toList; @@ -445,7 +444,7 @@ public class TimeSeriesMetrics { for (TimeSeriesMetricSelector selector : selectors) { metrics = metrics.filter(selector.asPredicate()); } - return metrics.collect(Collectors.toUnmodifiableList()); + return metrics.toList(); } private SearchRequest searchInRange(List metrics, List dimensions, long from, long to, int size) { diff --git a/server/src/test/java/org/elasticsearch/common/util/MapsTests.java b/server/src/test/java/org/elasticsearch/common/util/MapsTests.java index ab3d261ac239..35b849164742 100644 --- a/server/src/test/java/org/elasticsearch/common/util/MapsTests.java +++ b/server/src/test/java/org/elasticsearch/common/util/MapsTests.java @@ -48,10 +48,7 @@ public class MapsTests extends ESTestCase { final String key = randomValueOtherThanMany(keys::contains, () -> randomAlphaOfLength(16)); final String value = randomAlphaOfLength(16); final Map concatenation = Maps.copyMapWithAddedEntry(map, key, value); - assertMapEntriesAndImmutability( - concatenation, - Stream.concat(entries.stream(), Stream.of(entry(key, value))).collect(Collectors.toUnmodifiableList()) - ); + assertMapEntriesAndImmutability(concatenation, Stream.concat(entries.stream(), Stream.of(entry(key, value))).toList()); } public void testAddEntryInImmutableMap() { @@ -67,10 +64,7 @@ public class MapsTests extends ESTestCase { final String key = randomValueOtherThanMany(keys::contains, () -> randomAlphaOfLength(16)); final String value = randomAlphaOfLength(16); final Map add = Maps.copyMapWithAddedOrReplacedEntry(map, key, value); - assertMapEntriesAndImmutability( - add, - Stream.concat(entries.stream(), Stream.of(entry(key, value))).collect(Collectors.toUnmodifiableList()) - ); + assertMapEntriesAndImmutability(add, Stream.concat(entries.stream(), Stream.of(entry(key, value))).toList()); } public void testReplaceEntryInImmutableMap() { @@ -88,8 +82,7 @@ public class MapsTests extends ESTestCase { final Map replaced = Maps.copyMapWithAddedOrReplacedEntry(map, key, value); assertMapEntriesAndImmutability( replaced, - Stream.concat(entries.stream().filter(e -> key.equals(e.getKey()) == false), Stream.of(entry(key, value))) - .collect(Collectors.toUnmodifiableList()) + Stream.concat(entries.stream().filter(e -> key.equals(e.getKey()) == false), Stream.of(entry(key, value))).toList() ); } diff --git a/server/src/test/java/org/elasticsearch/common/util/iterable/IterablesTests.java b/server/src/test/java/org/elasticsearch/common/util/iterable/IterablesTests.java index b295801ec91f..041a8f2d52d9 100644 --- a/server/src/test/java/org/elasticsearch/common/util/iterable/IterablesTests.java +++ b/server/src/test/java/org/elasticsearch/common/util/iterable/IterablesTests.java @@ -15,7 +15,6 @@ import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.NoSuchElementException; -import java.util.stream.Collectors; import java.util.stream.Stream; import static org.hamcrest.Matchers.is; @@ -84,7 +83,7 @@ public class IterablesTests extends ESTestCase { final List list = Stream.generate(() -> randomAlphaOfLengthBetween(3, 9)) .limit(randomIntBetween(10, 30)) .distinct() - .collect(Collectors.toUnmodifiableList()); + .toList(); for (int i = 0; i < list.size(); i++) { final String val = list.get(i); assertThat(Iterables.indexOf(list, val::equals), is(i)); diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java index 185c4c9e0656..efa3256fe7db 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java @@ -284,13 +284,9 @@ public abstract class ESTestCase extends LuceneTestCase { .filter(unsupportedTZIdsPredicate.negate()) .filter(unsupportedZoneIdsPredicate.negate()) .sorted() - .collect(Collectors.toUnmodifiableList()); + .toList(); - JAVA_ZONE_IDS = ZoneId.getAvailableZoneIds() - .stream() - .filter(unsupportedZoneIdsPredicate.negate()) - .sorted() - .collect(Collectors.toUnmodifiableList()); + JAVA_ZONE_IDS = ZoneId.getAvailableZoneIds().stream().filter(unsupportedZoneIdsPredicate.negate()).sorted().toList(); } @SuppressForbidden(reason = "force log4j and netty sysprops") diff --git a/test/framework/src/main/java/org/elasticsearch/test/NodeRoles.java b/test/framework/src/main/java/org/elasticsearch/test/NodeRoles.java index 37b0d7070563..a1b4c6dd9001 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/NodeRoles.java +++ b/test/framework/src/main/java/org/elasticsearch/test/NodeRoles.java @@ -38,10 +38,7 @@ public class NodeRoles { public static Settings onlyRoles(final Settings settings, final Set roles) { return Settings.builder() .put(settings) - .putList( - NodeRoleSettings.NODE_ROLES_SETTING.getKey(), - roles.stream().map(DiscoveryNodeRole::roleName).collect(Collectors.toUnmodifiableList()) - ) + .putList(NodeRoleSettings.NODE_ROLES_SETTING.getKey(), roles.stream().map(DiscoveryNodeRole::roleName).toList()) .build(); } @@ -57,7 +54,7 @@ public class NodeRoles { .stream() .filter(Predicate.not(roles::contains)) .map(DiscoveryNodeRole::roleName) - .collect(Collectors.toUnmodifiableList()) + .toList() ); return builder.build(); } @@ -73,7 +70,7 @@ public class NodeRoles { Stream.concat(NodeRoleSettings.NODE_ROLES_SETTING.get(settings).stream(), roles.stream()) .map(DiscoveryNodeRole::roleName) .distinct() - .collect(Collectors.toUnmodifiableList()) + .toList() ); return builder.build(); } diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java index 245593cc5e76..85655b7c89cb 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java @@ -904,9 +904,7 @@ public abstract class ESRestTestCase extends ESTestCase { Request getShutdownStatus = new Request("GET", "_nodes/shutdown"); Map statusResponse = responseAsMap(adminClient().performRequest(getShutdownStatus)); List> nodesArray = (List>) statusResponse.get("nodes"); - List nodeIds = nodesArray.stream() - .map(nodeShutdownMetadata -> (String) nodeShutdownMetadata.get("node_id")) - .collect(Collectors.toUnmodifiableList()); + List nodeIds = nodesArray.stream().map(nodeShutdownMetadata -> (String) nodeShutdownMetadata.get("node_id")).toList(); for (String nodeId : nodeIds) { Request deleteRequest = new Request("DELETE", "_nodes/" + nodeId + "/shutdown"); assertOK(adminClient().performRequest(deleteRequest)); diff --git a/x-pack/plugin/autoscaling/src/internalClusterTest/java/org/elasticsearch/xpack/autoscaling/AutoscalingCountTestDeciderService.java b/x-pack/plugin/autoscaling/src/internalClusterTest/java/org/elasticsearch/xpack/autoscaling/AutoscalingCountTestDeciderService.java index 2d34b60ba4ce..368c1593bc12 100644 --- a/x-pack/plugin/autoscaling/src/internalClusterTest/java/org/elasticsearch/xpack/autoscaling/AutoscalingCountTestDeciderService.java +++ b/x-pack/plugin/autoscaling/src/internalClusterTest/java/org/elasticsearch/xpack/autoscaling/AutoscalingCountTestDeciderService.java @@ -21,7 +21,6 @@ import java.io.IOException; import java.util.List; import java.util.Objects; import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.Collectors; public class AutoscalingCountTestDeciderService implements AutoscalingDeciderService { @@ -46,7 +45,7 @@ public class AutoscalingCountTestDeciderService implements AutoscalingDeciderSer @Override public List roles() { - return DiscoveryNodeRole.roles().stream().collect(Collectors.toUnmodifiableList()); + return DiscoveryNodeRole.roles().stream().toList(); } @Override diff --git a/x-pack/plugin/autoscaling/src/internalClusterTest/java/org/elasticsearch/xpack/autoscaling/AutoscalingSyncTestDeciderService.java b/x-pack/plugin/autoscaling/src/internalClusterTest/java/org/elasticsearch/xpack/autoscaling/AutoscalingSyncTestDeciderService.java index ea4985de53ae..dd14f67f03ae 100644 --- a/x-pack/plugin/autoscaling/src/internalClusterTest/java/org/elasticsearch/xpack/autoscaling/AutoscalingSyncTestDeciderService.java +++ b/x-pack/plugin/autoscaling/src/internalClusterTest/java/org/elasticsearch/xpack/autoscaling/AutoscalingSyncTestDeciderService.java @@ -18,7 +18,6 @@ import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingDeciderService; import java.util.List; import java.util.concurrent.BrokenBarrierException; import java.util.concurrent.CyclicBarrier; -import java.util.stream.Collectors; public class AutoscalingSyncTestDeciderService implements AutoscalingDeciderService { @@ -62,7 +61,7 @@ public class AutoscalingSyncTestDeciderService implements AutoscalingDeciderServ @Override public List roles() { - return DiscoveryNodeRole.roles().stream().collect(Collectors.toUnmodifiableList()); + return DiscoveryNodeRole.roles().stream().toList(); } @Override diff --git a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/FixedAutoscalingDeciderService.java b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/FixedAutoscalingDeciderService.java index 33398f4f416e..69e1589f5eed 100644 --- a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/FixedAutoscalingDeciderService.java +++ b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/FixedAutoscalingDeciderService.java @@ -19,7 +19,6 @@ import org.elasticsearch.xcontent.XContentBuilder; import java.io.IOException; import java.util.List; import java.util.Objects; -import java.util.stream.Collectors; public class FixedAutoscalingDeciderService implements AutoscalingDeciderService { @@ -72,7 +71,7 @@ public class FixedAutoscalingDeciderService implements AutoscalingDeciderService @Override public List roles() { - return DiscoveryNodeRole.roles().stream().collect(Collectors.toUnmodifiableList()); + return DiscoveryNodeRole.roles().stream().toList(); } @Override diff --git a/x-pack/plugin/ccr/src/internalClusterTest/java/org/elasticsearch/xpack/ccr/AutoFollowIT.java b/x-pack/plugin/ccr/src/internalClusterTest/java/org/elasticsearch/xpack/ccr/AutoFollowIT.java index 0519b1ae9f48..c6e1a5c68627 100644 --- a/x-pack/plugin/ccr/src/internalClusterTest/java/org/elasticsearch/xpack/ccr/AutoFollowIT.java +++ b/x-pack/plugin/ccr/src/internalClusterTest/java/org/elasticsearch/xpack/ccr/AutoFollowIT.java @@ -50,7 +50,6 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; import java.util.stream.Stream; -import static java.util.stream.Collectors.toUnmodifiableList; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThanOrEqualTo; @@ -504,7 +503,7 @@ public class AutoFollowIT extends CcrIntegTestCase { final String pattern = prefix + "pattern"; putAutoFollowPatterns(pattern, new String[] { prefix + "*" }); return pattern; - }).collect(toUnmodifiableList()); + }).toList(); // pick up some random pattern to pause final List pausedAutoFollowerPatterns = randomSubsetOf(randomIntBetween(1, 3), autoFollowPatterns); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/LicenseService.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/LicenseService.java index 6adb564ce9e8..62ba1331e04f 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/LicenseService.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/LicenseService.java @@ -76,7 +76,7 @@ public class LicenseService extends AbstractLifecycleComponent implements Cluste public static final Setting> ALLOWED_LICENSE_TYPES_SETTING = Setting.listSetting( "xpack.license.upload.types", - ALLOWABLE_UPLOAD_TYPES.stream().map(License.LicenseType::getTypeName).collect(Collectors.toUnmodifiableList()), + ALLOWABLE_UPLOAD_TYPES.stream().map(License.LicenseType::getTypeName).toList(), License.LicenseType::parse, LicenseService::validateUploadTypesSetting, Setting.Property.NodeScope @@ -642,7 +642,7 @@ public class LicenseService extends AbstractLifecycleComponent implements Cluste } private static List getAllowableUploadTypes() { - return Stream.of(License.LicenseType.values()).filter(t -> t != License.LicenseType.BASIC).collect(Collectors.toUnmodifiableList()); + return Stream.of(License.LicenseType.values()).filter(t -> t != License.LicenseType.BASIC).toList(); } private static void validateUploadTypesSetting(List value) { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/XPackUsageResponse.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/XPackUsageResponse.java index 5b07a743735b..ec101b19908b 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/XPackUsageResponse.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/XPackUsageResponse.java @@ -14,7 +14,6 @@ import org.elasticsearch.xpack.core.XPackFeatureSet; import java.io.IOException; import java.util.List; import java.util.Objects; -import java.util.stream.Collectors; public class XPackUsageResponse extends ActionResponse { @@ -37,7 +36,7 @@ public class XPackUsageResponse extends ActionResponse { // we can only write the usages with version the coordinating node is compatible with otherwise it will not know the named writeable final List usagesToWrite = usages.stream() .filter(usage -> out.getVersion().onOrAfter(usage.getMinimalSupportedVersion())) - .collect(Collectors.toUnmodifiableList()); + .toList(); writeTo(out, usagesToWrite); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/inference/results/ClassificationInferenceResults.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/inference/results/ClassificationInferenceResults.java index ebe78b797f02..25cebdf4ded4 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/inference/results/ClassificationInferenceResults.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/inference/results/ClassificationInferenceResults.java @@ -113,7 +113,7 @@ public class ClassificationInferenceResults extends SingleValueInferenceResults return featureImportances.stream() .sorted((l, r) -> Double.compare(r.getTotalImportance(), l.getTotalImportance())) .limit(numTopFeatures) - .collect(Collectors.toUnmodifiableList()); + .toList(); } public ClassificationInferenceResults(StreamInput in) throws IOException { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/inference/results/RegressionInferenceResults.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/inference/results/RegressionInferenceResults.java index 7bff1f29245f..dcab4d9508c8 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/inference/results/RegressionInferenceResults.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/inference/results/RegressionInferenceResults.java @@ -69,7 +69,7 @@ public class RegressionInferenceResults extends SingleValueInferenceResults { return featureImportances.stream() .sorted((l, r) -> Double.compare(Math.abs(r.getImportance()), Math.abs(l.getImportance()))) .limit(numTopFeatures) - .collect(Collectors.toUnmodifiableList()); + .toList(); } public RegressionInferenceResults(StreamInput in) throws IOException { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/service/GetServiceAccountCredentialsNodesResponse.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/service/GetServiceAccountCredentialsNodesResponse.java index 6e81ab8e1925..34299c85a29f 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/service/GetServiceAccountCredentialsNodesResponse.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/service/GetServiceAccountCredentialsNodesResponse.java @@ -22,7 +22,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.stream.Collectors; /** * Unlike index-backed service account tokens, file-backed tokens are local to the node. @@ -67,8 +66,8 @@ public class GetServiceAccountCredentialsNodesResponse extends BaseNodesResponse } return fileTokenDistribution.entrySet() .stream() - .map(entry -> TokenInfo.fileToken(entry.getKey(), entry.getValue().stream().sorted().collect(Collectors.toUnmodifiableList()))) - .collect(Collectors.toUnmodifiableList()); + .map(entry -> TokenInfo.fileToken(entry.getKey(), entry.getValue().stream().sorted().toList())) + .toList(); } public static class Node extends BaseNodeResponse { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/service/GetServiceAccountCredentialsResponse.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/service/GetServiceAccountCredentialsResponse.java index d8634f66f2b5..1d2e8f746213 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/service/GetServiceAccountCredentialsResponse.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/service/GetServiceAccountCredentialsResponse.java @@ -18,8 +18,6 @@ import java.io.IOException; import java.util.Collection; import java.util.List; -import static java.util.stream.Collectors.toUnmodifiableList; - public class GetServiceAccountCredentialsResponse extends ActionResponse implements ToXContentObject { private final String principal; @@ -32,7 +30,7 @@ public class GetServiceAccountCredentialsResponse extends ActionResponse impleme GetServiceAccountCredentialsNodesResponse nodesResponse ) { this.principal = principal; - this.indexTokenInfos = indexTokenInfos == null ? List.of() : indexTokenInfos.stream().sorted().collect(toUnmodifiableList()); + this.indexTokenInfos = indexTokenInfos == null ? List.of() : indexTokenInfos.stream().sorted().toList(); this.nodesResponse = nodesResponse; } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/GetUserPrivilegesResponse.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/GetUserPrivilegesResponse.java index 074e2c0cd544..0002c5c7c196 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/GetUserPrivilegesResponse.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/GetUserPrivilegesResponse.java @@ -221,7 +221,7 @@ public final class GetUserPrivilegesResponse extends ActionResponse { builder.startArray(RoleDescriptor.Fields.FIELD_PERMISSIONS.getPreferredName()); final List sortedFieldSecurity = this.fieldSecurity.stream() .sorted() - .collect(Collectors.toUnmodifiableList()); + .toList(); for (FieldPermissionsDefinition.FieldGrantExcludeGroup group : sortedFieldSecurity) { builder.startObject(); if (nonEmpty(group.getGrantedFields())) { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/accesscontrol/IndicesAccessControl.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/accesscontrol/IndicesAccessControl.java index 233f88966528..3e797cb7f6bb 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/accesscontrol/IndicesAccessControl.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/accesscontrol/IndicesAccessControl.java @@ -108,11 +108,7 @@ public class IndicesAccessControl { } private List getIndexNames(Predicate predicate) { - return indexPermissions.entrySet() - .stream() - .filter(entry -> predicate.test(entry.getValue())) - .map(Map.Entry::getKey) - .collect(Collectors.toUnmodifiableList()); + return indexPermissions.entrySet().stream().filter(entry -> predicate.test(entry.getValue())).map(Map.Entry::getKey).toList(); } public enum DlsFlsUsage { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/permission/DocumentPermissions.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/permission/DocumentPermissions.java index cd52d51e36a5..d7576c3c8ced 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/permission/DocumentPermissions.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/permission/DocumentPermissions.java @@ -36,7 +36,6 @@ import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; import java.util.function.Function; -import java.util.stream.Collectors; import static org.apache.lucene.search.BooleanClause.Occur.FILTER; import static org.apache.lucene.search.BooleanClause.Occur.SHOULD; @@ -151,10 +150,10 @@ public final class DocumentPermissions implements CacheKey { private void evaluateQueries(DlsQueryEvaluationContext context) { if (queries != null && evaluatedQueries == null) { - evaluatedQueries = queries.stream().map(context::evaluate).collect(Collectors.toUnmodifiableList()); + evaluatedQueries = queries.stream().map(context::evaluate).toList(); } if (limitedByQueries != null && evaluatedLimitedByQueries == null) { - evaluatedLimitedByQueries = limitedByQueries.stream().map(context::evaluate).collect(Collectors.toUnmodifiableList()); + evaluatedLimitedByQueries = limitedByQueries.stream().map(context::evaluate).toList(); } } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/ClusterPrivilegeResolver.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/ClusterPrivilegeResolver.java index ff614fc09c4b..7a66e6c1d476 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/ClusterPrivilegeResolver.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/ClusterPrivilegeResolver.java @@ -46,7 +46,6 @@ import java.util.Objects; import java.util.Set; import java.util.SortedMap; import java.util.TreeMap; -import java.util.stream.Collectors; /** * Translates cluster privilege names into concrete implementations @@ -319,7 +318,7 @@ public class ClusterPrivilegeResolver { .stream() .filter(e -> e.getValue().permission().check(action, request, authentication)) .map(Map.Entry::getKey) - .collect(Collectors.toUnmodifiableList()); + .toList(); } /** diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/IndexPrivilege.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/IndexPrivilege.java index 036db70a9f9f..c8e2da6d060c 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/IndexPrivilege.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/IndexPrivilege.java @@ -46,7 +46,6 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Predicate; -import java.util.stream.Collectors; import static java.util.Map.entry; import static org.elasticsearch.xpack.core.security.support.Automatons.patterns; @@ -253,10 +252,6 @@ public final class IndexPrivilege extends Privilege { * @see Privilege#sortByAccessLevel */ public static Collection findPrivilegesThatGrant(String action) { - return VALUES.entrySet() - .stream() - .filter(e -> e.getValue().predicate.test(action)) - .map(e -> e.getKey()) - .collect(Collectors.toUnmodifiableList()); + return VALUES.entrySet().stream().filter(e -> e.getValue().predicate.test(action)).map(e -> e.getKey()).toList(); } } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ssl/SSLService.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ssl/SSLService.java index 92d5b6298656..a66cd19d72b9 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ssl/SSLService.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ssl/SSLService.java @@ -516,7 +516,7 @@ public class SSLService { .filter(e -> e.getValue().equals(configuration)) .limit(2) // we only need to distinguishing between 0/1/many .map(Entry::getKey) - .collect(Collectors.toUnmodifiableList()); + .toList(); final String name = switch (names.size()) { case 0 -> "(unknown)"; case 1 -> names.get(0); @@ -637,11 +637,7 @@ public class SSLService { ); } } else if (settings.hasValue(enabledSetting) == false) { - final List sslSettingNames = settings.keySet() - .stream() - .filter(s -> s.startsWith(prefix)) - .sorted() - .collect(Collectors.toUnmodifiableList()); + final List sslSettingNames = settings.keySet().stream().filter(s -> s.startsWith(prefix)).sorted().toList(); if (sslSettingNames.isEmpty() == false) { throw new ElasticsearchSecurityException( "invalid configuration for " diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicenseServiceTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicenseServiceTests.java index 1b9dde72218c..5df79bc62388 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicenseServiceTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicenseServiceTests.java @@ -41,7 +41,6 @@ import java.util.List; import java.util.UUID; import java.util.concurrent.TimeUnit; import java.util.function.Consumer; -import java.util.stream.Collectors; import static org.elasticsearch.discovery.DiscoveryModule.DISCOVERY_TYPE_SETTING; import static org.elasticsearch.discovery.DiscoveryModule.SINGLE_NODE_DISCOVERY_TYPE; @@ -93,7 +92,7 @@ public class LicenseServiceTests extends ESTestCase { randomIntBetween(1, LicenseService.ALLOWABLE_UPLOAD_TYPES.size() - 1), LicenseService.ALLOWABLE_UPLOAD_TYPES ); - final List allowedNames = allowed.stream().map(License.LicenseType::getTypeName).collect(Collectors.toUnmodifiableList()); + final List allowedNames = allowed.stream().map(License.LicenseType::getTypeName).toList(); final Settings settings = Settings.builder().putList("xpack.license.upload.types", allowedNames).build(); assertRegisterValidLicense(settings, randomFrom(allowed)); } @@ -107,7 +106,7 @@ public class LicenseServiceTests extends ESTestCase { randomIntBetween(1, LicenseService.ALLOWABLE_UPLOAD_TYPES.size() - 2), LicenseService.ALLOWABLE_UPLOAD_TYPES ); - final List allowedNames = allowed.stream().map(License.LicenseType::getTypeName).collect(Collectors.toUnmodifiableList()); + final List allowedNames = allowed.stream().map(License.LicenseType::getTypeName).toList(); final Settings settings = Settings.builder().putList("xpack.license.upload.types", allowedNames).build(); final License.LicenseType notAllowed = randomValueOtherThanMany( test -> allowed.contains(test), diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/LocalStateCompositeXPackPlugin.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/LocalStateCompositeXPackPlugin.java index 7e37ebfc4d22..d9746b53a332 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/LocalStateCompositeXPackPlugin.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/LocalStateCompositeXPackPlugin.java @@ -694,7 +694,7 @@ public class LocalStateCompositeXPackPlugin extends XPackPlugin .stream() .map(SearchPlugin::getRequestCacheKeyDifferentiator) .filter(Objects::nonNull) - .collect(Collectors.toUnmodifiableList()); + .toList(); if (differentiators.size() > 1) { throw new UnsupportedOperationException("Only the security SearchPlugin should provide the request cache key differentiator"); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/action/service/GetServiceAccountCredentialsResponseTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/action/service/GetServiceAccountCredentialsResponseTests.java index 7f4d781b8539..be0914f3d848 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/action/service/GetServiceAccountCredentialsResponseTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/action/service/GetServiceAccountCredentialsResponseTests.java @@ -31,7 +31,6 @@ import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.Stream; -import static java.util.stream.Collectors.toUnmodifiableList; import static org.hamcrest.Matchers.anEmptyMap; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; @@ -53,7 +52,7 @@ public class GetServiceAccountCredentialsResponseTests extends ESTestCase { final String principal = randomAlphaOfLengthBetween(3, 8) + "/" + randomAlphaOfLengthBetween(3, 8); final List indexTokenInfos = IntStream.range(0, randomIntBetween(0, 10)) .mapToObj(i -> TokenInfo.indexToken(randomAlphaOfLengthBetween(3, 8))) - .collect(Collectors.toUnmodifiableList()); + .toList(); final GetServiceAccountCredentialsNodesResponse fileTokensResponse = randomGetServiceAccountFileTokensResponse(); return new GetServiceAccountCredentialsResponse(principal, indexTokenInfos, fileTokensResponse); } @@ -130,7 +129,6 @@ public class GetServiceAccountCredentialsResponseTests extends ESTestCase { } private List getAllTokenInfos(GetServiceAccountCredentialsResponse response) { - return Stream.concat(response.getNodesResponse().getFileTokenInfos().stream(), response.getIndexTokenInfos().stream()) - .collect(toUnmodifiableList()); + return Stream.concat(response.getNodesResponse().getFileTokenInfos().stream(), response.getIndexTokenInfos().stream()).toList(); } } diff --git a/x-pack/plugin/identity-provider/src/main/java/org/elasticsearch/xpack/idp/saml/sp/SamlServiceProviderDocument.java b/x-pack/plugin/identity-provider/src/main/java/org/elasticsearch/xpack/idp/saml/sp/SamlServiceProviderDocument.java index 278fc186685c..3562ba866c04 100644 --- a/x-pack/plugin/identity-provider/src/main/java/org/elasticsearch/xpack/idp/saml/sp/SamlServiceProviderDocument.java +++ b/x-pack/plugin/identity-provider/src/main/java/org/elasticsearch/xpack/idp/saml/sp/SamlServiceProviderDocument.java @@ -41,7 +41,6 @@ import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; import java.util.function.BiConsumer; -import java.util.stream.Collectors; /** * This class models the storage of a {@link SamlServiceProvider} as an Elasticsearch document. @@ -171,14 +170,14 @@ public class SamlServiceProviderDocument implements ToXContentObject, Writeable } catch (CertificateEncodingException e) { throw new ElasticsearchException("Cannot read certificate", e); } - }).map(Base64.getEncoder()::encodeToString).collect(Collectors.toUnmodifiableList()); + }).map(Base64.getEncoder()::encodeToString).toList(); } private List decodeCertificates(List encodedCertificates) { if (encodedCertificates == null || encodedCertificates.isEmpty()) { return List.of(); } - return encodedCertificates.stream().map(this::decodeCertificate).collect(Collectors.toUnmodifiableList()); + return encodedCertificates.stream().map(this::decodeCertificate).toList(); } private X509Certificate decodeCertificate(String base64Cert) { diff --git a/x-pack/plugin/identity-provider/src/test/java/org/elasticsearch/xpack/idp/saml/sp/SamlServiceProviderDocumentTests.java b/x-pack/plugin/identity-provider/src/test/java/org/elasticsearch/xpack/idp/saml/sp/SamlServiceProviderDocumentTests.java index c04619b466d3..68e01ef18e12 100644 --- a/x-pack/plugin/identity-provider/src/test/java/org/elasticsearch/xpack/idp/saml/sp/SamlServiceProviderDocumentTests.java +++ b/x-pack/plugin/identity-provider/src/test/java/org/elasticsearch/xpack/idp/saml/sp/SamlServiceProviderDocumentTests.java @@ -29,7 +29,6 @@ import java.security.cert.X509Certificate; import java.util.HashSet; import java.util.List; import java.util.Set; -import java.util.stream.Collectors; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertToXContentEquivalent; import static org.hamcrest.Matchers.emptyIterable; @@ -92,9 +91,7 @@ public class SamlServiceProviderDocumentTests extends IdpSamlTestCase { private SamlServiceProviderDocument createFullDocument() throws GeneralSecurityException, IOException { final List credentials = readCredentials(); - final List certificates = credentials.stream() - .map(X509Credential::getEntityCertificate) - .collect(Collectors.toUnmodifiableList()); + final List certificates = credentials.stream().map(X509Credential::getEntityCertificate).toList(); final List spCertificates = randomSubsetOf(certificates); final List idpCertificates = randomSubsetOf(certificates); final List idpMetadataCertificates = randomSubsetOf(certificates); diff --git a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/LogstashPluginTests.java b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/LogstashPluginTests.java index 0f71b08baf0d..01648d0c222d 100644 --- a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/LogstashPluginTests.java +++ b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/LogstashPluginTests.java @@ -11,18 +11,13 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.indices.SystemIndexDescriptor; import org.elasticsearch.test.ESTestCase; -import java.util.stream.Collectors; - import static org.hamcrest.Matchers.contains; public class LogstashPluginTests extends ESTestCase { public void testSystemIndices() { assertThat( - new Logstash().getSystemIndexDescriptors(Settings.EMPTY) - .stream() - .map(SystemIndexDescriptor::getIndexPattern) - .collect(Collectors.toUnmodifiableList()), + new Logstash().getSystemIndexDescriptors(Settings.EMPTY).stream().map(SystemIndexDescriptor::getIndexPattern).toList(), contains(".logstash*") ); } diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/stats/ProgressTracker.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/stats/ProgressTracker.java index 170512a71c66..275effd6e383 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/stats/ProgressTracker.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/stats/ProgressTracker.java @@ -13,7 +13,6 @@ import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import java.util.stream.Collectors; /** * Tracks progress of a data frame analytics job. @@ -127,8 +126,6 @@ public class ProgressTracker { } public List report() { - return Arrays.stream(phasesInOrder) - .map(phase -> new PhaseProgress(phase, progressPercentPerPhase.get(phase))) - .collect(Collectors.toUnmodifiableList()); + return Arrays.stream(phasesInOrder).map(phase -> new PhaseProgress(phase, progressPercentPerPhase.get(phase))).toList(); } } diff --git a/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/type/DataTypes.java b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/type/DataTypes.java index 69451e51a655..4dc8bf046a90 100644 --- a/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/type/DataTypes.java +++ b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/type/DataTypes.java @@ -16,7 +16,6 @@ import java.util.Locale; import java.util.Map; import static java.util.stream.Collectors.toMap; -import static java.util.stream.Collectors.toUnmodifiableList; import static java.util.stream.Collectors.toUnmodifiableMap; public final class DataTypes { @@ -72,7 +71,7 @@ public final class DataTypes { BINARY, OBJECT, NESTED - ).stream().sorted(Comparator.comparing(DataType::typeName)).collect(toUnmodifiableList()); + ).stream().sorted(Comparator.comparing(DataType::typeName)).toList(); private static final Map NAME_TO_TYPE = TYPES.stream().collect(toUnmodifiableMap(DataType::typeName, t -> t)); diff --git a/x-pack/plugin/security/qa/operator-privileges-tests/src/javaRestTest/java/org/elasticsearch/xpack/security/operator/OperatorPrivilegesIT.java b/x-pack/plugin/security/qa/operator-privileges-tests/src/javaRestTest/java/org/elasticsearch/xpack/security/operator/OperatorPrivilegesIT.java index e9e4b949b364..55a6c6a03d3a 100644 --- a/x-pack/plugin/security/qa/operator-privileges-tests/src/javaRestTest/java/org/elasticsearch/xpack/security/operator/OperatorPrivilegesIT.java +++ b/x-pack/plugin/security/qa/operator-privileges-tests/src/javaRestTest/java/org/elasticsearch/xpack/security/operator/OperatorPrivilegesIT.java @@ -29,7 +29,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.stream.Collectors; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; @@ -53,9 +52,7 @@ public class OperatorPrivilegesIT extends ESRestTestCase { getShutdownStatus.setOptions(RequestOptions.DEFAULT.toBuilder().addHeader("Authorization", OPERATOR_AUTH_HEADER)); Map statusResponse = responseAsMap(adminClient().performRequest(getShutdownStatus)); List> nodesArray = (List>) statusResponse.get("nodes"); - List nodeIds = nodesArray.stream() - .map(nodeShutdownMetadata -> (String) nodeShutdownMetadata.get("node_id")) - .collect(Collectors.toUnmodifiableList()); + List nodeIds = nodesArray.stream().map(nodeShutdownMetadata -> (String) nodeShutdownMetadata.get("node_id")).toList(); for (String nodeId : nodeIds) { Request deleteRequest = new Request("DELETE", "_nodes/" + nodeId + "/shutdown"); deleteRequest.setOptions(RequestOptions.DEFAULT.toBuilder().addHeader("Authorization", OPERATOR_AUTH_HEADER)); diff --git a/x-pack/plugin/security/qa/security-basic/src/javaRestTest/java/org/elasticsearch/xpack/security/QueryApiKeyIT.java b/x-pack/plugin/security/qa/security-basic/src/javaRestTest/java/org/elasticsearch/xpack/security/QueryApiKeyIT.java index 08d88b602b34..1f38aa550599 100644 --- a/x-pack/plugin/security/qa/security-basic/src/javaRestTest/java/org/elasticsearch/xpack/security/QueryApiKeyIT.java +++ b/x-pack/plugin/security/qa/security-basic/src/javaRestTest/java/org/elasticsearch/xpack/security/QueryApiKeyIT.java @@ -231,7 +231,7 @@ public class QueryApiKeyIT extends SecurityInBasicRestTestCase { final int total = randomIntBetween(8, 12); final List apiKeyNames = IntStream.range(0, total) .mapToObj(i -> String.format(Locale.ROOT, "k-%02d", i)) - .collect(Collectors.toUnmodifiableList()); + .toList(); final List apiKeyIds = new ArrayList<>(total); for (int i = 0; i < total; i++) { apiKeyIds.add(createApiKey(apiKeyNames.get(i), null, authHeader).v1()); @@ -276,21 +276,21 @@ public class QueryApiKeyIT extends SecurityInBasicRestTestCase { // assert sort values match the field of API key information if ("name".equals(sortField)) { assertThat( - apiKeyInfos.stream().map(m -> (String) m.get("name")).collect(Collectors.toUnmodifiableList()), - equalTo(apiKeyInfos.stream().map(m -> (String) extractSortValues(m).get(0)).collect(Collectors.toUnmodifiableList())) + apiKeyInfos.stream().map(m -> (String) m.get("name")).toList(), + equalTo(apiKeyInfos.stream().map(m -> (String) extractSortValues(m).get(0)).toList()) ); } else { assertThat( - apiKeyInfos.stream().map(m -> (long) m.get("creation")).collect(Collectors.toUnmodifiableList()), - equalTo(apiKeyInfos.stream().map(m -> (long) extractSortValues(m).get(0)).collect(Collectors.toUnmodifiableList())) + apiKeyInfos.stream().map(m -> (long) m.get("creation")).toList(), + equalTo(apiKeyInfos.stream().map(m -> (long) extractSortValues(m).get(0)).toList()) ); } assertThat( - apiKeyInfos.stream().map(m -> (String) m.get("id")).collect(Collectors.toUnmodifiableList()), + apiKeyInfos.stream().map(m -> (String) m.get("id")).toList(), equalTo(apiKeyIds.subList(from, total)) ); assertThat( - apiKeyInfos.stream().map(m -> (String) m.get("name")).collect(Collectors.toUnmodifiableList()), + apiKeyInfos.stream().map(m -> (String) m.get("name")).toList(), equalTo(apiKeyNames.subList(from, total)) ); diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/action/enrollment/TransportNodeEnrollmentAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/action/enrollment/TransportNodeEnrollmentAction.java index 86d32116b229..65747c94590b 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/action/enrollment/TransportNodeEnrollmentAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/action/enrollment/TransportNodeEnrollmentAction.java @@ -81,7 +81,7 @@ public class TransportNodeEnrollmentAction extends HandledTransportAction> httpCaKeysAndCertificates = httpKeyConfig.getKeys() .stream() .filter(t -> t.v2().getBasicConstraints() != -1) - .collect(Collectors.toUnmodifiableList()); + .toList(); if (transportKeysAndCertificates.isEmpty()) { listener.onFailure( diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ApiKeyService.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ApiKeyService.java index bfa2cae74e23..280a39a56a5f 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ApiKeyService.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ApiKeyService.java @@ -1260,7 +1260,7 @@ public class ApiKeyService { } final List apiKeyItem = Arrays.stream(searchResponse.getHits().getHits()) .map(ApiKeyService::convertSearchHitToQueryItem) - .collect(Collectors.toUnmodifiableList()); + .toList(); listener.onResponse(new QueryApiKeyResponse(total, apiKeyItem)); }, listener::onFailure) ) diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/Realms.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/Realms.java index 7a6d9b022925..866d1109da1b 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/Realms.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/Realms.java @@ -167,7 +167,7 @@ public class Realms implements Iterable { } // Otherwise, we return anything in "all realms" that is not in the allowed realm list - return allConfiguredRealms.stream().filter(r -> activeSnapshot.contains(r) == false).collect(Collectors.toUnmodifiableList()); + return allConfiguredRealms.stream().filter(r -> activeSnapshot.contains(r) == false).toList(); } public Stream stream() { @@ -181,7 +181,7 @@ public class Realms implements Iterable { // Protected for testing protected List calculateLicensedRealms(XPackLicenseState licenseStateSnapshot) { - return allConfiguredRealms.stream().filter(r -> checkLicense(r, licenseStateSnapshot)).collect(Collectors.toUnmodifiableList()); + return allConfiguredRealms.stream().filter(r -> checkLicense(r, licenseStateSnapshot)).toList(); } private static boolean checkLicense(Realm realm, XPackLicenseState licenseState) { diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ldap/ActiveDirectoryGroupsResolver.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ldap/ActiveDirectoryGroupsResolver.java index a038583acfee..9638fa19ed5c 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ldap/ActiveDirectoryGroupsResolver.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ldap/ActiveDirectoryGroupsResolver.java @@ -72,7 +72,7 @@ class ActiveDirectoryGroupsResolver implements GroupsResolver { Math.toIntExact(timeout.seconds()), ignoreReferralErrors, ActionListener.wrap((results) -> { - List groups = results.stream().map(SearchResultEntry::getDN).collect(Collectors.toUnmodifiableList()); + List groups = results.stream().map(SearchResultEntry::getDN).toList(); listener.onResponse(groups); }, listener::onFailure), SearchRequest.NO_ATTRIBUTES diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ldap/SearchGroupsResolver.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ldap/SearchGroupsResolver.java index 3312afd4acb2..c55217431bf3 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ldap/SearchGroupsResolver.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ldap/SearchGroupsResolver.java @@ -24,7 +24,6 @@ import org.elasticsearch.xpack.security.authc.ldap.support.LdapSession.GroupsRes import java.util.Collection; import java.util.List; -import java.util.stream.Collectors; import static org.elasticsearch.common.Strings.isNullOrEmpty; import static org.elasticsearch.xpack.core.security.authc.ldap.support.SessionFactorySettings.IGNORE_REFERRAL_ERRORS_SETTING; @@ -79,9 +78,7 @@ class SearchGroupsResolver implements GroupsResolver { Math.toIntExact(timeout.seconds()), ignoreReferralErrors, ActionListener.wrap( - (results) -> listener.onResponse( - results.stream().map((r) -> r.getDN()).collect(Collectors.toUnmodifiableList()) - ), + (results) -> listener.onResponse(results.stream().map((r) -> r.getDN()).toList()), listener::onFailure ), SearchRequest.NO_ATTRIBUTES diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ldap/UserAttributeGroupsResolver.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ldap/UserAttributeGroupsResolver.java index 8bf42a8eadc8..3f3bc6010ef0 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ldap/UserAttributeGroupsResolver.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ldap/UserAttributeGroupsResolver.java @@ -21,7 +21,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Objects; -import java.util.stream.Collectors; import static org.elasticsearch.xpack.core.security.authc.ldap.support.SessionFactorySettings.IGNORE_REFERRAL_ERRORS_SETTING; import static org.elasticsearch.xpack.security.authc.ldap.support.LdapUtils.OBJECT_CLASS_PRESENCE_FILTER; @@ -57,7 +56,7 @@ class UserAttributeGroupsResolver implements GroupsResolver { final List groups = attributes.stream() .filter((attr) -> attr.getName().equals(attribute)) .flatMap(attr -> Arrays.stream(attr.getValues())) - .collect(Collectors.toUnmodifiableList()); + .toList(); listener.onResponse(groups); } else { searchForEntry( diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/saml/SamlAttributes.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/saml/SamlAttributes.java index fabf7da46ebb..320a39018d59 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/saml/SamlAttributes.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/saml/SamlAttributes.java @@ -13,7 +13,6 @@ import org.opensaml.saml.saml2.core.NameIDType; import java.util.List; import java.util.Objects; -import java.util.stream.Collectors; /** * An lightweight collection of SAML attributes @@ -52,7 +51,7 @@ public class SamlAttributes { return attributes.stream() .filter(attr -> attributeId.equals(attr.name) || attributeId.equals(attr.friendlyName)) .flatMap(attr -> attr.values.stream()) - .collect(Collectors.toUnmodifiableList()); + .toList(); } List attributes() { @@ -81,11 +80,7 @@ public class SamlAttributes { this( attribute.getName(), attribute.getFriendlyName(), - attribute.getAttributeValues() - .stream() - .map(x -> x.getDOM().getTextContent()) - .filter(Objects::nonNull) - .collect(Collectors.toUnmodifiableList()) + attribute.getAttributeValues().stream().map(x -> x.getDOM().getTextContent()).filter(Objects::nonNull).toList() ); } diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/saml/SamlRealm.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/saml/SamlRealm.java index 06ee389a3216..d47dd40b8777 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/saml/SamlRealm.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/saml/SamlRealm.java @@ -905,7 +905,7 @@ public final class SamlRealm extends Realm implements Releasable { return null; } return value; - }).filter(Objects::nonNull).collect(Collectors.toUnmodifiableList()) + }).filter(Objects::nonNull).toList() ); } else { return new AttributeParser( diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/service/FileServiceAccountTokenStore.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/service/FileServiceAccountTokenStore.java index 8857cccd9e69..5a5d42b92bc8 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/service/FileServiceAccountTokenStore.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/service/FileServiceAccountTokenStore.java @@ -39,7 +39,6 @@ import java.util.Locale; import java.util.Map; import java.util.Optional; import java.util.concurrent.CopyOnWriteArrayList; -import java.util.stream.Collectors; public class FileServiceAccountTokenStore extends CachingServiceAccountTokenStore { @@ -103,7 +102,7 @@ public class FileServiceAccountTokenStore extends CachingServiceAccountTokenStor List.of(clusterService.localNode().getName()) ) ) - .collect(Collectors.toUnmodifiableList()); + .toList(); } public void addListener(Runnable listener) { diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/enrollment/BaseEnrollmentTokenGenerator.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/enrollment/BaseEnrollmentTokenGenerator.java index 013d3dc86aba..a100348d6c48 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/enrollment/BaseEnrollmentTokenGenerator.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/enrollment/BaseEnrollmentTokenGenerator.java @@ -85,8 +85,8 @@ public class BaseEnrollmentTokenGenerator { }; localAddresses.sort(ipv4BeforeIpv6Comparator); nonLocalAddresses.sort(ipv4BeforeIpv6Comparator); - final List distinctLocalAddresses = localAddresses.stream().distinct().collect(Collectors.toUnmodifiableList()); - final List distinctNonLocalAddresses = nonLocalAddresses.stream().distinct().collect(Collectors.toUnmodifiableList()); + final List distinctLocalAddresses = localAddresses.stream().distinct().toList(); + final List distinctNonLocalAddresses = nonLocalAddresses.stream().distinct().toList(); return new Tuple<>(distinctLocalAddresses, distinctNonLocalAddresses); } diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/action/apikey/TransportQueryApiKeyActionTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/action/apikey/TransportQueryApiKeyActionTests.java index 8a68bc38f1b6..d1a0b5d7ca95 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/action/apikey/TransportQueryApiKeyActionTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/action/apikey/TransportQueryApiKeyActionTests.java @@ -16,7 +16,6 @@ import org.elasticsearch.test.ESTestCase; import java.util.List; import java.util.Set; -import java.util.stream.Collectors; import java.util.stream.IntStream; import static org.hamcrest.Matchers.equalTo; @@ -35,9 +34,7 @@ public class TransportQueryApiKeyActionTests extends ESTestCase { "metadata." + randomAlphaOfLengthBetween(3, 8) ); - final List originals = fieldNames.stream() - .map(this::randomFieldSortBuilderWithName) - .collect(Collectors.toUnmodifiableList()); + final List originals = fieldNames.stream().map(this::randomFieldSortBuilderWithName).toList(); final SearchSourceBuilder searchSourceBuilder = SearchSourceBuilder.searchSource(); TransportQueryApiKeyAction.translateFieldSortBuilders(originals, searchSourceBuilder); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/service/ServiceAccountServiceTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/service/ServiceAccountServiceTests.java index 8d54f58273fd..0b69ca48d058 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/service/ServiceAccountServiceTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/service/ServiceAccountServiceTests.java @@ -53,7 +53,6 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.concurrent.ExecutionException; -import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.Stream; @@ -644,7 +643,7 @@ public class ServiceAccountServiceTests extends ESTestCase { final List indexTokenInfos = IntStream.range(0, randomIntBetween(0, 3)) .mapToObj(i -> TokenInfo.indexToken(ValidationTests.randomTokenName())) .sorted() - .collect(Collectors.toUnmodifiableList()); + .toList(); doAnswer(inv -> { final Object[] args = inv.getArguments(); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/support/ApiKeyBoolQueryBuilderTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/support/ApiKeyBoolQueryBuilderTests.java index 41e9bba9ef2c..909fd9d24ec6 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/support/ApiKeyBoolQueryBuilderTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/support/ApiKeyBoolQueryBuilderTests.java @@ -35,7 +35,6 @@ import java.time.Instant; import java.time.temporal.ChronoUnit; import java.util.List; import java.util.function.Predicate; -import java.util.stream.Collectors; import static org.elasticsearch.xpack.security.support.ApiKeyFieldNameTranslators.FIELD_NAME_TRANSLATORS; import static org.hamcrest.Matchers.containsString; @@ -311,7 +310,7 @@ public class ApiKeyBoolQueryBuilderTests extends ESTestCase { .stream() .filter(q -> q.getClass() == TermQueryBuilder.class) .map(q -> (TermQueryBuilder) q) - .collect(Collectors.toUnmodifiableList()); + .toList(); assertTrue(tqb.stream().anyMatch(q -> q.equals(QueryBuilders.termQuery("doc_type", "api_key")))); if (authentication == null) { return; diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/type/SqlDataTypes.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/type/SqlDataTypes.java index d211b09289b3..08467e33af91 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/type/SqlDataTypes.java +++ b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/type/SqlDataTypes.java @@ -27,7 +27,6 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import static java.util.Collections.unmodifiableMap; -import static java.util.stream.Collectors.toUnmodifiableList; import static java.util.stream.Collectors.toUnmodifiableMap; import static org.elasticsearch.xpack.ql.type.DataTypes.BINARY; import static org.elasticsearch.xpack.ql.type.DataTypes.BOOLEAN; @@ -163,7 +162,7 @@ public class SqlDataTypes { GEO_POINT, SHAPE ) - ).sorted(Comparator.comparing(DataType::typeName)).collect(toUnmodifiableList()); + ).sorted(Comparator.comparing(DataType::typeName)).toList(); private static final Map NAME_TO_TYPE = TYPES.stream().collect(toUnmodifiableMap(DataType::typeName, t -> t)); diff --git a/x-pack/plugin/stack/src/main/java/org/elasticsearch/xpack/stack/StackTemplateRegistry.java b/x-pack/plugin/stack/src/main/java/org/elasticsearch/xpack/stack/StackTemplateRegistry.java index cf424208a0cf..5393f95d6c77 100644 --- a/x-pack/plugin/stack/src/main/java/org/elasticsearch/xpack/stack/StackTemplateRegistry.java +++ b/x-pack/plugin/stack/src/main/java/org/elasticsearch/xpack/stack/StackTemplateRegistry.java @@ -30,7 +30,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; import java.util.stream.Stream; public class StackTemplateRegistry extends IndexTemplateRegistry { @@ -127,7 +126,7 @@ public class StackTemplateRegistry extends IndexTemplateRegistry { new LifecyclePolicyConfig(ILM_90_DAYS_POLICY_NAME, "/" + ILM_90_DAYS_POLICY_NAME + ".json"), new LifecyclePolicyConfig(ILM_180_DAYS_POLICY_NAME, "/" + ILM_180_DAYS_POLICY_NAME + ".json"), new LifecyclePolicyConfig(ILM_365_DAYS_POLICY_NAME, "/" + ILM_365_DAYS_POLICY_NAME + ".json") - ).map(config -> config.load(LifecyclePolicyConfig.DEFAULT_X_CONTENT_REGISTRY)).collect(Collectors.toUnmodifiableList()); + ).map(config -> config.load(LifecyclePolicyConfig.DEFAULT_X_CONTENT_REGISTRY)).toList(); @Override protected List getPolicyConfigs() {