<commit_before>/*
    Weave (Web-based Analysis and Visualization Environment)
    Copyright (C) 2008-2011 University of Massachusetts Lowell

    This file is a part of Weave.

    Weave is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License, Version 3,
    as published by the Free Software Foundation.

    Weave is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Weave.  If not, see <http://www.gnu.org/licenses/>.
*/

package weave.services
{
	import flash.utils.Dictionary;
	
	import weave.api.data.IProgressIndicator;
	import weave.core.CallbackCollection;

	/**
	 * This class is used as a central location for reporting the progress of pending asynchronous requests.
	 * 
	 * @author adufilie
	 */
	public class ProgressIndicator extends CallbackCollection implements IProgressIndicator
	{
		/**
		 * This is the number of pending requests.
		 */
		public function getTaskCount():int
		{
			return _taskCount;
		}

		/**
		 * This function will register a pending request token and increase the pendingRequestCount if necessary.
		 * 
		 * @param taskToken The object whose progress to track.
		 */
		public function addTask(taskToken:Object):void
		{
			updateTask(taskToken, 0);
		}
		
		/**
		 * This function will report the current progress of a request.
		 * 
		 * @param taskToken The object whose progress to track.
		 * @param percent The current progress of the token's request.
		 */
		public function updateTask(taskToken:Object, percent:Number):void
		{
			// if this token isn't in the Dictionary yet, increase count
			if (_taskToProgressMap[taskToken] === undefined)
			{
				_taskCount++;
				_maxTaskCount++;
			}
			_taskToProgressMap[taskToken] = percent;
			triggerCallbacks();
		}
		
		/**
		 * This function will remove a previously registered pending request token and decrease the pendingRequestCount if necessary.
		 * 
		 * @param taskToken The object to remove from the progress indicator.
		 */
		public function removeTask(taskToken:Object):void
		{
			// if the token isn't in the dictionary, do nothing
			if (_taskToProgressMap[taskToken] === undefined)
				return;
			
			delete _taskToProgressMap[taskToken];
			_taskCount--;
			// reset max count when count goes to zero
			if (_taskCount == 0)
				_maxTaskCount = 0;
			
			triggerCallbacks();<commit_msg>progress indicator now checks for Infinity progress values.<commit_after>/*
    Weave (Web-based Analysis and Visualization Environment)
    Copyright (C) 2008-2011 University of Massachusetts Lowell

    This file is a part of Weave.

    Weave is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License, Version 3,
    as published by the Free Software Foundation.

    Weave is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Weave.  If not, see <http://www.gnu.org/licenses/>.
*/

package weave.services
{
	import flash.utils.Dictionary;
	
	import weave.api.data.IProgressIndicator;
	import weave.core.CallbackCollection;

	/**
	 * This class is used as a central location for reporting the progress of pending asynchronous requests.
	 * 
	 * @author adufilie
	 */
	public class ProgressIndicator extends CallbackCollection implements IProgressIndicator
	{
		/**
		 * This is the number of pending requests.
		 */
		public function getTaskCount():int
		{
			return _taskCount;
		}

		/**
		 * This function will register a pending request token and increase the pendingRequestCount if necessary.
		 * 
		 * @param taskToken The object whose progress to track.
		 */
		public function addTask(taskToken:Object):void
		{
			updateTask(taskToken, 0);
		}
		
		/**
		 * This function will report the current progress of a request.
		 * 
		 * @param taskToken The object whose progress to track.
		 * @param percent The current progress of the token's request.
		 */
		public function updateTask(taskToken:Object, percent:Number):void
		{
			// if this token isn't in the Dictionary yet, increase count
			if (_taskToProgressMap[taskToken] === undefined)
			{
				_taskCount++;
				_maxTaskCount++;
			}
			if (percent == Infinity)
				percent = 0.5; // undetermined
			_taskToProgressMap[taskToken] = percent;
			triggerCallbacks();
		}
		
		/**
		 * This function will remove a previously registered pending request token and decrease the pendingRequestCount if necessary.
		 * 
		 * @param taskToken The object to remove from the progress indicator.
		 */
		public function removeTask(taskToken:Object):void
		{
			// if the token isn't in the dictionary, do nothing
			if (_taskToProgressMap[taskToken] === undefined)
				return;
			
			delete _taskToProgressMap[taskToken];
			_taskCount--;
			// reset max count when count goes to zero
			if (_taskCount == 0)
				_maxTaskCount = 0;
			
			triggerCallbacks();
{'fraction_non_alphanumeric': 0.07122878985642364, 'fraction_numerical': 0.004848032817452918, 'mean_word_length': 3.311897106109325, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, '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': '6881790', 'n_tokens_mistral': 1631, 'n_tokens_neox': 1372, 'n_words': 584}