< Summary

Class:DCL.Helpers.CompositeLock
Assembly:Utils
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/Utils/CompositeLock.cs
Covered lines:12
Uncovered lines:11
Coverable lines:23
Total lines:53
Line coverage:52.1% (12 of 23)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
CompositeLock()0%110100%
AddLock(...)0%3.033085.71%
RemoveLock(...)0%16.765022.22%
RemoveAllLocks()0%2.062075%
GetLockIdsCopy()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/Utils/CompositeLock.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using UnityEngine;
 3
 4namespace DCL.Helpers
 5{
 6    public class CompositeLock
 7    {
 8        public static bool VERBOSE = false;
 9
 10        public event System.Action OnAllLocksRemoved;
 11
 12        int lockCounter = 0;
 24613        HashSet<object> lockIds = new HashSet<object>();
 14
 015        public bool isUnlocked => lockCounter == 0;
 16
 17        public void AddLock(object id)
 18        {
 10719            if (lockIds.Contains(id))
 120                return;
 21
 10622            lockIds.Add(id);
 10623            lockCounter++;
 24
 10625            if (VERBOSE)
 026                Debug.Log($"Lock added... {lockCounter}");
 10627        }
 28
 29        public void RemoveLock(object id)
 30        {
 18731            if (!lockIds.Contains(id))
 18732                return;
 33
 034            lockIds.Remove(id);
 035            lockCounter--;
 36
 037            if (VERBOSE)
 038                Debug.Log($"Locking removed... {lockCounter}");
 39
 040            if (lockCounter == 0)
 041                OnAllLocksRemoved?.Invoke();
 042        }
 43
 44        public void RemoveAllLocks()
 45        {
 146            lockCounter = 0;
 147            lockIds.Clear();
 148            OnAllLocksRemoved?.Invoke();
 049        }
 50
 051        public HashSet<object> GetLockIdsCopy() { return new HashSet<object>(lockIds); }
 52    }
 53}