Skip to content

Commit

Permalink
replace procedural optional logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Henry Coles committed Apr 19, 2021
1 parent 2ea07f4 commit 2354cd3
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ public List<String> getList(FeatureParameter key) {

public Optional<Integer> getInteger(FeatureParameter key) {
final Optional<String> val = getString(key);
if (val.isPresent()) {
return Optional.ofNullable(Integer.parseInt(val.get()));
}
return Optional.empty();
return val.map(Integer::parseInt);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ public ObjectOutputStreamHistoryStore(final WriterFactory output,
}

private BufferedReader createReader(Optional<Reader> input) {
if (input.isPresent()) {
return new BufferedReader(input.get());
}
return null;
return input.map(BufferedReader::new)
.orElse(null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ public CSVReportListener(final Writer out) {
}

private String createKillingTestDesc(final Optional<String> killingTest) {
if (killingTest.isPresent()) {
return killingTest.get();
} else {
return "none";
}
return killingTest.orElse("none");
}

private String makeCsv(final Object... os) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,8 @@ private String makeNode(final String value, final Tag tag) {
}

private String createKillingTestDesc(final Optional<String> killingTest) {
if (killingTest.isPresent()) {
return createTestDesc(Arrays.asList(killingTest.get()));
} else {
return null;
}
return killingTest.map(s -> createTestDesc(Arrays.asList(s)))
.orElse(null);
}

private String createTestDesc(final List<String> tests) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,8 @@ private boolean shouldTreatAsOneUnit(final Class<?> clazz, final Runner runner)

private boolean hasClassRuleAnnotations(final Class<?> clazz,
final Set<Method> methods) {
if (!CLASS_RULE.isPresent()) {
return false;
}

return hasAnnotation(methods, CLASS_RULE.get())
|| hasAnnotation(Reflection.publicFields(clazz), CLASS_RULE.get());
return CLASS_RULE.filter(aClass -> hasAnnotation(methods, aClass)
|| hasAnnotation(Reflection.publicFields(clazz), aClass)).isPresent();
}

private boolean hasAnnotation(final Set<? extends AccessibleObject> methods,
Expand Down

0 comments on commit 2354cd3

Please sign in to comment.