summaryrefslogtreecommitdiff
path: root/src/main/java/com/benburwell/planes/data/AirportStore.java
blob: 93f1ccc29c28878f6ca78c76b7201bca538973f9 (plain)
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
package com.benburwell.planes.data;

import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by ben on 11/19/16.
 */
public class AirportStore {
    private List<Airport> airports = new ArrayList<>();

    public void readFromFile(String filename) throws IOException {
        File csvData = new File(filename);
        CSVParser parser = CSVParser.parse(csvData, Charset.defaultCharset(), CSVFormat.RFC4180.withFirstRecordAsHeader());
        for (CSVRecord record : parser) {
            this.airports.add(new Airport(record));
        }
    }

    public List<Airport> getAirports() {
        return this.airports;
    }
}