File

projects/wms-framework/src/lib/baseframework/SimpleDictionary.ts

Extends

Dictionary

Index

Properties
Methods
Accessors

Constructor

constructor()

Properties

Private internalMap
Type : Map<K | V>
Abstract count
Type : number
Inherited from Dictionary
Defined in Dictionary:61

Gets the count of elements in the dictionary

Abstract internalArray
Type : []
Inherited from Dictionary
Defined in Dictionary:62
Abstract keys
Type : ICollection<K>
Inherited from Dictionary
Defined in Dictionary:41

The keys collection

Abstract values
Type : ICollection<V>
Inherited from Dictionary
Defined in Dictionary:51

The values collection

Methods

add
add(value: [K, V])
Inherited from Dictionary
Defined in Dictionary:66
Parameters :
Name Type Optional
value [K, V] No
Returns : void
addEntry
addEntry(key: K, value: V)
Inherited from Dictionary
Defined in Dictionary:46
Parameters :
Name Type Optional
key K No
value V No
Returns : void
clear
clear()
Inherited from Dictionary
Defined in Dictionary:69
Returns : void
contains
contains(value: [K, V])
Inherited from Dictionary
Defined in Dictionary:72
Parameters :
Name Type Optional
value [K, V] No
Returns : boolean
containsKey
containsKey(key: K)
Inherited from Dictionary
Defined in Dictionary:76
Parameters :
Name Type Optional
key K No
Returns : boolean
copyTo
copyTo(target: [], index: number)
Inherited from Dictionary
Defined in Dictionary:83
Parameters :
Name Type Optional
target [] No
index number No
Returns : void
filter
filter(predicate: (item: [K, V]) => void)

Creates a new SimpleDictionary object with the elements that matched the given predicate

Parameters :
Name Type Optional Description
predicate function No

a function that filters this SimpleDictionary elements.

Returns : SimpleDictionary<K, V>

a new SimpleDictionary with filtered in elements.

getItem
getItem(key: K)
Inherited from Dictionary
Defined in Dictionary:30
Parameters :
Name Type Optional
key K No
Returns : V
hasKey
hasKey(key: K)
Inherited from Dictionary
Defined in Dictionary:49
Parameters :
Name Type Optional
key K No
Returns : any
remove
remove(value: [K, V])
Inherited from Dictionary
Defined in Dictionary:79
Parameters :
Name Type Optional
value [K, V] No
Returns : boolean
removeEntry
removeEntry(key: K)
Inherited from Dictionary
Defined in Dictionary:52
Parameters :
Name Type Optional
key K No
Returns : void
setItem
setItem(key: K, value: V)
Inherited from Dictionary
Defined in Dictionary:37
Parameters :
Name Type Optional
key K No
value V No
Returns : void
tryGetValue
tryGetValue(key: K, value: (v: V) => void)
Inherited from Dictionary
Defined in Dictionary:55
Parameters :
Name Type Optional
key K No
value function No
Returns : boolean
()
Inherited from Dictionary
Defined in Dictionary:86
Returns : Iterator<, any, undefined>

Accessors

keys
getkeys()
values
getvalues()
count
getcount()
internalArray
getinternalArray()
import { Debugger } from '../diagnostics/Debugger';
import { ICollection, SimpleList } from './collections';
import { Dictionary } from './Dictionary';
import { KeyValue } from './KeyValue';

export class SimpleDictionary<K, V> extends Dictionary<K, V> {
  private internalMap: Map<K, V>;

  constructor() {
    super();
    this.internalMap = new Map<K, V>();
  }

  getItem(key: K): V {
    if (this.internalMap.has(key)) {
      return this.internalMap.get(key);
    } else {
      return null;
    }
  }
  setItem(key: K, value: V): void {
    this.internalMap.set(key, value);
  }
  get keys(): ICollection<K> {
    return new SimpleList(this.internalMap.keys());
  }
  get values(): ICollection<V> {
    return new SimpleList(this.internalMap.values());
  }
  addEntry(key: K, value: V) {
    this.setItem(key, value);
  }
  hasKey(key: K) {
    return this.internalMap.has(key);
  }
  removeEntry(key: K) {
    this.internalMap.delete(key);
  }
  tryGetValue(key: K, value: (v: V) => void) {
    if (this.internalMap.has(key)) {
      value(this.internalMap.get(key));
      return true;
    } else {
      return false;
    }
  }
  get count(): number {
    return this.internalMap.size;
  }
  add(value: [K, V]): void {
    this.setItem(value[0], value[1]);
  }
  clear(): void {
    this.internalMap.clear();
  }
  contains(value: [K, V]): boolean {
    // TODO implementation pending
    return false;
  }
  containsKey(key: K): boolean {
    return this.internalMap.has(key);
  }
  remove(value: [K, V]): boolean {
    // TODO implementation pending
    return false;
  }
  copyTo(target: [K, V][], index: number): void {
    Debugger.Throw('Method not implemented.');
  }
  [Symbol.iterator](): Iterator<[K, V], any, undefined> {
    return this.internalArray[Symbol.iterator]();
  }
  get internalArray(): [K, V][] {
    return [...this.internalMap].map((x) => KeyValue.pair(x[0], x[1]));
  }

  /**
   * Creates a new SimpleDictionary object with the elements that matched the given predicate
   * @param predicate a function that filters this SimpleDictionary elements.
   * @returns a new SimpleDictionary with filtered in elements.
   */
  filter(predicate: (item: [K, V]) => boolean): SimpleDictionary<K, V> {
    let result: SimpleDictionary<K, V> = new SimpleDictionary();
    this.internalArray.forEach((element) => {
      if (predicate(element)) {
        result.add(element);
      }
    });
    return result;
  }
}

result-matching ""

    No results matching ""