use of org.jgrapht.event.ConnectedComponentTraversalEvent in project alliance by codice.
the class ResultDAGConverter method getAttributeMap.
public static Map<String, String> getAttributeMap(DAG dag) {
Map<String, String> attributes = new HashMap<>();
Map<Integer, Node> nodeMap = createNodeMap(dag.nodes);
DirectedAcyclicGraph<Node, Edge> graph = getNodeEdgeDirectedAcyclicGraph(dag, nodeMap);
DepthFirstIterator<Node, Edge> graphIT = new DepthFirstIterator<>(graph, nodeMap.get(0));
List<String> nodeStack = new ArrayList<>();
graphIT.addTraversalListener(new TraversalListener<Node, Edge>() {
@Override
public void connectedComponentFinished(ConnectedComponentTraversalEvent connectedComponentTraversalEvent) {
// This method is not expected to be called
}
@Override
public void connectedComponentStarted(ConnectedComponentTraversalEvent connectedComponentTraversalEvent) {
// This method is not expected to be called
}
@Override
public void edgeTraversed(EdgeTraversalEvent<Node, Edge> edgeTraversalEvent) {
// This method is not expected to be called
}
@Override
public void vertexTraversed(VertexTraversalEvent<Node> vertexTraversalEvent) {
Node node = vertexTraversalEvent.getVertex();
if (node.node_type != NodeType.ATTRIBUTE_NODE) {
nodeStack.add(node.attribute_name);
}
}
@Override
public void vertexFinished(VertexTraversalEvent<Node> vertexTraversalEvent) {
Node node = vertexTraversalEvent.getVertex();
if (node.node_type == NodeType.ATTRIBUTE_NODE) {
StringBuilder attribute = new StringBuilder();
int currEntry = 0;
int size = nodeStack.size();
for (String nodeEntry : nodeStack) {
attribute.append(nodeEntry);
if (currEntry < (size - 1)) {
attribute.append(":");
} else {
attribute.append(".");
}
currEntry++;
}
attribute.append(node.attribute_name);
attributes.put(attribute.toString(), CorbaUtils.getNodeValue(node.value));
} else {
int lastIdx = nodeStack.size() - 1;
nodeStack.remove(lastIdx);
}
}
});
Node rootNode = null;
while (graphIT.hasNext()) {
graphIT.setCrossComponentTraversal(false);
Node node = graphIT.next();
if (rootNode == null) {
rootNode = node;
}
}
return attributes;
}
Aggregations