Skip to content

Commit

Permalink
Merge pull request #199 from ChinYanXu/NewAssertions
Browse files Browse the repository at this point in the history
Refactor loadFileContents
  • Loading branch information
ChinYanXu committed Apr 8, 2024
2 parents d86ef9e + 289b16a commit 4a4c025
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions src/main/java/seedu/omnitravel/storage/FileSave.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,36 @@ public void loadFileContents(TravelActivityList list) throws FileNotFoundExcepti
String duration = line[4];
String tag = line.length >= 6 ? line[5].trim() : "";
String expense = line.length >= 7 ? line[6].trim() : "";
TravelActivity activity;
switch (type) {
case "accommodation":
activity = new Accommodation(description, date, duration, tag, expense);
break;
case "food":
activity = new Food(description, date, duration, tag, expense);
break;
case "landmark":
activity = new Landmark(description, date, duration, tag, expense);
break;
case "general":
activity = new TravelActivity(description, date, duration, tag, expense);
break;
default:
throw new FileNotFoundException("File is corrupted or has invalid format");
}
TravelActivity activity = initialiseActivity (type, description, date, duration, tag, expense);
list.addTravelActivity(activity);
if (line[1].equals("1")) {
activity.setActivityStatus(true);
}
}
}

public TravelActivity initialiseActivity (String type, String description,
LocalDate date, String duration, String tag, String expense) throws FileNotFoundException {
TravelActivity activity;
switch (type) {
case "accommodation":
activity = new Accommodation(description, date, duration, tag, expense);
break;
case "food":
activity = new Food(description, date, duration, tag, expense);
break;
case "landmark":
activity = new Landmark(description, date, duration, tag, expense);
break;
case "general":
activity = new TravelActivity(description, date, duration, tag, expense);
break;
default:
throw new FileNotFoundException("File is corrupted or has invalid format");
}
return activity;
}

public void saveActivityList(TravelActivityList list) throws IOException {
logger.log(Level.INFO, "saveActivityList");
FileWriter fw = new FileWriter(filePath);
Expand Down

0 comments on commit 4a4c025

Please sign in to comment.