FIDS_DB.java (1960B)
1 import java.io.File; 2 import java.io.FileNotFoundException; 3 import java.io.IOException; 4 import java.util.ArrayList; 5 import java.util.Scanner; 6 7 public class FIDS_DB { 8 public ArrayList<FlightInfo> FlightsArr; 9 public InternationalDB InternationalFT; 10 public int parseLimit = 2; 11 12 public FIDS_DB() 13 { 14 FlightsArr = new ArrayList<>(); 15 InternationalFT = new InternationalDB(); 16 } 17 18 public void updateDB() throws FileNotFoundException { 19 try { 20 InternationalFT.downloadData(); 21 } catch (IOException e) { 22 System.out.println("No internet connection."); 23 } 24 25 FlightsArr = parseData(); 26 27 } 28 29 public ArrayList<FlightInfo> parseData() throws FileNotFoundException { 30 ArrayList<FlightInfo> data = new ArrayList<>(); 31 32 File fileObj = new File(InternationalFT.locPath); 33 Scanner reader = new Scanner(fileObj); 34 while (reader.hasNextLine()) { 35 String dat = reader.nextLine(); 36 37 38 String []p1 = dat.split("\\[\\["); 39 for (int i = 1; i <= parseLimit; i++) 40 { 41 String []p2 = p1[1].split(","); 42 43 FlightInfo f = new FlightInfo(p2[1], p2[2], p2[3], p2[5], p2[6], p2[7]); 44 data.add(f); 45 46 p1 = p1[1].split("],\\["); 47 } 48 } 49 50 return data; 51 } 52 53 public void showData() 54 { 55 System.out.println("F.I.D.S."); 56 System.out.println("--------"); 57 for (FlightInfo f : FlightsArr) 58 { 59 System.out.println("Origin country : " + f.originCountry); 60 System.out.println("Flight code : " + f.flightCode); 61 System.out.println("Latitude : " + f.lat); 62 System.out.println("Longtitude : " + f.lng); 63 System.out.println("Timepos : " + f.timePos); 64 System.out.println("Velocity : " + f.velocity); 65 System.out.println("--------"); 66 } 67 } 68 }