<commit_before>goog.provide('recoil.ui.widgets.TableMetaData');
goog.provide('recoil.ui.widgets.table.DefaultColumn');
goog.provide('recoil.ui.widgets.table.SeperatorColumn');

goog.require('recoil.structs.table.ColumnKey');
goog.require('recoil.structs.table.Table');
goog.require('recoil.ui.RenderedDecorator');
goog.require('recoil.ui.widgets.table.Column');
goog.require('recoil.ui.widgets.table.StringColumn');
goog.require('recoil.util.func');
goog.require('recoil.util.object');

/**
 * data that describes the table, it contains the columns and how to contruct the render widget
 * for that column
 * @constructor
 */
recoil.ui.widgets.TableMetaData = function() {
    this.columns_ = [];
    this.colSeperators_ = [];
    this.colSeperatorsOpts_ = [];
};

/**
 * @template CT
 * @param {!recoil.ui.widgets.table.Column<CT>} col
 */
recoil.ui.widgets.TableMetaData.prototype.addColumn = function(col) {
    if (!col) {
        throw new Error('undefined column');
    }
    this.columns_.push(col);
};
/**
 * @param {!recoil.structs.table.ColumnKey} key
 * @param {string|Node} name if you pass a node this will allow better formating of header
 * @param {!Object=} opt_meta
 * @param {!Object=} opt_DecOptions the options passed to createDom when the decorator is created
 */

recoil.ui.widgets.TableMetaData.prototype.addSeperatorCol = function(key, name, opt_meta, opt_DecOptions) {
    if (!key) {
        throw new Error('undefined column key');
    }

    this.addColumn(new recoil.ui.widgets.table.SeperatorColumn(key, name, opt_meta || {}));
    this.colSeperators_.push(key);
    this.colSeperatorsOpts_.push({key: key, opt: opt_DecOptions || {class: 'recoil-table-group'}});
};

/**
 * @param {!function(recoil.structs.table.ColumnKey,recoil.ui.widgets.table.Column)} func
 */
recoil.ui.widgets.TableMetaData.prototype.forEachColumn = function(func) {
    this.columns_.forEach(function(col) {
        func(col.getKey(), col);
    });
};


/**
 *
 * @template CT
 * @param {!recoil.structs.table.ColumnKey<CT>} key
 * @param {string|Node} name if you pass a node this will allow better formating of header
 * @param {!Object=} opt_meta
 */
recoil.ui.widgets.TableMetaData.prototype.add = function(key, name, opt_meta) {
    if (!key) {
        throw new Error('undefined column key');
    }

    this.addColumn(new recoil.ui.widgets.table.DefaultColumn(key, name, opt_meta || {}));
};

/**
 * creates a new table with the meta data applied to it
 * if table is a mutable table it will also apply the meta data it
 * @param {!recoil.structs.table.Table|!recoil.structs.table.MutableTable} table
 * @return {!recoil.structs.table.Table}
 */
recoil.ui.widgets.TableMetaData.prototype.applyMeta = function(table) {
    var mtable = table instanceof recoil.structs.table.MutableTable ? table : table.unfreeze();
    var pos = 0;
    this.columns_.forEach(function(col) {
        var inMeta = {};
        goog.object.extend(inMeta, table.getMeta(), mtable.getColumnMeta(col.getKey()));
        var meta = col.getMeta(inMeta);
        if (meta.position === undefined) {
            meta.position = pos;
        }<commit_msg>CT-4024 allow table meta to reset columns<commit_after>goog.provide('recoil.ui.widgets.TableMetaData');
goog.provide('recoil.ui.widgets.table.DefaultColumn');
goog.provide('recoil.ui.widgets.table.SeperatorColumn');

goog.require('recoil.structs.table.ColumnKey');
goog.require('recoil.structs.table.Table');
goog.require('recoil.ui.RenderedDecorator');
goog.require('recoil.ui.widgets.table.Column');
goog.require('recoil.ui.widgets.table.StringColumn');
goog.require('recoil.util.func');
goog.require('recoil.util.object');

/**
 * data that describes the table, it contains the columns and how to contruct the render widget
 * for that column
 * @param {boolean=} opt_reset if true will remove all previous shown columns when applied
 * @constructor
 */
recoil.ui.widgets.TableMetaData = function(opt_reset) {
    this.columns_ = [];
    this.colSeperators_ = [];
    this.colSeperatorsOpts_ = [];
    this.reset_ = !!opt_reset;
};


/**
 * @template CT
 * @param {!recoil.ui.widgets.table.Column<CT>} col
 */
recoil.ui.widgets.TableMetaData.prototype.addColumn = function(col) {
    if (!col) {
        throw new Error('undefined column');
    }
    this.columns_.push(col);
};
/**
 * @param {!recoil.structs.table.ColumnKey} key
 * @param {string|Node} name if you pass a node this will allow better formating of header
 * @param {!Object=} opt_meta
 * @param {!Object=} opt_DecOptions the options passed to createDom when the decorator is created
 */

recoil.ui.widgets.TableMetaData.prototype.addSeperatorCol = function(key, name, opt_meta, opt_DecOptions) {
    if (!key) {
        throw new Error('undefined column key');
    }

    this.addColumn(new recoil.ui.widgets.table.SeperatorColumn(key, name, opt_meta || {}));
    this.colSeperators_.push(key);
    this.colSeperatorsOpts_.push({key: key, opt: opt_DecOptions || {class: 'recoil-table-group'}});
};

/**
 * @param {!function(recoil.structs.table.ColumnKey,recoil.ui.widgets.table.Column)} func
 */
recoil.ui.widgets.TableMetaData.prototype.forEachColumn = function(func) {
    this.columns_.forEach(function(col) {
        func(col.getKey(), col);
    });
};


/**
 *
 * @template CT
 * @param {!recoil.structs.table.ColumnKey<CT>} key
 * @param {string|Node} name if you pass a node this will allow better formating of header
 * @param {!Object=} opt_meta
 */
recoil.ui.widgets.TableMetaData.prototype.add = function(key, name, opt_meta) {
    if (!key) {
        throw new Error('undefined column key');
    }

    this.addColumn(new recoil.ui.widgets.table.DefaultColumn(key, name, opt_meta || {}));
};

/**
 * creates a new table with the meta data applied to it
 * if table is a mutable table it will also apply the meta data it
 * @param {!recoil.structs.table.Table|!recoil.structs.table.MutableTable} table
 * @return {!recoil.structs.table.Table}
 */
recoil.ui.widgets.TableMetaData.prototype.applyMeta = function(table) {
    var mtable = table instanceof recoil.structs.table.MutableTable ? table : table.unfreeze();
    var pos = 0;
    if (this.reset_) {
        mtable.getColumns().forEach(function(col) {
            var meta = mtable.getColumnMeta(col);
            if (meta.hasOwnProperty('position')) {
                var newMeta = goog.object.clone(meta);
                delete newMeta.position;

                mtable.setColumnMeta(col, newMeta);
            }
        });
    }
    this.columns_.forEach(function(col) {
        var inMeta = {};
        goog.object.extend(inMeta, table.getMeta(), mtable.getColumnMeta(col.getKey()));
        var meta = col.getMeta(inMeta);
        if (meta.position === undefined) {
            meta.position = pos;
        }
{'fraction_non_alphanumeric': 0.1470458228967143, 'fraction_numerical': 0.0008840430234271402, 'mean_word_length': 3.7635087719298244, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1536935', 'n_tokens_mistral': 2265, 'n_tokens_neox': 2209, 'n_words': 452}