/// class PD.Web.UI.MutationSourceCollection

PD.Web.UI.MutationSourceCollection =
Class.extend({

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

    _innerDict: null,

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

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

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

    add: function (source) {
    
        var id = source.get_id();

        if (!this.exists(id)) {
            this._innerDict[id] = source;
        }

    },

    clear: function () {
        this._innerDict = {};
    },

    get: function (id) {
        return this._innerDict[id];
    },

    remove: function (id) {
        if (get(id) !== undefined) {
            delete this._innerDict[id];
        }
    },

    each: function (fn) {

        for (id in this._innerDict) {
            if (fn(id, this._innerDict[id]) === false) {
                break;
            };
        }

    },

    getDirty: function () {

        var result = new PD.BCL.List();

        this.each(function (id, source) {
            if (source.isDirty) {
                result.add(id);
            }
        });

        return result;

    },

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

    setClean: function () {
        this.each(function (id, source) {
            source.setClean();
        });
    }

});