Commit f6d5609d authored by Carl Gützkow's avatar Carl Gützkow
Browse files

enhance: set delimiter as constant in army file handler

parent 0c8df839
Pipeline #183784 passed with stages
in 45 seconds
......@@ -2,7 +2,6 @@ package edu.ntnu.idatt2001.carljgu.army;
import edu.ntnu.idatt2001.carljgu.FileExtensionException;
import edu.ntnu.idatt2001.carljgu.client.App;
import edu.ntnu.idatt2001.carljgu.army.Army;
import edu.ntnu.idatt2001.carljgu.units.Unit;
import edu.ntnu.idatt2001.carljgu.units.UnitFactory;
import edu.ntnu.idatt2001.carljgu.units.UnitType;
......@@ -22,12 +21,15 @@ import java.util.List;
public class ArmyFileHandler {
private final List<String> readLinesSkipped;
private final String DELIMITER;
/**
* Constructor which initiates the readLinesSkipped arraylist
* Sets the delimiter to a comma for comma seperated value.
*/
public ArmyFileHandler() {
readLinesSkipped = new ArrayList<>();
DELIMITER = ",";
}
/**
......@@ -62,7 +64,7 @@ public class ArmyFileHandler {
fileWriter.write(army.getName() + "\n");
for (Unit unit : army.getAllUnits()) {
fileWriter.write(
unit.getClassName() + "," + unit.getName() + "," + unit.getHealth() + "\n"
unit.getClassName() + DELIMITER + unit.getName() + DELIMITER + unit.getHealth() + "\n"
);
}
}
......@@ -93,7 +95,7 @@ public class ArmyFileHandler {
Army army = new Army(bufferedReader.readLine());
while ((line = bufferedReader.readLine()) != null) {
try {
String[] unit = line.split(",");
String[] unit = line.split(DELIMITER);
UnitType unitType = UnitType.getUnitType(unit[0].trim());
String name = unit[1].trim();
int health = Integer.parseInt(unit[2].trim());
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment