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

net.amygdalum.util.graph.Graph Maven / Gradle / Ivy

The newest version!
package net.amygdalum.util.graph;

import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;

public class Graph> {

	private Map> nodes;
	
	public Graph() {
		this.nodes = new LinkedHashMap>();
	}
	
	public GraphNode getNode(K key) {
		return nodes.get(key);
	}

	public GraphNode createNode(K key) {
		GraphNode node = nodes.get(key);
		if (node == null) {
			node = new GraphNode(key);
			nodes.put(key, node);
		}
		return node;
	}
	
	public Collection> getNodes() {
		return nodes.values();
	}

	public void connectNodes(K from, K to) {
		GraphNode toNode = nodes.get(to);
		GraphNode fromNode = nodes.get(from);
		fromNode.addSuccessor(toNode);
		toNode.addPredecessor(fromNode);
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy