<commit_before>// ----------------------------------------------------------------------
//This code is developed as part of the Java CoG Kit project
//The terms of the license can be found at http://www.cogkit.org/license
//This message may not be removed or altered.
//----------------------------------------------------------------------

/*
 * Created on Apr 20, 2005
 */
package org.globus.cog.karajan.arguments;

import java.util.Arrays;
import java.util.List;

import org.globus.cog.karajan.workflow.KarajanRuntimeException;
import org.globus.cog.karajan.workflow.nodes.FlowElement;

/**
 * An implementation of a channel that binds values to a set of NamedArguments
 * based on a list of names. This is done in order to allow access
 * to arguments by name while supplying them in a positional fashion.
 * 
 * @author <NAME>
 *
 */
public class NameBindingVariableArguments extends VariableArgumentsImpl {
	private final NamedArguments named;
	private final List<String> names;
	private int index;
	private final boolean hasVargs;
	private final FlowElement owner;

	public NameBindingVariableArguments(NamedArguments named, List<String> names, boolean hasVargs,
			FlowElement owner) {
		this.named = named;
		this.names = names;
		index = 0;
		this.hasVargs = hasVargs;
		this.owner = owner;
	}

	public synchronized void append(Object value) {
	    for (String name : names) {
	        if (!named.hasArgument(name)) {
	            named.add(name, value);
	            return;
	        }
	    }
		
		if (!hasVargs) {
			System.out.println("" + value);
			throw new KarajanRuntimeException("Illegal extra argument `" + value + "' to " + owner);
		}
		else {
			super.append(value);
		}
	}

	public void appendAll(List args) {
		int i = 0;
		for (String name : names) {
            if (!named.hasArgument(name)) {
                if (i < args.size()) {
                	named.add(name, args.get(i++));
                }
                else {
                    return;
                }
            }
        }
		if (!args.isEmpty()) {
			if (args.size() > i) {
				if (!hasVargs) {
					throw new KarajanRuntimeException("Illegal extra argument to " + owner);
				}<commit_msg>removed debugging message<commit_after>// ----------------------------------------------------------------------
//This code is developed as part of the Java CoG Kit project
//The terms of the license can be found at http://www.cogkit.org/license
//This message may not be removed or altered.
//----------------------------------------------------------------------

/*
 * Created on Apr 20, 2005
 */
package org.globus.cog.karajan.arguments;

import java.util.Arrays;
import java.util.List;

import org.globus.cog.karajan.workflow.KarajanRuntimeException;
import org.globus.cog.karajan.workflow.nodes.FlowElement;

/**
 * An implementation of a channel that binds values to a set of NamedArguments
 * based on a list of names. This is done in order to allow access
 * to arguments by name while supplying them in a positional fashion.
 * 
 * @author <NAME>
 *
 */
public class NameBindingVariableArguments extends VariableArgumentsImpl {
	private final NamedArguments named;
	private final List<String> names;
	private int index;
	private final boolean hasVargs;
	private final FlowElement owner;

	public NameBindingVariableArguments(NamedArguments named, List<String> names, boolean hasVargs,
			FlowElement owner) {
		this.named = named;
		this.names = names;
		index = 0;
		this.hasVargs = hasVargs;
		this.owner = owner;
	}

	public synchronized void append(Object value) {
	    for (String name : names) {
	        if (!named.hasArgument(name)) {
	            named.add(name, value);
	            return;
	        }
	    }
		
		if (!hasVargs) {
			throw new KarajanRuntimeException("Illegal extra argument `" + value + "' to " + owner);
		}
		else {
			super.append(value);
		}
	}

	public void appendAll(List args) {
		int i = 0;
		for (String name : names) {
            if (!named.hasArgument(name)) {
                if (i < args.size()) {
                	named.add(name, args.get(i++));
                }
                else {
                    return;
                }
            }
        }
		if (!args.isEmpty()) {
			if (args.size() > i) {
				if (!hasVargs) {
					throw new KarajanRuntimeException("Illegal extra argument to " + owner);
				}
{'fraction_non_alphanumeric': 0.16119402985074627, 'fraction_numerical': 0.0036739380022962113, 'mean_word_length': 2.0654468684025336, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '7492627', 'n_tokens_mistral': 1326, 'n_tokens_neox': 1190, 'n_words': 382}