<commit_before>package org.ucombinator.jaam.visualizer.layout;

import java.util.*;
import java.util.function.Function;

import javafx.scene.paint.Color;
import org.ucombinator.jaam.visualizer.graph.GraphUtils;
import org.ucombinator.jaam.visualizer.graph.Graph;
import org.ucombinator.jaam.visualizer.state.*;
import org.ucombinator.jaam.visualizer.taint.*;

public class LayerFactory
{
    // TODO: Template these functions instead of copying them.
    public static StateRootVertex getLayeredLoopGraph(Graph<StateVertex, StateEdge> graph) {
        return LayerFactory.getStronglyConnectedComponentsLoopGraph(graph);
    }

    private static StateRootVertex getStronglyConnectedComponentsLoopGraph(Graph<StateVertex, StateEdge> graph)
    {
        List<List<Integer>> sccs = GraphUtils.StronglyConnectedComponents(graph);
        HashMap<Integer, Integer> vertexToComponentIndex = getVertexToComponentMap(sccs);
        System.out.println("Strongly connected components in loop graph: " + sccs.size());

        StateRootVertex graphRoot = new StateRootVertex();
        graphRoot.setInnerGraph(graph);

        return (StateRootVertex) GraphUtils.compressGraph(graphRoot,
                v -> Integer.toString(vertexToComponentIndex.get(v.getId())),
                new Function<List<StateVertex>, StateVertex>() {
                    @Override
                    public StateVertex apply(List<StateVertex> stateVertices) {
                        StateSccVertex sccVertex = new StateSccVertex("SCC");
                        stateVertices.forEach(v -> {
                            sccVertex.getInnerGraph().addVertex(v);
                            v.setOuterGraph(sccVertex.getInnerGraph());
                        });
                        return sccVertex;
                    }
                },
                StateEdge::new);
    }

    public static TaintRootVertex getLayeredTaintGraph(Graph<TaintVertex, TaintEdge> graph) {
        System.out.println("JUAN: Found " + graph.getVertices().size() + " vertices");
        return getSuperTaintGraph(graph);
    }

    private static TaintRootVertex getStronglyConnectedComponentsTaintGraph(Graph<TaintVertex, TaintEdge> graph)
    {
        List<List<Integer>> sccs = GraphUtils.StronglyConnectedComponents(graph);
        HashMap<Integer, Integer> vertexToComponentIndex = getVertexToComponentMap(sccs);
        System.out.println("Strongly connected components in taint graph: " + sccs.size());

        TaintRootVertex graphRoot = new TaintRootVertex();
        graphRoot.setInnerGraph(graph);

        return (TaintRootVertex) GraphUtils.compressGraph(graphRoot,
                v -> Integer.toString(vertexToComponentIndex.get(v.getId())),
                new Function<List<TaintVertex>, TaintVertex>() {
                    @Override
                    public TaintVertex apply(List<TaintVertex> stateVertices) {
                        TaintSccVertex sccVertex = new TaintSccVertex("SCC");
                        stateVertices.forEach(v -> {
                            sccVertex.getInnerGraph().addVertex(v);
                            v.setOuterGraph(sccVertex.getInnerGraph());
                        });
                        return sccVertex;
                    }
                },
                TaintEdge::new);
    }

    private static HashMap<Integer, Integer> getVertexToComponentMap(List<List<Integer>> components) {
        HashMap<Integer, Integer> vertexToComponentIndex = new HashMap<>();
        for (int componentIndex = 0; componentIndex < components.size(); componentIndex++) {
            for (int vertexId : components.get(componentIndex)) {
                vertexToComponentIndex.put(vertexId, componentIndex);
            }
        }
        return vertexToComponentIndex;
    }

    private static TaintRootVertex getSuperTaintGraph(Graph<TaintVertex, TaintEdge> graph) {

        System.out.println("JUAN: Start there are " + calcSize(graph));
        TaintRootVertex classGraphRoot = getClassGroupingGraph(graph);

        System.out.println("JUAN After " + calcSize(classGraphRoot.getInnerGraph()));

        classGraphRoot.getInnerGraph().getVertices().forEach(classVertex -> {
            if (classVertex.getInnerGraph().getVertices().size() > 1) {
                TaintRootVertex methodRootVertex = getMethodGroupingGraph(classVertex.getInnerGraph());
                Graph<TaintVertex, TaintEdge> groupedMethodGraph = methodRootVertex.getInnerGraph();
                classVertex.setInnerGraph(groupedMethodGraph);
            }
        });
        return classGraphRoot;
    }

    private static int calcSize(Graph<TaintVertex, TaintEdge> graph) {
        int total = 0;

        for(TaintVertex v : graph.getVertices())
        {
            if (v.getInnerGraph().getVertices().size() > 1) total += calcSize(v.getInnerGraph());
            else total++;
        }

        return total;
    }

