je fait ce bloc dans la class destination juste après l'accolade de class car je le veux global mais ça marche pas et j'ai déjà changer le type d'exception comme vous m'avez dit :cry:
Version imprimable
je fait ce bloc dans la class destination juste après l'accolade de class car je le veux global mais ça marche pas et j'ai déjà changer le type d'exception comme vous m'avez dit :cry:
dans le main je faitCode:
1
2
3
4
5
6
7
8
9 public static int nbLigneGlob; public static int nbColonneGlobT; public static int nbColonneGlobTCP; Vector <Integer>a= MatricePreT.getTaille(); nbLigneGlob = a.get(0); nbColonneGlobT= a.get(1); nbColonneGlobTCP=a.get(2);
l'affichageCode:
1
2
3
4 System.out.println("le nb ligne globale est :"+nbLigneGlob); System.out.println("le nb colonne globaleT est :"+nbColonneGlobT); System.out.println("le nb colonne globaleTCP est :"+nbColonneGlobTCP);
le nb ligne globale est :226
le nb colonne globaleT est :117
le nb colonne globaleTCP est :52
--> dans le class tous MatricePreT ça marche bien mais comment je peux récuperer c'est résultat dans un autre class :(
et orsque je récupére directement les varible globale de class MatricePreT dans un autre variable globale de class cible
style
int n =MatricePreT.nbLigneGlob;
ça marche pas :?
Je pense que tu poses mal ton problème.
Pourquoi veux tu passer par des objets statiques?
Quelles sont les contraintes, s'il y en a, qui t'obligent à le faire?
Qui instancie tes objets source et destination?
Tu peux poster le code complet de MatricePreT
ainsi que celui de la classe qui appelle les valeurs ?
j'ai un grand projet et les class dépendent les uns des autres et je veux que je passe les taille dynamiquement pour que mon travail soit le plu possible automatique .
oui je peux bien sur . une minute
la classe source
Code:
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523 import java.io.IOException; import java.util.ArrayList; import java.util.Vector; import org.jdom2.Element; import org.jdom2.JDOMException; public class MatricePreT implements java.io.Serializable { public static ArrayList<Integer> recup = new ArrayList<Integer>(); public static int h ; public static ArrayList<Integer> TabPosXTiTj = new ArrayList<Integer>(); public static ArrayList<Integer> TabPosYTiTj = new ArrayList<Integer>(); public static int nbLigneGlob; public static int nbColonneGlobT; public static int nbColonneGlobTCP; public static Vector <Integer> getTaille()throws JDOMException, IOException{ TestXml xml = new TestXml() ; Element root = xml.getRoot("C:\\Users\\faten\\Desktop\\Tentative FiNALParcTool\\xmlparser\\src\\default.editeurparctool.xml") ; ArrayList<ContainTask> TaskC = xml.getContainTask(root); ArrayList<Place> Places = xml.getPlaces(root); Vector<Integer> tailleL_CT_CTCP= new Vector<Integer>(); ArrayList <ArrayList> Matrice = new ArrayList<ArrayList>(); Matrice.add(0,TaskC); Matrice.add(1,Places); int nbTache= TaskC.size(); int nbLigne=15; int nbPlaces=Places.size(); int nbColonneT=9; int nbColonneTCP=4; tailleL_CT_CTCP.add(0, nbPlaces+(7*nbTache)); tailleL_CT_CTCP.add(1, (nbColonneT*nbTache)); tailleL_CT_CTCP.add(2, (nbColonneTCP*nbTache)); return tailleL_CT_CTCP; } public static void matrice_Zero(int mat[][], int n, int m) { for (int i=0;i<n;i++) { for (int j=0;j<m;j++) { mat[i][j]=0; } } } public static void afficheenteteLigne()throws JDOMException, IOException { TestXml xml = new TestXml() ; Element root = xml.getRoot("C:\\Users\\faten\\Desktop\\Tentative FiNALParcTool\\xmlparser\\src\\default.editeurparctool.xml") ; ArrayList<ContainTask> TaskC = xml.getContainTask(root); ArrayList<Place> Places = xml.getPlaces(root); ArrayList <ArrayList> Matrice = new ArrayList<ArrayList>(); Matrice.add(0,TaskC); Matrice.add(1,Places); ArrayList<Place> Procstab = new ArrayList<Place>(); ArrayList<Place> TitoTi = new ArrayList<Place>(); // if (p.getIplace == p.getJplaace) ==> titoTi ArrayList<Place> TitoTj = new ArrayList<Place>(); int nbTache= TaskC.size(); int nbLigne=15; int nbPlaces=Places.size(); for(int i = 0; i <= 1; i++) { ArrayList s = Matrice.get(i); if(i==1) { for (int j = 0; j < s.size(); j++) { Place p = new Place(); p = (Place) s.get(j) ; if(p.getTypePlace()==9) // proc { Procstab.add(p) ; }//System.out.print(Procstab); if(p.getTypePlace()==10) { TitoTi.add(p) ; }//System.out.print(TitoTi); if(p.getTypePlace()==11) { TitoTj.add(p) ; } // System.out.print(TitoTj); } } } //System.out.println(); int tailleProcstab =Procstab.size(); int tailleTitoTi=TitoTi.size(); int tailleTitoTj=TitoTj.size(); int nb = nbTache*nbLigne+tailleTitoTi; int nb1 =nb+tailleProcstab ; for ( int i = 0 ; i < nbTache; i++ ) //ligne { for ( int l = 0 ; l <nbLigne; l++ ) {if (l ==0){System.out.println("P" +(i+1)+"Uncreated " );} if (l ==1){System.out.println("P" +(i+1)+"DeadLine " );} if (l ==2){System.out.println("P" +(i+1)+"RemainingPeriod" );} if (l ==3){System.out.println("P" +(i+1)+"Created " );} if (l ==4){System.out.println("P" +(i+1)+"ElapsedPeriod " );} if (l ==5){System.out.println("P" +(i+1)+"ReceivedData " );} if (l ==6){System.out.println("P" +(i+1)+"Ready " );} if (l ==7){System.out.println("P" +(i+1)+"Disabled " );} if (l ==8){System.out.println("P" +(i+1)+"Activated " );} if (l ==9){System.out.println("P" +(i+1)+"GetProc " );} if (l ==10){System.out.println("P" +(i+1)+"IncreExec " ); } if (l ==11){System.out.println("P" +(i+1)+"Maker " ); } if (l ==12){System.out.println("P" +(i+1)+"e" +(i+1)+" " ); } if (l ==13){System.out.println("P" +(i+1)+"ReleaseProc " );} if (l ==14){System.out.println("P" +(i+1)+"DataToSend " );} } } for ( int l = nbTache*nbLigne ; l <=nbTache*nbLigne+nbPlaces ; l++ ) { if(l>=nbTache*nbLigne && l <(nbTache*nbLigne+tailleTitoTi)) //TitoTi { for(l=nbTache*nbLigne;l <(nbTache*nbLigne+tailleTitoTi);l++) { System.out.println(TitoTi.get(l-nbTache*nbLigne)+" " );//T1toT1.....T1toT13 } } if(l>=nb && l < (nb + tailleProcstab+1)&& l <nb1) // Proc { for(l=nb;l <(nb + tailleTitoTi+1)&& l <nb1;l++) { System.out.println(Procstab.get(l-nb)+" ");//proc 1/2/3/4 } } if(l>=nb1 && l < (nb1+tailleTitoTj))//TitoTj { for(l=nb1;l <(nb1+tailleTitoTj);l++) { System.out.println(TitoTj.get(l-nb1)+" "); } } } } public static void afficheenteteColonne()throws JDOMException, IOException{ TestXml xml = new TestXml() ; Element root = xml.getRoot("C:\\Users\\faten\\Desktop\\Tentative FiNALParcTool\\xmlparser\\src\\default.editeurparctool.xml") ; ArrayList<ContainTask> TaskC = xml.getContainTask(root); ArrayList<Place> Places = xml.getPlaces(root); int nbTache= TaskC.size(); int nbColonne=9; int nbPlaces=Places.size(); System.out.print(" "); for ( int j = 0 ; j < nbTache; j++ ) //colonne { System.out.print(" "); for ( int k = 0 ; k <nbColonne; k++ ) { System.out.print(" "); if (k ==0){System.out.print("T"+(j+1)+"Creation" );} if (k ==1) {System.out.print("T" +(j+1)+"IncremtPeriod" );} if (k ==2) {System.out.print("T" +(j+1)+"Reset" );} if (k ==3) {System.out.print("T" +(j+1)+"Activation" );} if (k ==4) {System.out.print("T" +(j+1)+"Execution" );} if (k ==5) {System.out.print("T" +(j+1)+"Incrementing " );} if (k ==6) {System.out.print("T" +(j+1)+"Receiving" );} if (k ==7) {System.out.print("T" +(j+1)+"Releasing" );} if (k ==8) {System.out.print("T" +(j+1)+"Sending" );} } }System.out.println(); } public static void affiche(int mat[][], int n, int m)throws JDOMException, IOException { //afficheenteteLigne(); afficheenteteColonne(); for (int i=0;i<n;i++) {System.out.print(" "); for (int j=0;j<m;j++) { System.out.print(mat[i][j]); } System.out.println(); } } public static int getIndexTlocal (String Nom_T) { int index=-1; if(Nom_T.contains("Creation")){return index = 0;} if(Nom_T.contains("IncremtPeriod")){return index = 1;} if(Nom_T.contains("Reset")){return index = 2;} if(Nom_T.contains("Activation")){return index = 3;} if(Nom_T.contains("Execution")){return index = 4;} if(Nom_T.contains("Incrementing ")){return index = 5;} if(Nom_T.contains("Receiving" )){return index = 6;} if(Nom_T.contains("Releasing" )){return index = 7;} if(Nom_T.contains("Sending" )){return index = 8;} return index; } public static int getIndexTFromString (String Nom_T) { int i=-1; if (Nom_T.contains("Creation")) { String sub ="" ; int posT = Nom_T.indexOf("T") ; int posC = Nom_T.indexOf("C") ; sub = Nom_T.substring(posT+1,posC) ; return i = Integer.parseInt(sub) ; } if (Nom_T.contains("IncremtPeriod")) { String sub ="" ; int posT = Nom_T.indexOf("T") ; int posI = Nom_T.indexOf("I") ; sub = Nom_T.substring(posT+1,posI) ; return i = Integer.parseInt(sub) ; } if (Nom_T.contains("Reset")) { String sub ="" ; int posT = Nom_T.indexOf("T") ; int posR = Nom_T.indexOf("R") ; sub = Nom_T.substring(posT+1,posR) ; return i = Integer.parseInt(sub) ; } if (Nom_T.contains("Activation")) { String sub ="" ; int posT = Nom_T.indexOf("T") ; int posA = Nom_T.indexOf("A") ; sub = Nom_T.substring(posT+1,posA) ; return i = Integer.parseInt(sub) ; } if (Nom_T.contains("Execution")) { String sub ="" ; int posT = Nom_T.indexOf("T") ; int posE = Nom_T.indexOf("E") ; sub = Nom_T.substring(posT+1,posE) ; return i = Integer.parseInt(sub) ; } if (Nom_T.contains("Incrementing")) { String sub ="" ; int posT = Nom_T.indexOf("T") ; int posI = Nom_T.indexOf("I") ; sub = Nom_T.substring(posT+1,posI) ; return i = Integer.parseInt(sub) ; } if (Nom_T.contains("Receiving")) { String sub ="" ; int posT = Nom_T.indexOf("T") ; int posR = Nom_T.indexOf("R") ; sub = Nom_T.substring(posT+1,posR) ; return i = Integer.parseInt(sub) ; } if (Nom_T.contains("Releasing")) { String sub ="" ; int posT = Nom_T.indexOf("T") ; int posR = Nom_T.indexOf("R") ; sub = Nom_T.substring(posT+1,posR) ; return i = Integer.parseInt(sub) ; } if (Nom_T.contains("Sending")) { String sub ="" ; int posT = Nom_T.indexOf("T") ; int posS = Nom_T.indexOf("S") ; sub = Nom_T.substring(posT+1,posS) ; return i = Integer.parseInt(sub) ; } return i ; } public static int getIndexglobal (String Nom_T) {int i ; i =getIndexTlocal(Nom_T)+(getIndexTFromString (Nom_T)-1)* 9 ; return i; } public static Vector<Integer> extraire_vecteurT( int mat[][],int index) { Vector<Integer>vecteur =new Vector<Integer>(); for (int i=0; i<mat.length;i++){ vecteur.add(mat[i][index]); } return vecteur ; } public static void initializepre_T(int matpreT[][])throws JDOMException, IOException {TestXml xml = new TestXml() ; Element root = xml.getRoot("C:\\Users\\faten\\Desktop\\Tentative FiNALParcTool\\xmlparser\\src\\default.editeurparctool.xml") ; ArrayList<ContainTask> TaskC = xml.getContainTask(root); ArrayList<Place> Places = xml.getPlaces(root); ArrayList<Inarcttp> INTTP = xml.getInputArcTTP(root); ArrayList <ArrayList> Matrice = new ArrayList<ArrayList>(); Matrice.add(0,TaskC); Matrice.add(1,Places); Matrice.add(2, INTTP); ArrayList<ContainTask>listinfoTaskC= new ArrayList<ContainTask>(); ArrayList<Integer>listPi= new ArrayList<Integer>(); ArrayList<Place> Procstab = new ArrayList<Place>(); ArrayList<Place> TitoTi = new ArrayList<Place>(); // if (p.getIplace == p.getJplaace) ==> titoTi ArrayList<Place> TitoTj = new ArrayList<Place>(); int nbTache= TaskC.size(); int nbLigne=15; int nbColonne=9; int nbPlaces=Places.size(); //System.out.println(); for(int i = 0; i <= 2; i++) { ArrayList s = Matrice.get(i); if(i==0) { for (int j = 0; j < s.size(); j++) { ContainTask taskc = new ContainTask(); taskc = (ContainTask) s.get(j); listinfoTaskC.add(taskc); listPi.add(listinfoTaskC.get(j).getPi()); //System.out.println(listPi); } } if(i==1) { for (int j = 0; j < s.size(); j++) { Place p = new Place(); p = (Place) s.get(j) ; if(p.getTypePlace()==9) // proc { Procstab.add(p) ; }//System.out.print(Procstab); if(p.getTypePlace()==10) { TitoTi.add(p) ; }//System.out.print(TitoTi); if(p.getTypePlace()==11) { TitoTj.add(p) ; } // System.out.print(TitoTj); } } if(i==2)// les Transition Temporelles DATA TO SEND /TSending / RELEASING Treleasing/ TtoT Reciving .... { for (int j = 0; j < s.size(); j++) { Inarcttp inTArc = new Inarcttp(); inTArc = (Inarcttp) s.get(j) ; int posX; // plus tard sera affecté par place.Type (les lignes) int posY ; // plus tard sera affecté par place.getI (les colonne) if(inTArc.getTypePlace()== 10) // TitoTj/Receiving { posX= inTArc.getIPlace() ;// + 3 CAR COMMENCE A PARTIR DE 0 /1/2/3 posY= inTArc.getJplace() ; // matpreT[posX][posY] = inTArc.getWeight(); //System.out.println(mat[posX][posY]); //System.out.println("[ "+posX +" , "+posY +"] w = " + inTArc.getWeight()); TabPosXTiTj.add(posX); TabPosYTiTj.add(posY); //System.out.println(TabPosXTiTj); //System.out.println(TabPosYTiTj); } } // System.out.println(TabPosXTiTj); // System.out.println(TabPosYTiTj); } } int taille=( nbTache * nbLigne); int tailletot = (Procstab.size()+TitoTi.size()+TitoTj.size()); int tailleProcstab =Procstab.size(); int tailleTitoTi=TitoTi.size(); int tailleTitoTj=TitoTj.size(); int nb = nbTache*nbLigne+tailleTitoTi; int nb1 =nb+tailleProcstab ; //System.out.println(tailletot); for (int l=0;l<nbTache ;l++) //pour remplir la grande matricePreT colonne { matpreT[0+l*15][0+l*9]= 1 ; //15 nbrde ligne de petite matrice ,9 nbclonne petite matrice ,i lindice de tache quon est entrain de travaillé sur matpreT[2+l*15][1+l*9]=1 ; matpreT[3+l*15][3+l*9]=1; matpreT[4+l*15][2+l*9]=listPi.get(l); //pi existe dont larray liste contenat task I avec leur info matpreT[5+l*15][3+l*9]=1; matpreT[7+l*15][3+l*9]=1 ; matpreT[9+l*15][4+l*9]=1; matpreT[10+l*15][5+l*9]=1; matpreT[14+l*15][8+l*9]=1 ; matpreT[15*nbTache+l][6+l*9] = 1;//titoti-->Recieving ArrayList<Integer> resultat = new ArrayList<Integer>(); //parcour de array liste content les X et retour des Y for (int k =0 ;k<TabPosXTiTj.size() ;k++) { if(TabPosXTiTj.get(k)==l) resultat.add(TabPosYTiTj.get(k)); } while(resultat.size()!=0) { //System.out.println(resultat.get(0)); matpreT[nb1+h][6*resultat.get(0)+9] = 1; h++; resultat.remove(0); } } //affiche( matpreT, taille+tailletot, nbColonne*nbTache); Vector <Integer>a= MatricePreT.getTaille(); nbLigneGlob = a.get(0); nbColonneGlobT= a.get(1); nbColonneGlobTCP=a.get(2); } public static void main(String args [])throws JDOMException, IOException {TestXml xml = new TestXml() ; Element root = xml.getRoot("C:\\Users\\faten\\Desktop\\Tentative FiNALParcTool\\xmlparser\\src\\default.editeurparctool.xml") ; ArrayList<ContainTask> TaskC = xml.getContainTask(root); ArrayList<Place> Places = xml.getPlaces(root); int nbTache= TaskC.size(); int nbLigne=15; int nbColonne=9; int nbPlaces=Places.size(); ArrayList<Place> Procstab = new ArrayList<Place>(); ArrayList<Place> TitoTi = new ArrayList<Place>(); // if (p.getIplace == p.getJplaace) ==> titoTi ArrayList<Place> TitoTj = new ArrayList<Place>(); int taille=( nbTache * nbLigne); int tailletot = (Procstab.size()+TitoTi.size()+TitoTj.size()); int [] [] matpreT = new int[nbPlaces+(7*nbTache)][nbColonne*nbTache] ; matrice_Zero( matpreT, nbPlaces+(7*nbTache), nbColonne*nbTache); initializepre_T( matpreT); affiche( matpreT, nbPlaces+(7*nbTache), nbColonne*nbTache); System.out.print(getIndexTlocal ("T1Reset")); System.out.print("#"+getIndexTFromString ("T1Reset")); System.out.print("####"+getIndexglobal ("T1Reset")); Vector<Integer> resultat= extraire_vecteurT(matpreT,getIndexglobal("T1Reset")); System.out.println(resultat); System.out.println("le nb ligne globale est :"+nbLigneGlob); System.out.println("le nb colonne globaleT est :"+nbColonneGlobT); System.out.println("le nb colonne globaleTCP est :"+nbColonneGlobTCP); //Serialisation try { XMLTools.encodeToFile(matpreT, "MatricePreT.xml"); } catch(Exception e) { e.printStackTrace(); } } }
la classse destinationCode:
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384 import java.util.*; import org.jdom2.Element; import org.jdom2.JDOMException; public class StateGraph_Construction { public static int n=226;//MatricePreT.nbLigneGlob; public static int m=117;//MatricePreT.nbColonneGlobT; public static int k=52;//MatricePreT.nbColonneGlobTCP; public static int recup; public static ArrayList<Integer> recupTfTotalT =new ArrayList<Integer>(); public static Vector<Integer> FTs = new Vector<Integer>() ; public static Vector<Integer> FTstcp = new Vector<Integer>() ; public static Vector<Integer> soustraction(Vector<Integer> vecteur1,Vector<Integer> vecteur2 ) {Vector<Integer> vecteurrecup = new Vector<Integer>(); for (int i=0; i<vecteur1.size()&& i<vecteur2.size() ; i++) { int valeur = vecteur1.get(i)- vecteur2.get(i); vecteurrecup.add(valeur); } return vecteurrecup; } public static Vector<Integer> addition(Vector<Integer> vecteur1,Vector<Integer> vecteur2 ) {Vector<Integer> vecteurrecup = new Vector<Integer>(); for (int i=0; i<vecteur1.size()&& i<vecteur2.size() ; i++) { int valeur = vecteur1.get(i)+ vecteur2.get(i); vecteurrecup.add(valeur); } return vecteurrecup; } public static int Comparaison(Vector<Integer> vecteurMarquage,Vector<Integer> vecteur2 ) { for (int i=0; i<vecteurMarquage.size()&& i<vecteur2.size() ; i++) { if (vecteurMarquage.get(i) <= vecteur2.get(i)); return 0; } return 1; } public static int getIndexTlocal (String Nom_T) { int index=-1; if(Nom_T.contains("Creation")){return index = 0;} if(Nom_T.contains("IncremtPeriod")){return index = 1;} if(Nom_T.contains("Reset")){return index = 2;} if(Nom_T.contains("Activation")){return index = 3;} if(Nom_T.contains("Execution")){return index = 4;} if(Nom_T.contains("Incrementing ")){return index = 5;} if(Nom_T.contains("Receiving" )){return index = 6;} if(Nom_T.contains("Releasing" )){return index = 7;} if(Nom_T.contains("Sending" )){return index = 8;} return index; } public static int getIndexTFromString (String Nom_T) { int i=-1; if (Nom_T.contains("Creation")) { String sub ="" ; int posT = Nom_T.indexOf("T") ; int posC = Nom_T.indexOf("C") ; sub = Nom_T.substring(posT+1,posC) ; return i = Integer.parseInt(sub) ; } if (Nom_T.contains("IncremtPeriod")) { String sub ="" ; int posT = Nom_T.indexOf("T") ; int posI = Nom_T.indexOf("I") ; sub = Nom_T.substring(posT+1,posI) ; return i = Integer.parseInt(sub) ; } if (Nom_T.contains("Reset")) { String sub ="" ; int posT = Nom_T.indexOf("T") ; int posR = Nom_T.indexOf("R") ; sub = Nom_T.substring(posT+1,posR) ; return i = Integer.parseInt(sub) ; } if (Nom_T.contains("Activation")) { String sub ="" ; int posT = Nom_T.indexOf("T") ; int posA = Nom_T.indexOf("A") ; sub = Nom_T.substring(posT+1,posA) ; return i = Integer.parseInt(sub) ; } if (Nom_T.contains("Execution")) { String sub ="" ; int posT = Nom_T.indexOf("T") ; int posE = Nom_T.indexOf("E") ; sub = Nom_T.substring(posT+1,posE) ; return i = Integer.parseInt(sub) ; } if (Nom_T.contains("Incrementing")) { String sub ="" ; int posT = Nom_T.indexOf("T") ; int posI = Nom_T.indexOf("I") ; sub = Nom_T.substring(posT+1,posI) ; return i = Integer.parseInt(sub) ; } if (Nom_T.contains("Receiving")) { String sub ="" ; int posT = Nom_T.indexOf("T") ; int posR = Nom_T.indexOf("R") ; sub = Nom_T.substring(posT+1,posR) ; return i = Integer.parseInt(sub) ; } if (Nom_T.contains("Releasing")) { String sub ="" ; int posT = Nom_T.indexOf("T") ; int posR = Nom_T.indexOf("R") ; sub = Nom_T.substring(posT+1,posR) ; return i = Integer.parseInt(sub) ; } if (Nom_T.contains("Sending")) { String sub ="" ; int posT = Nom_T.indexOf("T") ; int posS = Nom_T.indexOf("S") ; sub = Nom_T.substring(posT+1,posS) ; return i = Integer.parseInt(sub) ; } return i ; } public static int getIndexglobal (String Nom_T) {int i ; i =getIndexTlocal(Nom_T)+(getIndexTFromString (Nom_T)-1)* 9 ; return i; } public static ArrayList<Integer> SDtf_T()throws JDOMException, IOException { TestXml xml = new TestXml() ; Element root = xml.getRoot("C:\\Users\\faten\\Desktop\\Tentative FiNALParcTool\\xmlparser\\src\\default.editeurparctool.xml") ; ArrayList<TTP> TTPs =xml.getTransitionTTP(root); ArrayList<TTP>listinfoTTP =xml.getTransitionTTP(root); ArrayList<Integer> listinfoTfdy =new ArrayList<Integer>(); for (int j = 0; j < TTPs.size(); j++) { TTP t = new TTP(); t = (TTP) TTPs.get(j); listinfoTTP.add(t); listinfoTfdy.add(listinfoTTP.get(j).getTF()); } for (int i=0;i<13;i++) {recupTfTotalT.add(0+i*9,0); recupTfTotalT.add(1+i*9,0); recupTfTotalT.add(2+i*9,0); recupTfTotalT.add(3+i*9,0); recupTfTotalT.add(4+i*9,0); recupTfTotalT.add(5+i*9,0); recupTfTotalT.add(6+i*9,listinfoTfdy.get(0+i*2)); recupTfTotalT.add(7+i*9,listinfoTfdy.get(1+i*2)); recupTfTotalT.add(8+i*9,listinfoTfdy.get(26+i)); } return recupTfTotalT ; } public static int tf_T(int index) { int tf ; for (int i=0;i<recupTfTotalT.size();i++) { tf=recupTfTotalT.get(i); recup=tf; } return recup; } public static void initialise_Hl(Vector <Integer> valeur_HL) {for (int i=0;i<n;i++) { valeur_HL.add(i, 0); } } public static void set_Hl(Vector <Integer> valeur_HL,int indice,int valeur) { for (int i=0;i<n;i++) { valeur_HL.set(indice, valeur); } } public static int get_Hl(Vector <Integer> valeur_HL,int indice) { return valeur_HL.get(indice); } public static int CompareTF_hl(int tf,int hl ) { if (tf >= hl) {return 1; } return 0; } public static void Firability ( Vector<Integer> FTs,Vector<Integer> FTstcp)throws JDOMException, IOException {int [] [] matpreT = new int[n][m] ; int [] [] matpreTCP = new int[n][k] ; Vector<Integer> M = new Vector<Integer>(n) ; MatricePreT.matrice_Zero( matpreT, n, m); MatricePreT.initializepre_T( matpreT); MatricePreTCP.matrice_Zero( matpreT, n, k); MatricePreTCP.initializepre_TCP( matpreT); VecteurM.Vecteur_Zero( M,n); VecteurM.initializevecteur_T(M); for (int i=0;i<m;i++) { Vector<Integer>Vect2T = MatricePreT.extraire_vecteurT( matpreT,i); int valeurCompFTs=Comparaison(M,Vect2T);; FTs.add(valeurCompFTs); } for (int i=0;i<k;i++) { Vector<Integer>Vect2TCP= MatricePreTCP.extraire_vecteurT( matpreTCP, i); int valeurCompFTstcp=Comparaison(M,Vect2TCP); FTstcp.add(valeurCompFTstcp); } } public static void Firing ( Vector<Integer> FTs,Vector<Integer> FTstcp,Vector<Integer> M)throws JDOMException, IOException {int [] [] matpreT = new int[n][m] ; int [] [] matpreTCP = new int[n][k] ; int [] [] matpostT = new int[n][m] ; int [] [] matpostTCP = new int[n][k] ; Vector<Integer>VectpreT = MatricePreT.extraire_vecteurT( matpreT,MatricePreT.getIndexglobal("T1Reset")); Vector<Integer>VectpreTCP= MatricePreTCP.extraire_vecteurT( matpreTCP, MatricePreTCP.getIndexglobal("T13Allocation")); Vector<Integer>VectpostT = MatricePreT.extraire_vecteurT( matpreT,MatricePreT.getIndexglobal("T1Reset")); Vector<Integer>VectpostTCP= MatricePreTCP.extraire_vecteurT( matpreTCP, MatricePreTCP.getIndexglobal("T13Allocation")); VecteurM.Vecteur_Zero(M, n); VecteurM.initializevecteur_T(M); Vector<Integer>M1T =addition ( M ,soustraction(VectpostT,VectpreT)); Vector<Integer>M1tcp =addition (M ,soustraction(VectpostTCP,VectpreTCP)); } public static void Validity(Vector <Integer> FTs)throws JDOMException, IOException { int [] [] matpreT = new int[n][m] ; Vector<Integer> M0 = new Vector<Integer>(n) ; MatricePreT.matrice_Zero( matpreT, n, m); MatricePreT.initializepre_T( matpreT); Vector <Integer>valeur_Hl=new Vector <Integer>(); for (int i=0;i<m;i++) { Vector<Integer>Vect2T = MatricePreT.extraire_vecteurT( matpreT,i); int valeurCompFTs=Comparaison(M0,Vect2T);; FTs.add(valeurCompFTs); initialise_Hl(valeur_Hl); if (tf_T(i)==get_Hl(valeur_Hl,i)) {////////// code ????????? } } } public static int voisinage (Inarcttp inTArc1, Inarcttp inTArc2)throws JDOMException, IOException {TestXml xml = new TestXml() ; Element root = xml.getRoot("C:\\Users\\faten\\Desktop\\Tentative FiNALParcTool\\xmlparser\\src\\default.editeurparctool.xml") ; ArrayList<Inarcttp> INTTP = xml.getInputArcTTP(root); for (int j = 0; j < INTTP.size(); j++) { inTArc1 = (Inarcttp) INTTP.get(j) ; j++; inTArc2 = (Inarcttp) INTTP.get(j) ; while(inTArc1.getWeight()!=0 &&inTArc1.getWeight()!=0) { if(inTArc1.getInPutArcFromPlace()==inTArc2.getInPutArcFromPlace()&&inTArc1.getInPutArcToTransitionT()!=inTArc2.getInPutArcToTransitionT()) System.out.println ("voisinage entre"+inTArc1.getInputArcFromPROC()+"et"+inTArc1.getInputArcFromPROC() );return 1; } } System.out.println ("voisinage entre"+inTArc1.getInputArcFromPROC()+"et"+inTArc1.getInputArcFromPROC() );return 0; } /*outil pour construire le programme totale à imlémenter public static void Firing ( Vector<Integer> FTs,Vector<Integer> FTstcp,VecteurM M){} public static void Sub(VecteurMI MI,VecteurM M){} public static void ResetTimer(Vector<Integer> horlogeVTS){} public static void setIncrementTimer(Vector<Integer> horlogeFTS){} public static void StepSelection(Vector<Integer>FTstcp){} void dPFM (Vector dFTs ,VecteurM M,VecteurMI MI ,int Hl) {//variable local temporelle Vector<Integer> HlVTs= new Vector<Integer>(); Vector<Integer> HlFTs= new Vector<Integer>(); Vector<Integer> FTs= new Vector<Integer>(); Vector<Integer> FTstcp= new Vector<Integer>(); dFTs == null ; if(MatricePreT.Comparaison(M,V) || MatricePreTCP.comparaison(M,V ){ Firability (FTs,FTstcp); FTs = TemporalTransition (dFTs); FTstcp = CompoudTransition(dFTs); if (FTs !=null){ VTs=Validity (FTs); if (VTs !=null ){ Firing (VTs, M); Sub (MI, M); ResetTimer(Hl_VTs);} else if (FTstcp ==null ) {setIncrementTimer(HlFTs);} } else if (FTstcp != null ) { StepSelection(FTstcp); Firing(FTs,FTstcp ,M); Sub(MI,M);} } }//End dPFM */ public static void main(String args [])throws JDOMException, IOException{ int [] [] matpreT = new int[n][m] ; int [] [] matpreTCP = new int[n][m] ; Vector<Integer> M0 = new Vector<Integer>() ; MatricePreT.matrice_Zero( matpreT, n, m); MatricePreT.initializepre_T( matpreT); MatricePreTCP.matrice_Zero( matpreTCP, n, m); MatricePreTCP.initializepre_TCP(matpreTCP); VecteurM.Vecteur_Zero(M0, n); VecteurM.initializevecteur_T(M0); Vector<Integer>Vect2T = MatricePreT.extraire_vecteurT( matpreT,MatricePreT.getIndexglobal("T1Creation")); Vector<Integer>Vect2TCP= MatricePreTCP.extraire_vecteurT( matpreTCP, MatricePreTCP.getIndexglobal("T13Allocation")); System.out.println("le vecteur de transition T1Creation:"+ Vect2T); System.out.println("le vecteur Marquage initiale M0 :"+M0); int a=Comparaison(M0,Vect2T); System.out.println("le resultat de comparaison de M0 et vect2T est: "+a); //affichage FTs,FTstcp for (int i=0;i<m;i++) { int valeurCompFTs=Comparaison(M0,Vect2T);; int valeurCompFTstcp=Comparaison(M0,Vect2TCP); FTs.add(valeurCompFTs); FTstcp.add(valeurCompFTstcp); } System.out.println("lerecupTfTotalT contient "+ SDtf_T()); int b= tf_T(getIndexglobal("T13Sending") ); System.out.println("tf de T13Sending est :"+b); Vector <Integer> valeur_HL = new Vector <Integer>(); initialise_Hl(valeur_HL); int x= CompareTF_hl(tf_T(getIndexglobal("T13Sending")),get_Hl(valeur_HL,getIndexglobal("T13Sending"))); System.out.println("le resultat de comparaison entre TF et Hl de T13Sending est :"+x); System.out.println("FTs="+FTs); System.out.println("FTstcp="+FTstcp); Firing(FTs,FTstcp,M0); System.out.println("M aprés firing :"+M0); System.out.println("T1Reset: "+getIndexglobal("T1Creation")); System.out.println(m); } }
Pour te répondre : tu demandes comment tu peux déclarer une variable dans une classe et y accéder dans une autre.
Pour moi, le fait que cette variable soit static ne change pas grand chose au problème ...
Tu as une classe qui fait ton calcul :
Et une classe qui accède au résultat calculé dans A. (que ce soit un main ou autre chose d'ailleurs)Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 public class A { private int taille; public void calculTaille() //Avec tous les paramètres dont tu as éventuellement besoin { //Ici, tu mets ton code permettant de trouver la bonne taille. } public int getTaille() { return taille; } }
A partir de cette architecture simpliste, si ton résultat n'est pas le bon, c'est que ta méthode de calcul contient peut être des erreurs ...Code:
1
2
3
4
5
6
7
8
9 public class MonMain { public static void main(String[] args) { A maVariable = new A(); System.out.println(maVariable.getTaille()); } }
Oups, j'ai bien sur oublié d'appeler la méthode de calcul. Au propre ça donnerait quelque chose du genre :
Code:
1
2
3
4
5
6
7
8
9
10 public class MonMain { public static void main(String[] args) { A maVariable = new A(); maVariable.calculTaille(); //Avec les arguments nécessaires System.out.println(maVariable.getTaille()); } }
merci à vous tous :zoubi::arf: