/* * 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 CreatorInputFunctionUnary { private LinkedList instance; private String creatorFunction = ""; private LinkedList prot_imp_inputs; private LinkedList prot; private LinkedList nomecanal; private String eventoprotocol1 = ""; private String eventoprotocol2 = ""; public CreatorInputFunctionUnary(Instance i,LinkedList p){ instance = new LinkedList<>(); instance.add(i); this.prot = p; nomecanal = new LinkedList<>(); nomecanal.add(p.get(0).getCanal().getName().replace(".","_")); nomecanal.add(p.get(1).getCanal().getName().replace(".","_")); prot_imp_inputs = new LinkedList<>(); //PROT_IMP prot_imp_inputs.add("PROT_IMP_"+ instance.get(0).getName() + "_"+nomecanal.get(0)); prot_imp_inputs.add("PROT_IMP_"+ instance.get(0).getName() + "_"+nomecanal.get(1)); //PROT_IMP_RIO prot_imp_inputs.add("PROT_IMP_"+instance.get(0).getName()+"_"+ nomecanal.get(0)+"_R_IO_"+ nomecanal.get(1)); prot_imp_inputs.add("PROT_IMP_"+instance.get(0).getName()+"_"+ nomecanal.get(1)+"_R_IO_"+ nomecanal.get(0)); //DUAL_PROT_RIO prot_imp_inputs.add("DUAL_PROT_IMP_"+instance.get(0).getName()+"_"+ nomecanal.get(0)+"_R_IO_"+ nomecanal.get(1)); // prot_imp_inputs.add("DUAL_PROT_IMP_"+instance.get(0).getName()+"_"+ nomecanal.get(1)+"_R_IO_"+ nomecanal.get(0)); //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 creatorInputFunction() { int cont = 0; //função inputs creatorFunction = creatorFunction + "\n"; // verificação para o contrato creatorFunction = creatorFunction + "\ninputs( P ) = "; creatorFunction = creatorFunction + "\n \t let f = \n\t<"; creatorFunction = creatorFunction + "\n \t ( " + instance.get(0).getName() + ", {| "; // coloca todos os canais de in associado com seus tipos. ex: {|c.1, c.2|} for (int i = 0; i < instance.get(0).getIn().size(); i++) { if (i == instance.get(0).getIn().size() - 1) { creatorFunction = creatorFunction + instance.get(0).getIn().get(i).getEvento(); } else { creatorFunction = creatorFunction + instance.get(0).getIn().get(i).getEvento() + ","; } } //if (cont == instance.size() - 1) { // creatorFunction = creatorFunction + " |})"; //} else { creatorFunction = creatorFunction + " |}),"; //} creatorFunction = creatorFunction + "\n\t"; creatorFunction = creatorFunction + "("+ prot_imp_inputs.get(0)+"," +"inputs_PROT_IMP(" +instance.get(0).getName()+","+ eventoprotocol1+ ")),"; creatorFunction = creatorFunction + "\n\n\t"; creatorFunction = creatorFunction + "("+ prot_imp_inputs.get(1)+ ","+"inputs_PROT_IMP(" +instance.get(0).getName()+","+ eventoprotocol2+ ")),"; creatorFunction = creatorFunction + "\n\n\t"; creatorFunction = creatorFunction + "("+ prot_imp_inputs.get(2)+"," +"inputs_R_IO("+prot_imp_inputs.get(0) +","+eventoprotocol1+","+ eventoprotocol2+")),"; creatorFunction = creatorFunction + "\n\n\t"; creatorFunction = creatorFunction + "("+ prot_imp_inputs.get(3)+ ","+"inputs_R_IO("+prot_imp_inputs.get(1) +","+eventoprotocol1+","+ eventoprotocol2+")),"; creatorFunction = creatorFunction + "\n\n\t"; creatorFunction = creatorFunction + "("+ prot_imp_inputs.get(4)+","+ "outputs("+prot_imp_inputs.get(2)+")),"; creatorFunction = creatorFunction + "\n\n\t"; creatorFunction = creatorFunction + "("+ prot_imp_inputs.get(5)+ ","+"outputs("+prot_imp_inputs.get(3)+"))"; creatorFunction = creatorFunction + "\n \t > \n"; creatorFunction = creatorFunction + "\n \t within apply(f, P )"; creatorFunction = creatorFunction + "\n\n"; return creatorFunction; } }