File

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

Description

Class to create a OrderedDictionary.

Index

Properties
Methods
Accessors

Constructor

constructor(item?: any)

Creates an instance of OrderedDictionary collection.

Parameters :
Name Type Optional
item any Yes

Properties

Private internalMap

Methods

add
add(key: any, value: any)

Inserts a new entry into the OrderedDictionary collection with the specified key and value at the specified index.

Parameters :
Name Type Optional
key any No
value any No
Returns : void
clear
clear()

Removes all elements from the OrderedDictionary collection

Returns : void
contains
contains(key: any)

Check if the item is contain in the OrderedDictionary.

Parameters :
Name Type Optional
key any No
Returns : boolean
copyTo
copyTo(target: Array, index: number)

Copies the OrderedDictionary elements to a one-dimensional Array object at the specified index.

Parameters :
Name Type Optional
target Array<any> No
index number No
Returns : any
item
item(key: any)

Return the item related to the key in the OrderedDictionary collection or null.

Parameters :
Name Type Optional
key any No
Returns : any
remove
remove(key: any)

Removes the entry with the specified key from the OrderedDictionary collection.

Parameters :
Name Type Optional
key any No
Returns : void
removeAt
removeAt(pos: number)

Removes the entry at the specified index from the OrderedDictionary collection.

Parameters :
Name Type Optional
pos number No
Returns : void
setItem
setItem(key: any, value: any)

Add a new item to the OrderedDictionary collection.

Parameters :
Name Type Optional
key any No
value any No
Returns : void

Accessors

count
getcount()

Return the size of the OrderedDictionary collection.

Returns : number
keys
getkeys()

Return a simple list of the Keys of the OrderedDictionary collection.

Returns : ICollection<any>
values
getvalues()

Return a simple list of the values of the OrderedDictionary collection.

Returns : ICollection<any>
getEnumerator
getgetEnumerator()

Returns an Symbol.iterator object that iterates through the OrderedDictionary collection.

Parameters :
Name Optional
key No
Returns : symbol
internalArray
getinternalArray()

Returns an interalArray based on the OrderedDictionary collection.

Parameters :
Name Optional
key No
Returns : []
import { Debugger } from '../diagnostics/Debugger';
import { ICollection, SimpleList } from './collections';
import { KeyValue } from './KeyValue';

/**
 * Class to create a OrderedDictionary.
 *
 * @export
 * @class OrderedDictionary
 * @wType System.Collections.Specialized.OrderedDictionary
 * @wNetSupport
 */
export class OrderedDictionary {
  private internalMap;

  /**
   * Creates an instance of OrderedDictionary collection.
   *
   * @memberof OrderedDictionary
   */
  constructor(item?: any) {
    this.internalMap = new Map();
  }

  /**
   * Return the size of the OrderedDictionary collection.
   *
   * @memberof OrderedDictionary
   * @wProperty Count
   */
  get count(): number {
    return this.internalMap.size;
  }

  /**
   * Return a simple list of the Keys of the OrderedDictionary collection.
   *
   * @memberof OrderedDictionary
   * @wProperty Keys
   */
  get keys(): ICollection<any> {
    return new SimpleList(this.internalMap.keys());
  }

  /**
   * Return a simple list of the values of the OrderedDictionary collection.
   *
   * @memberof OrderedDictionary
   * @wProperty Values
   */
  get values(): ICollection<any> {
    return new SimpleList(this.internalMap.values());
  }

  /**
   * Return the item related to the key in the OrderedDictionary collection or null.
   *
   * @param {any} key
   * @memberof OrderedDictionary
   * @wMethod Item
   */
  item(key: any): any {
    if (this.internalMap.has(key)) {
      return this.internalMap.get(key);
    } else {
      return null;
    }
  }

  /**
   * Add a new item to the OrderedDictionary collection.
   *
   * @param {any} key
   * @param {any} key
   * @memberof OrderedDictionary
   */
  setItem(key: any, value: any): void {
    this.internalMap.set(key, value);
  }

  /**
   * Inserts a new entry into the OrderedDictionary collection with the specified key and value at the specified index.
   *
   * @param {any} key
   * @param {any} key
   * @memberof OrderedDictionary
   * @wMethod Add
   */
  add(key: any, value: any) {
    this.setItem(key, value);
  }

  /**
   * Removes all elements from the OrderedDictionary collection
   *
   * @memberof OrderedDictionary
   * @wMethod Clear
   */
  clear(): void {
    this.internalMap.clear();
  }

  /**
   * Check if the item is contain in the OrderedDictionary.
   *
   * @param {any} key
   * @memberof OrderedDictionary
   * @wMethod Contains
   */
  contains(key: any): boolean {
    return this.internalMap.has(key);
  }

  /**
   * Copies the OrderedDictionary elements to a one-dimensional Array object at the specified index.
   *
   * @param {Array<any>} target
   * @param {number} index
   * @memberof OrderedDictionary
   * @wMethod CopyTo
   * @wNoMap
   */
  copyTo(target: Array<any>, index: number): any {
    Debugger.Throw('Method not implemented.');
  }

  /**
   * Returns an Symbol.iterator object that iterates through the OrderedDictionary collection.
   *
   * @param {any} key
   * @memberof OrderedDictionary
   * @wProperty GetEnumerator
   */
  get getEnumerator(): symbol {
    return this.internalMap[Symbol.iterator];
  }

  /**
   * Removes the entry with the specified key from the OrderedDictionary collection.
   *
   * @param {any} key
   * @memberof OrderedDictionary
   * @wMethod Remove
   */
  remove(key: any): void {
    if (key == null) {
      throw new Error('key is null');
    }
    this.internalMap.delete(key);
  }

  /**
   * Removes the entry at the specified index from the OrderedDictionary collection.
   *
   * @param {any} pos
   * @memberof OrderedDictionary
   * @wMethod RemoveAt
   */
  removeAt(pos: number) {
    if (pos < 0) {
      throw new Error('index is less than zero');
    }
    if (pos >= this.internalMap.size) {
      throw new Error('index is equal to or greater than Count');
    }
    const keys = [...this.internalMap.keys()];
    this.internalMap.delete(keys[pos]);
  }

  /**
   * Returns an interalArray based on the OrderedDictionary collection.
   *
   * @param {any} key
   * @memberof OrderedDictionary
   */
  get internalArray(): [any, any][] {
    return [...this.internalMap].map((x) => KeyValue.pair(x[0], x[1]));
  }
}

result-matching ""

    No results matching ""