public static IEnumerator<EventBean> For(
            IEnumerator<EventBean> sourceIterator,
            EventPropertyValueGetter distinctKeyGetter)
        {
            if (sourceIterator != null && sourceIterator.MoveNext()) {
                // there is at least one event...
                var first = sourceIterator.Current;
                // but is there only one event?
                if (!sourceIterator.MoveNext()) {
                    return EnumerationHelper.Singleton(first);
                }

                // build distinct set because there are multiple events
                var events = new ArrayDeque<EventBean>();
                events.Add(first);
                events.Add(sourceIterator.Current);
                while (sourceIterator.MoveNext()) {
                    events.Add(sourceIterator.Current);
                }

                // Determine the reader that we need to use for this use case
                var unique = EventBeanUtility.GetDistinctByProp(events, distinctKeyGetter);
                return unique.GetEnumerator();
            }

            return EnumerationHelper.Empty<EventBean>();
        }
        public void TestNext()
        {
            IEnumerator <string> it = EnumerationHelper.Singleton("a");

            Assert.IsTrue(it.MoveNext());
            Assert.AreEqual("a", it.Current);
            Assert.IsFalse(it.MoveNext());
        }
        private IEnumerator <EventBean> ObtainEnumerator()
        {
            var selectNewEvents = GetSelectListEvents(true, true, false);

            return(selectNewEvents != null
                ? EnumerationHelper.Singleton(selectNewEvents[0])
                : EnumerationHelper.Empty <EventBean>());
        }
Example #4
0
        public void TestNext()
        {
            IEnumerator <string> enumerator = EnumerationHelper.Singleton("a");

            Assert.That(enumerator.MoveNext(), Is.True);
            Assert.That(enumerator.Current, Is.EqualTo("a"));
            Assert.That(enumerator.MoveNext(), Is.False);
            //Assert.That(() => it.Current, Throws.InstanceOf<InvalidOperationException>());
        }
Example #5
0
        public IEnumerator<Cursor> GetCursors(int lookupFromStream)
        {
            if (lookupFromStream == rootStream) {
                var cursor = new Cursor(rootEvent, rootStream, null);
                return EnumerationHelper.Singleton(cursor);
            }

            var nodeList = NodesPerStream[lookupFromStream];
            if (nodeList == null) {
                return EnumerationHelper.Empty<Cursor>();
            }

            return GetCursorEnumerator(lookupFromStream, nodeList);
        }