mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
IDEA-163627 Simplify optional.isPresent() inspection could better handle some specific cases
IDEA-163462 Simplify Optional.isPresent() ? Optional.get() : ...
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace Optional.isPresent() condition with orElse()" "true"
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace Optional.isPresent() condition with orElse()" "true"
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace Optional.isPresent() condition with map().orElse()" "true"
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace Optional.isPresent() condition with map().orElseGet()" "true"
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace Optional.isPresent() condition with ifPresent()" "true"
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace Optional.isPresent() condition with ifPresent()" "true"
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace Optional.isPresent() condition with map().orElse()" "true"
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class Main {
|
||||
private static String test(List<Object> list) {
|
||||
Optional<Object> first = list.stream().filter(obj -> obj instanceof String).findFirst();
|
||||
return (String) first.orElse(null);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(Arrays.asList(null, null, "aa", "bbb", "c", null, "dd")));
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace Optional.isPresent() condition with map().orElse()" "true"
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace Optional.isPresent() condition with map().orElse()" "true"
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace Optional.isPresent() condition with map().orElse()" "true"
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace Optional.isPresent() condition with orElse()" "true"
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class Main {
|
||||
public Optional<String> get() {
|
||||
Optional<String> port = Optional.ofNullable(System.getProperty("abc");
|
||||
Optional<String> result;
|
||||
result = port.map(String::trim);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class Main {
|
||||
private static String test(List<Object> list) {
|
||||
Optional<Object> first = list.stream().filter(obj -> obj instanceof String).findFirst();
|
||||
return (String) first.orElse(null);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(Arrays.asList(null, null, "aa", "bbb", "c", null, "dd")));
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class Main {
|
||||
public static Optional<String> trimmed(String s) {
|
||||
return s.isEmpty() ? Optional.empty() : Optional.of(s.trim());
|
||||
}
|
||||
|
||||
private static Optional<String> test(List<Object> list) {
|
||||
Optional<Object> first = list.stream().filter(obj -> obj instanceof String).findFirst();
|
||||
return first.flatMap(o -> trimmed((String) o));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(Arrays.asList(null, null, "aa", "bbb", "c", null, "dd")));
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class Main {
|
||||
private static Optional<String> test(List<Object> list) {
|
||||
Optional<Object> first = list.stream().filter(obj -> obj instanceof String).findFirst();
|
||||
return first.map(o -> (String) o);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(Arrays.asList(null, null, "aa", "bbb", "c", null, "dd")));
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class Main {
|
||||
private static Optional<Object> test(List<Object> list) {
|
||||
Optional<Object> first = list.stream().filter(obj -> obj instanceof String).findFirst();
|
||||
return first;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(Arrays.asList(null, null, "aa", "bbb", "c", null, "dd")));
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace Optional.isPresent() condition with orElse()" "true"
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace Optional.isPresent() condition with orElse()" "true"
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace Optional.isPresent() condition with map().orElse()" "true"
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace Optional.isPresent() condition with map().orElseGet()" "true"
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace Optional.isPresent() condition with ifPresent()" "true"
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace Optional.isPresent() condition with ifPresent()" "true"
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace Optional.isPresent() condition with ifPresent()" "false"
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "false"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace Optional.isPresent() condition with ifPresent()" "false"
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "false"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace Optional.isPresent() condition with map().orElse()" "true"
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class Main {
|
||||
private static String test(List<Object> list) {
|
||||
Optional<Object> first = list.stream().filter(obj -> obj instanceof String).findFirst();
|
||||
if(first.isPre<caret>sent()) {
|
||||
return (String)first.get();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(Arrays.asList(null, null, "aa", "bbb", "c", null, "dd")));
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace Optional.isPresent() condition with map().orElse()" "true"
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace Optional.isPresent() condition with map().orElse()" "false"
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "false"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace Optional.isPresent() condition with map().orElse()" "true"
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace Optional.isPresent() condition with map().orElse()" "false"
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "false"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace Optional.isPresent() condition with map().orElse()" "true"
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace Optional.isPresent() condition with map().orElse()" "false"
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "false"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace Optional.isPresent() condition with orElse()" "true"
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class Main {
|
||||
public Optional<String> get() {
|
||||
Optional<String> port = Optional.ofNullable(System.getProperty("abc");
|
||||
Optional<String> result;
|
||||
if(po<caret>rt.isPresent()) {
|
||||
result = Optional.of(port.get().trim());
|
||||
} else {
|
||||
result = port;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class Main {
|
||||
private static String test(List<Object> list) {
|
||||
Optional<Object> first = list.stream().filter(obj -> obj instanceof String).findFirst();
|
||||
return fi<caret>rst.isPresent() ? (String) first.get() : null;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(Arrays.asList(null, null, "aa", "bbb", "c", null, "dd")));
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class Main {
|
||||
public static Optional<String> trimmed(String s) {
|
||||
return s.isEmpty() ? Optional.empty() : Optional.of(s.trim());
|
||||
}
|
||||
|
||||
private static Optional<String> test(List<Object> list) {
|
||||
Optional<Object> first = list.stream().filter(obj -> obj instanceof String).findFirst();
|
||||
return first.is<caret>Present() ? trimmed((String) first.get()) : Optional.empty();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(Arrays.asList(null, null, "aa", "bbb", "c", null, "dd")));
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class Main {
|
||||
private static Optional<String> test(List<Object> list) {
|
||||
Optional<Object> first = list.stream().filter(obj -> obj instanceof String).findFirst();
|
||||
return !fi<caret>rst.isPresent() ? Optional.empty() : Optional.of((String) first.get());
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(Arrays.asList(null, null, "aa", "bbb", "c", null, "dd")));
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class Main {
|
||||
private static Optional<Object> test(List<Object> list) {
|
||||
Optional<Object> first = list.stream().filter(obj -> obj instanceof String).findFirst();
|
||||
return fir<caret>st.isPresent() ? Optional.of(first.get()) : Optional.empty();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(Arrays.asList(null, null, "aa", "bbb", "c", null, "dd")));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user