Slt

j’aimerai savoir quelques informations sur les collections d’objets en occurrences les LinkedList et les ArrayList.

On peut les utiliser dans une classe jusqu’à combien au maximum. Je demande car je les utilise dans le programme ci dessous afin de :

Extraire les états et les transitions de deux automates représentés par des fichiers XML que je charge.

Essayer de calculer le produit asynchrone de ces 2 automates et stocker les attributs (États transitions, messages) de l’automate produit.

Au bout d’un moment de l’exécution cette erreur s’affiche :

Exception occurred during event dispatching:

java.lang.OutOfMemoryError: Java heap space

at java.util.Arrays.copyOfRange(Unknown Source)

at java.lang.String.<init>(Unknown Source)

at java.lang.StringBuilder.toString(Unknown Source)

at ProduitAutomates.calculProduit(ProduitAutomates.java:136)

at ProduitAutomates.chargerProtocole(ProduitAutomates.java:90)

at ProduitAutomates.<init>(ProduitAutomates.java:40)

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Iterator;
import java.util.List;
 
import org.jdom.*;
import org.jdom.input.SAXBuilder;
public class ProduitAutomates {
 
    //Les chemins des deux protocoles
    String cheminProtocole1;
    String cheminProtocole2;
 
    //**Les attributs de l'Ancien Automate
    public ArrayList<String> anciensEtats=new ArrayList<String>();
    public String ancienEtatinitial;
    public ArrayList<String> anciensEtatsFinals=new ArrayList<String>();
    public ArrayList<String> anciensMessages=new ArrayList<String>();
    public ArrayList<FonctionTransition> anciensTransitions=new ArrayList<FonctionTransition>();
 
    //**Les attributs du Nouveau Automate
    public ArrayList<String> newEtats=new ArrayList<String>();
    public String newEtatInitial;
    public ArrayList<String> newEtatsFinals=new ArrayList<String>();
    public ArrayList<String> newMessages=new ArrayList<String>();
    public ArrayList<FonctionTransition> newTransitions=new ArrayList<FonctionTransition>();
 
    //**Les attributs du Produits des deux Automates
    public ArrayList<EtatsProduit> prodEtats=new ArrayList<EtatsProduit>();
    public EtatsProduit prodEtatInitial=new EtatsProduit("","","","");
    public ArrayList<EtatsProduit> prodEtatsFinals=new ArrayList<EtatsProduit>();
    public ArrayList<String> prodMessages=new ArrayList<String>();
    public ArrayList<ProdFonctionTransition> prodTransitions=new ArrayList<ProdFonctionTransition>();
 
    public  ProduitAutomates(String chem1,String chem2){
        this.cheminProtocole1=chem1;
        this.cheminProtocole2=chem2;
        this.chargerProtocole(cheminProtocole1,cheminProtocole2);
    }
 
    public void chargerProtocole(String chemin1, String chemin2){
        SAXBuilder chargeur=new SAXBuilder();
        try {
            Document prot1=chargeur.build(new File(chemin1));
            Document prot2=chargeur.build(new File(chemin2));
            Element racine1=prot1.getRootElement();
            Element racine2=prot2.getRootElement();
            List<?> etats=racine1.getChild("Etats").getChildren();
            Iterator<?> it=etats.iterator();
            while(it.hasNext()){
                Element el=(Element)it.next();
                if (el.getAttributeValue("Type")=="Initial") this.ancienEtatinitial=el.getTextNormalize();
                if (el.getAttributeValue("Type")=="Final") this.anciensEtatsFinals.add(el.getTextNormalize());
                this.anciensEtats.add(el.getTextNormalize());
            }
 
            etats=racine1.getChild("Transitions").getChildren();
            it=etats.iterator();
            FonctionTransition ft=new FonctionTransition("","","");
            while(it.hasNext()){
                Element el=(Element)it.next();
                ft.etatSource=el.getAttributeValue("Etat_Source");
                ft.etatTerminal=el.getAttributeValue("Etat_Destination");
                ft.message=el.getTextNormalize();
                this.anciensTransitions.add(ft);
                this.anciensMessages.add(el.getTextNormalize());
            }
 
            etats=racine2.getChild("Etats").getChildren();
            it=etats.iterator();
            while(it.hasNext()){
                Element el=(Element)it.next();
                if (el.getAttributeValue("Type")=="Initial") this.newEtatInitial=el.getTextNormalize();
                if (el.getAttributeValue("Type")=="Final") this.newEtatsFinals.add(el.getTextNormalize());
                this.newEtats.add(el.getTextNormalize());
            }
 
            etats=racine2.getChild("Transitions").getChildren();
            it=etats.iterator();
            while(it.hasNext()){
                Element el=(Element)it.next();
                ft.etatSource=el.getAttributeValue("Etat_Source");
                ft.etatTerminal=el.getAttributeValue("Etat_Destination");
                ft.message=el.getTextNormalize();
                this.newTransitions.add(ft);
                this.newMessages.add(el.getTextNormalize());
            }
            calculProduit();
        } catch (JDOMException e) {
            // TODO Auto-generated catch block
            //e.printStackTrace();
            System.out.println("UNE ERREUR DE JDOM");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            //e.printStackTrace();
            System.out.println("UNE ERREUR DE CHEMIN");
        }
    }
 
