<commit_before>package com.nbsp.materialfilepicker.utils;

import android.support.annotation.Nullable;

import java.io.File;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.regex.Pattern;

/**
 * Created by Dimorinny on 24.10.15.
 */
public class FileUtils {
    public static List<File> getFileListByDirPath(String path,
                                                  @Nullable Pattern fileFilter,
                                                  boolean directoriesFilter,
                                                  boolean showHidden) {
        File directory = new File(path);
        List<File> resultFiles = new ArrayList<>();

        File[] files = directory.listFiles();
        if (files != null && files.length > 0) {
            for (File f : files) {
                if (f.isHidden()) {
                    if (showHidden) {
                        resultFiles.add(f);
                    }
                    continue;
                }

                if (f.isDirectory() && !directoriesFilter) {
                    resultFiles.add(f);
                    continue;
                }

                if (fileFilter != null && fileFilter.matcher(f.getName()).matches()) {
                    resultFiles.add(f);
                }
            }

            Collections.sort(resultFiles, new FileComparator());
        }

        return resultFiles;
    }

    public static String cutLastSegmentOfPath(String path) {
        return path.substring(0, path.lastIndexOf("/"));
    }

    public static String getReadableFileSize(long size) {
        if (size <= 0) return "0";
        final String[] units = new String[]{"B", "KB", "MB", "GB", "TB"};
        int digitGroups = (int) (Math.log10(size) / Math.log10(1024));
        return new DecimalFormat("#").format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups];
    }
}<commit_msg>Fix filters. Fixes #11 and #19<commit_after>package com.nbsp.materialfilepicker.utils;

import android.support.annotation.Nullable;

import java.io.File;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.regex.Pattern;

/**
 * Created by Dimorinny on 24.10.15.
 */
public class FileUtils {
    public static List<File> getFileListByDirPath(String path,
                                                  @Nullable Pattern fileFilter,
                                                  boolean directoriesFilter,
                                                  boolean showHidden) {
        File directory = new File(path);
        List<File> resultFiles = new ArrayList<>();

        File[] files = directory.listFiles();
        if (files != null && files.length > 0) {
            for (File f : files) {

                if (f.isDirectory() && !directoriesFilter) {
                    if (!f.isHidden() || (f.isHidden() && showHidden)) {
                        resultFiles.add(f);
                    }
                    continue;
                }

                if (fileFilter != null) {
                    if (fileFilter.matcher(f.getName()).matches())
                        if (!f.isHidden() || (f.isHidden() && showHidden)) {
                            resultFiles.add(f);
                        }
                } else {
                    resultFiles.add(f);
                }

            }

            Collections.sort(resultFiles, new FileComparator());
        }

        return resultFiles;
    }

    public static String cutLastSegmentOfPath(String path) {
        return path.substring(0, path.lastIndexOf("/"));
    }

    public static String getReadableFileSize(long size) {
        if (size <= 0) return "0";
        final String[] units = new String[]{"B", "KB", "MB", "GB", "TB"};
        int digitGroups = (int) (Math.log10(size) / Math.log10(1024));
        return new DecimalFormat("#").format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups];
    }
}
{'fraction_non_alphanumeric': 0.1184763789265397, 'fraction_numerical': 0.011872372000989364, 'mean_word_length': 1.5906470211402948, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7060671', 'n_tokens_mistral': 1081, 'n_tokens_neox': 998, 'n_words': 240}