export interface IDictionary < T > { add ( key , value ) : void ; containsKey ( key ) : boolean ; count ( ) : number ; item ( key ) : T ; keys ( ) : string [ ] ; remove ( key ) : T ; values ( ) : T [ ] ; pos ( key ) : number ; replace ( newkey , value , oldkey ) : boolean ; removeAll ( ) : void ; } export class Dictionary < T > implements IDictionary < T > { public items : { [ index ] : T ; } = { } ; public _count = 0 ; constructor ( private maxCount = - 1 ) { } public containsKey ( key ) { return this . items . hasOwnProperty ( key ) ; } public count ( ) { return this . _count ; } public add ( key , value ) { if ( ( ( this . _count < this . maxCount ) && ( this . maxCount > - 1 ) ) || ( this . maxCount === - 1 ) ) { this . items [ key ] = value ; this . _count ++ ; } } public remove ( key ) { if ( this . containsKey ( key ) ) { const val = this . items [ key ] ; delete this . items [ key ] ; this . _count -- ; return val ; } else { return null ; } } public removeAll ( ) { for ( const k of this . keys ( ) ) { this . remove ( k ) ; } } public item ( key ) { return this . items [ key ] ; } public keys ( ) { return Object . keys ( this . items ) ; } public values ( ) { const values = [ ] ; for ( const prop in this . items ) { if ( this . items . hasOwnProperty ( prop ) ) { values . push ( this . items [ prop ] ) ; } } return values ; } public pos ( key ) { return this . keys ( ) . indexOf ( key ) ; } public replace ( newkey , value , oldkey ) { if ( this . containsKey ( oldkey ) ) { const changedItems = { } ; for ( const key in this . items ) { if ( key === oldkey ) { changedItems [ newkey ] = value ; } else { changedItems [ key ] = this . item ( key ) ; } } this . items = changedItems ; return true ; } else { return false ; } } }