int forwardSize = Integer.parseInt(dimensions[0]);
int backwardSize = Integer.parseInt(dimensions[1]);
assert forwardSize > 0 && backwardSize > 0;
ConnectionCosts costs = new ConnectionCosts(forwardSize, backwardSize);
while ((line = lineReader.readLine()) != null) {
String[] fields = line.split("\\s+");
assert fields.length == 3;
short forwardId = Short.parseShort(fields[0]);
short backwardId = Short.parseShort(fields[1]);
short cost = Short.parseShort(fields[2]);
costs.add(forwardId, backwardId, cost);
}
return costs;
}