< Summary

Class:BaseDictionary_Legacy[TKey,TValue]
Assembly:BaseVariable
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/DataStore/Variables/BaseDictionary_Legacy.cs
Covered lines:21
Uncovered lines:22
Coverable lines:43
Total lines:104
Line coverage:48.8% (21 of 43)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
add_OnAdded(...)0%110100%
remove_OnAdded(...)0%110100%
add_OnRemoved(...)0%2100%
remove_OnRemoved(...)0%2100%
BaseDictionary_Legacy()0%2100%
Add(...)0%330100%
Add(...)0%6200%
Remove(...)0%3.043083.33%
Remove(...)0%6200%
Get(...)0%220100%
ContainsKey(...)0%110100%
TryGetValue(...)0%110100%
GetOrDefault(...)0%6200%
GetEnumerator()0%110100%
GetValues()0%2100%
Clear()0%330100%
OnEnable()0%2100%
CleanUp()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/DataStore/Variables/BaseDictionary_Legacy.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using UnityEngine;
 3
 4public class BaseDictionary_Legacy<TKey, TValue> : ScriptableObject
 5{
 6    public delegate void Added(TKey addedKey, TValue addedValue);
 7
 8    public delegate void Removed(TKey removedKey, TValue removedValue);
 9
 10    private event Added OnAddedElementValue;
 11
 12    private event Removed OnRemovedElementValue;
 13
 4214    public virtual event Added OnAdded { add => OnAddedElementValue += value; remove => OnAddedElementValue -= value; }
 15
 016    public virtual event Removed OnRemoved { add => OnRemovedElementValue += value; remove => OnRemovedElementValue -= v
 17
 018    private Dictionary<TKey, TValue> dictionary = new Dictionary<TKey, TValue>();
 19
 20    public void Add(TKey newKey, TValue newValue)
 21    {
 17222        if (dictionary.ContainsKey(newKey))
 3623            return;
 24
 13625        dictionary.Add(newKey, newValue);
 13626        OnAddedElementValue?.Invoke(newKey, newValue);
 227    }
 28
 29    public void Add(KeyValuePair<TKey, TValue>[] newValues)
 30    {
 031        int count = newValues.Length;
 032        for (int i = 0; i < count; ++i)
 33        {
 034            Add(newValues[i].Key, newValues[i].Value);
 35        }
 036    }
 37
 38    public void Remove(TKey key)
 39    {
 3940        if (!dictionary.ContainsKey(key))
 2541            return;
 42
 1443        var value = dictionary[key];
 1444        dictionary.Remove(key);
 45
 1446        OnRemovedElementValue?.Invoke(key, value);
 047    }
 48
 49    public void Remove(TKey[] keys)
 50    {
 051        int count = keys.Length;
 052        for (int i = 0; i < count; ++i)
 53        {
 054            Remove(keys[i]);
 55        }
 056    }
 57
 8158    public TValue Get(TKey key) { return dictionary.ContainsKey(key) ? dictionary[key] : default(TValue); }
 59
 7360    public bool ContainsKey(TKey key) { return dictionary.ContainsKey(key); }
 61
 4562    public bool TryGetValue(TKey key, out TValue value) { return dictionary.TryGetValue(key, out value); }
 63
 64    public TValue GetOrDefault(TKey key)
 65    {
 066        if (!dictionary.ContainsKey(key))
 067            return default;
 68
 069        return dictionary[key];
 70    }
 71
 1672    public Dictionary<TKey, TValue>.Enumerator GetEnumerator() { return dictionary.GetEnumerator(); }
 73
 074    public int Count => dictionary.Count;
 75
 076    public IEnumerable<TValue> GetValues() { return dictionary.Values; }
 77
 78    public void Clear()
 79    {
 10380        using (Dictionary<TKey, TValue>.Enumerator iterator = dictionary.GetEnumerator())
 81        {
 21482            while (iterator.MoveNext())
 83            {
 11184                OnRemovedElementValue?.Invoke(iterator.Current.Key, iterator.Current.Value);
 85            }
 10386        }
 87
 10388        dictionary.Clear();
 10389    }
 90
 91#if UNITY_EDITOR
 92    private void OnEnable()
 93    {
 094        Application.quitting -= CleanUp;
 095        Application.quitting += CleanUp;
 096    }
 97
 98    private void CleanUp()
 99    {
 0100        Application.quitting -= CleanUp;
 0101        Resources.UnloadAsset(this);
 0102    }
 103#endif
 104}