code: public static <V> void swapVertices(DirectedGraph<V, DefaultEdge> graph, Map<V, Set<V>> alternates) {
          Objects.requireNonNull(graph,"graph");
          Objects.requireNonNull(alternates, "alternates");
          // add all of the new vertices to prep for linking
          addAllVertices(graph, alternates.keySet());
  
          for (Entry<V, Set<V>> entry : alternates.entrySet()) {
              V alternateVertex = entry.getKey();
              Set<V> dependencies = entry.getValue();
              // make sure we can satisfy all dependencies before continuing
              // TODO: this should probably done outside so it can be handled better.
              if (!graph.vertexSet().containsAll(dependencies)) {
                  continue;
              }
  
              // figure out which vertices depend on the incumbent vertex
              Set<V> dependents = Collections.emptySet();
              if (graph.containsVertex(alternateVertex)) {
                  dependents = getIncomingVertices(graph, alternateVertex);
                  graph.removeVertex(alternateVertex);
              }
              // (re)insert the vertex and re-link the dependents
              graph.addVertex(alternateVertex);
              addIncomingEdges(graph, alternateVertex, dependents);
  
              // create the dependencies
              addOutgoingEdges(graph, alternateVertex, dependencies);
          }
      }
docs: replace the vertices in the graph with an alternate set of vertices.
  @param graph graph to be mutated
  @param alternates alternate vertices to insert into the graph. map of vertices to their direct dependents.