< Summary

Class:DCL.Multimap[KT,VT]
Assembly:Utils
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/Utils/Multimap.cs
Covered lines:0
Uncovered lines:53
Coverable lines:53
Total lines:140
Line coverage:0% (0 of 53)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Multimap()0%2100%
GetCountFor(...)0%6200%
GetValues(...)0%6200%
Add(...)0%6200%
ReplaceFirst(...)0%12300%
Sort(...)0%6200%
RemoveRange(...)0%6200%
Remove(...)0%12300%
RemoveFromEverywhere(...)0%20400%
Remove(...)0%2100%
ContainsKey(...)0%2100%
ContainsValue(...)0%12300%
Clear()0%2100%
ClearLists()0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/Utils/Multimap.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using System.Collections.Generic;
 4using System.Linq;
 5
 6namespace DCL
 7{
 8    public class Multimap<KT, VT>
 9    {
 010        private readonly Dictionary<KT, List<VT>> map = new Dictionary<KT, List<VT>>();
 11
 12        public IEnumerable<KT> Keys
 13        {
 014            get { return map.Keys; }
 15        }
 16
 17        public IEnumerable<VT> AllValues
 18        {
 019            get { return map.Values.SelectMany(list => list); }
 20        }
 21
 22        public int Count
 23        {
 024            get { return map.Count; }
 25        }
 26
 27        public int GetCountFor(KT key)
 28        {
 029            if (map.ContainsKey(key))
 030                return map[key].Count;
 031            return 0;
 32        }
 33
 34        public int ValuesCount
 35        {
 36            get
 37            {
 038                int count = 0;
 039                foreach (var list in map.Values)
 40                {
 041                    count += list.Count;
 42                }
 43
 044                return count;
 45            }
 46        }
 47
 48        public IEnumerable<VT> GetValues(KT key)
 49        {
 050            return map.ContainsKey(key) ? map[key] : null;
 51        }
 52
 53        public void Add(KT key, VT value)
 54        {
 055            if(map.ContainsKey(key))
 056                map[key].Add(value);
 57            else
 58            {
 059                map[key] = new List<VT>();
 060                map[key].Add(value);
 61            }
 062        }
 63
 64        public void ReplaceFirst(KT key, VT value, Predicate<VT> predicate)
 65        {
 066            if (map.ContainsKey(key))
 67            {
 068                var list = map[key];
 069                var index = list.FindIndex(predicate);
 070                if (index != -1)
 071                    list[index] = value;
 72            }
 073        }
 74
 75        public void Sort(KT key, Comparison<VT> comparison)
 76        {
 077            if(map.ContainsKey(key))
 078                map[key].Sort(comparison);
 079        }
 80
 81        public void RemoveRange(KT key, int startIndex, int count)
 82        {
 083            if(map.ContainsKey(key))
 084                map[key].RemoveRange(startIndex, count);
 085        }
 86
 87        public void Remove(KT key, VT value)
 88        {
 089            if (map.ContainsKey(key))
 90            {
 091                map[key].Remove(value);
 092                if (map[key].Count == 0)
 093                    map.Remove(key);
 94            }
 095        }
 96
 97        public void RemoveFromEverywhere(VT value)
 98        {
 099            foreach (var kvp in map.ToList())
 100            {
 0101                var list = kvp.Value;
 0102                list.RemoveAll(v => v.Equals(value));
 0103                if (list.Count == 0)
 0104                    map.Remove(kvp.Key);
 105            }
 0106        }
 107
 108        public void Remove(KT key)
 109        {
 0110            map.Remove(key);
 0111        }
 112
 113        public bool ContainsKey(KT key)
 114        {
 0115            return map.ContainsKey(key);
 116        }
 117
 118        public bool ContainsValue(VT value)
 119        {
 0120            foreach (var list in map.Values)
 121            {
 0122                if (list.Contains(value))
 0123                    return true;
 124            }
 125
 0126            return false;
 0127        }
 128
 129        public void Clear()
 130        {
 0131            map.Clear();
 0132        }
 133
 134        public void ClearLists()
 135        {
 0136            foreach(var key in map.Keys)
 0137                map[key].Clear();
 0138        }
 139    }
 140}