package fr.lteconsulting.pomexplorer.commands;

import java.util.Set;

import org.jgrapht.alg.ConnectivityInspector;
import org.jgrapht.alg.CycleDetector;
import org.jgrapht.alg.StrongConnectivityInspector;

import fr.lteconsulting.pomexplorer.Log;
import fr.lteconsulting.pomexplorer.Session;
import fr.lteconsulting.pomexplorer.graph.PomGraph.PomGraphReadTransaction;
import fr.lteconsulting.pomexplorer.graph.relation.Relation;
import fr.lteconsulting.pomexplorer.model.Gav;

public class StatsCommand
{
	@Help( "general statistics on the session" )
	public void main( Session session, Log log )
	{
		PomGraphReadTransaction tx = session.graph().read();

		log.html( "There are " + tx.gavs().size() + " gavs<br/>" );

		StrongConnectivityInspector<Gav, Relation> conn = new StrongConnectivityInspector<>( tx.internalGraph() );
		log.html( "There are " + conn.stronglyConnectedSets().size() + " strongly connected components<br/>" );

		ConnectivityInspector<Gav, Relation> ccon = new ConnectivityInspector<>( tx.internalGraph() );
		log.html( "There are " + ccon.connectedSets().size() + " weakly connected components<br/>" );

		CycleDetector<Gav, Relation> cycles = new CycleDetector<Gav, Relation>( tx.internalGraph() );
		log.html( "Is there cycles ? " + cycles.detectCycles() + "<br/>" );
	}

	@Help( "gives the details of the connected components of the pom graph" )
	public void components( Session session, Log log )
	{
		PomGraphReadTransaction tx = session.graph().read();

		ConnectivityInspector<Gav, Relation> ccon = new ConnectivityInspector<>( tx.internalGraph() );
		log.html( "There are " + ccon.connectedSets().size() + " weakly connected components<br/>" );

		for( Set<Gav> gavs : ccon.connectedSets() )
		{
			log.html( "<br/>Set of connected GAVs :<br/>" );
			for( Gav gav : gavs )
			{
				log.html( "- " + gav + "<br/>" );
			}
		}
	}

	@Help( "gives the details of the strongly connected components of the pom graph" )
	public void strongComponents( Session session, Log log )
	{
		PomGraphReadTransaction tx = session.graph().read();

		StrongConnectivityInspector<Gav, Relation> ccon = new StrongConnectivityInspector<>( tx.internalGraph() );
		log.html( "There are " + ccon.stronglyConnectedSets().size() + " weakly connected components<br/>" );

		for( Set<Gav> gavs : ccon.stronglyConnectedSets() )
		{
			log.html( "<br/>Set of connected GAVs :<br/>" );
			for( Gav gav : gavs )
			{
				log.html( "- " + gav + "<br/>" );
			}
		}
	}
}

@@ -1859,613 +1859,7 @@
 %7D%0A%09%7D
-%0A%0A%09@Help( %22gives the details of the strongly connected components of the pom graph%22 )%0A%09public void strongComponents( Session session, Log log )%0A%09%7B%0A%09%09PomGraphReadTransaction tx = session.graph().read();%0A%0A%09%09StrongConnectivityInspector%3CGav, Relation%3E ccon = new StrongConnectivityInspector%3C%3E( tx.internalGraph() );%0A%09%09log.html( %22There are %22 + ccon.stronglyConnectedSets().size() + %22 weakly connected components%3Cbr/%3E%22 );%0A%0A%09%09for( Set%3CGav%3E gavs : ccon.stronglyConnectedSets() )%0A%09%09%7B%0A%09%09%09log.html( %22%3Cbr/%3ESet of connected GAVs :%3Cbr/%3E%22 );%0A%09%09%09for( Gav gav : gavs )%0A%09%09%09%7B%0A%09%09%09%09log.html( %22- %22 + gav + %22%3Cbr/%3E%22 );%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D
 %0A%7D%0A

remove strongly connected composnenty feature, useless