<commit_before>/*
* Copyright (c) 2010 <NAME> [http://www.kaizimmer.com]
*
* Permission is hereby granted to use, modify, and distribute this file
* in accordance with the terms of the license agreement accompanying it.
*/
org.rialoom.utils.ClassUtils.createPackage("org.rialoom.base");
/**
 * CommandMap constructor
 * @author k.zimmer aka engimono
 */
org.rialoom.base.CommandMap = function ( eventDispatcher, mediatorMap, modelMap )
{
    var _this = this;
    var _dispatcher = eventDispatcher;
    var _mediatorMap = mediatorMap;
    var _modelMap = modelMap;
    // eventListEntry = { eventType: eventType, eventClass: eventClass, commands: [] };
    // commandEntry = { command: commandClass, isOneShot: oneShot };
    var _eventLists = {};
    /**
     *
     */
    function _execCommand ( e )
    {
        var type = e.getType();
        if ( !_eventLists[type] ) return;
        var cmds = _eventLists[type].commands;
        for ( var i = 0; i < cmds.length; i++ )
        {
            // prevent commands registered with an eventClass parameter from being executed if the event type is the wrong one
            if ( cmds[i].eventClass != null && !( e instanceof cmds[i].eventClass ) ) continue;
            // create mixin execute
            var cmd = new cmds[i].command();
            cmd.dispatch = function ( event )
            {
                _dispatcher.dispatchEvent(event)
            };
            cmd.getEventDispatcher = function () {return _dispatcher};
            cmd.getCommandMap = function () {return _this};
            cmd.getMediatorMap = function () {return _mediatorMap};
            cmd.getModelMap = function () {return _modelMap};
            cmd.execute(e);
        }
        // delete one shots
        for ( i = cmds.length - 1; i >= 0; i-- )
        {
            if ( cmds[i].eventClass != null && !( e instanceof cmds[i].eventClass ) ) continue;
            if ( cmds[i].isOneShot )
            {
                cmds.splice(i,1);
            }
        }
    }
    /**
     *  Registers controller class with the passed event
     */
    this.mapEvent = function ( eventType, commandClass, eventClass, oneShot )
    {
        // check commandClass
        //*/
        var baseClass = org.rialoom.mvcs.AbstractCommand;
        if ( !commandClass || !(commandClass.prototype instanceof baseClass) )
        {
            throw new Error("org.rialoom.base.CommandMap .mapEvent() | "
                            + "commandClass param "+ commandClass + " is no subclass of "
                            + baseClass + "!");
        }
        //*/
        // create event list if not existing
        if ( !_eventLists[eventType] )
        {
            _eventLists[eventType] =
            {
                eventType: eventType,
                commands: []
            };
        }
        // add listener
        _eventLists[eventType].commands.push(
            {
                command: commandClass,
                eventClass: eventClass,
                isOneShot: oneShot
            }
        );
        _dispatcher.addEventListener( eventType, this, _execCommand );
    };
    /**
     *  Removes controller class and returns boolean flag indicating success
     */
    this.unmapEvent = function ( eventType, commandClass, eventClass )
    {
        if ( !_eventLists[eventType] ) return false;
        if ( eventClass )
        {
            if ( _eventLists[eventType].eventClass != eventClass ) return false;
        }
        var cmds = _eventLists[eventType].commands;
        for ( i = 0; i < cmds.length; i++ )
        {
            if ( cmds[i].command == commandClass )
            {
                if ( cmds[i].eventClass != null && cmds[i].eventClass != eventClass ) continue;
                cmds.splice(i,1);
                return true;<commit_msg>Now registration of already registered cmd - event class couplings are prevented. Fixed Bug in CommandMap .unmapEvent() method.<commit_after>/*
* Copyright (c) 2010 <NAME> [http://www.kaizimmer.com]
*
* Permission is hereby granted to use, modify, and distribute this file
* in accordance with the terms of the license agreement accompanying it.
*/
org.rialoom.utils.ClassUtils.createPackage("org.rialoom.base");
/**
 * CommandMap constructor
 * @author k.zimmer aka engimono
 */
org.rialoom.base.CommandMap = function ( eventDispatcher, mediatorMap, modelMap )
{
    var _this = this;
    var _dispatcher = eventDispatcher;
    var _mediatorMap = mediatorMap;
    var _modelMap = modelMap;
    // eventListEntry = { eventType: eventType, eventClass: eventClass, commands: [] };
    // commandEntry = { command: commandClass, isOneShot: oneShot };
    var _eventLists = {};
    /**
     *
     */
    function _execCommand ( e )
    {
        var type = e.getType();
        if ( !_eventLists[type] ) return;
        var cmds = _eventLists[type].commands;
        for ( var i = 0; i < cmds.length; i++ )
        {
            // prevent commands registered with an eventClass parameter from being executed if the event type is the wrong one
            if ( cmds[i].eventClass != null && !( e instanceof cmds[i].eventClass ) ) continue;
            // create mixin execute
            var cmd = new cmds[i].command();
            cmd.dispatch = function ( event )
            {
                _dispatcher.dispatchEvent(event)
            };
            cmd.getEventDispatcher = function () {return _dispatcher};
            cmd.getCommandMap = function () {return _this};
            cmd.getMediatorMap = function () {return _mediatorMap};
            cmd.getModelMap = function () {return _modelMap};
            cmd.execute(e);
        }
        // delete one shots
        for ( i = cmds.length - 1; i >= 0; i-- )
        {
            if ( cmds[i].eventClass != null && !( e instanceof cmds[i].eventClass ) ) continue;
            if ( cmds[i].isOneShot )
            {
                cmds.splice(i,1);
            }
        }
    }
    /**
     *  Registers controller class with the passed event
     */
    this.mapEvent = function ( eventType, commandClass, eventClass, oneShot )
    {
        // check commandClass
        //*/
        var baseClass = org.rialoom.mvcs.AbstractCommand;
        if ( !commandClass || !(commandClass.prototype instanceof baseClass) )
        {
            throw new Error("org.rialoom.base.CommandMap .mapEvent() | "
                            + "commandClass param "+ commandClass + " is no subclass of "
                            + baseClass + "!");
        }
        //*/
        // create event list if not existing
        if ( !_eventLists[eventType] )
        {
            _eventLists[eventType] =
            {
                eventType: eventType,
                commands: []
            };
        }
        // prohibit multiple registrations of same cmd class + event class couplings
        var cmds = _eventLists[eventType].commands;
        for ( var i = 0; i < cmds.length; i++ )
        {
            if ( cmds[i].eventClass != eventClass ) continue;
            if ( cmds[i].command != commandClass ) continue;
            return false;
        }
        // add listener
        _eventLists[eventType].commands.push(
            {
                command: commandClass,
                eventClass: eventClass,
                isOneShot: oneShot
            }
        );
        _dispatcher.addEventListener( eventType, this, _execCommand );
    };
    /**
     *  Removes controller class and returns boolean flag indicating success
     */
    this.unmapEvent = function ( eventType, commandClass, eventClass )
    {
        if ( !_eventLists[eventType] ) return false;
        //
        var cmds = _eventLists[eventType].commands;
        for ( i = 0; i < cmds.length; i++ )
        {
            if ( cmds[i].command == commandClass )
            {
                if ( cmds[i].eventClass != eventClass ) continue;
                cmds.splice(i,1);
                return true;
{'fraction_non_alphanumeric': 0.10855923694779117, 'fraction_numerical': 0.0026355421686746986, 'mean_word_length': 1.7708623087621698, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 7, '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': '4919573', 'n_tokens_mistral': 2222, 'n_tokens_neox': 2147, 'n_words': 562}