// "Fix all 'Replace with Map.forEach' problems in file" "true" import java.util.Map; import java.util.function.Supplier; public class Test { public static void testInline(Map map) { map.forEach((key, value) -> System.out.println(key + ":" + value)); } public static void testKey(Map map) { map.forEach((str, value) -> System.out.println(str + ":" + value)); } public static void testValue(Map map) { map.forEach((str, num) -> System.out.println(str + ":" + num)); } public static void testTwoVarsWildcard(Map map) { map.forEach((str, num) -> { System.out.println(str + ":" + num); String str2 = str; System.out.println(str2); }); } public static > void testGeneric(Supplier map) { map.get().forEach((key, value) -> System.out.println(key + ":" + value)); } public static > void testUsedHashCode(Supplier map) { map.get().entrySet().forEach(e -> System.out.println(e.getKey()+":"+e.getValue()+":"+e.hashCode())); } public static void testForLoop(Map map) { map.forEach((key, value) -> System.out.println(key + ":" + value)); } public static void testForLoop2(Map map) { map.forEach((str, num) -> System.out.println(str + ":" + num)); } public static void testForLoop3(Map map) { map.forEach((str, num) -> { System.out.println(str + ":" + num); System.out.println(num + ":" + str); }); } public static void testForLoopSet(Map map) { for (Map.Entry entry : map.entrySet()) { String str = entry.getKey(); Integer num = entry.getValue(); System.out.println(str + ":" + entry.getValue()); entry.setValue(1); } } public static void testForLoopPrimitive(Map map) { map.forEach((str, value) -> { int num = value; System.out.println(str + ":" + num); }); } public static void testForLoopSideEffect(Map map) { Integer num; for (Map.Entry entry : map.entrySet()) { String str = entry.getKey(); num = entry.getValue(); System.out.println(str + ":" + num); } } public static void testForLoopThrow(Map map) throws Exception { for (Map.Entry entry : map.entrySet()) { String str = entry.getKey(); Integer num = entry.getValue(); if(num > 0) throw new Exception(); System.out.println(str + ":" + num); } } public static void testForLoopThrowRuntime(Map map) throws Exception { map.forEach((str, num) -> { if (num > 0) throw new RuntimeException(); System.out.println(str + ":" + num); }); } void forEach(Map map) { map.forEach((key, value) -> { //long comment }); } }