@@ -17,31 +17,62 @@ export class ChangedECInstanceCache {
17
17
this . _cache = new Map < Id64String , ChangedECInstance > ( ) ;
18
18
}
19
19
20
- private _getKey ( instance : ChangedECInstance ) : string {
20
+ /**
21
+ * Creates a key for the ChangedECInstance based on its Id and Class Id
22
+ * @param instance ChangedECInstance to create a key for
23
+ * @returns Key string for the ChangedECInstance in the cache, formatted as "instanceId:classId"
24
+ */
25
+ private _getKey ( instance : ChangedECInstance ) : string {
21
26
return `${ instance . ECInstanceId } :${ instance . ECClassId } ` ;
22
27
}
23
28
29
+ /**
30
+ * Initializes the cache with the given ChangedECInstances
31
+ * The cache will be cleared before adding the instances
32
+ * @param instances
33
+ */
24
34
public initialize ( instances : ChangedECInstance [ ] ) : void {
25
35
this . _cache . clear ( ) ;
26
36
for ( const instance of instances ) {
27
37
this . _cache . set ( this . _getKey ( instance ) , instance ) ;
28
38
}
29
39
}
30
40
41
+ /**
42
+ * Add instance to the cache
43
+ * @param instance ChangedECInstance to add to the cache
44
+ */
31
45
public add ( instance : ChangedECInstance ) : void {
32
46
this . _cache . set ( this . _getKey ( instance ) , instance ) ;
33
47
}
34
48
49
+ /**
50
+ * Gets the ChangedECInstance from the cache based on the instanceId and classId
51
+ * @param instanceId Id of the instance to get
52
+ * @param classId Class Id of the instance to get
53
+ * @returns ChangedECInstance if found, undefined otherwise
54
+ */
35
55
public get ( instanceId : Id64String , classId : Id64String ) : ChangedECInstance | undefined {
36
56
const key = `${ instanceId } :${ classId } ` ;
37
57
return this . _cache . get ( key ) ;
38
58
}
39
59
60
+ /**
61
+ * Returns whether the cache contains the ChangedECInstance with the given instanceId and classId
62
+ * @param instanceId Id of the instance to check
63
+ * @param classId Class Id of the instance to check
64
+ * @returns true if the cache contains the instance, false otherwise
65
+ */
40
66
public has ( instanceId : Id64String , classId : Id64String ) : boolean {
41
67
const key = `${ instanceId } :${ classId } ` ;
42
68
return this . _cache . has ( key ) ;
43
69
}
44
70
71
+ /**
72
+ * Similar to get, but uses the ChangedElementEntry to find the instance
73
+ * @param entry ChangedElementEntry to use for finding the instance
74
+ * @returns ChangedECInstance if found, undefined otherwise
75
+ */
45
76
public getFromEntry ( entry : ChangedElementEntry ) : ChangedECInstance | undefined {
46
77
return this . get ( entry . id , entry . classId ) ;
47
78
}
@@ -62,6 +93,9 @@ export class ChangedECInstanceCache {
62
93
return instances ;
63
94
}
64
95
96
+ /**
97
+ * Clears the cache of all ChangedECInstances
98
+ */
65
99
public clear ( ) : void {
66
100
this . _cache . clear ( ) ;
67
101
}
0 commit comments