List<CarBlock> carBlockList = new ArrayList<CarBlock>();
String line = bufferedReader.readLine();
long id = 0L;
while (!line.equals(";;;;;;")) {
String[] lineTokens = splitBySemicolonSeparatedValue(line, 7);
CarBlock carBlock = new CarBlock();
carBlock.setId(id);
id++;
carBlock.setCode(lineTokens[0]);
RailNode origin = nameToRailNodeMap.get(lineTokens[1]);
if (origin == null) {
throw new IllegalArgumentException("Read line (" + line
+ ") has a non existing origin (" + lineTokens[1] + ").");
}
carBlock.setOrigin(origin);
RailNode destination = nameToRailNodeMap.get(lineTokens[2]);
if (destination == null) {
throw new IllegalArgumentException("Read line (" + line
+ ") has a non existing destination (" + lineTokens[2] + ").");
}
carBlock.setDestination(destination);
carBlock.setNumberOfCars(Integer.parseInt(lineTokens[3]));
carBlock.setLength(Integer.parseInt(lineTokens[4]));
carBlock.setTonnage(Integer.parseInt(lineTokens[5]));
carBlock.setShortestDistance(readDistance(lineTokens[6]));
carBlockList.add(carBlock);
line = bufferedReader.readLine();
}
trainDesign.setCarBlockList(carBlockList);
}