<commit_before>package com.yo1000.daisychain;

import org.objectweb.asm.ClassReader;
import org.objectweb.asm.util.TraceClassVisitor;

import java.io.*;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;
import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by yoichi.kikuchi on 2016/01/12.
 */
public class ReferenceCounter {
    protected static final Pattern CLASS_NAME_PATTERN = Pattern.compile("[() ]L([a-zA-Z0-9_\\$/]+);");

    public static void main(String[] args) throws IOException {
        String directoryPath = args.length >= 1 ? "file:" + args[0] : null;
        String filterPackage = args.length >= 2 ? args[1] : "";

        new ReferenceCounter().count(Paths.get(URI.create(directoryPath))).entrySet().stream()
                .filter(entry -> entry.getKey().startsWith(filterPackage))
                .sorted((x, y) -> y.getValue() - x.getValue())
                .forEach(entry -> System.out.printf("%s %d\n", entry.getKey(), entry.getValue()));
    }

    public Map<String, Integer> count(Path directoryPath) throws IOException {
        Map<String, Integer> dependencies = new TreeMap<>();

        Files.list(directoryPath).forEach(path -> {
            File file = path.toFile();

            if (file.isFile() && file.getName().toLowerCase().endsWith(".class")) {
                try {
                    this.count(file).forEach((key, val) -> {
                        Integer count = dependencies.get(key);
                        dependencies.put(key, count != null ? count + val : val);
                    });<commit_msg>Change filter to use regex<commit_after>package com.yo1000.daisychain;

import org.objectweb.asm.ClassReader;
import org.objectweb.asm.util.TraceClassVisitor;

import java.io.*;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;
import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by yoichi.kikuchi on 2016/01/12.
 */
public class ReferenceCounter {
    protected static final Pattern CLASS_NAME_PATTERN = Pattern.compile("[() ]L([a-zA-Z0-9_\\$/]+);");

    public static void main(String[] args) throws IOException {
        String directoryPath = args.length >= 1 ? "file:" + args[0] : null;
        String filterPackage = args.length >= 2 ? args[1] : "";

        new ReferenceCounter().count(Paths.get(URI.create(directoryPath))).entrySet().stream()
                .filter(entry -> entry.getKey().matches(filterPackage))
                .sorted((x, y) -> y.getValue() - x.getValue())
                .forEach(entry -> System.out.printf("%s %d\n", entry.getKey(), entry.getValue()));
    }

    public Map<String, Integer> count(Path directoryPath) throws IOException {
        Map<String, Integer> dependencies = new TreeMap<>();

        Files.list(directoryPath).forEach(path -> {
            File file = path.toFile();

            if (file.isFile() && file.getName().toLowerCase().endsWith(".class")) {
                try {
                    this.count(file).forEach((key, val) -> {
                        Integer count = dependencies.get(key);
                        dependencies.put(key, count != null ? count + val : val);
                    });
{'fraction_non_alphanumeric': 0.15234143449911083, 'fraction_numerical': 0.01066982809721399, 'mean_word_length': 2.6329386437029063, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 23, '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': '253885', 'n_tokens_mistral': 1000, 'n_tokens_neox': 950, 'n_words': 208}