
org.psjava.ds.graph.MutableUndirectedGraph Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of psjava Show documentation
Show all versions of psjava Show documentation
Problem Solving Library for Java
package org.psjava.ds.graph;
import org.psjava.ds.Collection;
import org.psjava.util.AssertStatus;
public class MutableUndirectedGraph implements Graph> {
public static MutableUndirectedGraph create() {
return new MutableUndirectedGraph();
}
private final MutableGraph> g = MutableGraph.create();
public void insertVertex(V v) {
g.insertVertex(v);
}
public void addEdge(V v1, V v2) {
assertVertexExist(v1);
assertVertexExist(v2);
g.addEdge(SimpleUndirectedEdge.create(v1, v2));
}
@Override
public Collection getVertices() {
return g.getVertices();
}
private void assertVertexExist(V v) {
AssertStatus.assertTrue(g.getVertices().contains(v), "vertex is not in graph");
}
@Override
public Iterable> getEdges() {
return g.getEdges();
}
@Override
public String toString() {
return GraphToString.toString(this);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy