import { includeDSON , includeJSON , RadixSerializableObject , RadixSpin , RadixAddress , RadixSpunParticle , RadixParticle , RadixSerializer , } from '..' ; @ RadixSerializer . registerClass ( 'radix.particle_group' ) export class RadixParticleGroup extends RadixSerializableObject { @ includeDSON @ includeJSON public particles : RadixSpunParticle [ ] ; @ includeDSON @ includeJSON public metaData : { [ s ] : string ; } ; constructor ( particles = [ ] , metaData ? ) { super ( ) ; this . particles = particles ; this . metaData = metaData ; } public getParticles ( ) { return this . particles ; } public containsParticle ( ... types ) { for ( const spunParticle of this . getParticles ( ) ) { for ( const type of types ) { if ( spunParticle . particle instanceof type ) { return true ; } } } return false ; } public getParticlesOfType < T extends RadixParticle > ( type , spin ? ) { let particles = this . getParticles ( ) . filter ( spunParticle => spunParticle . particle instanceof type ) ; if ( spin ) { particles = particles . filter ( spunParticle => spunParticle . spin === spin ) ; } return particles . map ( spunParticle => spunParticle . particle ) as T [ ] ; } }