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

com.github.mdr.ascii.java.GraphBuilder Maven / Gradle / Ivy

The newest version!
package com.github.mdr.ascii.java;

import static com.github.mdr.ascii.java.ScalaJavaHelper.*;
import com.github.mdr.ascii.graph.Graph;
import java.util.*;
import scala.Tuple2;

/**
 * Utility to build a Graph easily from Java.
 */
public class GraphBuilder {

	private final Set vertices = new HashSet();

	private final List> edges = new ArrayList>();

	public GraphBuilder addVertex(V v) {
		vertices.add(v);
		return this;
	}

	public GraphBuilder addEdge(V v1, V v2) {
		addVertex(v1).addVertex(v2);
		edges.add(tuple(v1, v2));
		return this;
	}

	public Graph build() {
		return new Graph(asScalaSet(vertices), asScalaList(edges));
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy