-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMPCollection.ts
59 lines (54 loc) · 1.1 KB
/
MPCollection.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* A generic collection used by MapsIndoors.
*
* @export
* @abstract
* @class MPCollection
* @typedef {MPCollection}
* @template Type
*/
export default abstract class MPCollection<Type> {
/**
* The map the objects are kept in.
*
* @protected
* @type {!Map<String, Type>}
*/
protected map!: Map<String, Type>;
/**
* Creates an instance of MPCollection.
*
* @constructor
* @protected
*/
protected constructor() { }
/**
* Gets all objects contained in the collection.
*
* @public
* @returns {Array<Type>}
*/
public getAll(): Array<Type> {
return Array.from(this.map.values());
}
/**
* Get a object by its identifier.
*
* @public
* @param {string} id
* @returns {(Type | undefined)}
*/
public getById(id: string): Type | undefined {
return this.map.get(id);
}
/**
* The number of objects in the collection.
*
* @public
* @readonly
* @type {number}
*/
public get size(): number {
return this.map.size;
}
}