< Summary

Class:OwnersInfoController
Assembly:NFTPromptHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/NFTPromptHUD/Scripts/OwnersInfoController.cs
Covered lines:3
Uncovered lines:27
Coverable lines:30
Total lines:74
Line coverage:10% (3 of 30)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
OwnersInfoController(...)0%110100%
Dispose()0%12300%
SetOwners(...)0%30500%
GetElements()0%2100%
GetElement()0%6200%
PoolElement(...)0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/NFTPromptHUD/Scripts/OwnersInfoController.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using DCL.Helpers.NFT;
 4using Object = UnityEngine.Object;
 5
 6internal class OwnersInfoController : IDisposable
 7{
 78    private readonly Queue<IOwnerInfoElement> elementsPool = new Queue<IOwnerInfoElement>();
 79    private readonly List<IOwnerInfoElement> activeElements = new List<IOwnerInfoElement>();
 10    private readonly OwnerInfoElement ownerElementPrefab;
 11
 2112    public OwnersInfoController(OwnerInfoElement ownerElementPrefab) { this.ownerElementPrefab = ownerElementPrefab; }
 13
 14    public void Dispose()
 15    {
 016        while (elementsPool.Count > 0)
 17        {
 018            elementsPool.Dequeue().Dispose();
 19        }
 020        for (int i = 0; i < activeElements.Count; i++)
 21        {
 022            activeElements[i].Dispose();
 23        }
 024    }
 25
 26    public void SetOwners(NFTInfoSingleAsset.Owners[] owners)
 27    {
 028        int activeElementsCount = activeElements.Count;
 029        for (int i = activeElementsCount - 1; i >= 0; i--)
 30        {
 031            if (i < owners.Length)
 32            {
 033                activeElements[i].SetOwner(owners[i].owner);
 034            }
 35            else
 36            {
 037                PoolElement(activeElements[i]);
 038                activeElements.RemoveAt(i);
 39            }
 40        }
 41
 042        if (activeElementsCount < owners.Length)
 43        {
 044            for (int i = activeElementsCount; i < owners.Length; i++)
 45            {
 046                var element = GetElement();
 047                element.SetOwner(owners[i].owner);
 048                activeElements.Add(element);
 49            }
 50        }
 051    }
 52
 053    public List<IOwnerInfoElement> GetElements() { return activeElements; }
 54
 55    private IOwnerInfoElement GetElement()
 56    {
 57        IOwnerInfoElement ret;
 058        if (elementsPool.Count > 0)
 59        {
 060            ret = elementsPool.Dequeue();
 061        }
 62        else
 63        {
 064            ret = Object.Instantiate(ownerElementPrefab);
 65        }
 066        return ret;
 67    }
 68
 69    private void PoolElement(IOwnerInfoElement element)
 70    {
 071        elementsPool.Enqueue(element);
 072        element.SetActive(false);
 073    }
 74}