working on directto benchmark--removing code like unused constructors that hinder...
[IRC.git] / Robust / src / Benchmarks / mlp / directto / mlp-java / FlightList.java
1 // This is the class that manages all the flights
2
3 //import java.util.*;
4
5 public class FlightList {
6   public  int noFlights;
7   public  Vector f;
8
9   public FlightList() {
10     noFlights=0;
11     f=new Vector(100);
12   }
13
14   public  void addFlightPlan(D2 d2, int time, StringTokenizer st) { 
15     Flight newFlight=disjoint flightAdd new Flight(st.nextToken());
16     noFlights++;
17     f.addElement(newFlight);
18
19     FlightPlan fAux=new FlightPlan();
20     Aircraft aAux=d2.getAircraftList().getAircraft(st.nextToken());      
21     newFlight.setAircraftType(aAux);
22   
23     newFlight.setFlightType(st.nextToken());
24     Route rAux=new Route(Integer.parseInt(st.nextToken()));
25     for (int i=0;i<rAux.noFixes;i++)
26       rAux.addFix(d2,i,st.nextToken());           
27     fAux.setRoute(rAux);
28     fAux.setCruiseParam(Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()));
29     newFlight.setFlightPlan(fAux);
30   }
31
32   public  String getFlightName(int index) {
33     Flight fAux=(Flight) f.elementAt(index);
34     return fAux.flightID;
35   }
36
37   public  void amendFlightPlan(D2 d2, int time, StringTokenizer st) {
38     Flight fAux=getFlight(st.nextToken());
39     Route rAux=new Route(Integer.parseInt(st.nextToken()));    
40     for (int i=0;i<rAux.noFixes;i++)
41       rAux.addFix(d2,i,st.nextToken());      
42     fAux.fPlan.setRoute(rAux);
43     fAux.fPlan.setCruiseParam(Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()));
44   }
45
46     public  void amendFlightInfo(D2 d2, int time, StringTokenizer st) {
47     Flight fAux=getFlight(st.nextToken());
48     Aircraft aAux=d2.getAircraftList().getAircraft(st.nextToken());      
49     fAux.setAircraftType(aAux);
50     fAux.setFlightType(st.nextToken());
51   }
52
53     public  void sendingAircraft(D2 d2, int time, StringTokenizer st) {
54     int noF=Integer.parseInt(st.nextToken());
55     String id;
56     Point4d pos;
57     Velocity vel;
58     Track t;
59     String nameFix;
60     Flight fAux;
61     for (int counter=0; counter<noF; counter++) {
62       id=st.nextToken();
63       pos=new Point4d(time,
64                       Double.valueOf(st.nextToken()).doubleValue(),
65                       Double.valueOf(st.nextToken()).doubleValue(),
66                       Double.valueOf(st.nextToken()).doubleValue());
67       vel=new Velocity(Double.valueOf(st.nextToken()).doubleValue(),
68                        Double.valueOf(st.nextToken()).doubleValue(),
69                        Double.valueOf(st.nextToken()).doubleValue());
70       t=new Track(pos, vel);
71       nameFix=st.nextToken();
72       fAux=getFlight(id);
73       System.out.println(id+" Flight id: "+fAux.flightID);
74       fAux.setTrack(t);
75       System.out.println("Setting current fix ...");
76       fAux.fPlan.setCurrentFix(nameFix);
77       System.out.println("Sent flight "+
78                          fAux.flightID+
79                          "; position: "+
80                          fAux.track.pos);
81       d2.getTrajectorySynthesizer().updateTrajectory(d2, time, fAux);
82       fAux.traject.printInfo();      
83     }
84   }  
85
86   public  void removeFlightPlan(int time, StringTokenizer st) {
87     String id=st.nextToken();
88     int i=0;
89     while ((i<noFlights) && (((Flight) f.elementAt(i)).hasID(id))) i++;
90     if (i<noFlights) f.removeElementAt(i);
91   }
92
93   public  Flight getFlight(String id) {
94     for( int i = 0; i < f.size(); ++i ) {
95       Flight fAux=(Flight) f.elementAt(i);
96       if (fAux.hasID(id))
97         return fAux;
98     }
99     System.out.println("Flight not found - "+id);
100     System.exit(-1);
101     return null;
102   }
103
104   public  boolean anyPlanesAlive() {
105     for( int i = 0; i < f.size(); ++i ) {
106       Flight aAux=(Flight) f.elementAt(i);
107       Vector p1=aAux.traject.p;
108       Point4d pAux= (Point4d) p1.elementAt(0);
109       if (!pAux.outOfRange())
110         return true;
111     }
112     return false;
113   }
114
115   public  void printInfo() {
116     System.out.println("\n\nThe number of flights:"+noFlights);
117     System.out.println("The flights are:");
118     for( int i = 0; i < f.size(); ++i ) {
119       Flight fAux=(Flight) f.elementAt(i);
120       System.out.println(fAux);
121     }
122   }
123 }