List of usage examples for com.google.common.graph ImmutableGraph copyOf
@Deprecated public static <N> ImmutableGraph<N> copyOf(ImmutableGraph<N> graph)
From source file:com.google.errorprone.dataflow.nullnesspropagation.inference.InferredNullability.java
InferredNullability(Graph<InferenceVariable> constraints) {
this.constraintGraph = ImmutableGraph.copyOf(constraints);
}
From source file:org.jgrapht.graph.guava.ImmutableGraphAdapter.java
/** * Returns a shallow copy of this graph instance. Neither edges nor vertices are cloned. * * @return a shallow copy of this graph. * * @throws RuntimeException in case the clone is not supported * * @see java.lang.Object#clone()//from ww w .ja v a 2s. c om */ @Override public Object clone() { try { ImmutableGraphAdapter<V> newGraph = TypeUtil.uncheckedCast(super.clone()); newGraph.unmodifiableVertexSet = null; newGraph.unmodifiableEdgeSet = null; newGraph.graph = ImmutableGraph.copyOf(Graphs.copyOf(this.graph)); return newGraph; } catch (CloneNotSupportedException e) { e.printStackTrace(); throw new RuntimeException(); } }
From source file:org.jgrapht.graph.guava.ImmutableGraphAdapter.java
@SuppressWarnings("unchecked") private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException { ois.defaultReadObject();//from ww w .jav a 2 s . c om 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); }