public boolean containsCycle() throws WikiApiException  {
        DefaultEdge edge = findCycle();
        if (edge != null) {
            Category sourceCat = wiki.getCategory(categoryGraph.getGraph().getEdgeSource(edge));
            Category targetCat = wiki.getCategory(categoryGraph.getGraph().getEdgeTarget(edge));

            logger.info("Cycle: " + sourceCat.getTitle() + " - " + targetCat.getTitle());
            return true;
        }
        else {
            return false;
        }
    }
public boolean containsCycle ( ) throws WikiApiException { DefaultEdge edge = findCycle ( ) ; if ( edge != null ) { Category sourceCat = wiki . getCategory ( categoryGraph . getGraph ( ) . getEdgeSource ( edge ) ) ; Category targetCat = wiki . getCategory ( categoryGraph . getGraph ( ) . getEdgeTarget ( edge ) ) ; logger . info ( "Cycle: " + sourceCat . getTitle ( ) + " - " + targetCat . getTitle ( ) ) ; return true ; } else { return false ; } }
The JGraphT cycle detection seems not to find all cycles. Thus, I wrote my own cycle detection.
It is a colored DFS and should find all (viscious :) cycles.
@return True, if the graph contains a cycle.
@throws WikiApiException Thrown if errors occurred.