import _ from 'lodash' ; import SubsetPackage from '@/data/package/subset-package' ; export default class SubsetSelection { private items : Set < number > = new Set ( ) ; constructor ( items ? ) { if ( items ) { this . items = new Set ( items ) ; } } public serialize ( ) { return Array . from ( this . items ) ; } public deserialize ( items ) { this . items = new Set ( items ) ; } public clone ( ) { return new SubsetSelection ( this . serialize ( ) ) ; } public copyFrom ( selection ) { this . items = _ . clone ( selection . items ) ; } public numItems ( ) { return _ . size ( this . items ) ; } public setItems ( items ) { this . items = new Set ( items ) ; } public addItem ( index ) { this . items . add ( index ) ; } public addItems ( items ) { items . forEach ( index => this . items . add ( index ) ) ; } public removeItems ( items ) { items . forEach ( index => this . items . delete ( index ) ) ; } public getItems ( ) { return Array . from ( this . items ) ; } public hasItem ( index ) { return this . items . has ( index ) ; } public clear ( ) { this . items = new Set ( ) ; } public toSubsetPackage ( parentPkg ) { const pkg = new SubsetPackage ( parentPkg . getDataset ( ) ) ; this . items . forEach ( index => { pkg . addItem ( _ . merge ( { } , parentPkg . getItem ( index ) ) ) ; } ) ; return pkg ; } public isEqual ( selection ) { return _ . isEqual ( this . items , selection . items ) ; } }