<commit_before>package jenkins;

import hudson.Extension;
import hudson.FilePath;
import hudson.remoting.ChannelProperty;

import java.io.File;
import java.util.Collections;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * Maintains a bundle of {@link FilePathFilter} and implement a hook that broadcasts to all the filters.
 *
 * Accessible as channel property.
 *
 * @author <NAME>
 * @see FilePath
 * @since 1.THU
 */
class FilePathFilterAggregator extends FilePathFilter {
    private final CopyOnWriteArrayList<Entry> all = new CopyOnWriteArrayList<Entry>();

    private class Entry implements Comparable<Entry> {
        final FilePathFilter filter;
        final double ordinal;

        private Entry(FilePathFilter filter, double ordinal) {
            this.filter = filter;
            this.ordinal = ordinal;
        }

        @Override
        public int compareTo(Entry that) {
            double d = this.ordinal - that.ordinal;
            if (d<0)    return -1;
            if (d>0)    return 1;
            return 0;
        }
    }

    public final void add(FilePathFilter f) {
        add(f, DEFAULT_ORDINAL);
    }

    /**
     *
     * @param ordinal
     *      Crude ordering control among {@link FilePathFilter} ala {@link Extension#ordinal()}.
     *      A filter with a bigger value will get precedence. Defaults to 0.
     */
    public void add(FilePathFilter f, double ordinal) {
        all.add(new Entry(f,ordinal));
        Collections.sort(all);
    }

    public void remove(FilePathFilter f) {
        for (Entry e : all) {
            if (e.filter==f)
                all.remove(e);
        }
    }

    /**
     * If no filter cares, what to do?
     */
    protected boolean defaultAction() throws SecurityException {
        return false;
    }

    @Override
    public boolean read(File f) throws SecurityException {
        for (Entry e : all) {
            if (e.filter.read(f))
                return true;
        }
        return defaultAction();
    }

    @Override
    public boolean mkdirs(File f) throws SecurityException {
        for (Entry e : all) {
            if (e.filter.mkdirs(f))
                return true;
        }
        return defaultAction();
    }

    @Override
    public boolean write(File f) throws SecurityException {
        for (Entry e : all) {
            if (e.filter.write(f))
                return true;
        }
        return defaultAction();
    }

    @Override
    public boolean create(File f) throws SecurityException {
        for (Entry e : all) {
            if (e.filter.create(f))
                return true;
        }
        return defaultAction();
    }

    @Override
    public boolean delete(File f) throws SecurityException {
        for (Entry e : all) {
            if (e.filter.delete(f))
                return true;
        }
        return defaultAction();
    }

    @Override
    public boolean stat(File f) throws SecurityException {
        for (Entry e : all) {
            if (e.filter.stat(f))
                return true;
        }
        return defaultAction();
    }

    @Override public String toString() {
        return "FilePathFilterAggregator" + all;
    }

    static final ChannelProperty<FilePathFilterAggregator> KEY = new ChannelProperty<FilePathFilterAggregator>(FilePathFilterAggregator.class, "FilePathFilters");

    public static final int DEFAULT_ORDINAL = 0;
}
<commit_msg>Most ordinals will be zero, and it is undesirable for the order to be affected by the order of insertion, which is not necessarily predictable.<commit_after>package jenkins;

import hudson.Extension;
import hudson.FilePath;
import hudson.remoting.ChannelProperty;

import java.io.File;
import java.util.Collections;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * Maintains a bundle of {@link FilePathFilter} and implement a hook that broadcasts to all the filters.
 *
 * Accessible as channel property.
 *
 * @author <NAME>
 * @see FilePath
 * @since 1.THU
 */
class FilePathFilterAggregator extends FilePathFilter {
    private final CopyOnWriteArrayList<Entry> all = new CopyOnWriteArrayList<Entry>();

    private class Entry implements Comparable<Entry> {
        final FilePathFilter filter;
        final double ordinal;

        private Entry(FilePathFilter filter, double ordinal) {
            this.filter = filter;
            this.ordinal = ordinal;
        }

        @Override
        public int compareTo(Entry that) {
            double d = this.ordinal - that.ordinal;
            if (d<0)    return -1;
            if (d>0)    return 1;

            // to create predictable order that doesn't depend on the insertion order, use class name
            // to break a tie
            return this.filter.getClass().getName().compareTo(that.filter.getClass().getName());
        }
    }

    public final void add(FilePathFilter f) {
        add(f, DEFAULT_ORDINAL);
    }

    /**
     *
     * @param ordinal
     *      Crude ordering control among {@link FilePathFilter} ala {@link Extension#ordinal()}.
     *      A filter with a bigger value will get precedence. Defaults to 0.
     */
    public void add(FilePathFilter f, double ordinal) {
        all.add(new Entry(f,ordinal));
        Collections.sort(all);
    }

    public void remove(FilePathFilter f) {
        for (Entry e : all) {
            if (e.filter==f)
                all.remove(e);
        }
    }

    /**
     * If no filter cares, what to do?
     */
    protected boolean defaultAction() throws SecurityException {
        return false;
    }

    @Override
    public boolean read(File f) throws SecurityException {
        for (Entry e : all) {
            if (e.filter.read(f))
                return true;
        }
        return defaultAction();
    }

    @Override
    public boolean mkdirs(File f) throws SecurityException {
        for (Entry e : all) {
            if (e.filter.mkdirs(f))
                return true;
        }
        return defaultAction();
    }

    @Override
    public boolean write(File f) throws SecurityException {
        for (Entry e : all) {
            if (e.filter.write(f))
                return true;
        }
        return defaultAction();
    }

    @Override
    public boolean create(File f) throws SecurityException {
        for (Entry e : all) {
            if (e.filter.create(f))
                return true;
        }
        return defaultAction();
    }

    @Override
    public boolean delete(File f) throws SecurityException {
        for (Entry e : all) {
            if (e.filter.delete(f))
                return true;
        }
        return defaultAction();
    }

    @Override
    public boolean stat(File f) throws SecurityException {
        for (Entry e : all) {
            if (e.filter.stat(f))
                return true;
        }
        return defaultAction();
    }

    @Override public String toString() {
        return "FilePathFilterAggregator" + all;
    }

    static final ChannelProperty<FilePathFilterAggregator> KEY = new ChannelProperty<FilePathFilterAggregator>(FilePathFilterAggregator.class, "FilePathFilters");

    public static final int DEFAULT_ORDINAL = 0;
}

{'fraction_non_alphanumeric': 0.09010011123470522, 'fraction_numerical': 0.002085650723025584, 'mean_word_length': 2.0453005927180357, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '3629215', 'n_tokens_mistral': 1978, 'n_tokens_neox': 1908, 'n_words': 592}