Exemple #1
0
        public IEnumerable <AggregationResult> Modify(AggregationContext context, ITuple tuple, IEnumerable <IFact> facts)
        {
            var results = new List <AggregationResult>();

            foreach (var fact in facts)
            {
                var collection = (IEnumerable <TElement>)fact.Value;
                foreach (var value in collection)
                {
                    if (_firstElements.TryGetValue(fact, out var oldFirst))
                    {
                        if (Equals(oldFirst, value))
                        {
                            results.Add(AggregationResult.Modified(value, value, Enumerable.Repeat(fact, 1)));
                        }
                        else
                        {
                            results.Add(AggregationResult.Removed(oldFirst));
                            results.Add(AggregationResult.Added(value, Enumerable.Repeat(fact, 1)));
                        }
                    }
                    else
                    {
                        results.Add(AggregationResult.Added(value, Enumerable.Repeat(fact, 1)));
                    }
                    _firstElements[fact] = value;
                    break;
                }
            }
            return(results);
        }
Exemple #2
0
        public IEnumerable <AggregationResult> Remove(object fact)
        {
            var source  = (TSource)fact;
            var oldList = _sourceToList[source];

            _sourceToList.Remove(source);
            return(oldList.Select(x => AggregationResult.Removed(x)).ToArray());
        }
        public IEnumerable <AggregationResult> Remove(object fact)
        {
            var source   = (TSource)fact;
            var oldValue = _sourceToValue[source];

            _sourceToValue.Remove(source);
            return(new[] { AggregationResult.Removed(oldValue) });
        }
        private AggregationResult Remove(TKey key, TElement element)
        {
            var group = _groups[key];

            group.Remove(element);
            if (group.Count == 0)
            {
                _groups.Remove(key);
                return(AggregationResult.Removed(group));
            }
            return(AggregationResult.Modified(group));
        }
Exemple #5
0
        public IEnumerable <AggregationResult> Modify(object fact)
        {
            var source  = (TSource)fact;
            var value   = _selector(source);
            var list    = value.ToList();
            var oldList = _sourceToList[source];

            _sourceToList[source] = list;

            return(oldList.Select(x => AggregationResult.Removed(x)).Concat(
                       list.Select(x => AggregationResult.Added(x))).ToArray());
        }
Exemple #6
0
        public IEnumerable <AggregationResult> Remove(ITuple tuple, IEnumerable <IFact> facts)
        {
            var results = new List <AggregationResult>();

            foreach (var fact in facts)
            {
                var oldValue = _sourceToValue[fact];
                _sourceToValue.Remove(fact);
                results.Add(AggregationResult.Removed(oldValue));
            }
            return(results);
        }
Exemple #7
0
        public IEnumerable <AggregationResult> Remove(IEnumerable <object> facts)
        {
            var results = new List <AggregationResult>();

            foreach (var fact in facts)
            {
                var source   = (TSource)fact;
                var oldValue = _sourceToValue[source];
                _sourceToValue.Remove(source);
                results.Add(AggregationResult.Removed(oldValue));
            }
            return(results);
        }
Exemple #8
0
        public IEnumerable <AggregationResult> Remove(AggregationContext context, ITuple tuple, IEnumerable <IFact> facts)
        {
            var results = new List <AggregationResult>();

            foreach (var fact in facts)
            {
                if (_firstElements.TryGetValue(fact, out var oldFirst))
                {
                    results.Add(AggregationResult.Removed(oldFirst));
                    _firstElements.Remove(fact);
                }
            }
            return(results);
        }
Exemple #9
0
        public IEnumerable <AggregationResult> Remove(IEnumerable <object> facts)
        {
            var results = new List <AggregationResult>();

            foreach (var fact in facts)
            {
                var source  = (TSource)fact;
                var oldList = _sourceToList[source];
                _sourceToList.Remove(source);
                foreach (var item in oldList)
                {
                    results.Add(AggregationResult.Removed(item));
                }
            }
            return(results);
        }
        public IEnumerable <AggregationResult> Modify(object fact)
        {
            var source   = (TSource)fact;
            var value    = _selector(source);
            var oldValue = _sourceToValue[source];

            _sourceToValue[source] = value;

            if (Equals(oldValue, value))
            {
                return new[] { AggregationResult.Modified(value) }
            }
            ;

            return(new[] { AggregationResult.Removed(oldValue), AggregationResult.Added(value) });
        }
Exemple #11
0
        public IEnumerable <AggregationResult> Modify(IEnumerable <object> facts)
        {
            var results = new List <AggregationResult>();

            foreach (var fact in facts)
            {
                var source  = (TSource)fact;
                var value   = _selector(source);
                var list    = new List <TResult>(value);
                var oldList = _sourceToList[source];
                _sourceToList[source] = list;
                foreach (var item in oldList)
                {
                    results.Add(AggregationResult.Removed(item));
                }
                foreach (var item in list)
                {
                    results.Add(AggregationResult.Added(item));
                }
            }
            return(results);
        }
        public IEnumerable <AggregationResult> Modify(ITuple tuple, IEnumerable <IFact> facts)
        {
            var results = new List <AggregationResult>();

            foreach (var fact in facts)
            {
                var source   = (TSource)fact.Value;
                var value    = _selector.Invoke(tuple, fact);
                var oldValue = (TResult)_sourceToValue[source];
                _sourceToValue[source] = value;

                if (Equals(oldValue, value))
                {
                    results.Add(AggregationResult.Modified(value));
                }
                else
                {
                    results.Add(AggregationResult.Removed(oldValue));
                    results.Add(AggregationResult.Added(value));
                }
            }
            return(results);
        }
Exemple #13
0
        private IEnumerable <AggregationResult> Remove(TKey key, TElement element)
        {
            if (Equals(key, _defaultKey))
            {
                _defaultGroup.Remove(element);
                if (_defaultGroup.Count == 0)
                {
                    var removedGroup = _defaultGroup;
                    _defaultGroup = null;
                    return(new[] { AggregationResult.Removed(removedGroup) });
                }
                return(new[] { AggregationResult.Modified(_defaultGroup) });
            }

            var group = _groups[key];

            group.Remove(element);
            if (group.Count == 0)
            {
                _groups.Remove(key);
                return(new[] { AggregationResult.Removed(group) });
            }
            return(new[] { AggregationResult.Modified(group) });
        }