<commit_before>package fini.main;

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.stream.Collectors;

import fini.main.model.Command;
import fini.main.model.Command.CommandType;
import fini.main.model.FiniParser;
import fini.main.model.StatusSaver;
import fini.main.model.Storage;
import fini.main.model.Task;
import fini.main.util.ModsLoader;
import fini.main.util.Sorter;
import fini.main.view.RootController;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
/**
 * A Half-damaged Brain
 * @author gaieepo
 */
public class Brain {
	private static Brain brain;
	private RootController rootController;

	private Storage taskOrganiser;
	private FiniParser finiParser;
	private Sorter sorter;
	private StatusSaver statusSaver;

	private ArrayList<Task> taskMasterList;
	private ObservableList<Task> taskObservableList = FXCollections.observableArrayList();
	private ObservableList<Task> taskAuxiliaryList = FXCollections.observableArrayList(); 
	
	private boolean searchDisplayTrigger = false;
	private boolean completeDisplayTrigger = false;
	private boolean allDisplayTrigger = false;

	private Brain() {
		finiParser = FiniParser.getInstance();
		taskOrganiser = Storage.getInstance();
		statusSaver = StatusSaver.getInstance();
		
		// Everything stored here in Brain unless an updateFile is executed
		// taskMasterList: all existing tasks
		// taskObservableList: all displayed tasks
		taskMasterList = taskOrganiser.readFile();
		sortTaskMasterList();
		taskObservableList.setAll(taskMasterList.stream().filter(task -> !task.isCompleted()).collect(Collectors.toList()));
		taskAuxiliaryList.setAll(taskObservableList); 
		statusSaver.saveStatus(taskMasterList, taskObservableList);
	}

	public static Brain getInstance() {
		if (brain == null) {
			brain = new Brain();
		}
		return brain;
	}

	// Initialize first display when Fini is started - executed in MainApp 
	public void initDisplay() {
		rootController.updateMainDisplay(taskAuxiliaryList);
		rootController.updateProjectsOverviewPanel(taskAuxiliaryList);
		rootController.updateTasksOverviewPanel(taskAuxiliaryList);
		rootController.updateFiniPoints(taskMasterList.stream().filter(task -> task.isCompleted()).collect(Collectors.toList()));
	}

//	public static void main(String[] args) {
//		Brain testBrain = Brain.getInstance();
//		testBrain.executeCommand("add curry chicken tomorrow repeat everyday until dec priority high");
//	}
	
	public void executeCommand(String userInput) {
		Command newCommand = new Command(userInput);
		CommandType commandType = newCommand.getCommandType();
		int objectIndex = newCommand.getObjectIndex();
		String commandParameters = newCommand.getCommandParameters();
		
		String display = "";
		switch (commandType) {
		case ADD:
			display = addTask(commandParameters);
			saveThisStatus();
			break;
		case UPDATE:
			display = updateTask(objectIndex, commandParameters);
			saveThisStatus();
			break;
		case DELETE:
			display = deleteTask(objectIndex);
			saveThisStatus();
			break;
		case CLEAR:
			display = clearAllTasks();
			saveThisStatus();
			break;
		case UNDO:
			display = undo();
			break;
		case REDO:
			display = redo();
			break;
		case DISPLAY:
			display = displayTask(commandParameters);
			break;
//		case SEARCH:
//			searchDisplayTrigger = true;
//			display = "Searching...";
//			searchTask(commandParameters);
//			break;
//		case MODE:
//			MainApp.switchMode();
//			break;
		case MODS:
			display = loadNUSMods();
			saveThisStatus();
			break;
		case EXIT:
			System.exit(0);
		case COMPLETE:
			display = completeTask(objectIndex);
			saveThisStatus();
			break;
		case UNCOMPLETE:
			display = uncompleteTask(objectIndex);
			saveThisStatus();
			break;
		case INVALID:
			display = "commandType INVALID";
			break;
		default:
			break;
		}

		displayControl();
		
		sortTaskMasterList();
		taskAuxiliaryList.setAll(taskMasterList.stream().filter(task -> !task.isCompleted()).collect(Collectors.toList()));
		rootController.updateProjectsOverviewPanel(taskAuxiliaryList);
		rootController.updateTasksOverviewPanel(taskAuxiliaryList);
		
		rootController.updateDisplayToUser(display);
		rootController.updateFiniPoints(taskMasterList.stream().filter(task -> task.isCompleted()).collect(Collectors.toList()));
	}
	
