<commit_before>package udo.logic;

import udo.gui.GUI;
import udo.logic.command.Command;
import udo.storage.Storage;

public class Logic {
    private GUI gui;
    private static Logic logicObj = null;
    private Storage storage;

    private static final String ERR_FORMAT = "Error: %s";
    public static final String ERR_INVALID_CMD_NAME = "Invalid command";
    public static final String ERR_UNSUPPORTED_CMD = "Unsupported command";
    public static final String ERR_INVALID_CMD_ARG =
            "Invalid command's argument";
    public static final String ERR_UNSPECIFIED_INDEX =
            "A valid task's index is required";
    public static final String ERR_LATE_DEADLINE =
            "Deadline has already passed";
    public static final String ERR_NON_POSITIVE_DUR =
            "Task's duration must be positive";
    public static final String ERR_STORAGE =
            "Tasks' storage input/output error";
    public static final String ERR_INVALID_INDEX =
            "Specified task's index is not valid";
    public static final String ERR_EMPTY_CONTENT =
            "task's content cannot be empty";
    
    public static final String WARN_FORMAT = "Warning: %s";

    public static final Integer MAX_STATUS_LENGTH = 40;

    private InputParser parser;

    private static String status;

    private Logic() {
        parser = new InputParser();
        storage = new Storage();
        /* TODO:
         * Initialize and start up passive thread for reminder
         */
    }
    
    public static Logic getInstance() {
        if (logicObj == null) {
            logicObj = new Logic();
        }
        
        return logicObj;
    }
    
    public void setGUI(GUI guiObj) {
        gui = guiObj;
    }

    /**
     * Execute the command given in the command string
     * @param command the command string
     */
    public boolean executeCommand(String command) {
        Command parsedCommand = parser.parseCommand(command);
        if (parser.getErrorStatus() != null) {
            status = formatErrorStr(parser.getErrorStatus());
            gui.displayStatus(status);
            return false;
        }
        
        parsedCommand.setGUI(gui);
        parsedCommand.setStorage(storage);

        return parsedCommand.execute();
    }

    /**
     * @param parsedCommand
     * @return
     */
    public static String summarizeContent(String taskContent) {
        if (taskContent == null) {
            return "";
        }

        if (taskContent.length() > MAX_STATUS_LENGTH) {
            taskContent = taskContent.substring(0, MAX_STATUS_LENGTH);
            taskContent += "...";
        }
        return taskContent;
    }

    public static String formatErrorStr(String error) {
        return String.format(ERR_FORMAT, error);
    }
    
    public static String formatWarningStr(String warning) {
        return String.format(WARN_FORMAT, warning);
    }<commit_msg>Add autocomplete interface to Logic class<commit_after>package udo.logic;

import java.util.List;

import udo.gui.GUI;
import udo.logic.command.Command;
import udo.storage.Storage;

public class Logic {
    private GUI gui;
    private static Logic logicObj = null;
    private Storage storage;

    private static final String ERR_FORMAT = "Error: %s";
    public static final String ERR_INVALID_CMD_NAME = "Invalid command";
    public static final String ERR_UNSUPPORTED_CMD = "Unsupported command";
    public static final String ERR_INVALID_CMD_ARG =
            "Invalid command's argument";
    public static final String ERR_UNSPECIFIED_INDEX =
            "A valid task's index is required";
    public static final String ERR_LATE_DEADLINE =
            "Deadline has already passed";
    public static final String ERR_NON_POSITIVE_DUR =
            "Task's duration must be positive";
    public static final String ERR_STORAGE =
            "Tasks' storage input/output error";
    public static final String ERR_INVALID_INDEX =
            "Specified task's index is not valid";
    public static final String ERR_EMPTY_CONTENT =
            "task's content cannot be empty";
    
    public static final String WARN_FORMAT = "Warning: %s";

    public static final Integer MAX_STATUS_LENGTH = 40;

    private InputParser parser;
    private Autocompleter autocompleter;

    private static String status;

    private Logic() {
        parser = new InputParser();
        storage = new Storage();
        autocompleter = new Autocompleter();
        /* TODO:
         * Initialize and start up passive thread for reminder
         */
    }
    
    public static Logic getInstance() {
        if (logicObj == null) {
            logicObj = new Logic();
        }
        
        return logicObj;
    }
    
    public void setGUI(GUI guiObj) {
        gui = guiObj;
    }

    /**
     * Execute the command given in the command string
     * @param command the command string
     */
    public boolean executeCommand(String command) {
        Command parsedCommand = parser.parseCommand(command);
        if (parser.getErrorStatus() != null) {
            status = formatErrorStr(parser.getErrorStatus());
            gui.displayStatus(status);
            return false;
        }
        
        parsedCommand.setGUI(gui);
        parsedCommand.setStorage(storage);

        return parsedCommand.execute();
    }
    
    /******************************
     * Interface for autocomplete *
     ******************************/

    /**
     * Refer to same method in Autocompleter
     */
    public List<String> getSuggestions(String text) {
        return autocompleter.getSuggestions(text);
    }
    
    /**
     * Refer to same method in Autocompleter
     */
    public List<String> getSuggestions(String text, Integer maxWords) {
        return autocompleter.getSuggestions(text, maxWords);
    }
    
    /**
     * Refer to same method in Autocompleter
     */
    public String autocomplete(String text) {
        return autocompleter.autocomplete(text);
    }

    /**
     * Refer to same method in Autocompleter
     */
    public String getPreviousCmd() {
        return autocompleter.getPreviousCmd();
    }
    
    /**
     * Refer to same method in Autocompleter
     */
    public String getNextCmd() {
        return autocompleter.getNextCmd();
    }

    /**
     * @param parsedCommand
     * @return
     */
    public static String summarizeContent(String taskContent) {
        if (taskContent == null) {
            return "";
        }

        if (taskContent.length() > MAX_STATUS_LENGTH) {
            taskContent = taskContent.substring(0, MAX_STATUS_LENGTH);
            taskContent += "...";
        }
        return taskContent;
    }

    public static String formatErrorStr(String error) {
        return String.format(ERR_FORMAT, error);
    }
    
    public static String formatWarningStr(String warning) {
        return String.format(WARN_FORMAT, warning);
    }
{'fraction_non_alphanumeric': 0.08773191428160507, 'fraction_numerical': 0.0008629368617862793, 'mean_word_length': 2.327272727272727, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1172588', 'n_tokens_mistral': 1869, 'n_tokens_neox': 1804, 'n_words': 549}