@Override
  public <N> @NotNull MutableNetwork<N, EndpointPair<N>> toNetwork(@NotNull Graph<N> graph) {
    MutableNetwork<N, EndpointPair<N>> network = new NetworkBuilderImpl<N, EndpointPair<N>>(true)
      .allowsParallelEdges(true)
      .allowsSelfLoops(true)
      .nodeOrder(ElementOrder.unordered())
      .edgeOrder(ElementOrder.unordered())
      .build();

    for (N node : graph.getNodes()) {
      network.addNode(node);
      graph.getIn(node).forEachRemaining(prev -> {
        network.addEdge(prev, node, EndpointPair.ordered(prev, node));
      });
      graph.getOut(node).forEachRemaining(next -> {
        network.addEdge(node, next, EndpointPair.ordered(node, next));
      });
    }

    return network;
  }
@Override
  public <N> @NotNull MutableNetwork<N, EndpointPair<N>> toNetwork(@NotNull Graph<N> graph)