< 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:11
Uncovered lines:32
Coverable lines:43
Total lines:104
Line coverage:25.5% (11 of 43)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
add_OnAdded(...)0%2100%
remove_OnAdded(...)0%2100%
add_OnRemoved(...)0%2100%
remove_OnRemoved(...)0%2100%
BaseDictionary_Legacy()0%110100%
Add(...)0%3.073080%
Add()0%6200%
Remove(...)0%12300%
Remove()0%6200%
Get(...)0%220100%
ContainsKey(...)0%110100%
TryGetValue(...)0%110100%
GetOrDefault(...)0%6200%
GetEnumerator()0%2100%
GetValues()0%2100%
Clear()0%12300%
OnEnable()0%110100%
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
 014    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
 318    private Dictionary<TKey, TValue> dictionary = new Dictionary<TKey, TValue>();
 19
 20    public void Add(TKey newKey, TValue newValue)
 21    {
 2222        if (dictionary.ContainsKey(newKey))
 1423            return;
 24
 825        dictionary.Add(newKey, newValue);
 826        OnAddedElementValue?.Invoke(newKey, newValue);
 027    }
 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    {
 040        if (!dictionary.ContainsKey(key))
 041            return;
 42
 043        var value = dictionary[key];
 044        dictionary.Remove(key);
 45
 046        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
 3258    public TValue Get(TKey key) { return dictionary.ContainsKey(key) ? dictionary[key] : default(TValue); }
 59
 260    public bool ContainsKey(TKey key) { return dictionary.ContainsKey(key); }
 61
 2162    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
 072    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    {
 080        using (Dictionary<TKey, TValue>.Enumerator iterator = dictionary.GetEnumerator())
 81        {
 082            while (iterator.MoveNext())
 83            {
 084                OnRemovedElementValue?.Invoke(iterator.Current.Key, iterator.Current.Value);
 85            }
 086        }
 87
 088        dictionary.Clear();
 089    }
 90
 91#if UNITY_EDITOR
 92    private void OnEnable()
 93    {
 394        Application.quitting -= CleanUp;
 395        Application.quitting += CleanUp;
 396    }
 97
 98    private void CleanUp()
 99    {
 0100        Application.quitting -= CleanUp;
 0101        Resources.UnloadAsset(this);
 0102    }
 103#endif
 104}