<commit_before>package uk.org.taverna.scufl2.api.core;

import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.UUID;

import uk.org.taverna.scufl2.api.common.AbstractNamedChild;
import uk.org.taverna.scufl2.api.common.Child;
import uk.org.taverna.scufl2.api.common.NamedSet;
import uk.org.taverna.scufl2.api.common.Ported;
import uk.org.taverna.scufl2.api.common.Visitor;
import uk.org.taverna.scufl2.api.common.WorkflowBean;
import uk.org.taverna.scufl2.api.container.WorkflowBundle;
import uk.org.taverna.scufl2.api.port.InputWorkflowPort;
import uk.org.taverna.scufl2.api.port.OutputWorkflowPort;

/**
 * @author <NAME>
 *
 */
public class Workflow extends AbstractNamedChild implements
		Child<WorkflowBundle>, Ported {

	public static final URI WORKFLOW_ROOT = URI
			.create("http://ns.taverna.org.uk/2010/workflow/");

	public static URI generateIdentifier() {
		return WORKFLOW_ROOT.resolve(UUID.randomUUID().toString() + "/");
	}

	private Set<DataLink> dataLinks = new HashSet<DataLink>();

	private Set<ControlLink> controlLinks = new HashSet<ControlLink>();

	private NamedSet<InputWorkflowPort> inputPorts = new NamedSet<InputWorkflowPort>();
	private NamedSet<OutputWorkflowPort> outputPorts = new NamedSet<OutputWorkflowPort>();
	private NamedSet<Processor> processors = new NamedSet<Processor>();
	private URI workflowIdentifier;
	private WorkflowBundle parent;

	public Workflow() {
		setWorkflowIdentifier(generateIdentifier());
		String workflowId = WORKFLOW_ROOT.relativize(getWorkflowIdentifier())
				.toASCIIString();
		setName("wf-" + workflowId);
	}

	@Override
	public boolean accept(Visitor visitor) {
		if (visitor.visitEnter(this)) {
			List<Iterable<? extends WorkflowBean>> children = new ArrayList<Iterable<? extends WorkflowBean>>();
			children.add(getInputPorts());
			children.add(getOutputPorts());
			children.add(getProcessors());
			children.add(getDataLinks());
			children.add(getControlLinks());
			outer: for (Iterable<? extends WorkflowBean> it : children) {
				for (WorkflowBean bean : it) {
					if (!bean.accept(visitor)) {
						break outer;
					}
				}
			}
		}
		return visitor.visitLeave(this);
	}

	public Set<ControlLink> getControlLinks() {
		return controlLinks;
	}

	public Set<DataLink> getDataLinks() {
		return dataLinks;
	}

	public NamedSet<InputWorkflowPort> getInputPorts() {
		return inputPorts;
	}

	public NamedSet<OutputWorkflowPort> getOutputPorts() {
		return outputPorts;
	}

	@Override
	public WorkflowBundle getParent() {
		return parent;
	}

	public NamedSet<Processor> getProcessors() {
		return processors;
	}

	public URI getWorkflowIdentifier() {
		return workflowIdentifier;
	}

	public void setControlLinks(Set<ControlLink> controlLinks) {
		this.controlLinks = controlLinks;
	}

	public void setDataLinks(Set<DataLink> datalinks) {
		dataLinks = datalinks;
	}

	public void setInputPorts(Set<InputWorkflowPort> inputPorts) {
		this.inputPorts.clear();
		for (InputWorkflowPort inputPort : inputPorts) {
			inputPort.setParent(this);
		}
	}

	public void setOutputPorts(Set<OutputWorkflowPort> outputPorts) {
		this.outputPorts.clear();
		for (OutputWorkflowPort outputPort : outputPorts) {
			outputPort.setParent(this);<commit_msg>sorted control and data links<commit_after>package uk.org.taverna.scufl2.api.core;

import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.UUID;

import uk.org.taverna.scufl2.api.common.AbstractNamedChild;
import uk.org.taverna.scufl2.api.common.Child;
import uk.org.taverna.scufl2.api.common.NamedSet;
import uk.org.taverna.scufl2.api.common.Ported;
import uk.org.taverna.scufl2.api.common.Visitor;
import uk.org.taverna.scufl2.api.common.WorkflowBean;
import uk.org.taverna.scufl2.api.container.WorkflowBundle;
import uk.org.taverna.scufl2.api.port.InputWorkflowPort;
import uk.org.taverna.scufl2.api.port.OutputWorkflowPort;

/**
 * @author <NAME>
 *
 */
public class Workflow extends AbstractNamedChild implements
		Child<WorkflowBundle>, Ported {

	public static final URI WORKFLOW_ROOT = URI
			.create("http://ns.taverna.org.uk/2010/workflow/");

	public static URI generateIdentifier() {
		return WORKFLOW_ROOT.resolve(UUID.randomUUID().toString() + "/");
	}

	private TreeSet<DataLink> dataLinks = new TreeSet<DataLink>();

	private TreeSet<ControlLink> controlLinks = new TreeSet<ControlLink>();

	private NamedSet<InputWorkflowPort> inputPorts = new NamedSet<InputWorkflowPort>();
	private NamedSet<OutputWorkflowPort> outputPorts = new NamedSet<OutputWorkflowPort>();
	private NamedSet<Processor> processors = new NamedSet<Processor>();
	private URI workflowIdentifier;
	private WorkflowBundle parent;

	public Workflow() {
		setWorkflowIdentifier(generateIdentifier());
		String workflowId = WORKFLOW_ROOT.relativize(getWorkflowIdentifier())
				.toASCIIString();
		setName("wf-" + workflowId);
	}

	@Override
	public boolean accept(Visitor visitor) {
		if (visitor.visitEnter(this)) {
			List<Iterable<? extends WorkflowBean>> children = new ArrayList<Iterable<? extends WorkflowBean>>();
			children.add(getInputPorts());
			children.add(getOutputPorts());
			children.add(getProcessors());
			children.add(getDataLinks());
			children.add(getControlLinks());
			outer: for (Iterable<? extends WorkflowBean> it : children) {
				for (WorkflowBean bean : it) {
					if (!bean.accept(visitor)) {
						break outer;
					}
				}
			}
		}
		return visitor.visitLeave(this);
	}

	public Set<ControlLink> getControlLinks() {
		return controlLinks;
	}

	public Set<DataLink> getDataLinks() {
		return dataLinks;
	}

	public NamedSet<InputWorkflowPort> getInputPorts() {
		return inputPorts;
	}

	public NamedSet<OutputWorkflowPort> getOutputPorts() {
		return outputPorts;
	}

	@Override
	public WorkflowBundle getParent() {
		return parent;
	}

	public NamedSet<Processor> getProcessors() {
		return processors;
	}

	public URI getWorkflowIdentifier() {
		return workflowIdentifier;
	}

	public void setControlLinks(Set<ControlLink> controlLinks) {
		this.controlLinks.clear();
		this.controlLinks.addAll(controlLinks);
	}

	public void setDataLinks(Set<DataLink> datalinks) {
		dataLinks.clear();
		dataLinks.addAll(datalinks);
	}

	public void setInputPorts(Set<InputWorkflowPort> inputPorts) {
		this.inputPorts.clear();
		for (InputWorkflowPort inputPort : inputPorts) {
			inputPort.setParent(this);
		}
	}

	public void setOutputPorts(Set<OutputWorkflowPort> outputPorts) {
		this.outputPorts.clear();
		for (OutputWorkflowPort outputPort : outputPorts) {
			outputPort.setParent(this);
{'fraction_non_alphanumeric': 0.11852179034157832, 'fraction_numerical': 0.004122497055359246, 'mean_word_length': 5.255064456721915, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 55, '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': '3229076', 'n_tokens_mistral': 2430, 'n_tokens_neox': 2239, 'n_words': 411}