/// <summary> /// Initializes a new instance of the <see cref="DeltaLister{TItem}"/> class. /// </summary> /// <param name="oldList">The old list.</param> /// <param name="newList">The new list.</param> /// <param name="getItemId">The get item identifier.</param> /// <param name="options">The options.</param> /// <exception cref="ArgumentNullException"> /// oldList or newList or getItemId or oldItem or oldItemId or newItem is null. /// </exception> /// <exception cref="ArgumentOutOfRangeException">newItemId</exception> /// <exception cref="DuplicateNameException">newItemId</exception> public DeltaLister(IEnumerable <TItem> oldList, IEnumerable <TItem> newList, Func <TItem, long?> getItemId, DeltaOptions options = DeltaOptions.Default) { _options = options; _oldItems = oldList ?? throw new ArgumentNullException("oldList"); _newItems = newList ?? throw new ArgumentNullException("newList"); _getItemId = getItemId ?? throw new ArgumentNullException("getItemId"); _oldById = new Dictionary <long, TItem>(); _newById = new HashSet <long>(); foreach (var item in oldList) { if (item == null) { throw new ArgumentNullException("oldItem"); } var id = getItemId(item); if (id == null) { throw new ArgumentNullException("oldItemId"); } _oldById.Add(id.Value, item); } foreach (var item in newList) { if (item == null) { throw new ArgumentNullException("newItem"); } var id = getItemId(item); if (id != null) { if (!_oldById.ContainsKey(id.Value)) { if ((_options & DeltaOptions.IgnoreInvalidNewId) != DeltaOptions.IgnoreInvalidNewId) { throw new ArgumentOutOfRangeException("newItemId"); } } if (_newById.Contains(id.Value)) { throw new ArgumentException("newItemId"); } _newById.Add(id.Value); } } }
private static int RunDelta(DeltaOptions options) { foreach (var anon in Anons) { if (anon.Key != "Q") { continue; } Console.WriteLine($"Report for {anon.Key}:"); PrintDeltas(TrumpTweets, anon.Value); } return(0); }
public DeltaLister(IEnumerable <TItem> oldList, IEnumerable <TItem> newList, Func <TItem, Int64?> getItemId, DeltaOptions options = DeltaOptions.Default) { if (oldList == null) { throw new ArgumentNullException("oldList"); } if (newList == null) { throw new ArgumentNullException("newList"); } if (getItemId == null) { throw new ArgumentNullException("getItemId"); } _options = options; _oldItems = oldList; _newItems = newList; _getItemId = getItemId; _oldById = new Dictionary <Int64, TItem>(); _newById = new HashSet <Int64>(); foreach (var item in oldList) { if (item == null) { throw new ArgumentNullException("oldItem"); } var id = getItemId(item); if (id == null) { throw new ArgumentNullException("oldItemId"); } _oldById.Add(id.Value, item); } foreach (var item in newList) { if (item == null) { throw new ArgumentNullException("newItem"); } var id = getItemId(item); if (id != null) { if (!_oldById.ContainsKey(id.Value)) { if ((_options & DeltaOptions.IgnoreInvalidNewId) != DeltaOptions.IgnoreInvalidNewId) { throw new ArgumentOutOfRangeException("newItemId"); } } if (_newById.Contains(id.Value)) #if COREFX { throw new ArgumentException("newItemId"); } #else { throw new DuplicateNameException("newItemId"); } #endif _newById.Add(id.Value); } } }