/// class PD.Commands.CommandGroupCollection

PD.Commands.CommandGroupCollection =
Class.extend({

    //===================================
    // FIELDS
    //===================================

    _collection: null,

    //===================================
    // CONSTRUCTOR
    //===================================

    init: function () {
        this._collection = {};
    },

    //===================================
    // PUBLIC METHODS
    //===================================

    each: function (fn) {
        for (var key in this._collection) {
            if (fn != null) {
                fn(key, this._collection[key]);
            }
        }
    },

    add: function (group) {
        if (this.groupIsValid(group)
            && !this.groupIsDefined(group.get_id())) {
            this._collection[group.get_id()] = group;
        }
    },

    remove: function (id) {
        if (this.groupIsDefined(id)) {
            delete this._collection[id];
        }
    },

    groupIsValid: function (group) {
        return group.get_id != null
            && group.get_id() != null;
    },

    groupIsDefined: function (id) {
        return this._collection[id] !== undefined;
    },

    getByPath: function (commandPath) {
        
        var result = null,
            pieces = PD.Commands.CommandUtil.splitPath(commandPath);

        if (pieces.groupId != null) {
            result = this._collection[pieces.groupId];
        }

        return result;

    },
    
    getById: function (groupId) {
        return this._collection[groupId];
    }
    
});