Пример #1
0
    /**
     * Adds all elements of {@code graph} to the graph being built.
     *
     * @throws IllegalArgumentException under either of two conditions: (1) the {@code GraphConfig}
     *     objects held by the graph being built and by {@code graph} are not compatible (2) calling
     *     {@code Graph.addEdge(e, n1, n2)} on the graph being built throws IAE
     * @see Graph#addEdge(e, n1, n2)
     */
    public Builder<N, E> addGraph(UndirectedGraph<N, E> graph) {
      checkArgument(
          undirectedGraph.config().compatibleWith(graph.config()),
          "GraphConfigs for input and for graph being built are not compatible: input: %s, "
              + "this graph: %s",
          graph.config(),
          undirectedGraph.config());

      for (N node : graph.nodes()) {
        undirectedGraph.addNode(node);
      }
      for (E edge : graph.edges()) {
        Graphs.addEdge(undirectedGraph, edge, graph.incidentNodes(edge));
      }

      return this;
    }
Пример #2
0
 /** Creates a new builder with the default graph configuration. */
 public Builder() {
   this(Graphs.<N, E>createUndirected());
 }
Пример #3
0
 /** Creates a new builder with the specified configuration. */
 public Builder(GraphConfig config) {
   this(Graphs.<N, E>createUndirected(config));
 }
Пример #4
0
 @Override
 public boolean equals(@Nullable Object object) {
   return (object instanceof UndirectedGraph) && Graphs.equal(this, (UndirectedGraph) object);
 }