Graph<Node> (Map<Node, Set<Node>> resultGraph) { return new Graph<Node>() { @Override public @NotNull Collection<Node> getNodes() { return resultGraph.keySet(); } @Override public @NotNull Iterator<Node> getIn(Node node) { return Collections.emptyIterator(); } @Override public @NotNull Iterator<Node> getOut(Node node) { Set<Node> nodes = resultGraph.get(node); return nodes != null ? nodes.iterator() : Collections.emptyIterator(); } }; }