- #1
DottZakapa
- 239
- 17
- TL;DR Summary
- Hi i need some help in this portion of code, i have no clue what it does... in particular the highlighted portion
Java:
public static Region fromFile(String name, String file) {
Region r = new Region(name);
List<String> lines = readData(file);
String[] headers = lines.remove(0).split(";");
Map<String, Integer> h2i = new HashMap<>();
for (int i=0; i<headers.length; i++) {
h2i.put(headers[i], i);
}
lines.forEach(l -> {
String[] rows = l.split(";");
String provinceName = rows[h2i.get("Province")];
String municipalityName = rows[h2i.get("Municipality")];
Integer municipalityAltitude = Integer.parseInt(rows[h2i.get("MunicipalityAltitude")]);
Municipality municipality = r.createOrGetMunicipality(municipalityName,
provinceName, municipalityAltitude);
String mh_name = rows[h2i.get("Name")];
String altitude = rows[h2i.get("Altitude")];
String category = rows[h2i.get("Category")];
Integer bedsNumber = Integer.parseInt(rows[h2i.get("BedsNumber")]);
if (altitude.equals("")) {
r.createOrGetMountainHut(mh_name, category, bedsNumber, municipality);
} else {
r.createOrGetMountainHut(mh_name, Integer.parseInt(altitude), category, bedsNumber, municipality);
}
});
return r;
}