mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-09 16:39:37 +07:00
24 lines
757 B
Java
24 lines
757 B
Java
// "Fix all ''Optional' can be replaced with sequence of 'if' statements' problems in file" "true"
|
|
|
|
import java.util.*;
|
|
|
|
class Test {
|
|
|
|
String orElseThrowDefault(String in) {
|
|
return Optional.ofNullable<caret>(in).filter(s -> s.length() > 12).orElseThrow();
|
|
}
|
|
|
|
String orElseLambda(String in) {
|
|
return Optional.ofNullable(in).filter(s -> s.length() > 12).orElseThrow(() -> new IllegalArgumentException("value is null"));
|
|
}
|
|
|
|
String orElseThrowWithSideEffect(String in) {
|
|
return Optional.ofNullable(in).map(s -> s.substring(3)).filter(s -> s.length() > 12).orElseThrow(() -> sideEffect());
|
|
}
|
|
|
|
private RuntimeException sideEffect() {
|
|
System.out.println("side effect!");
|
|
return new IllegalArgumentException("value is null")
|
|
}
|
|
|
|
} |