-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMPCategoryCollection.ts
62 lines (58 loc) · 1.75 KB
/
MPCategoryCollection.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
60
61
62
import MPCategory from "./MPCategory";
import MPCollection from "./MPCollection";
import MPDataField from "./MPDataField";
/**
* A simple collection holder for categories.
*
* @export
* @class MPCategoryCollection
* @typedef {MPCategoryCollection}
* @extends {MPCollection<MPCategory>}
*/
export default class MPCategoryCollection extends MPCollection<MPCategory> {
/**
* Creates an instance of MPCategoryCollection.
*
* @constructor
* @private
* @param {MPCategory[]} category A collection of categories used in MapsIndoors.
*/
private constructor(category: MPCategory[]) {
super();
this.map = new Map(category.map((category) => [category.key, category]));
}
/**
* Get a category's value directly.
*
* @public
* @param {string} key
* @returns {(string | undefined)}
*/
public getValue(key: string) : string | undefined {
let category: MPCategory | undefined = this.getById(key);
return category?.value;
}
/**
* Get a category's fields directly.
*
* @public
* @param {string} key
* @returns {(Map<string, MPDataField> | undefined)}
*/
public getFields(key: string) : Map<string, MPDataField> | undefined {
let category: MPCategory | undefined = this.getById(key);
return category?.fields;
}
/**
* Creator for MPCategoryCollection, used to decode JSON from the MapsIndoors SDK.
*
* @public
* @static
* @param {?*} [object]
* @returns {MPCategoryCollection}
*/
public static create(object?: any) : MPCategoryCollection {
let category: MPCategory[] = object?.map((venue: any) => MPCategory.create(venue));
return new MPCategoryCollection(category);
}
}