/**
 * 
 */
package org.spoofax.sunshine.services.messages;

import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spoofax.sunshine.model.messages.IMessage;
import org.spoofax.sunshine.pipeline.ISinkMany;
import org.spoofax.sunshine.pipeline.diff.Diff;
import org.spoofax.sunshine.pipeline.diff.MultiDiff;

/**
 * @author Vlad Vergu <v.a.vergu add tudelft.nl>
 * 
 */
public class MessageSink implements ISinkMany<IMessage> {
	private static final Logger logger = LogManager.getLogger(MessageSink.class.getName());
	private Set<IMessage> messages = new HashSet<IMessage>();

	@Override
	public void sink(MultiDiff<IMessage> product) {
		logger.info("Sinking {} messages", product.size());

		final Iterator<Diff<IMessage>> diffIter = product.iterator();
		while (diffIter.hasNext()) {
			final Diff<IMessage> diff = diffIter.next();
			switch (diff.getDiffKind()) {
			case ADDITION:
				messages.add(diff.getPayload());
				break;
			case DELETION:
				messages.remove(diff.getPayload());
				break;
			default:
				throw new UnsupportedOperationException("MessageSink does not support DiffKind "
						+ diff.getDiffKind() + " for IMessage");
			}
		}
	}

	public Collection<IMessage> getMessages() {
		return new HashSet<IMessage>(messages);
	}

}

@@ -113,35 +113,8 @@
 et;%0A
-import java.util.Iterator;%0A
 impo
@@ -809,464 +809,86 @@
 %0A%09%09f
-inal Iterator%3CDiff%3CIMessage%3E%3E diffIter = product.iterator();%0A%09%09while (diffIter.hasNext()) %7B%0A%09%09%09final Diff%3CIMessage%3E diff = diffIter.next();%0A%09%09%09switch (diff.getDiffKind()) %7B%0A%09%09%09case ADDITION:%0A%09%09%09%09messages.add(diff.getPayload());%0A%09%09%09%09break;%0A%09%09%09case DELETION:%0A%09%09%09%09messages.remove(diff.getPayload());%0A%09%09%09%09break;%0A%09%09%09default:%0A%09%09%09%09throw new UnsupportedOperationException(%22MessageSink does not support DiffKind %22%0A%09%09%09%09%09%09+ diff.getDiffKind() + %22 for IMessage%22);%0A%09%09%09%7D
+or (Diff%3CIMessage%3E msgDiff : product) %7B%0A%09%09%09messages.add(msgDiff.getPayload());
 %0A%09%09%7D

Fix some insane code in the MessageSink