mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 00:11:26 +07:00
IDEA-163909 Inspection to replace computeIfAbsent returning a constant with putIfAbsent
This commit is contained in:
+10
@@ -0,0 +1,10 @@
|
||||
// "Use 'putIfAbsent' method without lambda" "true"
|
||||
import java.util.Map;
|
||||
|
||||
class Test {
|
||||
public void test(Map<String, String> map, String key) {
|
||||
/*comment in param*/
|
||||
/*comment in arrow*/
|
||||
map.putIfAbsent(key, (/*comment in parens*/"empty"));
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Use 'or' method without lambda" "true"
|
||||
package com.google.common.base;
|
||||
|
||||
interface Supplier<T> {
|
||||
T supply();
|
||||
}
|
||||
|
||||
abstract class Optional<T> {
|
||||
abstract T or(T value);
|
||||
abstract T or(Supplier<? extends T> supplier);
|
||||
}
|
||||
|
||||
class Test {
|
||||
public void test(Optional<String> opt) {
|
||||
System.out.println(opt.or(""));
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Use 'orElse' method without lambda" "true"
|
||||
import java.util.*;
|
||||
|
||||
class Test {
|
||||
public String test(List<String> data) {
|
||||
return data.stream().filter(Objects::nonNull).findFirst().orElse(null);
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Use 'putIfAbsent' method without lambda" "true"
|
||||
import java.util.Map;
|
||||
|
||||
class Test {
|
||||
public void test(Map<String, String> map, String key) {
|
||||
map.computeIfAbsent(key, (/*comment in param*/k) /*comment in arrow*/<caret>-> (/*comment in parens*/"empty"));
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Use 'putIfAbsent' method without lambda" "false"
|
||||
import java.util.Map;
|
||||
|
||||
class Test {
|
||||
public void test(Map<String, String> map, String key) {
|
||||
map.computeIfAbsent(key, (/*comment in param*/k) /*comment in arrow*/<caret>-> (/*comment in parens*/"empty"+key));
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Use 'putIfAbsent' method without lambda" "false"
|
||||
import java.util.Map;
|
||||
|
||||
class Test {
|
||||
public String test(Map<String, String> map, String key) {
|
||||
return map.computeIfAbsent(key, k <caret>-> ("empty"));
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Use 'or' method without lambda" "true"
|
||||
package com.google.common.base;
|
||||
|
||||
interface Supplier<T> {
|
||||
T supply();
|
||||
}
|
||||
|
||||
abstract class Optional<T> {
|
||||
abstract T or(T value);
|
||||
abstract T or(Supplier<? extends T> supplier);
|
||||
}
|
||||
|
||||
class Test {
|
||||
public void test(Optional<String> opt) {
|
||||
System.out.println(opt.or(() <caret>-> ""));
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Use 'or' method without lambda" "false"
|
||||
package com.google.common.base;
|
||||
|
||||
interface Supplier<T> {
|
||||
T supply();
|
||||
}
|
||||
|
||||
abstract class Optional<T> {
|
||||
abstract T or(T value);
|
||||
abstract T or(Supplier<? extends T> supplier);
|
||||
}
|
||||
|
||||
class Test {
|
||||
public void test(Optional<Supplier<String>> opt) {
|
||||
System.out.println(opt.or(() <caret>-> ""));
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Use 'orElse' method without lambda" "true"
|
||||
import java.util.*;
|
||||
|
||||
class Test {
|
||||
public String test(List<String> data) {
|
||||
return data.stream().filter(Objects::nonNull).findFirst().orElseGet((<caret>) -> null);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user