    private void calculProduit(){
        String etatSourceAnc="",etatSourceNew="";
        String msgCourantAnc="",msgCourantNew="";
        String expReguliereAnc="", expReguliereNew="";
        String etatTerminalAnc="",etatTerminalNew="";
        LinkedList <String> ancEtatsCandidats=new LinkedList<String>();
        LinkedList<String> newEtatsCandidats=new LinkedList<String>();
 
        this.prodEtatInitial=new EtatsProduit(this.ancienEtatinitial,this.newEtatInitial,expReguliereAnc,expReguliereNew);
 
        //Le produit assynchrone du 1er protocole par rapport au 2sd
        ancEtatsCandidats.add(ancienEtatinitial);
        //Iterator<String> itEtatsAnc=ancEtatsCandidats.iterator();
 
        while (ancEtatsCandidats.size()!=0){
            etatSourceAnc=ancEtatsCandidats.getFirst();
            Iterator<String> itMsgAnc=anciensMessages.iterator();
 
            while (itMsgAnc.hasNext()){
                msgCourantAnc=itMsgAnc.next();
                etatTerminalAnc=transitionTouver(etatSourceAnc,msgCourantAnc,this.anciensTransitions);
                if (!etatTerminalAnc.equals("")){
                    expReguliereNew="";
                    newEtatsCandidats.add(newEtatInitial);
                    //Iterator<String> itEtatsNew=newEtatsCandidats.iterator();
 
                    while (newEtatsCandidats.size()!=0){
                        etatSourceNew=newEtatsCandidats.getFirst();
                        Iterator<String> itMsgNew=newMessages.iterator();
 
                        while (itMsgNew.hasNext()){
                            msgCourantNew=itMsgNew.next();
                            etatTerminalNew=transitionTouver(etatSourceNew,msgCourantNew,this.newTransitions);
                            if (!etatTerminalNew.equals("")){
                                expReguliereNew +=msgCourantNew+"(+)/";
                                this.prodMessages.add(msgCourantNew+"(+)");
                                this.prodEtats.add(new EtatsProduit(etatSourceAnc,etatTerminalNew,expReguliereAnc,expReguliereNew));
                                newEtatsCandidats.addLast(etatTerminalNew);
                            }
                        }
                        newEtatsCandidats.removeFirst();
 
                    }
 
                    ancEtatsCandidats.addLast(etatTerminalAnc);
                    expReguliereAnc +=msgCourantAnc+"(-)/";
                    this.prodMessages.add(msgCourantAnc+"(-)");
                    if (estEtatFinal(etatTerminalAnc,this.anciensEtatsFinals)&& estEtatFinal(etatTerminalNew,this.newEtatsFinals)){
                        this.prodEtatsFinals.add(new EtatsProduit(etatTerminalAnc,etatTerminalNew,expReguliereAnc,expReguliereNew));
                    }
                }  
            }
            ancEtatsCandidats.removeFirst();
 
        }
 
        //Le produit assynchrone du 2sd protocole par rapport au 1er
        expReguliereAnc=""; expReguliereNew="";
        newEtatsCandidats.add(newEtatInitial);
        //Iterator<String> itEtatsNew=newEtatsCandidats.iterator();
 
        while (newEtatsCandidats.size()!=0){
            etatSourceNew=newEtatsCandidats.getFirst();
            Iterator<String> itMsgNew=newMessages.iterator();
 
            while (itMsgNew.hasNext()){
                msgCourantNew=itMsgNew.next();
                etatTerminalNew=transitionTouver(etatSourceNew,msgCourantNew,this.newTransitions);
                if (!etatTerminalNew.equals("")){
                    expReguliereAnc="";
                    ancEtatsCandidats.add(ancienEtatinitial);
                    //itEtatsAnc=ancEtatsCandidats.iterator();
 
                    while (ancEtatsCandidats.size()!=0){
                        etatSourceAnc=ancEtatsCandidats.getFirst();
                        Iterator<String> itMsgAnc=anciensMessages.iterator();
 
                        while (itMsgAnc.hasNext()){
                            msgCourantAnc=itMsgAnc.next();
                            etatTerminalAnc=transitionTouver(etatSourceAnc,msgCourantAnc,this.anciensTransitions);
                            if (!etatTerminalAnc.equals("")){
                                expReguliereAnc +=msgCourantAnc+"(-)/";
                                this.prodMessages.add(msgCourantAnc+"(-)");
                                ancEtatsCandidats.addLast(etatTerminalAnc);
                            }
                        }
 
                        ancEtatsCandidats.removeFirst();
                    }
                    newEtatsCandidats.addLast(etatTerminalNew);
                    expReguliereNew +=msgCourantNew+"(+)/";
                    this.prodMessages.add(msgCourantNew+"(+)");
                }
            }
 
            newEtatsCandidats.removeFirst();
        }
    }
 
    //Méthode qui donne la transition dont l'étiquette et l'etat source sont passés en paramètres.
    private String transitionTouver(String etatSource,String message, ArrayList<FonctionTransition> lesTransitions){
        FonctionTransition ft=new FonctionTransition();
        boolean tr=false;
        Iterator<FonctionTransition> it=lesTransitions.iterator();
        while (it.hasNext() && !tr){
            ft=(FonctionTransition)it.next();
            if(ft.etatSource.equals(etatSource) && ft.message.equals(message)) tr=true;
        }
        return ft.etatTerminal;
    }
 
    //Méthode qui determine si un état est oui ou non un état final.
    private boolean estEtatFinal(String etat,ArrayList<String> list){
        boolean res=false;
        Iterator<String> it=list.iterator();
        while (it.hasNext() && !res){
            String str=(String)it.next();
            if (str.equals(etat)) res=true;
        }
        return res;
    }
 
    // Méthode qui affiche la liste des éléments
    public void affichier (String titre, LinkedList<?> list){
        Iterator<?> it=list.iterator();
        System.out.println("\n"+titre+":");
        while(it.hasNext()){
            System.out.println("Valeur= "+it.next());
        }
    }