<commit_before>package seedu.geekeep;

import java.io.IOException;
import java.util.Map;
import java.util.Optional;
import java.util.logging.Logger;

import com.google.common.eventbus.Subscribe;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.stage.Stage;
import seedu.geekeep.commons.core.Config;
import seedu.geekeep.commons.core.EventsCenter;
import seedu.geekeep.commons.core.LogsCenter;
import seedu.geekeep.commons.core.Version;
import seedu.geekeep.commons.events.ui.ExitAppRequestEvent;
import seedu.geekeep.commons.exceptions.DataConversionException;
import seedu.geekeep.commons.util.ConfigUtil;
import seedu.geekeep.commons.util.StringUtil;
import seedu.geekeep.logic.Logic;
import seedu.geekeep.logic.LogicManager;
import seedu.geekeep.model.Model;
import seedu.geekeep.model.ModelManager;
import seedu.geekeep.model.ReadOnlyTaskManager;
import seedu.geekeep.model.TaskManager;
import seedu.geekeep.model.UserPrefs;
import seedu.geekeep.model.util.SampleDataUtil;
import seedu.geekeep.storage.Storage;
import seedu.geekeep.storage.StorageManager;
import seedu.geekeep.ui.Ui;
import seedu.geekeep.ui.UiManager;

/**
 * The main entry point to the application.
 */
public class MainApp extends Application {
    private static final Logger logger = LogsCenter.getLogger(MainApp.class);

    public static final Version VERSION = new Version(1, 0, 0, true);

    protected Ui ui;
    protected Logic logic;
    protected Storage storage;
    protected Model model;
    protected Config config;
    protected UserPrefs userPrefs;


    @Override
    public void init() throws Exception {
        logger.info("=============================[ Initializing AddressBook ]===========================");
        super.init();

        config = initConfig(getApplicationParameter("config"));
        storage = new StorageManager(config.getGeekeepFilePath(), config.getUserPrefsFilePath());

        userPrefs = initPrefs(config);

        initLogging(config);

        model = initModelManager(storage, userPrefs);

        logic = new LogicManager(model, storage);

        ui = new UiManager(logic, config, userPrefs);

        initEventsCenter();
    }

    private String getApplicationParameter(String parameterName) {
        Map<String, String> applicationParameters = getParameters().getNamed();
        return applicationParameters.get(parameterName);
    }

    private Model initModelManager(Storage storage, UserPrefs userPrefs) {
        Optional<ReadOnlyTaskManager> addressBookOptional;
        ReadOnlyTaskManager initialData;
        try {
            addressBookOptional = storage.readTaskManager();
            if (!addressBookOptional.isPresent()) {
                logger.info("Data file not found. Will be starting with a sample AddressBook");
            }
            initialData = addressBookOptional.orElseGet(SampleDataUtil::getSampleAddressBook);
        } catch (DataConversionException e) {
            logger.warning("Data file not in the correct format. Will be starting with an empty AddressBook");
            initialData = new TaskManager();
        } catch (IOException e) {
            logger.warning("Problem while reading from the file. Will be starting with an empty AddressBook");
            initialData = new TaskManager();
        }

        return new ModelManager(initialData, userPrefs);
    }

    private void initLogging(Config config) {
        LogsCenter.init(config);
    }

    protected Config initConfig(String configFilePath) {
        Config initializedConfig;
        String configFilePathUsed;
<commit_msg>Check whether getParameter returns null or not<commit_after>package seedu.geekeep;

import java.io.IOException;
import java.util.Map;
import java.util.Optional;
import java.util.logging.Logger;

import com.google.common.eventbus.Subscribe;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.stage.Stage;
import seedu.geekeep.commons.core.Config;
import seedu.geekeep.commons.core.EventsCenter;
import seedu.geekeep.commons.core.LogsCenter;
import seedu.geekeep.commons.core.Version;
import seedu.geekeep.commons.events.ui.ExitAppRequestEvent;
import seedu.geekeep.commons.exceptions.DataConversionException;
import seedu.geekeep.commons.util.ConfigUtil;
import seedu.geekeep.commons.util.StringUtil;
import seedu.geekeep.logic.Logic;
import seedu.geekeep.logic.LogicManager;
import seedu.geekeep.model.Model;
import seedu.geekeep.model.ModelManager;
import seedu.geekeep.model.ReadOnlyTaskManager;
import seedu.geekeep.model.TaskManager;
import seedu.geekeep.model.UserPrefs;
import seedu.geekeep.model.util.SampleDataUtil;
import seedu.geekeep.storage.Storage;
import seedu.geekeep.storage.StorageManager;
import seedu.geekeep.ui.Ui;
import seedu.geekeep.ui.UiManager;

/**
 * The main entry point to the application.
 */
public class MainApp extends Application {
    private static final Logger logger = LogsCenter.getLogger(MainApp.class);

    public static final Version VERSION = new Version(1, 0, 0, true);

    protected Ui ui;
    protected Logic logic;
    protected Storage storage;
    protected Model model;
    protected Config config;
    protected UserPrefs userPrefs;


    @Override
    public void init() throws Exception {
        logger.info("=============================[ Initializing AddressBook ]===========================");
        super.init();

        config = initConfig(getApplicationParameter("config"));
        storage = new StorageManager(config.getGeekeepFilePath(), config.getUserPrefsFilePath());

        userPrefs = initPrefs(config);

        initLogging(config);

        model = initModelManager(storage, userPrefs);

        logic = new LogicManager(model, storage);

        ui = new UiManager(logic, config, userPrefs);

        initEventsCenter();
    }

    private String getApplicationParameter(String parameterName) {
        if (getParameters() == null) {
            return null;
        } else {
            Map<String, String> applicationParameters = getParameters().getNamed();
            return applicationParameters.get(parameterName);
        }
    }

    private Model initModelManager(Storage storage, UserPrefs userPrefs) {
        Optional<ReadOnlyTaskManager> addressBookOptional;
        ReadOnlyTaskManager initialData;
        try {
            addressBookOptional = storage.readTaskManager();
            if (!addressBookOptional.isPresent()) {
                logger.info("Data file not found. Will be starting with a sample AddressBook");
            }
            initialData = addressBookOptional.orElseGet(SampleDataUtil::getSampleAddressBook);
        } catch (DataConversionException e) {
            logger.warning("Data file not in the correct format. Will be starting with an empty AddressBook");
            initialData = new TaskManager();
        } catch (IOException e) {
            logger.warning("Problem while reading from the file. Will be starting with an empty AddressBook");
            initialData = new TaskManager();
        }

        return new ModelManager(initialData, userPrefs);
    }

    private void initLogging(Config config) {
        LogsCenter.init(config);
    }

    protected Config initConfig(String configFilePath) {
        Config initializedConfig;
        String configFilePathUsed;

{'fraction_non_alphanumeric': 0.1022046815459989, 'fraction_numerical': 0.0008165487207403375, 'mean_word_length': 3.6571609632446136, 'pattern_counts': {'":': 0, '<': 7, '<?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': '5382838', 'n_tokens_mistral': 2008, 'n_tokens_neox': 1955, 'n_words': 472}