make use of Optional's orElseThrow
@@ -19,7 +19,6 @@ import java.lang.reflect.Method;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
-import java.util.Optional;
import java.util.Set;
@@ -200,12 +199,9 @@ public class DotSaver implements NetworkSaver {
try {
Vertex parentVertex = (Vertex) method.invoke(vertex);
GraphEdge parentEdge = new GraphEdge(vertex, parentVertex);
- Optional<GraphEdge> foundEdge = edges.stream().filter(parentEdge::equals).findFirst();
- if (foundEdge.isPresent()) {
- foundEdge.get().appendToLabel(parentName);
- } else {
- throw new IllegalStateException("Did not find parent edge " + parentName);
- }
+ GraphEdge foundEdge = edges.stream().filter(parentEdge::equals).findFirst()
+ .orElseThrow(() -> new IllegalStateException("Did not find parent edge " + parentName));
+ foundEdge.appendToLabel(parentName);
} catch (Exception e) {
throw new IllegalArgumentException("Invalid parent retrieval function specified", e);
}
