<commit_before>/*******************************************************************************
 * Copyright (c) 2004, 2007 Mylyn project committers and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/

package org.eclipse.mylyn.tasks.core;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;

import org.eclipse.mylyn.internal.tasks.core.ITasksCoreConstants;
import org.eclipse.mylyn.internal.tasks.core.LocalRepositoryConnector;
import org.eclipse.mylyn.internal.tasks.core.LocalTask;
import org.eclipse.mylyn.internal.tasks.core.OrphanedTasksContainer;
import org.eclipse.mylyn.internal.tasks.core.RepositoryTaskHandleUtil;
import org.eclipse.mylyn.internal.tasks.core.TaskArchive;
import org.eclipse.mylyn.internal.tasks.core.TaskCategory;
import org.eclipse.mylyn.internal.tasks.core.UnfiledCategory;
import org.eclipse.mylyn.monitor.core.StatusHandler;

/**
 * Stores and manages task list elements and their containment hierarchy.
 * 
 * @author <NAME>
 * @since 2.0
 */
public class TaskList {

	private int lastLocalTaskId = 0;

	private Set<ITaskListChangeListener> changeListeners = new CopyOnWriteArraySet<ITaskListChangeListener>();

	private Map<String, OrphanedTasksContainer> repositoryOrphansMap;

	private Map<String, AbstractTask> tasks;

	private Map<String, AbstractTaskCategory> categories;

	private Map<String, AbstractRepositoryQuery> queries;

	private List<AbstractTask> activeTasks;

	private TaskArchive archiveContainer;

	private UnfiledCategory defaultCategory;

	public TaskList() {
		reset();
	}

	/**
	 * @since 2.2
	 */
	private void addOrphan(AbstractTask task, Set<TaskContainerDelta> delta) {
		addOrphan(task, delta, 0);
	}

	/**
	 * @since 2.2
	 */
	private void addOrphan(AbstractTask task, Set<TaskContainerDelta> delta, int depth) {
		if (/*task.getLastReadTimeStamp() == null ||*/!getQueriesForHandle(task.getHandleIdentifier()).isEmpty()
				|| getCategoryForHandle(task.getHandleIdentifier()) != null) {
			// Current policy is not to archive/orphan if the task exists in some other container
			return;
		}

		if (task instanceof LocalTask) {
			moveTask(task, defaultCategory);
			return;
		}

		OrphanedTasksContainer orphans = repositoryOrphansMap.get(task.getRepositoryUrl());
		//		if (orphans == null) {
		//			orphans = new OrphanedTasksContainer(task.getConnectorKind(), task.getRepositoryUrl());
		//			repositoryOrphansMap.put(task.getRepositoryUrl(), orphans);
		//			//categories.put(orphans.getHandleIdentifier(), orphans);
		//		}

		if (orphans != null) {
			if (!orphans.contains(task.getHandleIdentifier())) {
				orphans.internalAddChild(task);
				if (delta != null) {
					delta.add(new TaskContainerDelta(orphans, TaskContainerDelta.Kind.CHANGED));
				}
			}
			task.addParentContainer(orphans);
		} else {
			//StatusHandler.log("Orphan container not found for: " + task.getRepositoryUrl(), this);
		}

		if (depth < ITasksCoreConstants.MAX_SUBTASK_DEPTH && !task.isEmpty()) {
			for (AbstractTask child : task.getChildren()) {<commit_msg>NEW - bug 213228: [performance] mylyn.tasks.ui locks up for a while upon start https://bugs.eclipse.org/bugs/show_bug.cgi?id=213228<commit_after>/*******************************************************************************
 * Copyright (c) 2004, 2007 Mylyn project committers and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/

package org.eclipse.mylyn.tasks.core;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;

import org.eclipse.mylyn.internal.tasks.core.ITasksCoreConstants;
import org.eclipse.mylyn.internal.tasks.core.LocalRepositoryConnector;
import org.eclipse.mylyn.internal.tasks.core.LocalTask;
import org.eclipse.mylyn.internal.tasks.core.OrphanedTasksContainer;
import org.eclipse.mylyn.internal.tasks.core.RepositoryTaskHandleUtil;
import org.eclipse.mylyn.internal.tasks.core.TaskArchive;
import org.eclipse.mylyn.internal.tasks.core.TaskCategory;
import org.eclipse.mylyn.internal.tasks.core.UnfiledCategory;
import org.eclipse.mylyn.monitor.core.StatusHandler;

/**
 * Stores and manages task list elements and their containment hierarchy.
 * 
 * @author <NAME>
 * @since 2.0
 */
public class TaskList {

	private int lastLocalTaskId = 0;

	private Set<ITaskListChangeListener> changeListeners = new CopyOnWriteArraySet<ITaskListChangeListener>();

	private Map<String, OrphanedTasksContainer> repositoryOrphansMap;

	private Map<String, AbstractTask> tasks;

	private Map<String, AbstractTaskCategory> categories;

	private Map<String, AbstractRepositoryQuery> queries;

	private List<AbstractTask> activeTasks;

	private TaskArchive archiveContainer;

	private UnfiledCategory defaultCategory;

	public TaskList() {
		reset();
	}

	/**
	 * @since 2.2
	 */
	private void addOrphan(AbstractTask task, Set<TaskContainerDelta> delta) {
		addOrphan(task, delta, 0);
	}

	/**
	 * @since 2.2
	 */
	private void addOrphan(AbstractTask task, Set<TaskContainerDelta> delta, int depth) {
		if (/*task.getLastReadTimeStamp() == null ||*/!getQueriesForHandle(task.getHandleIdentifier()).isEmpty()
				|| getCategoryForHandle(task.getHandleIdentifier()) != null) {
			// Current policy is not to archive/orphan if the task exists in some other container
			return;
		}

		if (task instanceof LocalTask) {
			moveTask(task, defaultCategory);
			return;
		}

		OrphanedTasksContainer orphans = repositoryOrphansMap.get(task.getRepositoryUrl());
		//		if (orphans == null) {
		//			orphans = new OrphanedTasksContainer(task.getConnectorKind(), task.getRepositoryUrl());
		//			repositoryOrphansMap.put(task.getRepositoryUrl(), orphans);
		//			//categories.put(orphans.getHandleIdentifier(), orphans);
		//		}

		if (orphans != null) {
			//if (!orphans.contains(task.getHandleIdentifier())) {
			orphans.internalAddChild(task);
			if (delta != null) {
				delta.add(new TaskContainerDelta(orphans, TaskContainerDelta.Kind.CHANGED));
			}
			//}
			task.addParentContainer(orphans);
		} else {
			//StatusHandler.log("Orphan container not found for: " + task.getRepositoryUrl(), this);
		}

		if (depth < ITasksCoreConstants.MAX_SUBTASK_DEPTH && !task.isEmpty()) {
			for (AbstractTask child : task.getChildren()) {
{'fraction_non_alphanumeric': 0.15312586064445055, 'fraction_numerical': 0.007160561828697329, 'mean_word_length': 5.176020408163265, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 23, 'https://': 1, 'lorem ipsum': 0, 'www.': 2, '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': '6891648', 'n_tokens_mistral': 2291, 'n_tokens_neox': 2077, 'n_words': 464}