* Updates used using the provided new value. * @param {UsageStateType} newValue new value of the used state * @param {RuntimeSpec} runtime only apply to this runtime * @returns {boolean} true when something has changed
(newValue, runtime)
| 1334 | * @returns {boolean} true when something has changed |
| 1335 | */ |
| 1336 | setUsed(newValue, runtime) { |
| 1337 | if (runtime === undefined) { |
| 1338 | if (this._globalUsed !== newValue) { |
| 1339 | this._globalUsed = newValue; |
| 1340 | return true; |
| 1341 | } |
| 1342 | } else if (this._usedInRuntime === undefined) { |
| 1343 | if (newValue !== UsageState.Unused) { |
| 1344 | this._usedInRuntime = new Map(); |
| 1345 | forEachRuntime(runtime, (runtime) => |
| 1346 | /** @type {UsedInRuntime} */ |
| 1347 | (this._usedInRuntime).set(/** @type {string} */ (runtime), newValue) |
| 1348 | ); |
| 1349 | return true; |
| 1350 | } |
| 1351 | } else { |
| 1352 | let changed = false; |
| 1353 | forEachRuntime(runtime, (_runtime) => { |
| 1354 | const runtime = /** @type {string} */ (_runtime); |
| 1355 | const usedInRuntime = |
| 1356 | /** @type {UsedInRuntime} */ |
| 1357 | (this._usedInRuntime); |
| 1358 | let oldValue = |
| 1359 | /** @type {UsageStateType} */ |
| 1360 | (usedInRuntime.get(runtime)); |
| 1361 | if (oldValue === undefined) oldValue = UsageState.Unused; |
| 1362 | if (newValue !== oldValue) { |
| 1363 | if (newValue === UsageState.Unused) { |
| 1364 | usedInRuntime.delete(runtime); |
| 1365 | } else { |
| 1366 | usedInRuntime.set(runtime, newValue); |
| 1367 | } |
| 1368 | changed = true; |
| 1369 | } |
| 1370 | }); |
| 1371 | if (changed) { |
| 1372 | if (this._usedInRuntime.size === 0) this._usedInRuntime = undefined; |
| 1373 | return true; |
| 1374 | } |
| 1375 | } |
| 1376 | return false; |
| 1377 | } |
| 1378 | |
| 1379 | /** |
| 1380 | * Returns true, if something has changed. |
no test coverage detected