<commit_before>/*
 * The Exomiser - A tool to annotate and prioritize genomic variants
 *
 * Copyright (c) 2016-2020 Queen Mary University of London.
 * Copyright (c) 2012-2016 Charité Universitätsmedizin Berlin and Genome Research Ltd.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.monarchinitiative.exomiser.core.analysis;

import org.monarchinitiative.exomiser.core.filters.FilterResult;
import org.monarchinitiative.exomiser.core.filters.FilterType;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @since 12.0.0
 * @author <NAME> <<EMAIL>>
 */
class FilterStats {

    private final Map<FilterType, FilterCounter> filterCounters = new EnumMap<>(FilterType.class);
    // filtersRun requires an ordered map.
    private final Set<FilterType> filtersRun = new LinkedHashSet<>();

    synchronized void addResult(FilterResult result) {
        FilterType filterType = result.getFilterType();
        filtersRun.add(filterType);

        FilterCounter counter = filterCounters.getOrDefault(filterType, new FilterCounter());
        if (result.passed()) {
            counter.passCount++;
        } else if (result.failed()) {
            counter.failCount++;
        }
        filterCounters.put(filterType, counter);
    }

    int getPassCountForFilter(FilterType filterType) {
        FilterCounter filterCounter = filterCounters.get(filterType);
        return filterCounter == null ? 0 : filterCounter.getPassCount();
    }

    int getFailCountForFilter(FilterType filterType) {
        FilterCounter filterCounter = filterCounters.get(filterType);
        return filterCounter == null ? 0 : filterCounter.getFailCount();
    }

    List<FilterType> getFilters() {
        return new ArrayList<>(filtersRun);
    }

    /**
     * @since 13.0.0
     */
    List<FilterCount> getFilterCounts() {
        return filtersRun.stream()
                .map(filterType -> new FilterCount(filterType, filterCounters.get(filterType)))
                .collect(Collectors.toList());
    }

    /**
     * @since 13.0.0
     */
    static class FilterCount {

        private final FilterType filterType;
        private int passCount;
        private int failCount;

        private FilterCount(FilterType filterType, FilterCounter filterCounter) {
            this.filterType = filterType;
            this.passCount = filterCounter.passCount;
            this.failCount = filterCounter.failCount;
        }

        public FilterType getFilterType() {
            return filterType;
        }

        public int getPassCount() {
            return passCount;
        }

        public int getFailCount() {
            return failCount;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (!(o instanceof FilterCount)) return false;
            FilterCount that = (FilterCount) o;
            return passCount == that.passCount &&
                    failCount == that.failCount &&
                    filterType == that.filterType;
        }
<commit_msg>Update FilterStats.FilterCount count fields to final<commit_after>/*
 * The Exomiser - A tool to annotate and prioritize genomic variants
 *
 * Copyright (c) 2016-2020 Queen Mary University of London.
 * Copyright (c) 2012-2016 <NAME>ätsmed<NAME> and Genome Research Ltd.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.monarchinitiative.exomiser.core.analysis;

import org.monarchinitiative.exomiser.core.filters.FilterResult;
import org.monarchinitiative.exomiser.core.filters.FilterType;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @since 12.0.0
 * @author <NAME> <<EMAIL>>
 */
class FilterStats {

    private final Map<FilterType, FilterCounter> filterCounters = new EnumMap<>(FilterType.class);
    // filtersRun requires an ordered map.
    private final Set<FilterType> filtersRun = new LinkedHashSet<>();

    synchronized void addResult(FilterResult result) {
        FilterType filterType = result.getFilterType();
        filtersRun.add(filterType);

        FilterCounter counter = filterCounters.getOrDefault(filterType, new FilterCounter());
        if (result.passed()) {
            counter.passCount++;
        } else if (result.failed()) {
            counter.failCount++;
        }
        filterCounters.put(filterType, counter);
    }

    int getPassCountForFilter(FilterType filterType) {
        FilterCounter filterCounter = filterCounters.get(filterType);
        return filterCounter == null ? 0 : filterCounter.getPassCount();
    }

    int getFailCountForFilter(FilterType filterType) {
        FilterCounter filterCounter = filterCounters.get(filterType);
        return filterCounter == null ? 0 : filterCounter.getFailCount();
    }

    List<FilterType> getFilters() {
        return new ArrayList<>(filtersRun);
    }

    /**
     * @since 13.0.0
     */
    List<FilterCount> getFilterCounts() {
        return filtersRun.stream()
                .map(filterType -> new FilterCount(filterType, filterCounters.get(filterType)))
                .collect(Collectors.toList());
    }

    /**
     * @since 13.0.0
     */
    static class FilterCount {

        private final FilterType filterType;
        private final int passCount;
        private final int failCount;

        private FilterCount(FilterType filterType, FilterCounter filterCounter) {
            this.filterType = filterType;
            this.passCount = filterCounter.passCount;
            this.failCount = filterCounter.failCount;
        }

        public FilterType getFilterType() {
            return filterType;
        }

        public int getPassCount() {
            return passCount;
        }

        public int getFailCount() {
            return failCount;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (!(o instanceof FilterCount)) return false;
            FilterCount that = (FilterCount) o;
            return passCount == that.passCount &&
                    failCount == that.failCount &&
                    filterType == that.filterType;
        }

{'fraction_non_alphanumeric': 0.08899392302498312, 'fraction_numerical': 0.00837272113436867, 'mean_word_length': 2.6536753823384314, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4158536', 'n_tokens_mistral': 1974, 'n_tokens_neox': 1889, 'n_words': 593}