mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-31 19:50:55 +07:00
27 lines
766 B
Java
27 lines
766 B
Java
// "Fix all ''Optional' can be replaced with sequence of 'if' statements' problems in file" "true"
|
|
|
|
import java.util.*;
|
|
|
|
class Test {
|
|
|
|
void exceptionIsThrownOnNullValue(String in) {
|
|
String out = Optional.of<caret>(in).get();
|
|
}
|
|
|
|
void exceptionIsTheSameWithOrElseThrow(String in) {
|
|
Integer out = Optional.of(in).map(s -> getLen(s)).orElseThrow(() -> new IllegalArgumentException("value is null"));
|
|
}
|
|
|
|
void redundantCheckIsRemoved() {
|
|
String in = "not null value";
|
|
String out = Optional.of(in).orElseThrow(() -> new IllegalArgumentException("value is null"));
|
|
}
|
|
|
|
private Integer getLen(String s) {
|
|
return s.startsWith("abc") ? null : s;
|
|
}
|
|
|
|
private Integer filterLen(String s) {
|
|
return s.length() > 42 ? s.length() : null;
|
|
}
|
|
} |