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

com.almondtools.util.graph.Graph Maven / Gradle / Ivy

Go to download

Regular expression matchers, searcher, lexers based on deterministic finite automata

There is a newer version: 0.3.3
Show newest version
package com.almondtools.util.graph;

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

public class Graph {

	private GraphNode root;
	private Map> nodes;
	
	public Graph() {
		this.nodes = new LinkedHashMap>();
	}
	
	public GraphNode getRoot() {
		return root;
	}

	public GraphNode createRoot(K key) {
		root = createNode(key);
		return root;
	}
	
	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