예제 #1
0
  public ArrayList<Flight> parseFlightCalendar(String path, HashMap<String, Airport> airports)
      throws NumberFormatException, IOException {
    System.out.println("Parsing " + path + " ...");

    File csvFile = new File(path);
    String line = null;

    BufferedReader buffer = new BufferedReader(new FileReader(csvFile));

    SimpleDateFormat df = new SimpleDateFormat("MM/dd/yy HH:mm");

    while ((line = buffer.readLine()) != null) {
      Connection temp = new Connection();
      String origin, destination;

      StringTokenizer st = new StringTokenizer(line, ",");

      temp.setFlightNo(Integer.parseInt(st.nextToken()));
      origin = st.nextToken();
      destination = st.nextToken();

      temp.setPlaneType(Integer.parseInt(st.nextToken()));

      try {
        // String departure = st.nextToken();
        temp.setDeparture(df.parse(st.nextToken()));
        // String arrival = st.nextToken();
        String arriv = st.nextToken();
        temp.setArrival(df.parse(arriv));
        System.out.println(arriv);
      } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      temp.setExecutiveSeats(Integer.parseInt(st.nextToken()));
      temp.setEconomicSeats(Integer.parseInt(st.nextToken()));
      temp.setExecutiveSeatsSold(Integer.parseInt(st.nextToken()));
      temp.setEconomicSeatsSold(Integer.parseInt(st.nextToken()));

      temp.setDest(airports.get(destination));

      Airport a = airports.get(origin);
      a.addConnection(temp);
      airports.put(origin, a);
    }

    return null;
  }
예제 #2
0
  public HashMap<String, Airport> parseAirports(String path) throws IOException {

    System.out.println("Parsing " + path + " ...");

    File csvFile = new File(path);
    String line = null;
    HashMap<String, Airport> hash = new HashMap<String, Airport>();
    BufferedReader buffer = new BufferedReader(new FileReader(csvFile));

    while ((line = buffer.readLine()) != null) {
      Airport temp = new Airport();
      StringTokenizer st = new StringTokenizer(line, ",");

      temp.setIataCode(st.nextToken());
      temp.setIcaoCode(st.nextToken());
      temp.setName(st.nextToken());
      temp.setCity(st.nextToken());
      temp.setLatitude(Float.parseFloat(st.nextToken()));
      temp.setLongitude(Float.parseFloat(st.nextToken()));
      temp.setCountry(st.nextToken());
      temp.setNbLandingCost(Float.parseFloat(st.nextToken()));
      temp.setNbParkingCost(Float.parseFloat(st.nextToken()));
      temp.setWbLandingCost(Float.parseFloat(st.nextToken()));
      temp.setWbParkingCost(Float.parseFloat(st.nextToken()));

      hash.put(temp.getIataCode(), temp);
    }

    return hash;
  }