Esempio n. 1
0
        /// <summary>Returns the distinct events by properties. </summary>
        /// <param name="events">to inspect</param>
        /// <param name="reader">for retrieving properties</param>
        /// <returns>distinct events</returns>
        public static EventBean[] GetDistinctByProp(LinkedList <EventBean> events,
                                                    EventBeanReader reader)
        {
            if (events == null || events.IsEmpty())
            {
                return(new EventBean[0]);
            }
            if (events.Count < 2)
            {
                return(events.ToArray());
            }

            var set = new LinkedHashSet <MultiKeyUntypedEventPair>();

            if (events.First.Value is NaturalEventBean)
            {
                foreach (EventBean theEvent in events)
                {
                    var inner = ((NaturalEventBean)theEvent).OptionalSynthetic;
                    var keys  = reader.Read(inner);
                    var pair  = new MultiKeyUntypedEventPair(keys, theEvent);
                    set.Add(pair);
                }
            }
            else
            {
                foreach (EventBean theEvent in events)
                {
                    Object[] keys = reader.Read(theEvent);
                    var      pair = new MultiKeyUntypedEventPair(keys, theEvent);
                    set.Add(pair);
                }
            }

            var result = new EventBean[set.Count];
            var count  = 0;

            foreach (MultiKeyUntypedEventPair row in set)
            {
                result[count++] = row.EventBean;
            }
            return(result);
        }
Esempio n. 2
0
        /// <summary>Returns the distinct events by properties. </summary>
        /// <param name="events">to inspect</param>
        /// <param name="reader">for retrieving properties</param>
        /// <returns>distinct events</returns>
        public static EventBean[] GetDistinctByProp(EventBean[] events,
                                                    EventBeanReader reader)
        {
            if ((events == null) || (events.Length < 2))
            {
                return(events);
            }

            var set = new LinkedHashSet <MultiKeyUntypedEventPair>();

            if (events[0] is NaturalEventBean)
            {
                foreach (EventBean theEvent in events)
                {
                    var inner = ((NaturalEventBean)theEvent).OptionalSynthetic;
                    var keys  = reader.Read(inner);
                    var pair  = new MultiKeyUntypedEventPair(keys, theEvent);
                    set.Add(pair);
                }
            }
            else
            {
                foreach (EventBean theEvent in events)
                {
                    Object[] keys = reader.Read(theEvent);
                    var      pair = new MultiKeyUntypedEventPair(keys, theEvent);
                    set.Add(pair);
                }
            }

            var result = new EventBean[set.Count];
            int count  = 0;

            foreach (MultiKeyUntypedEventPair row in set)
            {
                result[count++] = row.EventBean;
            }
            return(result);
        }