<commit_before>package seedu.manager.model;

import javafx.collections.transformation.FilteredList;
import seedu.manager.commons.core.ComponentManager;
import seedu.manager.commons.core.LogsCenter;
import seedu.manager.commons.core.UnmodifiableObservableList;
import seedu.manager.commons.events.model.ActivityManagerChangedEvent;
import seedu.manager.commons.events.ui.ActivityListPanelUpdateEvent;
import seedu.manager.commons.util.StringUtil;
import seedu.manager.model.activity.*;

import java.util.ArrayList;
import java.util.Set;
import java.util.function.Predicate;
import java.util.logging.Logger;

/**
 * Represents the in-memory model of the activity manager data.
 * All changes to any model should be synchronized.
 */
public class ModelManager extends ComponentManager implements Model {
    private static final Logger logger = LogsCenter.getLogger(ModelManager.class);

    private ActivityManager activityManager;
    private FilteredList<Activity> filteredActivities;
    
    private ArrayList<ActivityManager> managerHistory = new ArrayList<ActivityManager>();
    private int historyIndex = -1;
    
    /**
     * Initializes a ModelManager with the given ActivityManager
     * ActivityManager and its variables should not be null
     */
    public ModelManager(ActivityManager src, UserPrefs userPrefs) {
        super();
        assert src != null;
        assert userPrefs != null;

        logger.fine("Initializing with activity manager: " + src + " and user prefs " + userPrefs);

        activityManager = new ActivityManager(src);
        filteredActivities = new FilteredList<>(activityManager.getActivities());
        // recordManagerHistory(activityManager);
    }

    public ModelManager() {
        this(new ActivityManager(), new UserPrefs());
    }

    public ModelManager(ReadOnlyActivityManager initialData, UserPrefs userPrefs) {
        activityManager = new ActivityManager(initialData);
        filteredActivities = new FilteredList<>(activityManager.getActivities());
        updateFilteredActivityList();
        recordManagerHistory(activityManager);
    }

    @Override
    public void resetData(ReadOnlyActivityManager newData) {
        activityManager.resetData(newData);
        recordManagerHistory(activityManager);
        indicateActivityManagerChanged();
    }

    @Override
    public ReadOnlyActivityManager getActivityManager() {
        return activityManager;
    }

    /** Raises an event to indicate the model has changed */
    private void indicateActivityManagerChanged() {
        raise(new ActivityManagerChangedEvent(activityManager));
        
    }
    
    //@@author A0139797E
    private void indicateActivityListPanelUpdate(){
        raise(new ActivityListPanelUpdateEvent(getFilteredFloatingActivityList(), getFilteredDeadlineAndEventList(), -1));
    }

    
    private void indicateActivityListPanelUpdate(Activity newActivity){
    	// Find index of new/updated activity and set it as our target to scroll to
    	int index = -1;
        UnmodifiableObservableList<Activity> activities = getFilteredActivityList();
    	for (int i = activities.size() - 1; i >= 0; i--) {
    	    Activity activity = activities.get(i);
    	    if (activity.equals(newActivity)) {
    	        index = i;
    	        activity.setSelected(true);
    	    } else {
    	        // clear previous selection status (on UI)
    	        activity.setSelected(false);
    	    }
    	}
    	raise(new ActivityListPanelUpdateEvent(getFilteredFloatingActivityList(), getFilteredDeadlineAndEventList(), index));
    }

    //@@author A0139797E
    @Override
    public synchronized void addActivity(Activity activity, boolean isLastRecurring) {
        activityManager.addActivity(activity);
        updateFilteredActivityList();
        indicateActivityListPanelUpdate(activity);
        indicateActivityManagerChanged();
        // Record state only for the last addition (esp. for recurring tasks)
        if (isLastRecurring) {
            recordManagerHistory(activityManager);
        }
    }
    
    //@@author A0144881Y
    @Override
    public synchronized void deleteActivity(Activity target) {
        activityManager.removeActivity(target);
        updateFilteredActivityList();
        indicateActivityListPanelUpdate();
        indicateActivityManagerChanged();
        recordManagerHistory(activityManager);
    }
    
    @Override
    public synchronized void updateActivity(Activity activity, String newName, String newDateTime, String newEndDateTime) {
        activityManager.updateActivity(activity, newName, newDateTime, newEndDateTime);
        updateFilteredActivityList();
        indicateActivityManagerChanged();
        indicateActivityListPanelUpdate(activity);
        recordManagerHistory(activityManager);
    }

    //@@author A0144704L
    @Override
    public synchronized void markActivity(Activity activity) {
        activityManager.markActivity(activity);
        updateFilteredActivityList();
        indicateActivityManagerChanged();
        recordManagerHistory(activityManager);
    }

