<commit_before>package com.fathomdb.cli;

import java.lang.reflect.Constructor;
import java.text.MessageFormat;

import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.OptionDef;
import org.kohsuke.args4j.spi.OptionHandler;
import org.kohsuke.args4j.spi.Parameters;
import org.kohsuke.args4j.spi.Setter;

public class StringWrapperOptionHandler<T> extends OptionHandler<T> {

	private static final String ILLEGAL_OPERAND = "\"{1}\" is not a valid value for \"{0}\"";

	public StringWrapperOptionHandler(CmdLineParser parser, OptionDef option, Setter<? super T> setter) {
		super(parser, option, setter);
	}

	@Override
	public int parseArguments(Parameters params) throws CmdLineException {
		String token = params.getParameter(0);
		try {
			Class<? super T> fieldType = setter.getType();
			Constructor<? super T> constructor = fieldType.getConstructor(String.class);
			T o = (T) constructor.newInstance(token);
			setter.addValue(o);
			return 1;
		} catch (SecurityException e) {
			throw new CmdLineException(owner, MessageFormat.format(ILLEGAL_OPERAND, option.toString(), token));
		} catch (ReflectiveOperationException e) {
			throw new CmdLineException(owner, MessageFormat.format(ILLEGAL_OPERAND, option.toString(), token));
		} catch (IllegalArgumentException e) {
			throw new CmdLineException(owner, MessageFormat.format(ILLEGAL_OPERAND, option.toString(), token));
		}
	}

	@Override
	public String getDefaultMetaVariable() {<commit_msg>Sadly ReflectiveOperationException is Java 7<commit_after>package com.fathomdb.cli;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.text.MessageFormat;

import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.OptionDef;
import org.kohsuke.args4j.spi.OptionHandler;
import org.kohsuke.args4j.spi.Parameters;
import org.kohsuke.args4j.spi.Setter;

public class StringWrapperOptionHandler<T> extends OptionHandler<T> {

	private static final String ILLEGAL_OPERAND = "\"{1}\" is not a valid value for \"{0}\"";

	public StringWrapperOptionHandler(CmdLineParser parser, OptionDef option, Setter<? super T> setter) {
		super(parser, option, setter);
	}

	@Override
	public int parseArguments(Parameters params) throws CmdLineException {
		String token = params.getParameter(0);
		try {
			Class<? super T> fieldType = setter.getType();
			Constructor<? super T> constructor = fieldType.getConstructor(String.class);
			T o = (T) constructor.newInstance(token);
			setter.addValue(o);
			return 1;
		} catch (SecurityException e) {
			throw new CmdLineException(owner, MessageFormat.format(ILLEGAL_OPERAND, option.toString(), token));
		} catch (InvocationTargetException e) {
			throw new CmdLineException(owner, MessageFormat.format(ILLEGAL_OPERAND, option.toString(), token));
		} catch (IllegalArgumentException e) {
			throw new CmdLineException(owner, MessageFormat.format(ILLEGAL_OPERAND, option.toString(), token));
		} catch (InstantiationException e) {
			throw new CmdLineException(owner, MessageFormat.format(ILLEGAL_OPERAND, option.toString(), token));
		} catch (IllegalAccessException e) {
			throw new CmdLineException(owner, MessageFormat.format(ILLEGAL_OPERAND, option.toString(), token));
		} catch (NoSuchMethodException e) {
			throw new CmdLineException(owner, MessageFormat.format(ILLEGAL_OPERAND, option.toString(), token));
		}
	}

	@Override
	public String getDefaultMetaVariable() {
{'fraction_non_alphanumeric': 0.11019596705481398, 'fraction_numerical': 0.005964214711729622, 'mean_word_length': 5.933070866141732, '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': '3438349', 'n_tokens_mistral': 1171, 'n_tokens_neox': 1088, 'n_words': 247}