package jfdi.logic;

import jfdi.logic.commands.InvalidCommand;
import jfdi.logic.interfaces.Command;
import jfdi.logic.interfaces.ILogic;
import jfdi.parser.InputParser;
import jfdi.parser.exceptions.InvalidInputException;
import jfdi.storage.apis.MainStorage;
import jfdi.storage.exceptions.FilesReplacedException;

/**
 * @author Liu Xinan
 */
public class ControlCenter implements ILogic {

    private static ControlCenter ourInstance = new ControlCenter();

    private ControlCenter() {
        try {
            MainStorage.getInstance().initialize();
        } catch (FilesReplacedException e) {
            e.printStackTrace();
        }
    }

    public static ControlCenter getInstance() {
        return ourInstance;
    }

    @Override
    public void handleInput(String input) {
        InputParser parser = InputParser.getInstance();
        Command command;
        try {
            command = parser.parse(input);
        } catch (InvalidInputException e) {
            command = new InvalidCommand.Builder().build();
        }
        command.execute();
    }
}

@@ -217,16 +217,50 @@
 eption;%0A
+import jfdi.storage.apis.AliasDb;%0A
 import j
@@ -289,16 +289,16 @@
 torage;%0A
-
 import j
@@ -533,153 +533,44 @@
     
-try %7B%0A            MainStorage.getInstance().initialize();%0A        %7D catch (FilesReplacedException e) %7B%0A            e.printStackTrace();%0A        %7D
+initStorage();%0A        initParser();
 %0A   
@@ -966,16 +966,16 @@
       %7D%0A
-
         
@@ -998,11 +998,322 @@
 );%0A    %7D
+%0A%0A    private void initStorage() %7B%0A        try %7B%0A            MainStorage.getInstance().initialize();%0A        %7D catch (FilesReplacedException e) %7B%0A            e.printStackTrace();%0A        %7D%0A    %7D%0A%0A    private void initParser() %7B%0A        InputParser.getInstance().setAliases(AliasDb.getInstance().getAll());%0A    %7D
 %0A%7D%0A

Initialize Parser with aliases at startup