Home Manual Reference Source Repository
public class | source

MultiMap

Provides a multi-level Map implementation that mirrors the Map API except for exclusion of forEach.

Each method takes a variable list of parameters. By not including any parameters when invoking methods of MultiLevelMap the base Map is the target. A list of comma separated parameters will index into the backing multi-level map structure.

Errors will be thrown for methods that require a minimum number of keys including: delete(1), get(1), has(1), set(2). In particular set requires the actual value being set in addition to any number of keys. Another caveat of set() is that if at any level of indexed keys a value is already set for the given key index an Error will be thrown due to the pre-existing value not being a Map.

See:

Example:

const map = new MultiMap();

map.set('key1', 'key2', 1);  // creates a 2nd level Map indexed by 'key1' with value '1' indexed by 'key2'.
map.get('key1'); // returns the 2nd level Map.
map.get('key1', 'key2'); // returns '1'; 'key1' indexes into the 2nd level map with 'key2'.
map.has('key1', 'key2'); // is true.

Constructor Summary

Public Constructor
public

Initializes the MultiLevelMap

Method Summary

Public Methods
public

clear(keys: *)

The clear() method removes all elements from a Map object.

public

delete(keys: *): boolean

The delete() method removes the specified element from a Map object.

public

entries(keys: *): Iterator

The entries() method returns a new Iterator object that contains the [key, value] pairs for each element in the Map object in insertion order.

public

get(keys: *): *

The get() method returns a specified element from a Map object.

public

has(keys: *): boolean

The has() method returns a boolean indicating whether an element with the specified key exists or not.

public

isMap(keys: *): boolean

The isMap() method returns a boolean indicating whether specified sequence of keys resolves to an existing Map.

public

keys(keys: *): Iterator

The keys() method returns a new Iterator object that contains the keys for each element in the Map object in insertion order.

public

set(params: *): Map | undefined

The set() method adds a new element with a specified key and value to a Map object.

public

size(keys: *): number

The size() method returns an integer representing how many entries the Map object has.

public

values(keys: *): Iterator

The values() method returns a new Iterator object that contains the values for each element in the Map object in insertion order.

Public Constructors

public constructor source

Initializes the MultiLevelMap

Public Methods

public clear(keys: *) source

The clear() method removes all elements from a Map object. If no keys are provided then the base map is cleared. Subsequent keys will attempt to index into additional levels of the MultiLevelMap.

Params:

NameTypeAttributeDescription
keys *

A variable list of keys to index subsequent levels of the MultiLevelMap.

See:

public delete(keys: *): boolean source

The delete() method removes the specified element from a Map object. If one key is provided then the base map is the target. Subsequent keys will attempt to index into additional levels of the MultiLevelMap.

Params:

NameTypeAttributeDescription
keys *

A variable list of keys to index subsequent levels of the MultiLevelMap.

Return:

boolean

See:

public entries(keys: *): Iterator source

The entries() method returns a new Iterator object that contains the [key, value] pairs for each element in the Map object in insertion order. If one key is provided then the base map is the target. Subsequent keys will attempt to index into additional levels of the MultiLevelMap. If no Map is found then an empty iterator is returned.

Params:

NameTypeAttributeDescription
keys *

A variable list of keys to index subsequent levels of the MultiLevelMap.

Return:

Iterator

See:

public get(keys: *): * source

The get() method returns a specified element from a Map object. If one key is provided then the base map is the target. Subsequent keys will attempt to index into additional levels of the MultiLevelMap. If no indexed Map is found then undefined is returned.

Params:

NameTypeAttributeDescription
keys *

A variable list of keys to index subsequent levels of the MultiLevelMap.

Return:

*

See:

public has(keys: *): boolean source

The has() method returns a boolean indicating whether an element with the specified key exists or not. If one key is provided then the base map is the target. Subsequent keys will attempt to index into additional levels of the MultiLevelMap. If no indexed Map is found then false is returned.

Params:

NameTypeAttributeDescription
keys *

A variable list of keys to index subsequent levels of the MultiLevelMap.

Return:

boolean

See:

public isMap(keys: *): boolean source

The isMap() method returns a boolean indicating whether specified sequence of keys resolves to an existing Map. If one key is provided then the base map is the target. Subsequent keys will attempt to index into additional levels of the MultiLevelMap. If no indexed Map is found then false is returned.

Params:

NameTypeAttributeDescription
keys *

A variable list of keys to index subsequent levels of the MultiLevelMap.

Return:

boolean

public keys(keys: *): Iterator source

The keys() method returns a new Iterator object that contains the keys for each element in the Map object in insertion order. If one key is provided then the base map is the target. Subsequent keys will attempt to index into additional levels of the MultiLevelMap. If no Map is found then an empty iterator is returned.

Params:

NameTypeAttributeDescription
keys *

A variable list of keys to index subsequent levels of the MultiLevelMap.

Return:

Iterator

See:

public set(params: *): Map | undefined source

The set() method adds a new element with a specified key and value to a Map object. If one key is provided then the base map is the target. Subsequent keys will attempt to index into additional levels of the MultiLevelMap. New Maps are automatically created at each level for the given key parameters. The target Map that the value is added to is returned.

Params:

NameTypeAttributeDescription
params *

A variable list of keys to index subsequent levels of the MultiLevelMap with the last entry being the value to be set / added.

Return:

Map | undefined

See:

public size(keys: *): number source

The size() method returns an integer representing how many entries the Map object has. If no key is provided then the base map is the target. Subsequent keys will attempt to index into additional levels of the MultiLevelMap. If no indexed Map is found then 0 is returned.

Params:

NameTypeAttributeDescription
keys *

A variable list of keys to index subsequent levels of the MultiLevelMap.

Return:

number

public values(keys: *): Iterator source

The values() method returns a new Iterator object that contains the values for each element in the Map object in insertion order. If one key is provided then the base map is the target. Subsequent keys will attempt to index into additional levels of the MultiLevelMap. If no Map is found then an empty iterator is returned.

Params:

NameTypeAttributeDescription
keys *

A variable list of keys to index subsequent levels of the MultiLevelMap.

Return:

Iterator

See: