<commit_before>/* ***** BEGIN LICENSE BLOCK *****
 *
 * This file is part of Weave.
 *
 * The Initial Developer of Weave is the Institute for Visualization
 * and Perception Research at the University of Massachusetts Lowell.
 * Portions created by the Initial Developer are Copyright (C) 2008-2015
 * the Initial Developer. All Rights Reserved.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/.
 * 
 * ***** END LICENSE BLOCK ***** */

package weavejs.util
{
	import weavejs.api.core.DynamicState;
	import weavejs.api.core.ILinkableCompositeObject;
	import weavejs.api.core.ILinkableObject;
	
	/**
	 * Tools for debugging.
	 * 
	 * @author adufilie
	 */
	public class DebugUtils
	{
		/****************************
		 **  Object id and lookup  **
		 ****************************/
		
		private static var map_id_obj:Object = new JS.Map();
		private static var map_obj_id:Object = new JS.Map();
		private static var _nextId:int = 0;
		
		/**
		 * This function calls trace() using debugId() on each parameter.
		 */
		public static function debugTrace(...args):void
		{
			for (var i:int = 0; i < args.length; i++)
				args[i] = debugId(args[i]);
			
			JS.log.apply(JS, args);
		}
		
		/**
		 * This function generates or returns a previously generated identifier for an object.
		 */
		public static function debugId(object:Object):String
		{
			if (JS.isPrimitive(object))
				return String(object);
			var idString:String = map_obj_id.get(object);
			if (!idString)
			{
				var idNumber:int = _nextId++;
				var className:String = Weave.className(object).split(':').pop();
				idString = className + '#' + idNumber;
				
				// save lookup from object to idString
				map_obj_id.set(object, idString);
				// save lookup from idString and idNumber to object
				map_id_obj.set(idNumber, object);
				map_id_obj.set(idString, object);
			}
			return idString;
		}
		
		/**
		 * This function will look up the object corresponding to the specified debugId.
		 * @param debugId A debugId String or integer.
		 */
		public static function debugLookup(debugId:* = undefined):Object
		{
			if (debugId === undefined)
				return getAllDebugIds();
			return map_id_obj.get(debugId);
		}
		
		public static function getAllDebugIds():Array
		{
			var ids:Array = new Array(_nextId);
			for (var i:int = 0; i < _nextId; i++)
				ids[i] = map_obj_id.get(map_id_obj.get(i));
			return ids;<commit_msg>fixed bug generating debug id from qualified class name<commit_after>/* ***** BEGIN LICENSE BLOCK *****
 *
 * This file is part of Weave.
 *
 * The Initial Developer of Weave is the Institute for Visualization
 * and Perception Research at the University of Massachusetts Lowell.
 * Portions created by the Initial Developer are Copyright (C) 2008-2015
 * the Initial Developer. All Rights Reserved.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/.
 * 
 * ***** END LICENSE BLOCK ***** */

package weavejs.util
{
	import weavejs.api.core.DynamicState;
	import weavejs.api.core.ILinkableCompositeObject;
	import weavejs.api.core.ILinkableObject;
	
	/**
	 * Tools for debugging.
	 * 
	 * @author adufilie
	 */
	public class DebugUtils
	{
		/****************************
		 **  Object id and lookup  **
		 ****************************/
		
		private static var map_id_obj:Object = new JS.Map();
		private static var map_obj_id:Object = new JS.Map();
		private static var _nextId:int = 0;
		
		/**
		 * This function calls trace() using debugId() on each parameter.
		 */
		public static function debugTrace(...args):void
		{
			for (var i:int = 0; i < args.length; i++)
				args[i] = debugId(args[i]);
			
			JS.log.apply(JS, args);
		}
		
		/**
		 * This function generates or returns a previously generated identifier for an object.
		 */
		public static function debugId(object:Object):String
		{
			if (JS.isPrimitive(object))
				return String(object);
			var idString:String = map_obj_id.get(object);
			if (!idString)
			{
				var idNumber:int = _nextId++;
				var className:String = Weave.className(object).split('.').pop();
				idString = className + '#' + idNumber;
				
				// save lookup from object to idString
				map_obj_id.set(object, idString);
				// save lookup from idString and idNumber to object
				map_id_obj.set(idNumber, object);
				map_id_obj.set(idString, object);
			}
			return idString;
		}
		
		/**
		 * This function will look up the object corresponding to the specified debugId.
		 * @param debugId A debugId String or integer.
		 */
		public static function debugLookup(debugId:* = undefined):Object
		{
			if (debugId === undefined)
				return getAllDebugIds();
			return map_id_obj.get(debugId);
		}
		
		public static function getAllDebugIds():Array
		{
			var ids:Array = new Array(_nextId);
			for (var i:int = 0; i < _nextId; i++)
				ids[i] = map_obj_id.get(map_id_obj.get(i));
			return ids;
{'fraction_non_alphanumeric': 0.13400857031554345, 'fraction_numerical': 0.00584339696143358, 'mean_word_length': 3.3078859060402683, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7134713', 'n_tokens_mistral': 1849, 'n_tokens_neox': 1545, 'n_words': 505}