Replace Map operations with computeIfAbsent
This commit is contained in:
@@ -76,9 +76,7 @@ public class CompilerConfiguration {
|
||||
public <T> void add(@NotNull CompilerConfigurationKey<List<T>> key, @NotNull T value) {
|
||||
checkReadOnly();
|
||||
Key<List<T>> ideaKey = key.ideaKey;
|
||||
if (map.get(ideaKey) == null) {
|
||||
map.put(ideaKey, new ArrayList<T>());
|
||||
}
|
||||
map.computeIfAbsent(ideaKey, k -> new ArrayList<T>());
|
||||
List<T> list = (List<T>) map.get(ideaKey);
|
||||
list.add(value);
|
||||
}
|
||||
@@ -86,9 +84,7 @@ public class CompilerConfiguration {
|
||||
public <K, V> void put(@NotNull CompilerConfigurationKey<Map<K, V>> configurationKey, @NotNull K key, @NotNull V value) {
|
||||
checkReadOnly();
|
||||
Key<Map<K, V>> ideaKey = configurationKey.ideaKey;
|
||||
if (map.get(ideaKey) == null) {
|
||||
map.put(ideaKey, new HashMap<K, V>());
|
||||
}
|
||||
map.computeIfAbsent(ideaKey, k -> new HashMap<K, V>());
|
||||
Map<K, V> data = (Map<K, V>) map.get(ideaKey);
|
||||
data.put(key, value);
|
||||
}
|
||||
@@ -97,9 +93,7 @@ public class CompilerConfiguration {
|
||||
checkReadOnly();
|
||||
checkForNullElements(values);
|
||||
Key<List<T>> ideaKey = key.ideaKey;
|
||||
if (map.get(ideaKey) == null) {
|
||||
map.put(ideaKey, new ArrayList<T>());
|
||||
}
|
||||
map.computeIfAbsent(ideaKey, k -> new ArrayList<T>());
|
||||
List<T> list = (List<T>) map.get(ideaKey);
|
||||
list.addAll(values);
|
||||
}
|
||||
|
||||
+1
-5
@@ -332,11 +332,7 @@ public class ValueArgumentsToParametersMapper {
|
||||
|
||||
private void putVararg(ValueParameterDescriptor valueParameterDescriptor, ValueArgument valueArgument) {
|
||||
if (valueParameterDescriptor.getVarargElementType() != null) {
|
||||
VarargValueArgument vararg = varargs.get(valueParameterDescriptor);
|
||||
if (vararg == null) {
|
||||
vararg = new VarargValueArgument();
|
||||
varargs.put(valueParameterDescriptor, vararg);
|
||||
}
|
||||
VarargValueArgument vararg = varargs.computeIfAbsent(valueParameterDescriptor, k -> new VarargValueArgument());
|
||||
vararg.addArgument(valueArgument);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -348,13 +348,9 @@ public class CommonSupertypes {
|
||||
new DFS.NodeHandlerWithListResult<SimpleType, TypeConstructor>() {
|
||||
@Override
|
||||
public boolean beforeChildren(SimpleType current) {
|
||||
TypeConstructor constructor = current.getConstructor();
|
||||
|
||||
Set<SimpleType> instances = constructorToAllInstances.get(constructor);
|
||||
if (instances == null) {
|
||||
instances = new HashSet<SimpleType>();
|
||||
constructorToAllInstances.put(constructor, instances);
|
||||
}
|
||||
Set<SimpleType> instances = constructorToAllInstances.computeIfAbsent(
|
||||
current.getConstructor(), k -> new HashSet<SimpleType>()
|
||||
);
|
||||
instances.add(current);
|
||||
|
||||
return true;
|
||||
|
||||
@@ -33,11 +33,7 @@ public class TrackingSlicedMap extends SlicedMapImpl {
|
||||
}
|
||||
|
||||
private <K, V> SliceWithStackTrace<K, V> wrapSlice(ReadOnlySlice<K, V> slice) {
|
||||
SliceWithStackTrace<?, ?> translated = sliceTranslationMap.get(slice);
|
||||
if (translated == null) {
|
||||
translated = new SliceWithStackTrace<K, V>(slice);
|
||||
sliceTranslationMap.put(slice, translated);
|
||||
}
|
||||
SliceWithStackTrace<?, ?> translated = sliceTranslationMap.computeIfAbsent(slice, k -> new SliceWithStackTrace<K, V>(slice));
|
||||
//noinspection unchecked
|
||||
return (SliceWithStackTrace) translated;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user