List of usage examples for com.google.common.graph GraphBuilder undirected
public static GraphBuilder<Object> undirected()
From source file:org.jgrapht.graph.guava.ImmutableGraphAdapter.java
@SuppressWarnings("unchecked") private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException { ois.defaultReadObject();// w ww.ja v a 2 s . c o m GraphType type = (GraphType) ois.readObject(); if (type.isMixed() || type.isAllowingMultipleEdges()) { throw new IOException("Graph type not supported"); } MutableGraph<V> mutableGraph = (type.isDirected() ? GraphBuilder.directed() : GraphBuilder.undirected()) .allowsSelfLoops(type.isAllowingSelfLoops()).build(); // read vertices int n = ois.readInt(); for (int i = 0; i < n; i++) { V v = (V) ois.readObject(); mutableGraph.addNode(v); } // read edges int m = ois.readInt(); for (int i = 0; i < m; i++) { V s = (V) ois.readObject(); V t = (V) ois.readObject(); mutableGraph.putEdge(s, t); } // setup the immutable copy this.graph = ImmutableGraph.copyOf(mutableGraph); }
From source file:org.jgrapht.graph.guava.MutableGraphAdapter.java
@SuppressWarnings("unchecked") private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException { ois.defaultReadObject();// w ww .j av a 2 s . c o m GraphType type = (GraphType) ois.readObject(); if (type.isMixed() || type.isAllowingMultipleEdges()) { throw new IOException("Graph type not supported"); } graph = (type.isDirected() ? GraphBuilder.directed() : GraphBuilder.undirected()) .allowsSelfLoops(type.isAllowingSelfLoops()).build(); // read vertices int n = ois.readInt(); for (int i = 0; i < n; i++) { V v = (V) ois.readObject(); graph.addNode(v); } // read edges int m = ois.readInt(); for (int i = 0; i < m; i++) { V s = (V) ois.readObject(); V t = (V) ois.readObject(); graph.putEdge(s, t); } }