HiddenFromGUIInfo.java 8.69 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
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
package jcircus.parallelism;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Vector;

import jcircus.complementaryenvs.ChanComplexCommEnv;
import jcircus.complementaryenvs.ChanDimEnv;
import jcircus.complementaryenvs.ChanTransMSEnv;
import jcircus.complementaryenvs.Coadj2SimpleSynchTransEnv;
import jcircus.translator.Translator2Java;

public class HiddenFromGUIInfo {
private HashMap <String, String> map;
private HashMap <String, Vector <String>> reversemap;
private HashMap <String, Boolean> hasHidden;
private HashMap <String, Boolean> putChannelsDecl;
private HashMap <String, Boolean> putChannelsAtt;
private HashMap <String, Boolean> putChannelsActionPerformed;

public void putPutDecl (String chan, Boolean put) {
if (putChannelsDecl.containsKey(chan))
this.putChannelsDecl.remove(chan);
this.putChannelsDecl.put(chan, put);
}
public Boolean getPutDecl (String chan) {
if (this.putChannelsDecl.get(chan) == null) {
return false;
}
return this.putChannelsDecl.get(chan);
}

public void putPutAtt (String chan, Boolean put) {
if (putChannelsAtt.containsKey(chan))
this.putChannelsAtt.remove(chan);
this.putChannelsAtt.put(chan, put);
}
public Boolean getPutAtt (String chan) {
if (this.putChannelsAtt.get(chan) == null) {
return false;
}
return this.putChannelsAtt.get(chan);
}

public void putPutActionPerformed (String chan, Boolean put) {
if (putChannelsActionPerformed.containsKey(chan))
this.putChannelsActionPerformed.remove(chan);
this.putChannelsActionPerformed.put(chan, put);
}
public Boolean getPutActionPerformed (String chan) {
if (this.putChannelsActionPerformed.get(chan) == null) {
return false;
}
return this.putChannelsActionPerformed.get(chan);
}

private Vector <String> mainChannels = new Vector <String> ();
private Vector <String> coadjChannels = new Vector <String> ();
public HiddenFromGUIInfo () {
this.map = new LinkedHashMap <String, String> ();
this.reversemap = new LinkedHashMap <String, Vector <String>> ();
this.hasHidden = new LinkedHashMap <String, Boolean> ();
this.putChannelsDecl = new LinkedHashMap <String, Boolean> ();
this.putChannelsAtt = new LinkedHashMap <String, Boolean> ();
this.putChannelsActionPerformed = new LinkedHashMap <String, Boolean> ();
}
private void putMainChannel (String mainChannel) {
if (!mainChannels.contains(mainChannel))
mainChannels.add(mainChannel);
}
private void putCoadjChannel (String coadj) {
if (!coadjChannels.contains(coadj))
coadjChannels.add(coadj);
}
public Vector <String> getMainChannels () {
return this.mainChannels;
}
public Vector <String> getCoadjChannels () {
return this.coadjChannels;
}
public void put (String hidden, String chan) {
putMainChannel (chan);
putCoadjChannel (hidden);
if (!this.map.containsKey(hidden))
this.map.put(hidden, chan);
}
public String get (String hidden) {
return this.map.get(hidden);
}
public HashMap <String, String> getMap () {
return this.map;
}
private void addWithoutDuplicate (Vector <String> target, Vector <String> add) {
for (int i = 0; i < add.size(); i++) {
if (!target.contains(add.elementAt(i))) {
target.addElement(add.elementAt(i));
}
}
}
public void reversePut (String chan, Vector <String> hidden) {
if (this.mainChannels.contains(chan)) {
Vector <String> newhid = new Vector <String> ();
if (this.reverseGet(chan) != null)
newhid.addAll(this.reverseGet(chan));
addWithoutDuplicate (newhid, hidden);
this.reversemap.remove(chan);
this.reversemap.put(chan, newhid);
}
else {
this.reversemap.put(chan, hidden);
}
}
public Vector <String> reverseGet (String chan) {
//reverseGet retorna os canais coadjuvantes do canal principal + o próprio canal principal. Ex:
//reverseGet ("chan") = ["chan, "chan0", "chan1", "chan2"]
Vector <String> reverseget = this.reversemap.get(chan);
if (reverseget == null) {
//Se reverseget for vazio,
//significa que o canal não tem canais coadjuvantes, e portanto não foi renomeado.
//Isso tudo significa que ele não precisou de intercalação forçada. Retornamos um vector com o seu nome por facilidade de implementação
Vector <String> itself = new Vector <String> ();
itself.addElement(chan);
return itself;
}
else
return reverseget;
}
public Vector <String> reverseGetWithoutMainChannel (String chan) {
//reverseGetWithoutMainChannel retorna os canais coadjuvantes do canal principal
//difere de reverseGet porque este não retorna o canal principal. Ex:
//reverseGet ("chan") = ["chan0", "chan1", "chan2"]
Vector <String> withoutmainchannel = new Vector <String> (this.reverseGet(chan));
withoutmainchannel.remove(chan);
return new Vector <String> (withoutmainchannel);
}
public void put (String chan, Vector <String> hidden) {
int vecsize = hidden.size();
for (int i = 0; i < vecsize; i++) {
this.put(hidden.elementAt (i), chan);
this.reversePut(chan, hidden);
}
this.hasHidden.put(chan, true);
}
public boolean hiddenGet (String chan) {
if (hasHidden.containsKey(chan))
return hasHidden.get(chan);
else {
return false;
}
}
public static Vector <String> toVector (String [] s) {
Vector <String> vec = new Vector <String> ();
for (int i = 0; i < s.length; i++) {
vec.add(s [i]);
}
return vec;
}
//readOrWrite =
//0, se READ
//1, se WRITE
//Se nem 0 nem 1, SYNC
private static String syncKind (boolean simpleSync, int readOrWrite, String chanName, int dim/*, String content*/) {
if (!simpleSync) {
return "timerSync(area, new int [] {0}, finalvaluesstr" + /*content +*/ ")/*syncKind*/";
}
else {
if (readOrWrite == 1)
//return "guiTimerSimpleWrite (values " + Translator2Java.guibracketized (dim - 1) + ", area, finalvaluesstr)/*syncKind*/";
return "timerSync(area, new int [] {0}, finalvaluesstr" + /*content +*/ ")/*syncKindTimerSimpleWrite*/";
else //if (readOrWrite == 1)
return "guiTimerSimpleRead (area, finalvaluesstr);";
}
}
public static String hiddenSyncCode (Vector <String> hiddenChans,
ChanComplexCommEnv cce, ChanDimEnv cde, Coadj2SimpleSynchTransEnv c2sste,
int readOrWrite, HiddenFromGUIInfo hid/*, String content*/) {
String str = "";
str = str + "\n\t\tSystem.out.println (\"btn time millis: \" + System.currentTimeMillis());\n";
str = str + "\t\tfinal String finalvaluesstr = valuesstr;\n";
Vector <String> mainChannels = hid.getMainChannels();
for (int i = 0; i < hiddenChans.size(); i++) {
String currentChannel = hiddenChans.elementAt(i);
boolean isComplex = cce.get (currentChannel);
Integer dimension = cde.get (currentChannel);
boolean simpleSync = c2sste.get (currentChannel);
String syncKind = syncKind (simpleSync, readOrWrite, currentChannel, dimension/*, content*/);
String bracketizeds = (
isComplex?
Translator2Java.ccBracketizedsValues (dimension, currentChannel) :
Translator2Java.bracketizedsValues (dimension)
);
if (!mainChannels.contains(currentChannel)) {
String mainChannelOfCurrentChannel = hid.get(currentChannel);
Vector <String> reverseWithoutMain = hid.reverseGetWithoutMainChannel (mainChannelOfCurrentChannel);
if (reverseWithoutMain.size() <= 1) {
str = str + "\t\t/*Deprecated condition in this line...*/ \n";

/*"\t\tCSProcess p_" + mainChannelOfCurrentChannel
+ " = new CSProcess () {public void run () {"
+ mainChannelOfCurrentChannel + "" +
bracketizeds + "." +
syncKind + ";}};\n";*/
}
else {
str = str +
"\t\tCSProcess p_" + currentChannel
+ " = new CSProcess () {public void run () {"
+ currentChannel + "" +
bracketizeds/*dimCode*/ + "." +
syncKind + ";}};/*****/\n";
System.out.print ("");
}
}
else {
str = str +
"\t\tCSProcess p_" + currentChannel
+ " = new CSProcess () {public void run () {"
+ currentChannel + "" +
bracketizeds + "." +
syncKind + ";}};/***/\n";
}
}
for (int i = 0; i < hiddenChans.size(); i++) {
String currentChannel = hiddenChans.elementAt(i);
if (!mainChannels.contains(currentChannel)) {
String mainChannelOfCurrentChannel = hid.get(currentChannel);
Vector <String> reverseWithoutMain = hid.reverseGetWithoutMainChannel (mainChannelOfCurrentChannel);
if (reverseWithoutMain.size() <= 1) {
str = str +
" p_" + mainChannelOfCurrentChannel + "";
str = str + ".run();\n";
}
else {
str = str +
" p_" + currentChannel + "";
str = str + ".run();\n";
}
}
}
return str;
}
}