<commit_before>package org.jasome.input;

import org.jasome.metrics.Calculator;
import org.jasome.metrics.Metric;

import java.util.HashSet;
import java.util.Set;


//TODO: try to figure out a way to move this to org.jasome.metrics - it needs to access a package-level method on Code which prevents this
public class Processor {
    private Set<Calculator<Project>> projectCalculators;
    private Set<Calculator<Package>> packageCalculators;
    private Set<Calculator<Type>> typeCalculators;
    private Set<Calculator<Method>> methodCalculators;

    public Processor() {
        projectCalculators = new HashSet<>();
        packageCalculators = new HashSet<>();
        typeCalculators = new HashSet<>();
        methodCalculators = new HashSet<>();
    }

    public void registerProjectCalculator(Calculator<Project> calculator) {
        projectCalculators.add(calculator);
    }

    public void registerPackageCalculator(Calculator<Package> calculator) {
        packageCalculators.add(calculator);
    }

    public void registerTypeCalculator(Calculator<Type> calculator) {
        typeCalculators.add(calculator);
    }

    public void registerMethodCalculator(Calculator<Method> calculator) {
        methodCalculators.add(calculator);
    }

    public void process(Project project) {

        for (Package aPackage : project.getPackages()) {

            for (Type type : aPackage.getTypes()) {

                for (Method method : type.getMethods()) {

                    for (Calculator<Method> methodMetricCalculator : methodCalculators) {
                        Set<Metric> methodMetrics = methodMetricCalculator.calculate(method);
                        method.addMetrics(methodMetrics);
                    }
                }

                for (Calculator<Type> typeMetricCalculator : typeCalculators) {
                    Set<Metric> classMetrics = typeMetricCalculator.calculate(type);
                    type.addMetrics(classMetrics);
                }
            }

            for (Calculator<Package> packageMetricCalculator : packageCalculators) {
                Set<Metric> packageMetrics = packageMetricCalculator.calculate(aPackage);
                aPackage.addMetrics(packageMetrics);
            }
        }

        for (Calculator<Project> projectMetricCalculator : projectCalculators) {
            Set<Metric> projectMetrics = projectMetricCalculator.calculate(project);
            project.addMetrics(projectMetrics);
        }


        for (Package aPackage : project.getPackages()) {
            System.out.println(aPackage.getName());
            System.out.println("+" + aPackage.getMetrics());

            for (Type type : aPackage.getTypes()) {

                System.out.println("  " + type.getName());
                System.out.println("  +" + type.getMetrics());

                for (Method method : type.getMethods()) {

                    System.out.println("    " + method.getName());
                    System.out.println("    +" + aPackage.getMetrics());

                }
            }

        }
    }
}<commit_msg>parallelized execution of calculators<commit_after>package org.jasome.input;

import org.jasome.metrics.Calculator;
import org.jasome.metrics.Metric;

import java.util.HashSet;
import java.util.Set;


//TODO: try to figure out a way to move this to org.jasome.metrics - it needs to access a package-level method on Code which prevents this
public class Processor {
    private Set<Calculator<Project>> projectCalculators;
    private Set<Calculator<Package>> packageCalculators;
    private Set<Calculator<Type>> typeCalculators;
    private Set<Calculator<Method>> methodCalculators;

    public Processor() {
        projectCalculators = new HashSet<>();
        packageCalculators = new HashSet<>();
        typeCalculators = new HashSet<>();
        methodCalculators = new HashSet<>();
    }

    public void registerProjectCalculator(Calculator<Project> calculator) {
        projectCalculators.add(calculator);
    }

    public void registerPackageCalculator(Calculator<Package> calculator) {
        packageCalculators.add(calculator);
    }

    public void registerTypeCalculator(Calculator<Type> calculator) {
        typeCalculators.add(calculator);
    }

    public void registerMethodCalculator(Calculator<Method> calculator) {
        methodCalculators.add(calculator);
    }

    public void process(Project project) {

        project.getPackages().parallelStream().forEach(aPackage -> {

            aPackage.getTypes().parallelStream().forEach(type -> {

                type.getMethods().parallelStream().forEach(method -> {

                    methodCalculators.parallelStream().forEach(methodMetricCalculator -> {
                        Set<Metric> methodMetrics = methodMetricCalculator.calculate(method);
                        method.addMetrics(methodMetrics);
                    });
                });

                typeCalculators.parallelStream().forEach(typeMetricCalculator -> {
                    Set<Metric> classMetrics = typeMetricCalculator.calculate(type);
                    type.addMetrics(classMetrics);
                });
            });

            packageCalculators.parallelStream().forEach(packageMetricCalculator -> {
                Set<Metric> packageMetrics = packageMetricCalculator.calculate(aPackage);
                aPackage.addMetrics(packageMetrics);
            });

        });

        projectCalculators.parallelStream().forEach(projectMetricCalculator -> {
            Set<Metric> projectMetrics = projectMetricCalculator.calculate(project);
            project.addMetrics(projectMetrics);
        });


//        for (Package aPackage : project.getPackages()) {
//            System.out.println(aPackage.getName());
//            System.out.println("+" + aPackage.getMetrics());
//
//            for (Type type : aPackage.getTypes()) {
//
//                System.out.println("  " + type.getName());
//                System.out.println("  +" + type.getMetrics());
//
//                for (Method method : type.getMethods()) {
//
//                    System.out.println("    " + method.getName());
//                    System.out.println("    +" + aPackage.getMetrics());
//
//                }
//            }
//
//        }
    }
}
{'fraction_non_alphanumeric': 0.10851975249881009, 'fraction_numerical': 0.0, 'mean_word_length': 2.3301637612255677, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 54, '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': '6123217', 'n_tokens_mistral': 1693, 'n_tokens_neox': 1551, 'n_words': 290}