< 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:11
Uncovered lines:12
Coverable lines:23
Total lines:53
Line coverage:47.8% (11 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.213071.43%
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        {
 10519            if (lockIds.Contains(id))
 020                return;
 21
 10522            lockIds.Add(id);
 10523            lockCounter++;
 24
 10525            if (VERBOSE)
 026                Debug.Log($"Lock added... {lockCounter}");
 10527        }
 28
 29        public void RemoveLock(object id)
 30        {
 16531            if (!lockIds.Contains(id))
 16532                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}