projects/wms-framework/src/lib/baseframework/OrderedDictionary.ts
Class to create a OrderedDictionary.
Properties |
|
Methods |
Accessors |
constructor(item?: any)
|
||||||
Creates an instance of OrderedDictionary collection.
Parameters :
|
Private internalMap |
add |
add(key: any, value: any)
|
Inserts a new entry into the OrderedDictionary collection with the specified key and value at the specified index.
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 :
Returns :
boolean
|
copyTo | |||||||||
copyTo(target: Array
|
|||||||||
Copies the OrderedDictionary elements to a one-dimensional Array object at the specified index.
Parameters :
Returns :
any
|
item | ||||||
item(key: any)
|
||||||
Return the item related to the key in the OrderedDictionary collection or null.
Parameters :
Returns :
any
|
remove | ||||||
remove(key: any)
|
||||||
Removes the entry with the specified key from the OrderedDictionary collection.
Parameters :
Returns :
void
|
removeAt | ||||||
removeAt(pos: number)
|
||||||
Removes the entry at the specified index from the OrderedDictionary collection.
Parameters :
Returns :
void
|
setItem |
setItem(key: any, value: any)
|
Add a new item to the OrderedDictionary collection.
Returns :
void
|
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 :
Returns :
symbol
|
internalArray | ||||
getinternalArray()
|
||||
Returns an interalArray based on the OrderedDictionary collection.
Parameters :
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]));
}
}