Exemple #1
0
 public void Add(CfgNodeValue <TK, TV> value)
 {
     lock (_lock)
     {
         AllItems.Add(value);
         if (!RepeatedItems.ContainsKey(value.Key))
         {
             if (SingleItems.ContainsKey(value.Key))
             {
                 RepeatedItems.Add(value.Key, new List <CfgNodeValue <TK, TV> > {
                     SingleItems[value.Key]
                 });
                 SingleItems.Remove(value.Key);
                 RepeatedItems[value.Key].Add(value);
             }
             else
             {
                 SingleItems.Add(value.Key, value);
             }
         }
         else
         {
             RepeatedItems[value.Key].Add(value);
         }
     }
 }
Exemple #2
0
 /// <summary>
 /// Remove all the elements that have the given key
 /// </summary>
 public void Remove(TK key)
 {
     lock (_lock)
     {
         AllItems.RemoveAll(v => v.Key.Equals(key));
         if (SingleItems.ContainsKey(key))
         {
             SingleItems.Remove(key);
         }
         else
         {
             RepeatedItems.Remove(key);
         }
     }
 }
Exemple #3
0
        /// <summary>
        /// Replaces ALL the elements that match in KEY and VALUE for the new one
        /// </summary>
        public void Replace(CfgNodeValue <TK, TV> oldKeyVal, CfgNodeValue <TK, TV> newKeyVal)
        {
            lock (_lock)
            {
                var index = AllItems.IndexOf(oldKeyVal);
                if (index >= 0)
                {
                    AllItems[index] = newKeyVal;

                    if (SingleItems.ContainsKey(oldKeyVal.Key))
                    {
                        if (oldKeyVal.Key.Equals(newKeyVal.Key))
                        {
                            SingleItems[oldKeyVal.Key] = newKeyVal;
                        }
                        else
                        {
                            SingleItems.Remove(oldKeyVal.Key);
                            SingleItems.Add(newKeyVal.Key, newKeyVal);
                        }
                    }
                    else
                    {
                        if (RepeatedItems.ContainsKey(oldKeyVal.Key))
                        {
                            if (oldKeyVal.Key.Equals(newKeyVal.Key))
                            {
                                for (var i = 0; i < RepeatedItems[oldKeyVal.Key].Count; i++)
                                {
                                    if (RepeatedItems[oldKeyVal.Key][i].Equals(oldKeyVal))
                                    {
                                        RepeatedItems[oldKeyVal.Key][i] = newKeyVal;
                                    }
                                }
                            }
                            else
                            {
                                Remove(oldKeyVal);
                                Add(newKeyVal);
                            }
                        }
                    }
                }
            }
        }
Exemple #4
0
 /// <summary>
 /// Removes a specific value
 /// </summary>
 public void Remove(CfgNodeValue <TK, TV> keyVal)
 {
     lock (_lock)
     {
         AllItems.RemoveAll(v => v.Value.Equals(keyVal));
         if (SingleItems.ContainsKey(keyVal.Key))
         {
             SingleItems.Remove(keyVal.Key);
         }
         else if (RepeatedItems.ContainsKey(keyVal.Key))
         {
             RepeatedItems[keyVal.Key].RemoveAll(v => v.Equals(keyVal));
             if (!RepeatedItems[keyVal.Key].Any())
             {
                 RepeatedItems.Remove(keyVal.Key);
             }
         }
     }
 }