Skip to content

Commit

Permalink
Immutable collections
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-ivanov-es committed Dec 9, 2024
1 parent 9174a3d commit 0292929
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
12 changes: 5 additions & 7 deletions server/src/main/java/org/elasticsearch/TransportVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
import org.elasticsearch.plugins.ExtensionLoader;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* Represents the version of the wire protocol used to communicate between a pair of ES nodes.
Expand Down Expand Up @@ -172,14 +172,12 @@ private static class VersionsHolder {
if (extendedVersions.isEmpty()) {
ALL_VERSIONS = TransportVersions.DEFINED_VERSIONS;
} else {
List<TransportVersion> allVersions = new ArrayList<>(TransportVersions.DEFINED_VERSIONS.size() + extendedVersions.size());
allVersions.addAll(TransportVersions.DEFINED_VERSIONS);
allVersions.addAll(extendedVersions);
Collections.sort(allVersions);
ALL_VERSIONS = Collections.unmodifiableList(allVersions);
ALL_VERSIONS = Stream.concat(TransportVersions.DEFINED_VERSIONS.stream(), extendedVersions.stream())
.sorted()
.toList();
}

ALL_VERSIONS_MAP = ALL_VERSIONS.stream().collect(Collectors.toMap(TransportVersion::id, Function.identity()));
ALL_VERSIONS_MAP = ALL_VERSIONS.stream().collect(Collectors.toUnmodifiableMap(TransportVersion::id, Function.identity()));

CURRENT = ALL_VERSIONS.getLast();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public static List<TransportVersion> collectAllVersionIdsDefinedInClass(Class<?>

Collections.sort(definedTransportVersions);

return Collections.unmodifiableList(definedTransportVersions);
return List.copyOf(definedTransportVersions);
}

static final IntFunction<String> VERSION_LOOKUP = ReleaseVersions.generateVersionsLookup(TransportVersions.class, LATEST_DEFINED.id());
Expand Down

0 comments on commit 0292929

Please sign in to comment.