< 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:4
Uncovered lines:19
Coverable lines:23
Total lines:53
Line coverage:17.3% (4 of 23)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
CompositeLock()0%110100%
AddLock(...)0%12300%
RemoveLock(...)0%30500%
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;
 113        HashSet<object> lockIds = new HashSet<object>();
 14
 015        public bool isUnlocked => lockCounter == 0;
 16
 17        public void AddLock(object id)
 18        {
 019            if (lockIds.Contains(id))
 020                return;
 21
 022            lockIds.Add(id);
 023            lockCounter++;
 24
 025            if (VERBOSE)
 026                Debug.Log($"Lock added... {lockCounter}");
 027        }
 28
 29        public void RemoveLock(object id)
 30        {
 031            if (!lockIds.Contains(id))
 032                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}