Exemplo n.º 1
0
        /// <summary>
        /// Get filtered events in the specified range.
        /// </summary>
        public List <Event> GetFilteredEvents(EventFilter filter, int lastCount, int startEvNum, out bool reversed)
        {
            if (filter == null)
            {
                throw new ArgumentNullException(nameof(filter));
            }
            filter.Check();

            reversed = false;
            List <Event> filteredEvents = lastCount > 0 ? new List <Event>(lastCount) : new List <Event>();
            int          startEvInd     = Math.Max(0, startEvNum - 1);
            int          allEventsCnt   = allEvents.Count;

            void AddEventAction(int i)
            {
                var ev = allEvents[i];

                if (filter.Satisfied(ev))
                {
                    filteredEvents.Add(ev);
                }
            }

            if (lastCount > 0)
            {
                for (int i = allEventsCnt - 1; i >= startEvInd && filteredEvents.Count < lastCount; i--)
                {
                    AddEventAction(i);
                }
                reversed = true;
            }
            else
            {
                for (int i = startEvInd; i < allEventsCnt; i++)
                {
                    AddEventAction(i);
                }
            }

            return(filteredEvents);
        }