public void EnumMessages(long fromPosition, Func <IMessage, bool> callback, EnumMessagesFlag flags) { var forward = (flags & EnumMessagesFlag.Forward) != 0; var idx = ListUtils.GetBound(messages, null, forward ? ValueBound.Lower : ValueBound.UpperReversed, new PositionsComparer(fromPosition)); if (forward) { for (; idx < messages.Count; ++idx) { if (!callback(messages[idx])) { return; } } } else { for (; idx >= 0; --idx) { if (messages[idx].EndPosition <= fromPosition && !callback(messages[idx])) { return; } } } }
public DateBoundPositionResponseData GetDateBoundPosition(DateTime d, ValueBound bound) { var idx = ListUtils.GetBound(messages, (IMessage)null, bound, new DatesComparer(d)); if (idx < 0) { return new DateBoundPositionResponseData() { Position = -1, Index = -1, IsBeforeBeginPosition = true, } } ; if (idx >= messages.Count) { return new DateBoundPositionResponseData() { Position = messages.Count == 0 ? 0 : (messages[messages.Count - 1].Position + 1), Index = messages.Count, IsEndPosition = true, } } ; return(new DateBoundPositionResponseData() { Position = messages[idx].Position, Index = idx, Message = messages[idx] }); } }; }
static void TestBound(int value, ListUtils.ValueBound bound, int expectedIdx) { List <int> lst = new List <int>(new int[] { 0, 2, 2, 2, 3, 5, 7, 8, 8, 10 }); int actual = ListUtils.GetBound(lst, value, bound, Comparer <int> .Default); Assert.AreEqual(expectedIdx, actual); }