package linenux.control;

import java.nio.file.Paths;

import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import linenux.command.result.CommandResult;
import linenux.model.Schedule;
import linenux.storage.XmlScheduleStorage;

/**
 * Controls data flow for the entire application.
 */
public class ControlUnit {
    private Schedule schedule;
    private XmlScheduleStorage scheduleStorage;
    private CommandManager commandManager;
    private ObjectProperty<CommandResult> lastCommandResult = new SimpleObjectProperty<>();

    public ControlUnit() {
        this.scheduleStorage = new XmlScheduleStorage(getDefaultFilePath());
        this.schedule = (hasExistingSchedule()) ? getExistingSchedule() : new Schedule();
        this.commandManager = new CommandManager(schedule);
    }

    public CommandResult execute(String userInput) {
        CommandResult result = commandManager.delegateCommand(userInput);
        lastCommandResult.setValue(result);
        scheduleStorage.saveScheduleToFile(schedule);
        return result;
    }

    private boolean hasExistingSchedule() {
        return scheduleStorage.getFile().exists();
    }

    private Schedule getExistingSchedule() {
        return scheduleStorage.loadScheduleFromFile();
    }

    private String getDefaultFilePath() {
        return Paths.get(".").toAbsolutePath().toString();
    }

    public Schedule getSchedule() {
        return this.schedule;
    }

    public ObjectProperty<CommandResult> getLastCommandResultProperty() {
        return this.lastCommandResult;
    }
}

@@ -668,24 +668,25 @@
 ath());%0A
+%0A
         
 this.sch
@@ -681,25 +681,17 @@
     
+if (
 this.
-schedule = (
 hasE
@@ -711,35 +711,124 @@
 le()
-) ?
+ &&
  get
-ExistingSchedule() :
+Schedule() != null) %7B%0A            this.schedule = getSchedule();%0A        %7D else %7B%0A            this.schedule =
  new
@@ -832,32 +832,43 @@
 new Schedule();%0A
+        %7D%0A%0A
         this.com

Fix loading schedule from file