	// Display Control Methods
	private void displayControl() {
		if (completeDisplayTrigger) {
			taskObservableList.setAll(taskMasterList.stream().filter(task -> task.isCompleted()).collect(Collectors.toList()));
			rootController.updateCompletedDisplay(taskObservableList);
		} else if (searchDisplayTrigger) {
			// TODO
		} else if (allDisplayTrigger) {
			rootController.updateAllDisplay(taskObservableList);
		} else {
			sortTaskMasterList();
			taskObservableList.setAll(taskMasterList.stream().filter(task -> !task.isCompleted()).collect(Collectors.toList()));<commit_msg>display complete very ugly code design<commit_after>package fini.main;

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.stream.Collectors;

import fini.main.model.Command;
import fini.main.model.Command.CommandType;
import fini.main.model.FiniParser;
import fini.main.model.StatusSaver;
import fini.main.model.Storage;
import fini.main.model.Task;
import fini.main.util.ModsLoader;
import fini.main.util.Sorter;
import fini.main.view.RootController;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
/**
 * A Half-damaged Brain
 * @author gaieepo
 */
public class Brain {
	private static Brain brain;
	private RootController rootController;

	private Storage taskOrganiser;
	private FiniParser finiParser;
	private Sorter sorter;
	private StatusSaver statusSaver;

	private ArrayList<Task> taskMasterList;
	private ObservableList<Task> taskObservableList = FXCollections.observableArrayList();
	private ObservableList<Task> taskAuxiliaryList = FXCollections.observableArrayList(); 
	
	private boolean searchDisplayTrigger = false;
	private boolean completeDisplayTrigger = false;
	private boolean allDisplayTrigger = false;

	private Brain() {
		finiParser = FiniParser.getInstance();
		taskOrganiser = Storage.getInstance();
		statusSaver = StatusSaver.getInstance();
		
		// Everything stored here in Brain unless an updateFile is executed
		// taskMasterList: all existing tasks
		// taskObservableList: all displayed tasks
		taskMasterList = taskOrganiser.readFile();
		sortTaskMasterList();
		taskObservableList.setAll(taskMasterList.stream().filter(task -> !task.isCompleted()).collect(Collectors.toList()));
		taskAuxiliaryList.setAll(taskObservableList); 
		statusSaver.saveStatus(taskMasterList, taskObservableList);
	}

	public static Brain getInstance() {
		if (brain == null) {
			brain = new Brain();
		}
		return brain;
	}

	// Initialize first display when Fini is started - executed in MainApp 
	public void initDisplay() {
		rootController.updateMainDisplay(taskAuxiliaryList);
		rootController.updateProjectsOverviewPanel(taskAuxiliaryList);
		rootController.updateTasksOverviewPanel(taskAuxiliaryList);
		rootController.updateFiniPoints(taskMasterList.stream().filter(task -> task.isCompleted()).collect(Collectors.toList()));
	}

//	public static void main(String[] args) {
//		Brain testBrain = Brain.getInstance();
//		testBrain.executeCommand("add curry chicken tomorrow repeat everyday until dec priority high");
//	}
	
	public void executeCommand(String userInput) {
		Command newCommand = new Command(userInput);
		CommandType commandType = newCommand.getCommandType();
		int objectIndex = newCommand.getObjectIndex();
		String commandParameters = newCommand.getCommandParameters();
		
		String display = "";
		switch (commandType) {
		case ADD:
			display = addTask(commandParameters);
			saveThisStatus();
			break;
		case UPDATE:
			display = updateTask(objectIndex, commandParameters);
			saveThisStatus();
			break;
		case DELETE:
			display = deleteTask(objectIndex);
			saveThisStatus();
			break;
		case CLEAR:
			display = clearAllTasks();
			saveThisStatus();
			break;
		case UNDO:
			display = undo();
			break;
		case REDO:
			display = redo();
			break;
		case DISPLAY:
			display = displayTask(commandParameters);
			break;
//		case SEARCH:
//			searchDisplayTrigger = true;
//			display = "Searching...";
//			searchTask(commandParameters);
//			break;
//		case MODE:
//			MainApp.switchMode();
//			break;
		case MODS:
			display = loadNUSMods();
			saveThisStatus();
			break;
		case EXIT:
			System.exit(0);
		case COMPLETE:
			display = completeTask(objectIndex);
			saveThisStatus();
			break;
		case UNCOMPLETE:
			display = uncompleteTask(objectIndex);
			saveThisStatus();
			break;
		case INVALID:
			display = "commandType INVALID";
			break;
		default:
			break;
		}

		displayControl();
		sortTaskMasterList();
		taskAuxiliaryList.setAll(taskMasterList.stream().filter(task -> !task.isCompleted()).collect(Collectors.toList()));
		rootController.updateProjectsOverviewPanel(taskAuxiliaryList);
		rootController.updateTasksOverviewPanel(taskAuxiliaryList);
		
		rootController.updateDisplayToUser(display);
		rootController.updateFiniPoints(taskMasterList.stream().filter(task -> task.isCompleted()).collect(Collectors.toList()));
	}
	
	// Display Control Methods
	private void displayControl() {
		if (completeDisplayTrigger) {
			taskObservableList.setAll(taskMasterList.stream().filter(task -> task.isCompleted()).collect(Collectors.toList()));
			rootController.updateCompletedDisplay(taskObservableList);
		} else if (searchDisplayTrigger) {
			// TODO
		} else if (allDisplayTrigger) {
			rootController.updateAllDisplay(taskObservableList);
		} else {
			sortTaskMasterList();
			taskObservableList.setAll(taskMasterList.stream().filter(task -> !task.isCompleted()).collect(Collectors.toList()));
{'fraction_non_alphanumeric': 0.11029859841560025, 'fraction_numerical': 0.00020312817387771684, 'mean_word_length': 5.037400367872471, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 21, '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': '4790114', 'n_tokens_mistral': 3201, 'n_tokens_neox': 2847, 'n_words': 600}