[java-inspections] UseBulkOperationInspection: support Maps (IDEA-262786)

GitOrigin-RevId: 9aae98c287f6e2057b09bfda78fb007ba45eeee6
This commit is contained in:
Andrey.Cherkasov
2021-05-25 16:22:10 +03:00
committed by intellij-monorepo-bot
parent 480de17a92
commit f68f593aa4
15 changed files with 230 additions and 73 deletions

View File

@@ -0,0 +1,10 @@
// "Replace iteration with bulk 'Map.putAll' call" "true"
import java.util.*;
class Main {
void test(Map<String, Integer> map) {
Map<String, Integer> result = new HashMap<>();
result.put("answer", 42);
result.putAll(map);
}
}

View File

@@ -0,0 +1,10 @@
// "Replace iteration with bulk 'Map.putAll' call" "true"
import java.util.*;
class Main {
void test(Map<String, Integer> map) {
Map<String, Integer> result = new HashMap<>();
result.put("answer", 42);
result.putAll(map);
}
}

View File

@@ -0,0 +1,10 @@
// "Replace iteration with bulk 'Map.putAll' call" "true"
import java.util.*;
class Main {
void test(Map<String, Integer> map) {
Map<String, Integer> result = new HashMap<>();
result.put("answer", 42);
result.putAll(map);
}
}

View File

@@ -0,0 +1,10 @@
// "Replace iteration with bulk 'Map.putAll' call" "true"
import java.util.*;
class Main {
void test(Map<String, Integer> map) {
Map<String, Integer> result = new HashMap<>();
result.put("answer", 42);
result.putAll(map);
}
}

View File

@@ -0,0 +1,10 @@
// "Replace iteration with bulk 'Map.putAll' call" "true"
import java.util.*;
class Main {
void test(Map<String, Integer> map) {
Map<String, Integer> result = new HashMap<>();
result.put("answer", 42);
result.putAll(map);
}
}

View File

@@ -0,0 +1,10 @@
// "Replace iteration with bulk 'Map.putAll' call" "true"
import java.util.*;
class Main {
void test(Map<String, Integer> map) {
Map<String, Integer> result = new HashMap<>();
result.put("answer", 42);
result.putAll(map);
}
}

View File

@@ -0,0 +1,10 @@
// "Replace iteration with bulk 'Map.putAll' call" "true"
import java.util.*;
class Main {
void test(Map<String, Integer> map) {
Map<String, Integer> result = new HashMap<>();
result.put("answer", 42);
map.entrySet().forEach(e -> result<caret>.put(e.getKey(), e.getValue()));
}
}

View File

@@ -0,0 +1,10 @@
// "Replace iteration with bulk 'Map.putAll' call" "true"
import java.util.*;
class Main {
void test(Map<String, Integer> map) {
Map<String, Integer> result = new HashMap<>();
result.put("answer", 42);
map.forEach((key, value) -> result<caret>.put(key, value));
}
}

View File

@@ -0,0 +1,12 @@
// "Replace iteration with bulk 'Map.putAll' call" "true"
import java.util.*;
class Main {
void test(Map<String, Integer> map) {
Map<String, Integer> result = new HashMap<>();
result.put("answer", 42);
for (Map.Entry<String, Integer> e : map.entrySet()) {
result<caret>.put(e.getKey(), e.getValue());
}
}
}

View File

@@ -0,0 +1,10 @@
// "Replace iteration with bulk 'Map.putAll' call" "true"
import java.util.*;
class Main {
void test(Map<String, Integer> map) {
Map<String, Integer> result = new HashMap<>();
result.put("answer", 42);
map.forEach(result::put<caret>);
}
}

View File

@@ -0,0 +1,13 @@
// "Replace iteration with bulk 'Map.putAll' call" "true"
import java.util.*;
class Main {
void test(Map<String, Integer> map) {
Map<String, Integer> result = new HashMap<>();
result.put("answer", 42);
for (Iterator<Map.Entry<String, Integer>> iterator = map.entrySet().iterator(); iterator.hasNext(); ) {
Map.Entry<String, Integer> e = iterator.next();
result<caret>.put(e.getKey(), e.getValue());
}
}
}

View File

@@ -0,0 +1,14 @@
// "Replace iteration with bulk 'Map.putAll' call" "true"
import java.util.*;
class Main {
void test(Map<String, Integer> map) {
Map<String, Integer> result = new HashMap<>();
result.put("answer", 42);
Iterator<Map.Entry<String, Integer>> iterator = map.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, Integer> e = iterator.next();
result<caret>.put(e.getKey(), e.getValue());
}
}
}