<commit_before>// Copyright (c) 2003-2014, Jodd Team (jodd.org). All Rights Reserved.

package jodd.util;

import java.util.ArrayList;
import java.util.List;

/**
 * One-class rule engine for includes/excludes logic. It can be used when
 * set of objects has to filtered using includes and excludes rules.
 * For example, when filtering files by file name etc.
 * <p>
 * Rule engine works in one of two modes:
 * <ul>
 *		<li><i>blacklist</i> - when any input is allowed by default and when you specify
 *			explicit excludes.
 *		</li>
 *		<li><i>whitelist</i> - when any input is disabled by default and when you specify
 *			explicit includes.
 *		</li>
 * </ul>
 * <p>
 * The logic of this rule engine depends on the current mode. In both cases,
 * always the inverse rules are considered first. For example, for <i>blacklist</i>
 * mode, engine first examine excludes, and then includes. This way you can
 * set any filter combination.
 * <p>
 * All Jodd classes that filters something uses this class to unify the
 * behavior across the Jodd library.
 */
public class InExRules<T, R> implements InExRuleMatcher<T, R> {

	protected List<Rule<R>> rules;
	protected final InExRuleMatcher<T, R> inExRuleMatcher;
	protected int includesCount;
	protected int excludesCount;
	protected boolean blacklist = true;

	/**
	 * Creates default instance.
	 */
	public InExRules() {
		this.inExRuleMatcher = this;
	}

	/**
	 * Creates instance that uses provided matcher.
	 */
	public InExRules(InExRuleMatcher<T, R> inExRuleMatcher) {
		this.inExRuleMatcher = inExRuleMatcher;
	}

	/**
	 * Returns total number of rules.
	 */
	public int count() {
		if (rules == null) {
			return 0;
		}
		return rules.size();
	}

	/**
	 * Returns <code>true</code> if rule engine has at least one rule set.
	 */
	public boolean hasRules() {
		if (rules == null) {
			return false;
		}
		return rules.size() > 0;
	}

	/**
	 * Rule definition.
	 */
	public static class Rule<R> {
		public final R value;
		public final boolean include;

		public Rule(R value, boolean include) {
			this.value = value;
			this.include = include;
		}

		@Override<commit_msg>added total counts for included/excluded rules<commit_after>// Copyright (c) 2003-2014, Jodd Team (jodd.org). All Rights Reserved.

package jodd.util;

import java.util.ArrayList;
import java.util.List;

/**
 * One-class rule engine for includes/excludes logic. It can be used when
 * set of objects has to filtered using includes and excludes rules.
 * For example, when filtering files by file name etc.
 * <p>
 * Rule engine works in one of two modes:
 * <ul>
 *		<li><i>blacklist</i> - when any input is allowed by default and when you specify
 *			explicit excludes.
 *		</li>
 *		<li><i>whitelist</i> - when any input is disabled by default and when you specify
 *			explicit includes.
 *		</li>
 * </ul>
 * <p>
 * The logic of this rule engine depends on the current mode. In both cases,
 * always the inverse rules are considered first. For example, for <i>blacklist</i>
 * mode, engine first examine excludes, and then includes. This way you can
 * set any filter combination.
 * <p>
 * All Jodd classes that filters something uses this class to unify the
 * behavior across the Jodd library.
 */
public class InExRules<T, R> implements InExRuleMatcher<T, R> {

	protected List<Rule<R>> rules;
	protected final InExRuleMatcher<T, R> inExRuleMatcher;
	protected int includesCount;
	protected int excludesCount;
	protected boolean blacklist = true;

	/**
	 * Creates default instance.
	 */
	public InExRules() {
		this.inExRuleMatcher = this;
	}

	/**
	 * Creates instance that uses provided matcher.
	 */
	public InExRules(InExRuleMatcher<T, R> inExRuleMatcher) {
		this.inExRuleMatcher = inExRuleMatcher;
	}

	/**
	 * Returns total number of all rules.
	 */
	public int totalRules() {
		if (rules == null) {
			return 0;
		}
		return rules.size();
	}

	/**
	 * Returns total number of include rules.
	 */
	public int totalIncludeRules() {
		return includesCount;
	}

	/**
	 * Returns total number of exclude rules.
	 */
	public int totalExcludeRules() {
		return excludesCount;
	}

	/**
	 * Returns <code>true</code> if rule engine has at least one rule set.
	 */
	public boolean hasRules() {
		if (rules == null) {
			return false;
		}
		return rules.size() > 0;
	}

	/**
	 * Rule definition.
	 */
	public static class Rule<R> {
		public final R value;
		public final boolean include;

		public Rule(R value, boolean include) {
			this.value = value;
			this.include = include;
		}

		@Override
{'fraction_non_alphanumeric': 0.10648148148148148, 'fraction_numerical': 0.004409171075837742, 'mean_word_length': 3.3457854406130267, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 53, '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': '1208846', 'n_tokens_mistral': 1505, 'n_tokens_neox': 1383, 'n_words': 533}