Files
openide/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/streamApiMigration/afterTooLazyCalculation.java
Tagir Valeev 478cae19bf IDEA-170032 Replace with foreach is not proposed in alt-enter
Now both options (when unchecked) only disable warning and batch-mode replacement, but the action is still available as an intention.
2017-03-30 13:07:18 +07:00

20 lines
549 B
Java

// "Replace with forEach" "INFORMATION"
import java.util.*;
class A {
public static void main(String[] args) {
List<String> names = Arrays.asList("Bob", "Alice", "Bob", "Carol");
Set<String> uniqNames = new HashSet<>(names.size());
names.forEach(name -> uniqNames.add(makeNameUnique(name, uniqNames)));
uniqNames.forEach(System.out::println);
}
private static String makeNameUnique(final String name, final Set<String> uniqNames) {
if (uniqNames.contains(name)) {
return name + "1";
}
return name;
}
}