Files
openide/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/optionalToIf/afterMap.java
Artemiy Sartakov d98814d304 OptionalToIfInspection: added missing imports (IDEA-212269)
GitOrigin-RevId: afbeaa1f10b2266cd1401da83b71cf0bf6862824
2019-08-07 17:02:43 +03:00

41 lines
1.1 KiB
Java

// "Fix all 'Optional can be replaced with sequence of if statements' problems in file" "true"
import java.util.*;
class Test {
String checkForNullable(String in) {
if (in == null) throw new NullPointerException();
String strOrNull = getStrOrNull(in);
if (strOrNull == null) throw new NoSuchElementException("No value present");
return strOrNull;
}
String checkIsRemovedForNotNull(String in) {
if (in == null) throw new NullPointerException();
String s = id(in);
if (s.length() <= 2) throw new NoSuchElementException("No value present");
return s;
}
String twoMapsProduceTwoVariables(String in, boolean b) {
if (in == null) throw new NullPointerException();
String s = id(in);
String strIfTrue = getStrIfTrue(s, b);
if (strIfTrue == null || strIfTrue.length <= 2) throw new NoSuchElementException("No value present");
return strIfTrue;
}
private String id(String s) {
return s;
}
private String getStrOrNull(String s) {
return s.length() > 2 ? s : null;
}
private String getStrIfTrue(String s, boolean b) {
return b ? s : null;
}
}