11
11
*/
12
12
function nodesService ( $log , Properties , Prefixes , RequestConfig ) {
13
13
14
- var classUriIdMap = new Map ( ) ;
15
- var nodes = new Map ( ) ;
14
+ let classUriIdMap = new Map ( ) ;
15
+ let nodes = new Map ( ) ;
16
16
let equivalentClasses = new Map ( ) ;
17
17
18
18
const classDatatypesMap = new Map ( ) ;
19
19
20
- var subClassSet = new Set ( ) ;
20
+ let subClassSet = new Set ( ) ;
21
21
22
22
const that = this ;
23
23
@@ -131,7 +131,7 @@ function nodesService($log, Properties, Prefixes, RequestConfig) {
131
131
/**
132
132
* Add a new node to the graph.
133
133
*
134
- * @param {* } newNode - the node which should be added to the graph
134
+ * @param {{uri: string, type: string} } newNode - the node which should be added to the graph
135
135
* @return {string } id of the new node
136
136
*/
137
137
that . addNode = function ( newNode ) {
@@ -206,7 +206,7 @@ function nodesService($log, Properties, Prefixes, RequestConfig) {
206
206
* @returns {* }
207
207
*/
208
208
that . getById = function ( idToSearch ) {
209
- var nodeToReturn = null ;
209
+ let nodeToReturn = null ;
210
210
211
211
if ( idToSearch !== undefined && typeof idToSearch === 'string' ) {
212
212
nodeToReturn = nodes . get ( idToSearch ) ;
@@ -221,9 +221,9 @@ function nodesService($log, Properties, Prefixes, RequestConfig) {
221
221
* @returns {number } number of instances
222
222
*/
223
223
that . getInstanceCountById = function ( id ) {
224
- var instanceCount = - 1 ;
224
+ let instanceCount = - 1 ;
225
225
226
- var searchedItem = nodes . get ( id ) ;
226
+ const searchedItem = nodes . get ( id ) ;
227
227
228
228
if ( searchedItem !== undefined && searchedItem . hasOwnProperty ( 'value' ) ) {
229
229
instanceCount = searchedItem . value ;
@@ -275,7 +275,7 @@ function nodesService($log, Properties, Prefixes, RequestConfig) {
275
275
* @param {string } commentToAdd - the comment to add to the node with the given id
276
276
*/
277
277
that . insertComment = function ( id , commentToAdd ) {
278
- var searchedItem = nodes . get ( id ) ;
278
+ const searchedItem = nodes . get ( id ) ;
279
279
280
280
if ( searchedItem !== undefined ) {
281
281
searchedItem . comment = commentToAdd ;
@@ -285,8 +285,14 @@ function nodesService($log, Properties, Prefixes, RequestConfig) {
285
285
}
286
286
} ;
287
287
288
+ /**
289
+ * Set the given URI for the node with the also given id.
290
+ *
291
+ * @param {string } id
292
+ * @param {string } newUri
293
+ */
288
294
that . setURI = function ( id , newUri ) {
289
- var nodeToChange = nodes . get ( id ) ;
295
+ const nodeToChange = nodes . get ( id ) ;
290
296
291
297
if ( nodeToChange !== undefined ) {
292
298
nodeToChange . uri = newUri ;
@@ -304,7 +310,7 @@ function nodesService($log, Properties, Prefixes, RequestConfig) {
304
310
that . setTypesLoaded = function ( classId ) {
305
311
if ( classId !== undefined && typeof classId === 'string' ) {
306
312
307
- var clazz = nodes . get ( classId ) ;
313
+ const clazz = nodes . get ( classId ) ;
308
314
309
315
if ( clazz !== undefined && clazz . type === 'class' ) {
310
316
clazz . typesLoaded = true ;
@@ -398,11 +404,16 @@ function nodesService($log, Properties, Prefixes, RequestConfig) {
398
404
return nodeToReturn ;
399
405
} ;
400
406
407
+ /**
408
+ * Removes all given nodes from the node map.
409
+ *
410
+ * @param {Array } nodeArr - an array of nodes to be removed
411
+ */
401
412
that . removeNodes = function ( nodeArr ) {
402
413
if ( nodeArr !== undefined && nodeArr . length > 0 ) {
403
- for ( let i = 0 ; i < nodeArr . length ; i ++ ) {
404
- nodes . delete ( nodeArr [ i ] ) ;
405
- }
414
+ nodeArr . forEach ( ( node ) => {
415
+ nodes . delete ( node ) ;
416
+ } ) ;
406
417
}
407
418
} ;
408
419
@@ -413,7 +424,7 @@ function nodesService($log, Properties, Prefixes, RequestConfig) {
413
424
* @return {number } the new value of the node or -1 if node was not found
414
425
*/
415
426
that . incValueOfId = function ( id ) {
416
- var searchedItem = nodes . get ( id ) ;
427
+ const searchedItem = nodes . get ( id ) ;
417
428
418
429
if ( searchedItem !== undefined && searchedItem . hasOwnProperty ( 'value' ) ) {
419
430
searchedItem . value += 1 ;
0 commit comments