com.almondtools.util.graph.Graph Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rexlex Show documentation
Show all versions of rexlex Show documentation
Regular expression matchers, searcher, lexers based on deterministic finite automata
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