*/
public Set<String> listCycles() {
/*
* convert nodeRefs datastructure to a directed graph
*/
DirectedGraph dg = new DefaultDirectedGraph();
DirectedEdgeFactory def = new EdgeFactories.DirectedEdgeFactory();
/*
* add the course structure as directed graph, where
*/
Visitor v = new Convert2DGVisitor(dg);
(new TreeVisitor(v, cetm.getRootNode(), true)).visitAll();
/*
* iterate over nodeRefs, add each not existing node id as vertex, for each
* key - child relation add an edge to the directed graph.
*/
Iterator<String> keys = nodeRefs.keySet().iterator();
while(keys.hasNext()) {
//a node
String key = keys.next();
if(!dg.containsVertex(key)) {
dg.addVertex(key);
}
//and its children
Set<String> children = nodeRefs.get(key);
Iterator<String> childrenIt = children.iterator();
while(childrenIt.hasNext()){
String child = childrenIt.next();
if(!dg.containsVertex(child)) {
dg.addVertex(child);
}
//add edge, precondition: vertex key - child are already added to the graph
Edge de = def.createEdge(key, child);
dg.addEdge(de);
}
}
/*
* find the id's participating in the cycle, and return the intersection
* with set of id's which actually produce references.