<commit_before>'use strict';

var assign           = require('es5-ext/object/assign')
  , create           = require('es5-ext/object/create')
  , d                = require('d/d')
  , lazy             = require('d/lazy')
  , Set              = require('es6-set/polyfill')
  , DbjsError        = require('../error')
  , Event            = require('../event')
  , serialize        = require('../serialize/key')
  , defineObservable = require('../utils/define-set-observable')
  , Iterator         = require('./iterator')

  , keys = Object.keys, defineProperties = Object.defineProperties
  , isTruthy, Multiple;

isTruthy = function (sKey) {
	var item = this[sKey];
	if (!item.hasOwnProperty('_value_')) return false;
	return item._value_;
};

module.exports = Multiple = function (obj, pSKey) {
	defineProperties(this, {
		object: d('', obj),
		dbId: d('', obj.__id__ + '/' + pSKey),
		__pSKey__: d('', pSKey),
		__setData__: d('', obj._getMultipleItems_(pSKey))
	});
};

Multiple.prototype = create(Set.prototype, assign({
	constructor: d(Multiple),
	_serialize: d(serialize),
	add: d(function (key) {
		var obj = this.object;
		key = obj._validateMultipleAdd_(this.__pSKey__, key);
		obj._multipleAdd_(this.__pSKey__, key, serialize(key));
		return this;
	}),
	clear: d(function () {
		this.object.database._postponed += 1;
		this._validateClear_().forEach(function (sKey) {
			var item = this.__setData__[sKey];
			if (!item.hasOwnProperty('_value_')) return;
			new Event(item, undefined); //jslint: skip
		}, this);
		this.object.database._postponed -= 1;
	}),
	delete: d(function (key) {
		var obj = this.object;
		key = obj._validateMultipleDelete_(this.__pSKey__, key);
		if (key == null) return false;
		return obj._multipleDelete_(this.__pSKey__, key, serialize(key));
	}),
	entries: d(function () { return new Iterator(this, 'key+value'); }),
	has: d(function (key) {
		var item;
		if (key == null) return false;
		key = this.object._normalize_(this.__pSKey__, key);
		if (key == null) return false;
		item = this.__setData__[this._serialize(key)];
		if (!item) return false;
		return Boolean(item._value_);
	}),
	size: d.gs(function () {
		if (this.hasOwnProperty('__size__')) return this.__size__;
		return this.object._getMultipleSize_(this.__pSKey__);
	}),
	values: d(function () { return new Iterator(this); }),
	$getOwn: d(function (key) {
		key = this._validate_(key);
		return this.object._getOwnMultipleItem_(this.__pSKey__,
			key, this._serialize(key));
	}),
	$get: d(function (key) {
		key = this._validate_(key);
		return this.object._getMultipleItem_(this.__pSKey__,
			this._serialize(key));
	}),
	_get: d(function (key) {
		key = this._validate_(key);
		return this.object._getMultipleItemObservable_(this.__pSKey__,
			this._serialize(key), key);
	}),
	getLastModifiedByValue: d(function (key) {
		var item;
		if (key == null) return null;
		key = this.object._normalize_(this.__pSKey__, key);
		if (key == null) return null;
		item = this.__setData__[key];
		if (!item) return 0;
		return item.lastModified;
	}),
	_validateClear_: d(function () {
		var desc, sKeys;
		this.object._assertWritable_(this.__pSKey__);
		desc = this.object._getDescriptor_(this.__pSKey__);
		sKeys = keys(this.__setData__);<commit_msg>Add `copy` method to multiple set<commit_after>'use strict';

var assign           = require('es5-ext/object/assign')
  , create           = require('es5-ext/object/create')
  , d                = require('d/d')
  , lazy             = require('d/lazy')
  , Set              = require('es6-set/polyfill')
  , setCopy          = require('es6-set/ext/copy')
  , DbjsError        = require('../error')
  , Event            = require('../event')
  , serialize        = require('../serialize/key')
  , defineObservable = require('../utils/define-set-observable')
  , Iterator         = require('./iterator')

  , keys = Object.keys, defineProperties = Object.defineProperties
  , isTruthy, Multiple;

isTruthy = function (sKey) {
	var item = this[sKey];
	if (!item.hasOwnProperty('_value_')) return false;
	return item._value_;
};

module.exports = Multiple = function (obj, pSKey) {
	defineProperties(this, {
		object: d('', obj),
		dbId: d('', obj.__id__ + '/' + pSKey),
		__pSKey__: d('', pSKey),
		__setData__: d('', obj._getMultipleItems_(pSKey))
	});
};

Multiple.prototype = create(Set.prototype, assign({
	constructor: d(Multiple),
	_serialize: d(serialize),
	add: d(function (key) {
		var obj = this.object;
		key = obj._validateMultipleAdd_(this.__pSKey__, key);
		obj._multipleAdd_(this.__pSKey__, key, serialize(key));
		return this;
	}),
	clear: d(function () {
		this.object.database._postponed += 1;
		this._validateClear_().forEach(function (sKey) {
			var item = this.__setData__[sKey];
			if (!item.hasOwnProperty('_value_')) return;
			new Event(item, undefined); //jslint: skip
		}, this);
		this.object.database._postponed -= 1;
	}),
	delete: d(function (key) {
		var obj = this.object;
		key = obj._validateMultipleDelete_(this.__pSKey__, key);
		if (key == null) return false;
		return obj._multipleDelete_(this.__pSKey__, key, serialize(key));
	}),
	entries: d(function () { return new Iterator(this, 'key+value'); }),
	has: d(function (key) {
		var item;
		if (key == null) return false;
		key = this.object._normalize_(this.__pSKey__, key);
		if (key == null) return false;
		item = this.__setData__[this._serialize(key)];
		if (!item) return false;
		return Boolean(item._value_);
	}),
	size: d.gs(function () {
		if (this.hasOwnProperty('__size__')) return this.__size__;
		return this.object._getMultipleSize_(this.__pSKey__);
	}),
	values: d(function () { return new Iterator(this); }),
	copy: d(setCopy),
	$getOwn: d(function (key) {
		key = this._validate_(key);
		return this.object._getOwnMultipleItem_(this.__pSKey__,
			key, this._serialize(key));
	}),
	$get: d(function (key) {
		key = this._validate_(key);
		return this.object._getMultipleItem_(this.__pSKey__,
			this._serialize(key));
	}),
	_get: d(function (key) {
		key = this._validate_(key);
		return this.object._getMultipleItemObservable_(this.__pSKey__,
			this._serialize(key), key);
	}),
	getLastModifiedByValue: d(function (key) {
		var item;
		if (key == null) return null;
		key = this.object._normalize_(this.__pSKey__, key);
		if (key == null) return null;
		item = this.__setData__[key];
		if (!item) return 0;
		return item.lastModified;
	}),
	_validateClear_: d(function () {
		var desc, sKeys;
		this.object._assertWritable_(this.__pSKey__);
		desc = this.object._getDescriptor_(this.__pSKey__);
		sKeys = keys(this.__setData__);
{'fraction_non_alphanumeric': 0.1638271980529358, 'fraction_numerical': 0.001977487070276848, 'mean_word_length': 3.859571322985957, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4312850', 'n_tokens_mistral': 2353, 'n_tokens_neox': 2234, 'n_words': 460}