/* * 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 */ //falta receber uma string public class CreatorChannelFunction { private LinkedList instance; private String creatorChannel = ""; private LinkedList prot_imp_getChannel; //string com definição de pro_imp e seu canal private LinkedList prot; private LinkedList nomecanal; private String eventoprotocol1 = ""; private String eventoprotocol2 = ""; public CreatorChannelFunction(LinkedList i, LinkedList p){ this.instance = i; this.prot = p; //nomeando protocolos para função GET_CHANNEL nomecanal = new LinkedList<>(); nomecanal.add(p.get(0).getCanal().getName().replace(".","_")); nomecanal.add(p.get(1).getCanal().getName().replace(".","_")); prot_imp_getChannel = new LinkedList<>(); prot_imp_getChannel.add("PROT_IMP_"+ instance.get(0).getName() + "_"+nomecanal.get(0)); prot_imp_getChannel.add("PROT_IMP_"+ instance.get(1).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"; for (Instance instance1 : instance) { creatorChannel = creatorChannel + "\t(" + instance1.getName() + ", { "; for (int j = 0; j < instance1.getChannel().size(); j++) { if (j == instance1.getChannel().size() - 1) { creatorChannel = creatorChannel + instance1.getChannel().get(j).getName(); } else { creatorChannel = creatorChannel + instance1.getChannel().get(j).getName() + ","; } } cont++; //if (cont == instance.size() - 1) { creatorChannel = creatorChannel + " }),"; creatorChannel = creatorChannel + "\n\n"; //} else { // creatorChannel = creatorChannel + " })"; // creatorChannel = creatorChannel + "\n"; //} } creatorChannel = creatorChannel + "\t"; //definição dos canais dos protocolos //EX: PROT_IMP__ = {} 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; } }