private ImmutableMap readPopulationData()

in bigtop-data-generators/bigtop-location-data/src/main/java/org/apache/bigtop/datagenerators/locations/LocationReader.java [82:111]


  private ImmutableMap<String, Long> readPopulationData(InputStream path)
          throws FileNotFoundException {
    Scanner scanner = new Scanner(path);

    // skip header
    scanner.nextLine();

    Map<String, Long> entries = Maps.newHashMap();
    while (scanner.hasNextLine()) {
      String line = scanner.nextLine().trim();

      if (line.length() == 0)
        continue;

      String[] cols = line.split(",");

      String zipcode = cols[0].trim();
      Long population = Long.parseLong(cols[1].trim());

      if (entries.containsKey(zipcode)) {
        entries.put(zipcode, Math.max(entries.get(zipcode), population));
      } else {
        entries.put(zipcode, population);
      }
    }

    scanner.close();

    return ImmutableMap.copyOf(entries);
  }