IDEA-179280 java9 - intention to use Map.ofEntries

This commit is contained in:
Tagir Valeev
2017-09-21 13:24:48 +07:00
parent 0b99eeb259
commit f533da27ef
6 changed files with 98 additions and 19 deletions
@@ -0,0 +1,9 @@
// "Replace with 'Map.ofEntries' call" "true"
import java.util.*;
public class Test {
public void test() {
Map<String, String> myMap;
myMap = Map.ofEntries(Map.entry("a", "1"), Map.entry("b", "1"), Map.entry("c", "1"), Map.entry("d", "1"), Map.entry("e", "1"), Map.entry("f", "1"), Map.entry("g", "1"), Map.entry("h", "1"), Map.entry("i", "1"), Map.entry("j", "1"), Map.entry("k", "1"));
}
}
@@ -0,0 +1,17 @@
// "Replace with 'Map.ofEntries' call" "true"
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public class Test {
static final Map<String, String> map;
static {
//_map.put("a", "b");
map = Map.ofEntries(Map.entry("c", "d"), Map.entry("e", "f"), Map.entry("g", "h"), Map.entry("i", "j"), Map.entry("k", "l"),
// and m
Map.entry("m", "n"), Map.entry("o", "p"), Map.entry("r", "s"), Map.entry("t", /*uuuu*/"u"), Map.entry("v", "w"), Map.entry("x", /*you*/ "y"),
// q was forgotten!
Map.entry("q", "z"));
}
}
@@ -1,4 +1,4 @@
// "Replace with 'Map.of' call" "false"
// "Replace with 'Map.ofEntries' call" "true"
import java.util.*;
public class Test {
@@ -0,0 +1,28 @@
// "Replace with 'Map.ofEntries' call" "true"
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public class Test {
static final Map<String, String> map;
static {
Map<String, String> _map = new HashMap<>();
//_map.put("a", "b");
_map.put("c", "d");
_map.put("e", "f");
_map.put("g", "h");
_map.put("i", "j");
_map.put("k", "l");
// and m
_map.put("m", "n");
_map.put("o", "p");
_map.put("r", "s");
_map.put("t" /*uuuu*/, "u");
_map.put("v", "w");
_map.put("x", /*you*/ "y");
// q was forgotten!
_map.put("q", "z");
map = Collections.unmodifiab<caret>leMap(_map);
}
}