mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
IDEA-185167 Allow to convert automatically Optional.orElse(...) to Optional.orElseGet(() -> ...)
This commit is contained in:
+10
@@ -0,0 +1,10 @@
|
||||
// "Use 'computeIfAbsent' method with functional argument" "true"
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
class Test {
|
||||
public void test(Map<String, List<Integer>> map, String key) {
|
||||
map.computeIfAbsent(key, k -> new ArrayList<>());
|
||||
map.get(key).add(0);
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Use 'orElseGet' method with functional argument" "true"
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
class Test {
|
||||
String createDefaultString() {
|
||||
return "foo";
|
||||
}
|
||||
|
||||
public void test(Optional<String> opt) {
|
||||
String result = opt.orElseGet(this::createDefaultString);
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Use 'orElseGet' method with functional argument" "true"
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
class Test {
|
||||
String createDefaultString(int x) {
|
||||
return "foo"+x;
|
||||
}
|
||||
|
||||
public void test(Optional<String> opt) {
|
||||
int x = 5;
|
||||
String result = opt.orElseGet(() -> createDefaultString(x));
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Use 'computeIfAbsent' method with functional argument" "true"
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
class Test {
|
||||
public void test(Map<String, List<Integer>> map, String key) {
|
||||
map.putIfAbsent(key, new ArrayL<caret>ist<>());
|
||||
map.get(key).add(0);
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Use 'computeIfAbsent' method with functional argument" "false"
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
class Test {
|
||||
public void test(Map<String, List<Integer>> map, String key) {
|
||||
List<Integer> old = map.putIfAbsent(key, new ArrayL<caret>ist<>());
|
||||
map.get(key).add(0);
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Use 'orElseGet' method with functional argument" "true"
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
class Test {
|
||||
String createDefaultString() {
|
||||
return "foo";
|
||||
}
|
||||
|
||||
public void test(Optional<String> opt) {
|
||||
String result = opt.orElse(createDef<caret>aultString());
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Use 'orElseGet' method with functional argument" "true"
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
class Test {
|
||||
String createDefaultString(int x) {
|
||||
return "foo"+x;
|
||||
}
|
||||
|
||||
public void test(Optional<String> opt) {
|
||||
int x = 5;
|
||||
String result = opt.orElse(createDef<caret>aultString(x));
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Use 'orElseGet' method with functional argument" "false"
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
class Test {
|
||||
String createDefaultString(int x) {
|
||||
return "foo"+x;
|
||||
}
|
||||
|
||||
public void test(Optional<String> opt) {
|
||||
int x = 5;
|
||||
x++;
|
||||
String result = opt.orElse(createDef<caret>aultString(x));
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Use 'orElseGet' method with functional argument" "false"
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
class Test {
|
||||
public void test(Optional<String> opt) {
|
||||
String result = opt.orElse("f<caret>oo");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user