package org.psjava.ds.graph;

import org.psjava.ds.Collection;
import org.psjava.ds.array.DynamicArray;
import org.psjava.ds.set.MutableSet;
import org.psjava.goods.GoodMutableSetFactory;

public class MutableGraph<V, E> implements Graph<V, E> {

	public static <V, E> MutableGraph<V, E> create() {
		return new MutableGraph<V, E>();
	}

	private MutableSet<V> vertices = GoodMutableSetFactory.getInstance().create();
	private DynamicArray<E> edges = DynamicArray.create();

	public void insertVertex(V v) {
		vertices.insert(v);
	}

	public void addEdge(E edge) {
		edges.addToLast(edge);
	}

	@Override
	public Collection<V> getVertices() {
		return vertices;
	}

	@Override
	public Iterable<E> getEdges() {
		return edges;
	}

	@Override
	public String toString() { // TODO extract to util class
		String r = "";
		for (E e : getEdges()) {
			if (r.length() != 0)
				r += ", ";
			r += e.toString();
		}
		return "Graph: " + r;
	}

}

@@ -29,42 +29,8 @@
 %0D%0A%0D%0A
-import org.psjava.ds.Collection;%0D%0A
 impo
@@ -105,16 +105,47 @@
 leSet;%0D%0A
+import org.psjava.ds.set.Set;%0D%0A
 import o
@@ -632,18 +632,11 @@
 lic 
-Collection
+Set
 %3CV%3E 
@@ -790,177 +790,47 @@
 () %7B
- // TODO extract to util class%0D%0A%09%09String r = %22%22;%0D%0A%09%09for (E e : getEdges()) %7B%0D%0A%09%09%09if (r.length() != 0)%0D%0A%09%09%09%09r += %22, %22;%0D%0A%09%09%09r += e.toString();%0D%0A%09%09%7D%0D%0A%09%09return %22Graph: %22 + r
+%0D%0A%09%09return GraphToString.toString(this)
 ;%0D%0A%09

extend interface to reuse. change to use common code.