<commit_before>const util = require('util');
const TASK = require('./tasks.js');
/**
 * TaskCollection - an instance of this structure holds tasks that have already been defined
 * and from which some can be invoked.
 *
 * The constructor TaskCollection can be called without the use of the keyword "new".
 *
 * The properties of the class were originally hidden as local vars inside the constructor
 * and no setter methods are provided to enforce immutability - but that makes them invisible
 * to the debugger.
 *
 * @class      TaskCollection
 * @param   {array of Tasks}        Can initialize a TaskCollection from an array of tasks
 */
 exports.TaskCollection = TaskCollection;
function TaskCollection(arrayOfTasks = undefined)
{
    let obj;

    if (!(this instanceof TaskCollection))
    {
        obj = new TaskCollection(arrayOfTasks);

        return obj;
    }
    this._map = new Map();
    this._tasks = [];
    this._taskNames = [];
    this._tasksByName = {};
    
    if( arrayOfTasks !== undefined)
    {
        arrayOfTasks.forEach((task)=>
        {
            // only add if name not already there
            // if(this._taskNames.find(task.name()) === undefined )
            if( this._tasksByName.hasOwnProperty(task.name()) === false )
            {
                const t = TASK.Task.copy(task);
                add.bind(this)(t);
            }
        })
    }

    function add (task)
    {
        this._map.set(task.name(), task);

        this._tasks.push(task);
        this._taskNames.push(task.name());
        this._tasksByName[task.name()] = task;
        this._map.set(task.name(), task);
    }

    this.addTask = function addTask(task)
	{
        this._map.set(task.name(), task.clone());

        this._tasks.push(task.clone());
        this._taskNames.push(task.name());
        this._tasksByName[task.name()] = task;
        return 
    };

    this.getByName = function getByName(key)
	{
        // if (this._tasksByName.hasOwnProperty(key))
        return this._map.get(key);

        if (this._map.has(key))
		{
            return this._map.get(key);
        }

        return undefined;
    };

    this.getAll = function getAll()
	{
        return this._tasksByName;
    };<commit_msg>before revamp of collection using map<commit_after>const util = require('util');
const TASK = require('./tasks.js');
/**
 * TaskCollection - an instance of this structure holds tasks that have already been defined
 * and from which some can be invoked.
 *
 * The constructor TaskCollection can be called without the use of the keyword "new".
 *
 * The properties of the class were originally hidden as local vars inside the constructor
 * and no setter methods are provided to enforce immutability - but that makes them invisible
 * to the debugger.
 *
 * @class      TaskCollection
 * @param   {array of Tasks}        Can initialize a TaskCollection from an array of tasks
 */
 exports.TaskCollection = TaskCollection;
function TaskCollection(arrayOfTasks = undefined)
{
    let obj;

    if (!(this instanceof TaskCollection))
    {
        obj = new TaskCollection(arrayOfTasks);

        return obj;
    }
    this._map = new Map();
    // this._tasks = [];
    // this._taskNames = [];
    // this._tasksByName = {};
    
    if( arrayOfTasks !== undefined)
    {
        arrayOfTasks.forEach((task)=>
        {
            // only add if name not already there
            // if(this._taskNames.find(task.name()) === undefined )
            if( this._tasksByName.hasOwnProperty(task.name()) === false )
            {
                const t = TASK.Task.copy(task);
                add.bind(this)(t);
            }
        })
    }

    function add (task)
    {
        this._map.set(task.name(), task);

        // this._tasks.push(task);
        // this._taskNames.push(task.name());
        // this._tasksByName[task.name()] = task;
        // this._map.set(task.name(), task);
    }

    this.addTask = function addTask(task)
	{
        this._map.set(task.name(), task.clone());

        // this._tasks.push(task.clone());
        // this._taskNames.push(task.name());
        // this._tasksByName[task.name()] = task;
        return 
    };

    this.getByName = function getByName(key)
	{
        // if (this._tasksByName.hasOwnProperty(key))
        return this._map.get(key);

  //       if (this._map.has(key))
		// {
  //           return this._map.get(key);
  //       }

  //       return undefined;
    };

    this.getAll = function getAll()
	{
        return this._map;
        // return this._tasksByName;
    };
{'fraction_non_alphanumeric': 0.12647702407002187, 'fraction_numerical': 0.0, 'mean_word_length': 2.1502412129565815, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '331658', 'n_tokens_mistral': 1294, 'n_tokens_neox': 1289, 'n_words': 339}