<commit_before>package org.gambi.tapestry5.cli.services.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Set;

import javax.validation.ConstraintViolation;
import javax.validation.ValidationException;
import javax.validation.Validator;

import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.gambi.tapestry5.cli.data.ApplicationConfiguration;
import org.gambi.tapestry5.cli.data.CLIOption;
import org.gambi.tapestry5.cli.services.ApplicationConfigurationSource;
import org.gambi.tapestry5.cli.services.CLIParser;
import org.slf4j.Logger;

public class CLIParserImpl implements CLIParser {

	private Logger logger;
	private ApplicationConfigurationSource applicationConfigurationSource;
	private Validator validator;

	private Collection<CLIOption> cliOptions;

	// Internal implementation
	private CommandLineParser parser;
	private CommandLine parsedOptions;

	// private Options configuration;

	public CLIParserImpl(Logger logger,
			ApplicationConfigurationSource applicationBeanSource,
			Validator validator, Collection<CLIOption> _options) {

		this.logger = logger;
		this.validator = validator;
		this.applicationConfigurationSource = applicationBeanSource;

		validateAndMerge(_options);
	}

	/**
	 * 
	 */
	private void validateAndMerge(Collection<CLIOption> _options) {
		ArrayList<CLIOption> cliOptions = new ArrayList<CLIOption>();

		for (CLIOption cliOption : _options) {
			if (!cliOptions.contains(_options)) {
				logger.debug("Adding " + _options);
				cliOptions.add(cliOption);
			} else {
				logger.debug("Merging options "
						+ cliOptions.get(cliOptions.indexOf(_options))
						+ " with " + cliOption);
				cliOptions.get(cliOptions.indexOf(_options)).merge(cliOption);
			}<commit_msg>Bug Fixed inside validateAndMerge. note tests are failing because we need to merge the AppConf code<commit_after>package org.gambi.tapestry5.cli.services.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Set;

import javax.validation.ConstraintViolation;
import javax.validation.ValidationException;
import javax.validation.Validator;

import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.gambi.tapestry5.cli.data.ApplicationConfiguration;
import org.gambi.tapestry5.cli.data.CLIOption;
import org.gambi.tapestry5.cli.services.ApplicationConfigurationSource;
import org.gambi.tapestry5.cli.services.CLIParser;
import org.slf4j.Logger;

public class CLIParserImpl implements CLIParser {

	private Logger logger;
	private ApplicationConfigurationSource applicationConfigurationSource;
	private Validator validator;

	private Collection<CLIOption> cliOptions;

	// Internal implementation
	private CommandLineParser parser;
	private CommandLine parsedOptions;

	// private Options configuration;

	public CLIParserImpl(Logger logger,
			ApplicationConfigurationSource applicationBeanSource,
			Validator validator, Collection<CLIOption> _options) {

		this.logger = logger;
		this.validator = validator;
		this.applicationConfigurationSource = applicationBeanSource;

		validateAndMerge(_options);
	}

	/**
	 * 
	 */
	private void validateAndMerge(Collection<CLIOption> _options) {
		ArrayList<CLIOption> cliOptions = new ArrayList<CLIOption>();

		for (CLIOption cliOption : _options) {

			if (!cliOptions.contains(cliOption)) {
				logger.debug("Adding " + cliOption);
				cliOptions.add(cliOption);
			} else {
				logger.info("\t Merging options "
						+ cliOptions.get(cliOptions.indexOf(cliOption))
						+ " with " + cliOption);
				cliOptions.get(cliOptions.indexOf(cliOption)).merge(cliOption);
			}
{'fraction_non_alphanumeric': 0.096113074204947, 'fraction_numerical': 0.0028268551236749115, 'mean_word_length': 5.593167701863354, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '534450', 'n_tokens_mistral': 1330, 'n_tokens_neox': 1213, 'n_words': 236}