Esempio n. 1
0
 public static List<Station> loadMetars() throws IOException {
   BufferedReader br =
       new BufferedReader(new FileReader("/home/gorka/MyProjects/Android/Tolomet/Docs/metar.txt"));
   List<Station> list = new ArrayList<Station>();
   Map<String, Set<String>> mapRegions = new HashMap<String, Set<String>>();
   String line, region = null, country, code;
   while ((line = br.readLine()) != null) {
     if (line.isEmpty() || line.startsWith("!") || line.startsWith("CD")) continue;
     if (line.length() < 83) {
       region = line.substring(0, 19).trim();
       System.out.println(String.format("Region '%s'", region));
       continue;
     }
     code = line.substring(20, 24).trim();
     if (code.isEmpty()) continue;
     country = line.substring(81, 83);
     Set<String> regions = mapRegions.get(country);
     if (regions == null) {
       regions = new LinkedHashSet<String>();
       mapRegions.put(country, regions);
     }
     regions.add(region);
     Station station = new Station();
     station.setProviderType(WindProviderType.Metar);
     station.setCode(code);
     station.setCountry(country);
     station.setName(line.substring(3, 20).trim());
     station.setLatitude(parseLatitude(line));
     station.setLongitude(parseLongitude(line));
     list.add(station);
     station.setRegion(regions.size());
   }
   br.close();
   saveRegions(mapRegions);
   return list;
 }
Esempio n. 2
0
 public static void main(String[] args) throws IOException {
   for (Station station : loadMetars())
     System.out.println(String.format("%s ... ", station.toString()));
   System.out.println("finished!");
 }