Ejemplo n.º 1
0
        /// <summary>
        /// Unions the dictionary with other dictionary
        /// </summary>
        /// <param name="list">List where the values have to be added from</param>
        public void Union(ONListDictionary <TKey, TValue> list)
        {
            if (list == null)
            {
                return;
            }

            if (Count == 0)
            {
                foreach (ONListDictionaryEntry <TKey, TValue> lEntry in list)
                {
                    Add(lEntry.Key, lEntry.Value);
                }
            }
            else
            {
                foreach (ONListDictionaryEntry <TKey, TValue> lEntry in list)
                {
                    if (!ContainsKey(lEntry.Key))
                    {
                        Add(lEntry.Key, lEntry.Value);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Unions 2 dictionaries
        /// </summary>
        /// <param name="list1">First dictionary where the values have to be added from</param>
        /// <param name="list2">Second dictionary where the values have to be added from</param>
        /// <returns>The union list</returns>
        public ONListDictionary <TKey, TValue> Union(ONListDictionary <TKey, TValue> list1, ONListDictionary <TKey, TValue> list2)
        {
            ONListDictionary <TKey, TValue> lList = new ONListDictionary <TKey, TValue>();

            lList.Union(list1);
            lList.Union(list2);

            return(lList);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Intersects the list with other list of elements
        /// </summary>
        /// <param name="list">List to intersect</param>
        public void Intersection(ONList <TKey, TValue> list)
        {
            ONListDictionary <TKey, TValue> lList = List;

            mList = new ONListDictionary <TKey, TValue>();

            if (list == null)
            {
                return;
            }

            foreach (ONListDictionaryEntry <TKey, TValue> lEntry in lList)
            {
                if (list.Contains(lEntry.Value))
                {
                    Add(lEntry.Value);
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Intersect two lists
        /// </summary>
        /// <param name="list1">First dictionary of instances to intersect</param>
        /// <param name="list2">Second dictionary of instances to intersect</param>
        public static ONListDictionary <TKey, TValue> Intersection(ONListDictionary <TKey, TValue> list1, ONListDictionary <TKey, TValue> list2)
        {
            ONListDictionary <TKey, TValue> lList = new ONListDictionary <TKey, TValue>();

            if ((list1 == null) || (list2 == null))
            {
                return(lList);
            }

            foreach (ONListDictionaryEntry <TKey, TValue> lEntry in list1)
            {
                if (list2.ContainsKey(lEntry.Key))
                {
                    lList.Add(lEntry.Key, lEntry.Value);
                }
            }

            return(lList);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Intersects the dictionary with other dictionary
        /// </summary>
        /// <param name="list">Dictionary to intersect</param>
        public void Intersection(ONListDictionary <TKey, TValue> list)
        {
            if (list == null)
            {
                Clear();
                return;
            }

            int mMaxIndex = -1;

            foreach (ONListDictionaryEntry <TKey, TValue> lEntry in this)
            {
                if (!list.ContainsKey(lEntry.Key))
                {
                    Remove(lEntry.Key);
                }
                else
                {
                    mMaxIndex++;
                    lEntry.Index = mMaxIndex;
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Checks if the dictionary is equals to other dictionary
        /// </summary>
        /// <param name="item">Dictionary to check</param>
        /// <returns>If the dictionaries are equals</returns>
        public override bool Equals(object item)
        {
            ONListDictionary <TKey, TValue> lList = item as ONListDictionary <TKey, TValue>;

            if ((lList == null) || (Count != lList.Count))
            {
                return(false);
            }

            ONListDictionaryEnumerator <TKey, TValue> lEnum1 = GetEnumerator();
            ONListDictionaryEnumerator <TKey, TValue> lEnum2 = lList.GetEnumerator();

            while (lEnum1.MoveNext())
            {
                lEnum2.MoveNext();

                if (!lEnum1.Current.Value.Equals(lEnum2.Current.Value))
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Constructor of the list
 /// </summary>
 public ONList()
 {
     mList = new ONListDictionary <TKey, TValue>();
 }