<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 Jul 2, 2005
 */
package org.globus.cog.karajan.arguments;

import java.util.ArrayList;
import java.util.List;

import org.globus.cog.karajan.util.TypeUtil;

public class OrderedParallelVariableArguments extends AbstractWriteOnlyVariableArguments {
	private final VariableArguments dest;
	private final OrderedParallelVariableArguments prev;
	private OrderedParallelVariableArguments next;
	private List buffer;
	private boolean closed, prevClosed;

	public OrderedParallelVariableArguments(VariableArguments dest,
			OrderedParallelVariableArguments prev) {
		this.dest = dest;
		this.prev = prev;
		if (prev != null) {
			prev.next = this;
		}
	}

	private final boolean isPrevClosed() {
		if (prevClosed) {
			return true;
		}
		if (prev == null) {
			prevClosed = true;
			return true;
		}
		else {
			prevClosed = prev.isClosed();
			return prevClosed;
		}
	}

	private void initBuffer() {
		if (buffer == null) {
			buffer = new ArrayList();
		}
	}

	public final boolean isClosed() {
		return closed && isPrevClosed();
	}

	public synchronized void close() {
		this.closed = true;

		if (isPrevClosed()) {
			flushBuffer();
		}

		if (next != null && isPrevClosed()) {
			next.prevClosed();
		}
	}

	private void flushBuffer() {
		if (buffer != null) {
			dest.appendAll(buffer);
			buffer = null;
		}
	}

	protected synchronized void prevClosed() {
		flushBuffer();

		if (closed && next != null) {
			next.prevClosed();
		}
	}

	public void merge(VariableArguments args) {
		appendAll(args.getAll());
	}

	public synchronized void append(Object value) {
		if (isPrevClosed()) {
			dest.append(value);
		}
		else {
			initBuffer();
			buffer.add(value);
		}
	}

	public synchronized void appendAll(List args) {
		if (isPrevClosed()) {
			dest.appendAll(args);
		}
		else {
			initBuffer();
			buffer.addAll(args);
		}
	}

	public String toString() {
		if (buffer != null) {
			return "-" + TypeUtil.listToString(buffer) + "-";
		}
		else {
			return "-||-";
		}
	}

	public OrderedParallelVariableArguments getNext() {
		return next;
	}

	public boolean isCommutative() {
		return dest.isCommutative();
	}
}
<commit_msg>I think I fixed a concurrency bug<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 Jul 2, 2005
 */
package org.globus.cog.karajan.arguments;

import java.util.ArrayList;
import java.util.List;

import org.globus.cog.karajan.util.TypeUtil;

public class OrderedParallelVariableArguments extends AbstractWriteOnlyVariableArguments {
	private final VariableArguments dest;
	private final OrderedParallelVariableArguments prev;
	private OrderedParallelVariableArguments next;
	private List buffer;
	private boolean closed, prevClosed;

	public OrderedParallelVariableArguments(VariableArguments dest,
			OrderedParallelVariableArguments prev) {
		this.dest = dest;
		this.prev = prev;
		if (prev != null) {
			prev.next = this;
		}
	}

	private synchronized boolean isPrevClosed() {
		if (prev == null) {
			return true;
		}
		else {
			return prevClosed;
		}
	}

	private void initBuffer() {
		if (buffer == null) {
			buffer = new ArrayList();
		}
	}

	public final boolean isClosed() {
		return closed && isPrevClosed();
	}

	public synchronized void close() {
		boolean prevClosed = isPrevClosed();

		if (prevClosed) {
			flushBuffer();
		}

		if (next != null && prevClosed) {
			next.prevClosed();
		}
		this.closed = true;
	}

	private void flushBuffer() {
		if (buffer != null) {
			dest.appendAll(buffer);
			buffer = null;
		}
	}

	protected synchronized void prevClosed() {
		flushBuffer();
		
		prevClosed = true;

		if (closed && next != null) {
			next.prevClosed();
		}
	}

	public void merge(VariableArguments args) {
		appendAll(args.getAll());
	}

	public synchronized void append(Object value) {
		if (isPrevClosed()) {
			dest.append(value);
		}
		else {
			initBuffer();
			buffer.add(value);
		}
	}

	public synchronized void appendAll(List args) {
		if (isPrevClosed()) {
			dest.appendAll(args);
		}
		else {
			initBuffer();
			buffer.addAll(args);
		}
	}

	public String toString() {
		if (buffer != null) {
			return "-" + TypeUtil.listToString(buffer) + "-";
		}
		else {
			return "-||-";
		}
	}

	public OrderedParallelVariableArguments getNext() {
		return next;
	}

	public boolean isCommutative() {
		return dest.isCommutative();
	}
}

{'fraction_non_alphanumeric': 0.1693889897156685, 'fraction_numerical': 0.002016535591853196, 'mean_word_length': 2.749055177626606, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5533024', 'n_tokens_mistral': 1712, 'n_tokens_neox': 1489, 'n_words': 397}