CreatorChannelFunction.java 3.57 KB
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
/*
* 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> 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 CreatorChannelFunction(LinkedList<Instance> i, LinkedList<Protocols> 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_<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;

}
}