All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.psjava.ds.graph.MutableUndirectedGraph Maven / Gradle / Ivy

There is a newer version: 0.1.19
Show newest version
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