/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package CREATOR_CONDICTIONS_RULES;
import LOGIC.Instance;
import LOGIC.Protocols;
import java.util.LinkedList;
/**
*
* @author sarah
*/
class CreatorChannelFunctionUnary {
private Instance instance;
private String creatorChannel = "";
private LinkedList<String> prot_imp_getChannel; //string com definição de pro_imp e seu canal
private LinkedList<Protocols> prot;
private LinkedList<String> nomecanal;
private String eventoprotocol1 = "";
private String eventoprotocol2 = "";
public CreatorChannelFunctionUnary(Instance i, LinkedList<Protocols> p) {
this.instance = i;
this.prot = p;
nomecanal = new LinkedList<>();
nomecanal.add(p.get(0).getCanal().getName().replace(".", "_"));
nomecanal.add(p.get(1).getCanal().getName().replace(".", "_"));
//nomeando protocolos para função GET_CHANNEL
prot_imp_getChannel = new LinkedList<>();
prot_imp_getChannel.add("PROT_IMP_" + instance.getName()
+ "_" + nomecanal.get(0));
prot_imp_getChannel.add("PROT_IMP_" + instance.getName()
+ "_" + nomecanal.get(1));
//pegando o nome do evento que passei por paramentro no protocolo
int pr1, pr2, pr3, pr4;
pr1 = p.get(0).getProtocol().indexOf("(");
pr2 = p.get(0).getProtocol().lastIndexOf(")");
eventoprotocol1 = p.get(0).getProtocol().substring(pr1 + 1, pr2);
pr3 = p.get(1).getProtocol().indexOf("(");
pr4 = p.get(1).getProtocol().lastIndexOf(")");
eventoprotocol2 = p.get(1).getProtocol().substring(pr3 + 1, pr4);
}
public String creatorChannelFunction() {
// CHANNELS, INPUTS AND OUTPUTS
int cont = 0;
//channels
creatorChannel = creatorChannel + "\nGET_CHANNELS(P) =";
creatorChannel = creatorChannel + "\n \t let f =";
creatorChannel = creatorChannel + "\n \t < \n";
creatorChannel = creatorChannel + "\t(" + instance.getName() + ", { ";
for (int j = 0; j < instance.getChannel().size(); j++) {
if (j == instance.getChannel().size() - 1) {
creatorChannel = creatorChannel + instance.getChannel().get(j).getName();
} else {
creatorChannel = creatorChannel + instance.getChannel().get(j).getName() + ",";
}
}
cont++;
creatorChannel = creatorChannel + " }),";
creatorChannel = creatorChannel + "\n\n";
creatorChannel = creatorChannel + "\t";
//definição dos canais dos protocolos
//EX: PROT_IMP_<contract>_<channel> = {<channel>}
creatorChannel = creatorChannel + "(" + prot_imp_getChannel.get(0) + ",{" +
eventoprotocol1 + "}),";
creatorChannel = creatorChannel + "\n\n\t";
creatorChannel = creatorChannel + "(" + prot_imp_getChannel.get(1) + ",{" +
eventoprotocol2 + "})";
creatorChannel = creatorChannel + " \t > \n";
creatorChannel = creatorChannel + "\n \t within apply(f,P )";
return creatorChannel;
}
}