Skip to content

Commit

Permalink
Merge pull request #1066 from amvanbaren/use-map-entry
Browse files Browse the repository at this point in the history
Replace SimpleEntry with Map.entry
  • Loading branch information
amvanbaren authored Dec 9, 2024
2 parents ca404c1 + 9551247 commit c1f83fd
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ private Map<String, String> getDownloads(Extension extension, String targetPlatf
logger.warn("Could not find download for: {}", NamingUtil.toLogFormat(ev));
return null;
} else {
return new AbstractMap.SimpleEntry<>(ev.getTargetPlatform(), download);
return Map.entry(ev.getTargetPlatform(), download);
}
})
.filter(Objects::nonNull)
Expand Down Expand Up @@ -788,7 +788,7 @@ private List<SearchEntryJson> toSearchEntries(SearchHits<ExtensionSearch> search
var entry = e.getValue().toSearchEntryJson();
entry.setUrl(createApiUrl(serverUrl, "api", entry.getNamespace(), entry.getName()));
entry.setVerified(isVerified(e.getValue(), membershipsByNamespaceId));
return new AbstractMap.SimpleEntry<>(e.getKey(), entry);
return Map.entry(e.getKey(), entry);
})
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private List<Pair<FileResource, FileResource>> copyResources(Streamable<FileReso
newExtension.setId(extension.getId());
newExtension.setName(extension.getName());
newExtension.setNamespace(newNamespace);
return new AbstractMap.SimpleEntry<>(entry.getKey(), newExtension);
return Map.entry(entry.getKey(), newExtension);
})
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

Expand All @@ -151,7 +151,7 @@ private List<Pair<FileResource, FileResource>> copyResources(Streamable<FileReso
}

var newBinaryNames = extVersions.values().stream()
.map(extVersion -> new AbstractMap.SimpleEntry<>(extVersion.getId(), newBinaryName(newNamespace, extVersion)))
.map(extVersion -> Map.entry(extVersion.getId(), newBinaryName(newNamespace, extVersion)))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

return resources.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public void updateMetadata(String namespaceName, String extensionName, Extension

var remoteReviews = upstream.getReviews(namespaceName, extensionName);
var localReviews = repositories.findAllReviews(extension)
.map(review -> new AbstractMap.SimpleEntry<>(review.toReviewJson(), review));
.map(review -> Map.entry(review.toReviewJson(), review));

remoteReviews.getReviews().stream()
.filter(review -> localReviews.stream().noneMatch(entry -> entry.getKey().equals(review)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public Map<Integer, Integer> countActiveExtensionPublishersGroupedByExtensionsPu
.groupBy(extensionCountsByPublisher.field(aliasExtensionCount, Integer.class))
.fetch()
.stream()
.map(l -> new AbstractMap.SimpleEntry<>(l.value1(), l.value2()))
.map(l -> Map.entry(l.value1(), l.value2()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}

Expand All @@ -108,7 +108,7 @@ public Map<Integer,Integer> countActiveExtensionsGroupedByExtensionReviewRating(
.groupBy(averageRatingByExtension.field(aliasAverageRating, Integer.class))
.fetch()
.stream()
.map(l -> new AbstractMap.SimpleEntry<>(l.value1(), l.value2()))
.map(l -> Map.entry(l.value1(), l.value2()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public Map<Long, List<String>> findActiveVersionStringsSorted(Collection<Long> e
.map(row -> {
var extensionId = row.get(top.field(EXTENSION_VERSION.EXTENSION_ID));
var version = row.get(top.field(EXTENSION_VERSION.VERSION));
return new AbstractMap.SimpleEntry<>(extensionId, version);
return Map.entry(extensionId, version);
})
.collect(Collectors.groupingBy(Map.Entry::getKey, Collectors.mapping(Map.Entry::getValue, Collectors.toList())));
}
Expand Down Expand Up @@ -797,7 +797,7 @@ public Map<Long, Boolean> findLatestIsPreview(Collection<Long> extensionIds) {
return query.fetch(row -> {
var id = row.get(EXTENSION.ID);
var preview = row.get(latest.field(EXTENSION_VERSION.PREVIEW));
return new AbstractMap.SimpleEntry<>(id, preview);
return Map.entry(id, preview);
})
.stream()
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void persistProcessedItem(String name, LocalDateTime processedOn, int exe
public Map<Long, Integer> processDownloadCounts(Map<String, Integer> files) {
return Observation.createNotStarted("AzureDownloadCountProcessor#processDownloadCounts", observations).observe(() -> {
return repositories.findDownloadsByStorageTypeAndName(STORAGE_AZURE, files.keySet()).stream()
.map(fileResource -> new AbstractMap.SimpleEntry<>(fileResource, files.get(fileResource.getName().toUpperCase())))
.map(fileResource -> Map.entry(fileResource, files.get(fileResource.getName().toUpperCase())))
.collect(Collectors.groupingBy(
e -> e.getKey().getExtension().getExtension().getId(),
Collectors.summingInt(Map.Entry::getValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,13 @@ && isExtensionPackageUri(node)
}).map(node -> {
var uri = node.get("uri").asText();
var pathParams = uri.substring(storageServiceEndpoint.length()).split("/");
return new AbstractMap.SimpleEntry<>(pathParams, node.get("time").asText());
return Map.entry(pathParams, node.get("time").asText());
})
.filter(entry -> storageBlobContainer.equals(entry.getKey()[1]))
.map(entry -> {
var pathParams = entry.getKey();
var fileName = UriUtils.decode(pathParams[pathParams.length - 1], StandardCharsets.UTF_8).toUpperCase();
return new AbstractMap.SimpleEntry<>(fileName, 1);
return Map.entry(fileName, 1);
})
.collect(Collectors.groupingBy(Map.Entry::getKey, Collectors.summingInt(Map.Entry::getValue)));
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ public TempFile downloadFile(FileResource resource) throws IOException {
*/
public Map<Long, Map<String, String>> getFileUrls(Collection<ExtensionVersion> extVersions, String serverUrl, String... types) {
var type2Url = extVersions.stream()
.map(ev -> new AbstractMap.SimpleEntry<Long, Map<String, String>>(ev.getId(), Maps.newLinkedHashMapWithExpectedSize(types.length)))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
.map(ev -> Map.<Long, Map<String, String>>entry(ev.getId(), Maps.newLinkedHashMapWithExpectedSize(types.length)))
.collect(Collectors.<Map.Entry<Long, Map<String, String>>, Long, Map<String, String>>toMap(Map.Entry::getKey, Map.Entry::getValue));

var resources = repositories.findFilesByType(extVersions, Arrays.asList(types));
for (var resource : resources) {
Expand Down

0 comments on commit c1f83fd

Please sign in to comment.