Exemplo n.º 1
0
        /// <summary>
        /// Fill the passed in dictionary with the passed in entries
        /// </summary>
        /// <param name="newEntries"></param>
        /// <param name="oldEntries"></param>
        /// <param name="dictionary"> the dictionary to add the entries to</param>
        protected void populateDictionary(IEnumerable<Entry> oldEntries, IEnumerable<Entry> newEntries, IDictionary<string,CombinedEntry> dictionary)
        {
            // Add each entry in the old list into the list of entrys
            foreach (Entry entry in oldEntries)
            {
                CombinedEntry combEntry = new CombinedEntry(entry, null);
                CombinedEntry existingEntry;
                bool found = dictionary.TryGetValue(combEntry.getKey(), out existingEntry);
                if (found)
                {
                    existingEntry.Combine(combEntry);
                }
                else
                {
                    dictionary.Add(new KeyValuePair<string, CombinedEntry>(combEntry.getKey(), combEntry));
                }

            }
            // Check each entry if they are in the old list.  If they are combine them if not create a new entry
            foreach (Entry entry in newEntries)
            {
                CombinedEntry combEntry = new CombinedEntry(null, entry);
                CombinedEntry oldEntry;
                bool found = dictionary.TryGetValue(combEntry.getKey(), out oldEntry);
                if (found)
                {
                    oldEntry.Combine(combEntry);
                }
                else
                {
                    dictionary.Add(combEntry.getKey(), combEntry);
                }
            }
        }
Exemplo n.º 2
0
 public void Combine(CombinedEntry combEntry)
 {
     foreach(Entry entry in combEntry.m_oldEntries)
     {
         m_oldEntries.Add(entry);
     }
     foreach (Entry entry in combEntry.m_newEntries)
     {
         m_newEntries.Add(entry);
     }
     if(combEntry.m_oldEntries.Count == 0 && combEntry.m_newEntries.Count == 0)
     {
         // If they are both null we cannot combine it.
         throw new InvalidOperationException("Cannot combine an entry that is already full");
     }
     string key = getKey();
     if (keysEqual(m_newEntries, key) != keysEqual(m_oldEntries,key))
     {
         throw new InvalidOperationException("Cannot combine entries with different keys");
     }
 }