/// <summary> /// Adds all the elements of the other collection to this collection and keeps it sorted by time if both collections were sorted by time already /// </summary> /// <param name="other">The collection to merge with</param> public void MergeWith(RelevantObjectCollection other) { // Merge all types in this var keys = new List <Type>(Keys); foreach (var key in keys) { if (other.TryGetValue(key, out var otherValue)) { this[key] = SortedMerge(this[key], otherValue); } } // Add the types that only the other has foreach (var type in other.Keys.Except(Keys)) { Add(type, other[type]); } }
public static RelevantObjectCollection Merge(RelevantObjectCollection collection1, RelevantObjectCollection collection2) { var result = new RelevantObjectCollection(); // Merge all types in this foreach (var kvp in collection1) { result.Add(kvp.Key, collection2.TryGetValue(kvp.Key, out var otherValue) ? SortedMerge(kvp.Value, otherValue) : kvp.Value); } // Add the types that only the other has foreach (var type in collection2.Keys.Except(collection1.Keys)) { result.Add(type, collection2[type]); } return(result); }
public RelevantObjectCollection GetSubset(SelectionPredicateCollection predicate, RelevantObjectsGenerator generator) { var result = new RelevantObjectCollection(); if (predicate == null) { foreach (var kvp in this) { result.Add(kvp.Key, kvp.Value); } return(result); } foreach (var kvp in this) { result.Add(kvp.Key, kvp.Value.Where(o => predicate.Check(o, generator)).ToList()); } return(result); }