<commit_before>package eu.icolumbo.breeze.build;

import eu.icolumbo.breeze.SpringBolt;
import eu.icolumbo.breeze.SpringComponent;
import eu.icolumbo.breeze.SpringSpout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.TreeMap;

import static java.util.Arrays.asList;
import static java.util.Collections.addAll;


/**
 * Performs dependency calculation.
 * @author <NAME>
 */
public class TopologyCompilation extends TreeMap<SpringSpout,List<SpringBolt>> implements Runnable {

	private static final Logger logger = LoggerFactory.getLogger(TopologyCompilation.class);

	private final List<SpringBolt> unbound = new ArrayList<>();


	/**
	 * Default constructor.
	 */
	public TopologyCompilation() {
		super(new Comparator<SpringComponent>() {

			@Override
			public int compare(SpringComponent o1, SpringComponent o2) {
				String id1 = o1.getId();
				String id2 = o2.getId();
				Objects.requireNonNull(id1, "Missing required component id");
				Objects.requireNonNull(id2, "Missing required component id");
				return id1.compareTo(id2);
			}

		});
	}

	public void add(SpringSpout... values) {
		for (SpringSpout spout : values)
			put(spout, new ArrayList<SpringBolt>());
	}

	public void add(SpringBolt... values) {
		addAll(unbound, values);
	}

	@Override
	public void run() {
		logger.debug("Matching {} spouts with {} bolts", size(), unbound.size());
		for (Map.Entry<SpringSpout,List<SpringBolt>> line : entrySet()) {
			Set<String> availableFields = new HashSet<>();
			addAll(availableFields, line.getKey().getOutputFields());

			List<SpringBolt> options = new ArrayList<>(unbound);
			for (boolean collected = true; collected; ) {
				collected = false;
				Iterator<SpringBolt> todo = options.iterator();
				while (todo.hasNext()) {
					SpringBolt option = todo.next();
					logger.trace("Trying {} for {}", option, line.getKey());
					if (availableFields.containsAll(asList(option.getInputFields()))) {
						line.getValue().add(option);
						addAll(availableFields, option.getOutputFields());
						todo.remove();
						collected = true;
					}
				}
			}

			logger.debug("Found {} bolts for {}", line.getValue().size(), line.getKey());
		}

		for (List<SpringBolt> processed: values()) {
			unbound.removeAll(processed);

			Set<String> requiredFields = new HashSet<>();
			for (int i = processed.size(); --i >= 0; ) {
				SpringBolt bolt = processed.get(i);
				requiredFields.removeAll(asList(bolt.getOutputFields()));
				bolt.setPassThroughFields(requiredFields.toArray(new String[requiredFields.size()]));
				addAll(requiredFields, bolt.getInputFields());
			}
		}

		logger.trace("Compilation: {}", this);
		logger.info("Compilation finished");
	}

	@Override
	public void clear() {
		super.clear();
		unbound.clear();
	}

	/**
	 * Checks whether {@link #run() the complitation} succeeded.
	 */
	public void verify() throws IllegalStateException {
		if (unbound.isEmpty()) return;
		throw new IllegalStateException("Can't resolve all input fields for: " + unbound);
	}

}<commit_msg>Log compilation result on info level.<commit_after>package eu.icolumbo.breeze.build;

import eu.icolumbo.breeze.SpringBolt;
import eu.icolumbo.breeze.SpringComponent;
import eu.icolumbo.breeze.SpringSpout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.TreeMap;

import static java.util.Arrays.asList;
import static java.util.Collections.addAll;


/**
 * Performs dependency calculation.
 * @author <NAME>
 */
public class TopologyCompilation extends TreeMap<SpringSpout,List<SpringBolt>> implements Runnable {

	private static final Logger logger = LoggerFactory.getLogger(TopologyCompilation.class);

	private final List<SpringBolt> unbound = new ArrayList<>();


	/**
	 * Default constructor.
	 */
	public TopologyCompilation() {
		super(new Comparator<SpringComponent>() {

			@Override
			public int compare(SpringComponent o1, SpringComponent o2) {
				String id1 = o1.getId();
				String id2 = o2.getId();
				Objects.requireNonNull(id1, "Missing required component id");
				Objects.requireNonNull(id2, "Missing required component id");
				return id1.compareTo(id2);
			}

		});
	}

	public void add(SpringSpout... values) {
		for (SpringSpout spout : values)
			put(spout, new ArrayList<SpringBolt>());
	}

	public void add(SpringBolt... values) {
		addAll(unbound, values);
	}

	@Override
	public void run() {
		logger.debug("Matching {} spouts with {} bolts", size(), unbound.size());
		for (Map.Entry<SpringSpout,List<SpringBolt>> line : entrySet()) {
			Set<String> availableFields = new HashSet<>();
			addAll(availableFields, line.getKey().getOutputFields());

			List<SpringBolt> options = new ArrayList<>(unbound);
			for (boolean collected = true; collected; ) {
				collected = false;
				Iterator<SpringBolt> todo = options.iterator();
				while (todo.hasNext()) {
					SpringBolt option = todo.next();
					logger.trace("Trying {} for {}", option, line.getKey());
					if (availableFields.containsAll(asList(option.getInputFields()))) {
						line.getValue().add(option);
						addAll(availableFields, option.getOutputFields());
						todo.remove();
						collected = true;
					}
				}
			}

			logger.debug("Found {} bolts for {}", line.getValue().size(), line.getKey());
		}

		for (List<SpringBolt> processed: values()) {
			unbound.removeAll(processed);

			Set<String> requiredFields = new HashSet<>();
			for (int i = processed.size(); --i >= 0; ) {
				SpringBolt bolt = processed.get(i);
				requiredFields.removeAll(asList(bolt.getOutputFields()));
				bolt.setPassThroughFields(requiredFields.toArray(new String[requiredFields.size()]));
				addAll(requiredFields, bolt.getInputFields());
			}
		}

		logger.info("Compiled as: {}", this);
	}

	@Override
	public void clear() {
		super.clear();
		unbound.clear();
	}

	/**
	 * Checks whether {@link #run() the complitation} succeeded.
	 */
	public void verify() throws IllegalStateException {
		if (unbound.isEmpty()) return;
		throw new IllegalStateException("Can't resolve all input fields for: " + unbound);
	}

}
{'fraction_non_alphanumeric': 0.14133456904541242, 'fraction_numerical': 0.004016064257028112, 'mean_word_length': 4.33800494641385, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 39, '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': '5450881', 'n_tokens_mistral': 2270, 'n_tokens_neox': 1989, 'n_words': 446}