    @Override
    public synchronized void unmarkActivity(Activity activity) {
        activityManager.unmarkActivity(activity);
        updateFilteredActivityList();<commit_msg>Revert to fix mark test<commit_after>package seedu.manager.model;

import javafx.collections.transformation.FilteredList;
import seedu.manager.commons.core.ComponentManager;
import seedu.manager.commons.core.LogsCenter;
import seedu.manager.commons.core.UnmodifiableObservableList;
import seedu.manager.commons.events.model.ActivityManagerChangedEvent;
import seedu.manager.commons.events.ui.ActivityListPanelUpdateEvent;
import seedu.manager.commons.util.StringUtil;
import seedu.manager.model.activity.*;

import java.util.ArrayList;
import java.util.Set;
import java.util.function.Predicate;
import java.util.logging.Logger;

/**
 * Represents the in-memory model of the activity manager data.
 * All changes to any model should be synchronized.
 */
public class ModelManager extends ComponentManager implements Model {
    private static final Logger logger = LogsCenter.getLogger(ModelManager.class);

    private ActivityManager activityManager;
    private FilteredList<Activity> filteredActivities;
    
    private ArrayList<ActivityManager> managerHistory = new ArrayList<ActivityManager>();
    private int historyIndex = -1;
    
    /**
     * Initializes a ModelManager with the given ActivityManager
     * ActivityManager and its variables should not be null
     */
    public ModelManager(ActivityManager src, UserPrefs userPrefs) {
        super();
        assert src != null;
        assert userPrefs != null;

        logger.fine("Initializing with activity manager: " + src + " and user prefs " + userPrefs);

        activityManager = new ActivityManager(src);
        filteredActivities = new FilteredList<>(activityManager.getActivities());
        // recordManagerHistory(activityManager);
    }

    public ModelManager() {
        this(new ActivityManager(), new UserPrefs());
    }

    public ModelManager(ReadOnlyActivityManager initialData, UserPrefs userPrefs) {
        activityManager = new ActivityManager(initialData);
        filteredActivities = new FilteredList<>(activityManager.getActivities());
        updateFilteredActivityList();
        recordManagerHistory(activityManager);
    }

    @Override
    public void resetData(ReadOnlyActivityManager newData) {
        activityManager.resetData(newData);
        recordManagerHistory(activityManager);
        indicateActivityManagerChanged();
    }

    @Override
    public ReadOnlyActivityManager getActivityManager() {
        return activityManager;
    }

    /** Raises an event to indicate the model has changed */
    private void indicateActivityManagerChanged() {
        raise(new ActivityManagerChangedEvent(activityManager));
        
    }
    
    //@@author A0139797E
    private void indicateActivityListPanelUpdate(){
        raise(new ActivityListPanelUpdateEvent(getFilteredFloatingActivityList(), getFilteredDeadlineAndEventList(), -1));
    }

    
    private void indicateActivityListPanelUpdate(Activity newActivity){
    	// Find index of new/updated activity and set it as our target to scroll to
    	int index = -1;
        UnmodifiableObservableList<Activity> activities = getFilteredActivityList();
    	for (int i = activities.size() - 1; i >= 0; i--) {
    	    Activity activity = activities.get(i);
    	    if (activity.equals(newActivity)) {
    	        index = i;
    	        activity.setSelected(true);
    	    } else {
    	        // clear previous selection status (on UI)
    	        activity.setSelected(false);
    	    }
    	}
    	raise(new ActivityListPanelUpdateEvent(getFilteredFloatingActivityList(), getFilteredDeadlineAndEventList(), index));
    }

    //@@author A0139797E
    @Override
    public synchronized void addActivity(Activity activity, boolean isLastRecurring) {
        activityManager.addActivity(activity);
        updateFilteredListToShowAll();
        indicateActivityListPanelUpdate(activity);
        indicateActivityManagerChanged();
        // Record state only for the last addition (esp. for recurring tasks)
        if (isLastRecurring) {
            recordManagerHistory(activityManager);
        }
    }
    
    //@@author A0144881Y
    @Override
    public synchronized void deleteActivity(Activity target) {
        activityManager.removeActivity(target);
        updateFilteredListToShowAll();
        indicateActivityListPanelUpdate();
        indicateActivityManagerChanged();
        recordManagerHistory(activityManager);
    }
    
    @Override
    public synchronized void updateActivity(Activity activity, String newName, String newDateTime, String newEndDateTime) {
        activityManager.updateActivity(activity, newName, newDateTime, newEndDateTime);
        updateFilteredListToShowAll();
        indicateActivityManagerChanged();
        indicateActivityListPanelUpdate(activity);
        recordManagerHistory(activityManager);
    }

    //@@author A0144704L
    @Override
    public synchronized void markActivity(Activity activity) {
        activityManager.markActivity(activity);
        updateFilteredActivityList();
        indicateActivityManagerChanged();
        recordManagerHistory(activityManager);
    }

    @Override
    public synchronized void unmarkActivity(Activity activity) {
        activityManager.unmarkActivity(activity);
        updateFilteredActivityList();
{'fraction_non_alphanumeric': 0.0807353359234341, 'fraction_numerical': 0.006254145740547712, 'mean_word_length': 3.504481434058899, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, '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': '6738055', 'n_tokens_mistral': 2625, 'n_tokens_neox': 2586, 'n_words': 609}