use jdk9+ Map.entry API instead of AbstractMap.SimpleImmutableEntry

GitOrigin-RevId: bac64af4495e36b044873f6a97625342af907bec
This commit is contained in:
Vladimir Krivosheev
2021-04-12 09:29:18 +00:00
committed by intellij-monorepo-bot
parent 3c2dc5d7e8
commit 4b445ebc43
10 changed files with 21 additions and 26 deletions
@@ -1,4 +1,4 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.intellij.build.devServer
import com.intellij.openapi.application.PathManager
@@ -24,7 +24,6 @@ import java.nio.file.ClosedWatchServiceException
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import java.util.*
import java.util.concurrent.CountDownLatch
import java.util.concurrent.atomic.AtomicBoolean
import kotlin.system.exitProcess
@@ -200,7 +199,7 @@ fun parseQuery(url: URI): Map<String, List<String?>> {
val index = it.indexOf('=')
val key = if (index > 0) it.substring(0, index) else it
val value = if (index > 0 && it.length > index + 1) it.substring(index + 1) else null
AbstractMap.SimpleImmutableEntry(key, value)
java.util.Map.entry(key, value)
}
.groupBy(keySelector = { it.key }, valueTransform = { it.value })
}
@@ -685,7 +685,7 @@ final class DistributionJARsBuilder {
}
pluginsToIncludeInCustomRepository.add(new PluginRepositorySpec(pluginZip: destFile.toString(), pluginXml: pluginXml.toString()))
}
toArchive.add(new AbstractMap.SimpleImmutableEntry(directory, destFile))
toArchive.add(Map.entry(directory, destFile))
}
BuildHelper.bulkZipWithPrefix(buildContext, pluginsToPublishDir, toArchive, compressPluginArchive)
@@ -1,8 +1,6 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.externalSystem.util
import java.util.*
/**
* [PrefixTreeMap] uses keys, that is specified by the paths.
* @see PrefixTreeMap
@@ -42,7 +40,7 @@ class PathPrefixTreeMap<V>(
fun getAllAncestorValues(path: String) = delegate.getAllAncestorValues(path.toPrefixList())
private fun Iterable<Map.Entry<List<String>, V>>.toPathEntries(): List<Map.Entry<String, V>> {
return map { AbstractMap.SimpleImmutableEntry(it.key.joinToString(pathSeparator), it.value) }
return map { java.util.Map.entry(it.key.joinToString(pathSeparator), it.value) }
}
private fun Iterable<List<String>>.toPathKeys() = map { it.joinToString(pathSeparator) }
@@ -1,10 +1,7 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.externalSystem.util
import com.intellij.util.containers.FList
import java.util.*
import kotlin.NoSuchElementException
import kotlin.collections.LinkedHashMap
import kotlin.collections.component1
import kotlin.collections.component2
@@ -116,11 +113,11 @@ internal class PrefixTreeMap<K, V> : Map<List<K>, V> {
fun getEntries(): Sequence<Map.Entry<FList<K>, V>> {
return sequence {
if (value.isPresent) {
yield(AbstractMap.SimpleImmutableEntry(FList.emptyList(), value.get()))
yield(java.util.Map.entry(FList.emptyList(), value.get()))
}
for ((key, child) in children) {
for ((path, value) in child.getEntries()) {
yield(AbstractMap.SimpleImmutableEntry(path.prepend(key), value))
yield(java.util.Map.entry(path.prepend(key), value))
}
}
}
@@ -129,19 +126,20 @@ internal class PrefixTreeMap<K, V> : Map<List<K>, V> {
fun getAllAncestors(path: FList<K>): Sequence<Map.Entry<FList<K>, V>> {
return sequence {
if (value.isPresent) {
yield(AbstractMap.SimpleImmutableEntry(FList.emptyList(), value.get()))
yield(java.util.Map.entry(FList.emptyList(), value.get()))
}
if (path.isEmpty()) return@sequence
val (head, tail) = path
val child = children[head] ?: return@sequence
for ((relative, value) in child.getAllAncestors(tail)) {
yield(AbstractMap.SimpleImmutableEntry(relative.prepend(head), value))
yield(java.util.Map.entry(relative.prepend(head), value))
}
}
}
fun getAllDescendants(path: FList<K>) =
root.get(path)?.getEntries()?.map { AbstractMap.SimpleImmutableEntry(path + it.key, it.value) } ?: emptySequence()
fun getAllDescendants(path: FList<K>): Sequence<MutableMap.MutableEntry<List<K>, V>> {
return root.get(path)?.getEntries()?.map { java.util.Map.entry(path + it.key, it.value) } ?: emptySequence()
}
}
private class Value<out T> private constructor(val isPresent: Boolean, private val value: Any?) {
@@ -176,7 +176,7 @@ public final class ConsentOptions {
allDefaults.remove(STATISTICS_OPTION_ID);
}
if (allDefaults.isEmpty()) {
return new AbstractMap.SimpleImmutableEntry<>(Collections.emptyList(), Boolean.FALSE);
return Map.entry(Collections.emptyList(), Boolean.FALSE);
}
final Map<String, ConfirmedConsent> allConfirmed = loadConfirmedConsents();
final List<Consent> result = new ArrayList<>();
@@ -189,7 +189,7 @@ public final class ConsentOptions {
}
result.sort(Comparator.comparing(ConsentBase::getId));
boolean confirmationEnabled = Boolean.parseBoolean(System.getProperty(CONSENTS_CONFIRMATION_PROPERTY, "true"));
return new AbstractMap.SimpleImmutableEntry<>(result, confirmationEnabled && needReconfirm(allDefaults, allConfirmed));
return Map.entry(result, confirmationEnabled && needReconfirm(allDefaults, allConfirmed));
}
public void setConsents(@NotNull Collection<Consent> confirmedByUser) {
@@ -633,7 +633,7 @@ public final class MVMap<K, V> extends AbstractMap<K, V> implements ConcurrentMa
@Override
public Entry<K, V> next() {
K k = cursor.next();
return new SimpleImmutableEntry<>(k, cursor.getValue());
return Map.entry(k, cursor.getValue());
}
};
}
@@ -1,4 +1,4 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.concurrency;
/*
@@ -1488,7 +1488,7 @@ final class ConcurrentHashMap<K,V> extends AbstractMap<K,V>
for (Node<K,V> p; (p = it.advance()) != null; ) {
K k = p.key;
V v = p.val;
Map.Entry<K,V> e = new AbstractMap.SimpleImmutableEntry<>(k, v);
Map.Entry<K,V> e = Map.entry(k, v);
if (function.test(e) && replaceNode(k, null, v) != null)
removed = true;
}
@@ -502,7 +502,7 @@ public class ClassWriter {
}
private static boolean isVarArgRecord(StructClass cl) {
String canonicalConstructorDescriptor =
String canonicalConstructorDescriptor =
cl.getRecordComponents().stream().map(c -> c.getDescriptor()).collect(Collectors.joining("", "(", ")V"));
StructMethod init = cl.getMethod(CodeConstants.INIT_NAME, canonicalConstructorDescriptor);
return init != null && init.hasModifier(CodeConstants.ACC_VARARGS);
@@ -137,7 +137,7 @@ public class VSCBundle extends Bundle {
//noinspection SSBasedInspection
return configToScopes.get(FileUtilRt.toSystemIndependentName(
Objects.requireNonNull(FileUtilRt.getRelativePath(bundleFile, file)))).stream()
.map(scope -> new AbstractMap.SimpleImmutableEntry<>(scope, fromJson))
.map(scope -> Map.entry(scope, fromJson))
.collect(Collectors.toList());
}
@@ -30,7 +30,7 @@ public final class PreferencesReadUtil {
settingsValuePlist = settingsValue.getPlist();
}
}
return settingsValuePlist != null ? new AbstractMap.SimpleImmutableEntry<>(scopeName, settingsValuePlist) : null;
return settingsValuePlist != null ? Map.entry(scopeName, settingsValuePlist) : null;
}
@Nullable