Map.getOrDefault/putIfAbsent/merge used where safe; warnings fixed

This commit is contained in:
Tagir Valeev
2018-02-19 16:51:26 +07:00
parent fdd6bb2ca8
commit 9005a8c6cb
4 changed files with 4 additions and 10 deletions
@@ -148,7 +148,7 @@ public class LibraryDownloadSettings {
}
libraryEditor.setName(myLibraryName);
for (Pair<VirtualFile, DownloadableFileDescription> pair : downloaded) {
final OrderRootType rootType = rootTypes.containsKey(pair.getSecond()) ? rootTypes.get(pair.getSecond()) : OrderRootType.CLASSES;
final OrderRootType rootType = rootTypes.getOrDefault(pair.getSecond(), OrderRootType.CLASSES);
libraryEditor.addRoot(pair.getFirst(), rootType);
}
return libraryEditor;
@@ -361,9 +361,7 @@ public class JavaPsiFacadeImpl extends JavaPsiFacadeEx {
// (the Kotlin plugin can do that), the Java package takes precedence.
PsiPackage[] packages = finder.getSubPackages(psiPackage, scope);
for (PsiPackage aPackage : packages) {
if (result.get(aPackage.getName()) == null) {
result.put(aPackage.getName(), aPackage);
}
result.putIfAbsent(aPackage.getName(), aPackage);
}
}
return result.values().toArray(PsiPackage.EMPTY_ARRAY);
@@ -642,6 +642,6 @@ public abstract class OptionTreeWithPreviewPanel extends CustomizableLanguageCod
}
private String getRemappedGroup(String fieldName, String defaultName) {
return myRemappedGroups.containsKey(fieldName) ? myRemappedGroups.get(fieldName) : defaultName;
return myRemappedGroups.getOrDefault(fieldName, defaultName);
}
}
@@ -46,11 +46,7 @@ public class DuplicateMap {
SliceNode putNodeCheckDupe(@NotNull final SliceNode node) {
return ReadAction.compute(() -> {
SliceUsage usage = node.getValue();
SliceNode eq = myDuplicates.get(usage);
if (eq == null) {
myDuplicates.put(usage, node);
}
return eq;
return myDuplicates.putIfAbsent(usage, node);
});
}