mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 06:05:01 +07:00
Java8MapApiInspection: support some scenarios to produce Map.merge (IDEA-163910)
This commit is contained in:
@@ -4,7 +4,6 @@ import java.util.Map;
|
||||
public class Main {
|
||||
|
||||
public void test(Map<String, List<String>> map, String key) {
|
||||
List<String> list = map.get(key);
|
||||
map.computeIfAbsent(key, k -> new ArrayList<>());
|
||||
System.out.println(map);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
// "Replace with 'merge' method call" "true"
|
||||
import java.util.Map;
|
||||
|
||||
public class Main {
|
||||
public void testMerge(Map<String, Integer> map, String key, int max) {
|
||||
/*get!*/
|
||||
// check
|
||||
/*get max*/
|
||||
map.merge(key, /* passed max value */ max, Math::max)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Replace with 'merge' method call" "true"
|
||||
import java.util.Map;
|
||||
|
||||
public class Main {
|
||||
public void testMerge(Map<String, Integer> map, String key) {
|
||||
map.merge(key, 1, (a, b) -> a + b)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Replace with 'merge' method call" "true"
|
||||
import java.util.Map;
|
||||
|
||||
public class Main {
|
||||
public void testMerge(Map<String, Integer> map, String key) {
|
||||
map.merge(key, 1, (a, b) -> b + a)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Replace with 'merge' method call" "true"
|
||||
import java.util.Map;
|
||||
|
||||
public class Main {
|
||||
public void testMerge(Map<String, Integer> map, String key, int add) {
|
||||
Integer val = map.get(key);
|
||||
map.merge(key, add, (a, b) -> b + a)
|
||||
System.out.println(val);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// "Replace with 'merge' method call" "true"
|
||||
import java.util.Map;
|
||||
|
||||
public class Main {
|
||||
public void testMerge(Map<String, Integer> map, String key, int max) {
|
||||
Integer val = /*get!*/map.get(key);
|
||||
// check
|
||||
if(val<caret> == null) {
|
||||
map.put(key, /* passed max value */ max)
|
||||
} else {
|
||||
map.put(key, Math.max(/*get max*/val, max));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// "Replace with 'merge' method call" "false"
|
||||
import java.util.Map;
|
||||
|
||||
public class Main {
|
||||
public void testMerge(Map<String, Integer> map, String key, int add) {
|
||||
Integer val = map.get(key);
|
||||
if(val<caret> == null) {
|
||||
map.put(key, add + val);
|
||||
} else {
|
||||
map.put(key, add)
|
||||
}
|
||||
System.out.println(val);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// "Replace with 'merge' method call" "false"
|
||||
import java.util.Map;
|
||||
|
||||
public class Main {
|
||||
public void testMerge(Map<String, Integer> map, String key, int add) {
|
||||
Integer val = map.get(key);
|
||||
if(val<caret> == null) {
|
||||
map.put(key, add);
|
||||
} else {
|
||||
map.put(key, add + 1)
|
||||
}
|
||||
System.out.println(val);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// "Replace with 'merge' method call" "true"
|
||||
import java.util.Map;
|
||||
|
||||
public class Main {
|
||||
public void testMerge(Map<String, Integer> map, String key) {
|
||||
if(map.get(key)<caret> == null) {
|
||||
map.put(key, 1)
|
||||
} else {
|
||||
map.put(key, map.get(key) + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// "Replace with 'merge' method call" "true"
|
||||
import java.util.Map;
|
||||
|
||||
public class Main {
|
||||
public void testMerge(Map<String, Integer> map, String key) {
|
||||
Integer val = map.get(key);
|
||||
if(val<caret> == null) {
|
||||
map.put(key, 1)
|
||||
} else {
|
||||
map.put(key, 1 + val);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// "Replace with 'merge' method call" "true"
|
||||
import java.util.Map;
|
||||
|
||||
public class Main {
|
||||
public void testMerge(Map<String, Integer> map, String key, int add) {
|
||||
Integer val = map.get(key);
|
||||
if(val<caret> == null) {
|
||||
map.put(key, add)
|
||||
} else {
|
||||
map.put(key, add + val);
|
||||
}
|
||||
System.out.println(val);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user