Pass around pointer to D2 as an argument to everything, rather than stash the pointer...
[IRC.git] / Robust / src / Benchmarks / mlp / directto / original-java / ConflictList.java
1 // This class keeps a list of conflicts.
2 // The conflicts are updated at every moment of time 
3 // We detect only the first conflict between every pair of flights
4
5 import java.util.*;
6
7 final class ConflictList
8 {   
9     public int noConflicts; // the number of conflicts
10     private ArrayList conflicts; // the conflicts
11
12         
13     public ConflictList()
14     {
15         noConflicts=0;
16         conflicts=new ArrayList(100);
17     }
18     
19     public void clear()
20     {           
21         noConflicts=0;
22         conflicts.clear();      
23     }
24
25     public Conflict conflictAt(int index)
26     {
27         return (Conflict) conflicts.get(index);
28     }
29
30     public Iterator getConflicts()
31     {
32         return conflicts.iterator();
33     }
34     
35     public String printInfo()
36     // this is a test procedure
37     {
38         String st;
39         if (noConflicts==0)
40             st="No conflicts!";
41         else 
42             {
43                 st=""+noConflicts+" conflicts\n";
44                 Iterator iter=getConflicts();
45                 while (iter.hasNext())
46                     {       
47                         Conflict cAux=(Conflict) iter.next();       
48                         st=st+"\n"+cAux;          
49                     }
50             }
51         return st;
52     }
53
54     public void newConflict(Point4d coord, Flight f1, Flight f2)
55     {
56         noConflicts++;
57         conflicts.add(new Conflict(coord,f1,f2));
58     }
59   
60
61     public Conflict findConflict(Flight f1, Flight f2)
62     {   
63         Iterator iter=getConflicts();
64         while (iter.hasNext())
65             {
66                 Conflict cAux=(Conflict) iter.next();
67                 if (cAux.hasFlights(f1,f2))
68                     return cAux;
69             }
70         return null;
71     }
72
73     
74     public void removeConflict(Flight f1, Flight f2)
75     {
76         noConflicts--;
77         Conflict cAux=findConflict(f1,f2);
78         conflicts.remove(cAux);
79     }
80
81 }
82
83
84
85
86
87
88
89
90
91