mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-161257 Add Java-8 migration fix to use Map.computeIfAbsent where appropriate
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
// "Replace with 'computeIfAbsent' method call" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Main {
|
||||
public void testMap(Map<String, List<String>> map, String key, String value) {
|
||||
List<String> list = map.computeIfAbsent(key, k -> new ArrayList<>());
|
||||
list.add(value);
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Replace with 'computeIfAbsent' method call" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Main {
|
||||
String k;
|
||||
|
||||
public void testMap(Map<String, List<String>> map, String value) {
|
||||
List<String> list = map.computeIfAbsent(this.k, k1 -> new ArrayList<>());
|
||||
list.add(value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// "Replace with 'computeIfAbsent' method call" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Main {
|
||||
public void testMap(Map<String, List<String>> map, String key, String value) {
|
||||
List<String> list = map.get(key);
|
||||
if(list == nul<caret>l) {
|
||||
list = new ArrayList<>();
|
||||
map.put(key, list);
|
||||
}
|
||||
list.add(value);
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Replace with 'computeIfAbsent' method call" "false"
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Main {
|
||||
public void testMap(Map<String, List<String>> map, String key, String value) {
|
||||
int size = 5;
|
||||
if(map.isEmpty()) size = 10;
|
||||
List<String> list = map.get(key);
|
||||
if(list == <caret>null) {
|
||||
list = new ArrayList<>(size);
|
||||
map.put(key, list);
|
||||
}
|
||||
list.add(value);
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Replace with 'computeIfAbsent' method call" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Main {
|
||||
String k;
|
||||
|
||||
public void testMap(Map<String, List<String>> map, String value) {
|
||||
List<String> list = map.get(this.k);
|
||||
if(list == nul<caret>l) {
|
||||
list = new ArrayList<>();
|
||||
map.put(this.k, list);
|
||||
}
|
||||
list.add(value);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -6,8 +6,8 @@ public class Main {
|
||||
public void testGetOrDefault(Map<String, String> map, String key) {
|
||||
Integer num = 123;
|
||||
System.out.println(num);
|
||||
num = map.get(k<caret>ey);
|
||||
if(num == null) num = 0;
|
||||
num = map.get(key);
|
||||
if(num == nu<caret>ll) num = 0;
|
||||
System.out.println(num);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -7,8 +7,8 @@ public class Main {
|
||||
private String str;
|
||||
|
||||
public void testGetOrDefault(Map<String, String> map, String key, Main other) {
|
||||
str = map.get(k<caret>ey);
|
||||
if(str == null) {
|
||||
str = map.get(key);
|
||||
if(str == nul<caret>l) {
|
||||
/*
|
||||
block comment
|
||||
*/
|
||||
|
||||
+2
-2
@@ -5,8 +5,8 @@ public class Main {
|
||||
private String str;
|
||||
|
||||
public void testGetOrDefault(Map<String, String> map, String key, Main other) {
|
||||
str = map.get(k<caret>ey);
|
||||
if(other.str == null) {
|
||||
str = map.get(key);
|
||||
if(other.str ==<caret> null) {
|
||||
// comment
|
||||
str = "";
|
||||
}
|
||||
|
||||
+2
-2
@@ -5,8 +5,8 @@ public class Main {
|
||||
private String str;
|
||||
|
||||
public void testGetOrDefault(Map<String, String> map, String key, Main other) {
|
||||
str = map.get(k<caret>ey);
|
||||
if(str == null) {
|
||||
str = map.get(key);
|
||||
if(s<caret>tr == null) {
|
||||
// comment
|
||||
other.str = "";
|
||||
}
|
||||
|
||||
+2
-2
@@ -4,8 +4,8 @@ import java.util.Map;
|
||||
public class Main {
|
||||
|
||||
public void testGetOrDefault(Map<String, String> map, String key, Main other) {
|
||||
String a = null, str = map.get(k<caret>ey);
|
||||
if(str == null) {
|
||||
String a = null, str = map.get(key);
|
||||
if(str == nu<caret>ll) {
|
||||
// comment
|
||||
str = "";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user