using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Framework.DataStructures
{
    public class ListMap<Key,Value> : Dictionary<Key,List<Value>>
    {
        public void Add(Key key, Value valueToAdd)
        {
            if (!ContainsKey(key))
            {
                Add(key, new List<Value>());
            }
            this[key].Add(valueToAdd);
        }

        public void Remove(Key key, Value valueToRemove)
        {
            if (ContainsKey(key) && this[key].Contains(valueToRemove))
            {
                this[key].Remove(valueToRemove);
            }
        }

        public void Remove(Value valueToRemove)
        {
            foreach (KeyValuePair<Key,List<Value>> kvp in this)
            {
                if (kvp.Value.Contains(valueToRemove))
                {
                    kvp.Value.Remove(valueToRemove);
                }
            }
        }

        public bool Contains(Key key, Value valueToCheckFor)
        {
            if (ContainsKey(key) && this[key].Contains(valueToCheckFor))
            {
                return true;
            }
            return false;
        }

        public bool Contains(Value valueToCheckFor)
        {
            foreach (KeyValuePair<Key, List<Value>> kvp in this)
            {
                if (kvp.Value.Contains(valueToCheckFor))
                {
                    return true;
                }
            }
            return false;
        }
    }
}