    public static long longHash(String string) {
        long h = 98764321261L;<commit_msg>Set SCC Taint graph as default<commit_after>package org.ucombinator.jaam.visualizer.layout;

import java.util.*;
import java.util.function.Function;

import javafx.scene.paint.Color;
import org.ucombinator.jaam.visualizer.graph.GraphUtils;
import org.ucombinator.jaam.visualizer.graph.Graph;
import org.ucombinator.jaam.visualizer.state.*;
import org.ucombinator.jaam.visualizer.taint.*;

public class LayerFactory
{
    // TODO: Template these functions instead of copying them.
    public static StateRootVertex getLayeredLoopGraph(Graph<StateVertex, StateEdge> graph) {
        return LayerFactory.getStronglyConnectedComponentsLoopGraph(graph);
    }

    private static StateRootVertex getStronglyConnectedComponentsLoopGraph(Graph<StateVertex, StateEdge> graph)
    {
        List<List<Integer>> sccs = GraphUtils.StronglyConnectedComponents(graph);
        HashMap<Integer, Integer> vertexToComponentIndex = getVertexToComponentMap(sccs);
        System.out.println("Strongly connected components in loop graph: " + sccs.size());

        StateRootVertex graphRoot = new StateRootVertex();
        graphRoot.setInnerGraph(graph);

        return (StateRootVertex) GraphUtils.compressGraph(graphRoot,
                v -> Integer.toString(vertexToComponentIndex.get(v.getId())),
                new Function<List<StateVertex>, StateVertex>() {
                    @Override
                    public StateVertex apply(List<StateVertex> stateVertices) {
                        StateSccVertex sccVertex = new StateSccVertex("SCC");
                        stateVertices.forEach(v -> {
                            sccVertex.getInnerGraph().addVertex(v);
                            v.setOuterGraph(sccVertex.getInnerGraph());
                        });
                        return sccVertex;
                    }
                },
                StateEdge::new);
    }

    public static TaintRootVertex getLayeredTaintGraph(Graph<TaintVertex, TaintEdge> graph) {
        return getStronglyConnectedComponentsTaintGraph(graph);
    }

    private static TaintRootVertex getStronglyConnectedComponentsTaintGraph(Graph<TaintVertex, TaintEdge> graph)
    {
        List<List<Integer>> sccs = GraphUtils.StronglyConnectedComponents(graph);
        HashMap<Integer, Integer> vertexToComponentIndex = getVertexToComponentMap(sccs);
        System.out.println("Strongly connected components in taint graph: " + sccs.size());

        TaintRootVertex graphRoot = new TaintRootVertex();
        graphRoot.setInnerGraph(graph);

        return (TaintRootVertex) GraphUtils.compressGraph(graphRoot,
                v -> Integer.toString(vertexToComponentIndex.get(v.getId())),
                new Function<List<TaintVertex>, TaintVertex>() {
                    @Override
                    public TaintVertex apply(List<TaintVertex> stateVertices) {
                        TaintSccVertex sccVertex = new TaintSccVertex("SCC");
                        stateVertices.forEach(v -> {
                            sccVertex.getInnerGraph().addVertex(v);
                            v.setOuterGraph(sccVertex.getInnerGraph());
                        });
                        return sccVertex;
                    }
                },
                TaintEdge::new);
    }

    private static HashMap<Integer, Integer> getVertexToComponentMap(List<List<Integer>> components) {
        HashMap<Integer, Integer> vertexToComponentIndex = new HashMap<>();
        for (int componentIndex = 0; componentIndex < components.size(); componentIndex++) {
            for (int vertexId : components.get(componentIndex)) {
                vertexToComponentIndex.put(vertexId, componentIndex);
            }
        }
        return vertexToComponentIndex;
    }

    private static TaintRootVertex getClassClusteredTaintGraph(Graph<TaintVertex, TaintEdge> graph) {

        TaintRootVertex classGraphRoot = getClassGroupingGraph(graph);

        classGraphRoot.getInnerGraph().getVertices().forEach(classVertex -> {
            if (classVertex.getInnerGraph().getVertices().size() > 1) {
                TaintRootVertex methodRootVertex = getMethodGroupingGraph(classVertex.getInnerGraph());
                Graph<TaintVertex, TaintEdge> groupedMethodGraph = methodRootVertex.getInnerGraph();
                classVertex.setInnerGraph(groupedMethodGraph);
            }
        });
        return classGraphRoot;
    }

    private static int calcSize(Graph<TaintVertex, TaintEdge> graph) {
        int total = 0;

        for(TaintVertex v : graph.getVertices())
        {
            if (v.getInnerGraph().getVertices().size() > 1) total += calcSize(v.getInnerGraph());
            else total++;
        }

        return total;
    }

    public static long longHash(String string) {
        long h = 98764321261L;
{'fraction_non_alphanumeric': 0.09478189971463515, 'fraction_numerical': 0.0030574806359559724, 'mean_word_length': 2.4971489665003563, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6347380', 'n_tokens_mistral': 2649, 'n_tokens_neox': 2510, 'n_words': 450}