package nl.cwi.reo.pr.autom.libr;

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

import nl.cwi.reo.pr.autom.UserDefinedAutomaton;
import nl.cwi.reo.pr.autom.UserDefinedInitializer;
import nl.cwi.reo.pr.autom.ConstraintFactory.Constraint;
import nl.cwi.reo.pr.autom.StateFactory.State;
import nl.cwi.reo.pr.misc.PortFactory.Port;

public class Replicator extends UserDefinedInitializer {

	@Override
	public boolean canInitialize(UserDefinedAutomaton automaton) {
		if (automaton == null)
			throw new NullPointerException();

		return automaton.countInputPorts() == 1
				&& automaton.countOutputPorts() == 2
				&& automaton.countExtralogicals() == 0;
	}

	@Override
	public void initialize(UserDefinedAutomaton automaton) {
		if (automaton == null)
			throw new NullPointerException();

		Port[] inputPorts = automaton.getInputPorts();
		Port[] outputPorts = automaton.getOutputPorts();
		// Extralogical[] extralogicals = automaton.getExtralogicals();

		State state = automaton.addThenGetState(true);

		List<Port> ports;
		Constraint constraint;

		ports = Arrays.asList(inputPorts[0], outputPorts[0], outputPorts[1]);
		constraint = automaton.newConstraint(Arrays.asList(automaton
				.newLiteral(true, automaton.newTerm(inputPorts[0]),
						automaton.newTerm(outputPorts[0])), automaton
				.newLiteral(true, automaton.newTerm(inputPorts[0]),
						automaton.newTerm(outputPorts[1]))));
		automaton.addOrKeepTransition(state, state, ports, constraint);
	}
}

@@ -28,16 +28,44 @@
 .libr;%0A%0A
+import java.util.ArrayList;%0A
 import j
@@ -262,16 +262,67 @@
 traint;%0A
+import nl.cwi.reo.pr.autom.LiteralFactory.Literal;%0A
 import n
@@ -1103,36 +1103,291 @@
 orts
-;%0A%09%09Constraint constraint;%0A%0A
+ = new ArrayList%3CPort%3E();%0A%09%09List%3CLiteral%3E literals = new ArrayList%3CLiteral%3E();%0A%09%09Constraint constraint;%0A%09%09ports.add(inputPorts%5B0%5D);%0A%09%09for(Port p: outputPorts)%7B%0A%09%09%09ports.add(p);%0A%09%09%09literals.add(automaton.newLiteral(true, automaton.newTerm(inputPorts%5B0%5D),automaton.newTerm(p)));%0A%09%09%7D%0A//
 %09%09po
@@ -1451,19 +1451,36 @@
 Ports%5B1%5D
+,outputPorts%5B2%5D
 );%0A
+//
 %09%09constr
@@ -1526,32 +1526,34 @@
 sList(automaton%0A
+//
 %09%09%09%09.newLiteral(
@@ -1584,32 +1584,34 @@
 inputPorts%5B0%5D),%0A
+//
 %09%09%09%09%09%09automaton.
@@ -1646,16 +1646,18 @@
 tomaton%0A
+//
 %09%09%09%09.new
@@ -1704,16 +1704,18 @@
 ts%5B0%5D),%0A
+//
 %09%09%09%09%09%09au
@@ -1746,17 +1746,178 @@
 rts%5B1%5D))
-)
+,automaton%0A//%09%09%09%09.newLiteral(true, automaton.newTerm(inputPorts%5B0%5D),%0A//%09%09%09%09%09%09automaton.newTerm(outputPorts%5B2%5D))));%0A%09%09constraint = automaton.newConstraint(literals
 );%0A%09%09aut

change Replicator lykos class to accepte multiple output