Exemple #1
0
        //TODO: Need to account for re-evaluate (as it is not mutually excluse to clear and replace)

        private void Requery(Func <T, bool> predicate, List <ItemWithMatch> allWithMatch, List <T> all, ChangeAwareList <T> filtered)
        {
            _predicate = predicate;

            var newState = allWithMatch.Select(item =>
            {
                var match    = _predicate(item.Item);
                var wasMatch = item.IsMatch;

                //reflect filtered state
                if (item.IsMatch != match)
                {
                    item.IsMatch = match;
                }

                return(new
                {
                    Item = item,
                    IsMatch = match,
                    WasMatch = wasMatch
                });
            }).ToList();

            //reflect items which are no longer matched
            var noLongerMatched = newState.Where(state => !state.IsMatch && state.WasMatch).Select(state => state.Item.Item);

            filtered.RemoveMany(noLongerMatched);

            //reflect new matches in the list
            var newMatched = newState.Where(state => state.IsMatch && !state.WasMatch).Select(state => state.Item.Item);

            filtered.AddRange(newMatched);
        }
Exemple #2
0
        private IChangeSet <T> ProcessImpl(IChangeSet <T> changes)
        {
            changes.ForEach(change =>
            {
                switch (change.Reason)
                {
                case ListChangeReason.Add:
                    {
                        var current = change.Item.Current;
                        Insert(current);
                        break;
                    }

                case ListChangeReason.AddRange:
                    {
                        var ordered = change.Range.OrderBy(t => t, _comparer).ToList();
                        if (_innerList.Count == 0)
                        {
                            _innerList.AddRange(ordered);
                        }
                        else
                        {
                            ordered.ForEach(Insert);
                        }
                        break;
                    }

                case ListChangeReason.Replace:
                    {
                        var current = change.Item.Current;
                        //TODO: check whether an item should stay in the same position
                        //i.e. update and move
                        Remove(change.Item.Previous.Value);
                        Insert(current);
                        break;
                    }

                case ListChangeReason.Remove:
                    {
                        var current = change.Item.Current;
                        Remove(current);
                        break;
                    }

                case ListChangeReason.RemoveRange:
                    {
                        _innerList.RemoveMany(change.Range);
                        break;
                    }

                case ListChangeReason.Clear:
                    {
                        _innerList.Clear();
                        break;
                    }
                }
            });

            return(_innerList.CaptureChanges());
        }
Exemple #3
0
        private IChangeSet <T> ProcessImpl(ChangeAwareList <T> target, IChangeSet <T> changes)
        {
            foreach (var change in changes)
            {
                switch (change.Reason)
                {
                case ListChangeReason.Add:
                {
                    var current = change.Item.Current;
                    Insert(target, current);
                    break;
                }

                case ListChangeReason.AddRange:
                {
                    var ordered = change.Range.OrderBy(t => t, _comparer).ToList();
                    if (target.Count == 0)
                    {
                        target.AddRange(ordered);
                    }
                    else
                    {
                        ordered.ForEach(item => Insert(target, item));
                    }
                    break;
                }

                case ListChangeReason.Replace:
                {
                    var current = change.Item.Current;
                    //TODO: check whether an item should stay in the same position
                    //i.e. update and move
                    Remove(target, change.Item.Previous.Value);
                    Insert(target, current);
                    break;
                }

                case ListChangeReason.Remove:
                {
                    var current = change.Item.Current;
                    Remove(target, current);
                    break;
                }

                case ListChangeReason.RemoveRange:
                {
                    target.RemoveMany(change.Range);
                    break;
                }

                case ListChangeReason.Clear:
                {
                    target.Clear();
                    break;
                }
                }
            }
            return(target.CaptureChanges());
        }
Exemple #4
0
        private IChangeSet <T> Reset(ChangeAwareList <T> original, ChangeAwareList <T> target)
        {
            var sorted = original.OrderBy(t => t, _comparer).ToList();

            target.Clear();
            target.AddRange(sorted);
            return(target.CaptureChanges());
        }
Exemple #5
0
        private IChangeSet <T> ChangeComparer(ChangeAwareList <T> target, IComparer <T> comparer)
        {
            _comparer = comparer;
            var sorted = target.OrderBy(t => t, _comparer).ToList();

            target.Clear();
            target.AddRange(sorted);
            return(target.CaptureChanges());
        }