[smuxi/experiments/sqlite: 7/27] [Engine] Added GetRange() implementation to MessageBufferBase based on class indexer
- From: Mirco M. M. Bauer <mmmbauer src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [smuxi/experiments/sqlite: 7/27] [Engine] Added GetRange() implementation to MessageBufferBase based on class indexer
- Date: Sun, 23 Feb 2014 17:06:58 +0000 (UTC)
commit 9818683dc5da346af352e4cc9563b81c4a88e2c8
Author: Mirco Bauer <meebey meebey net>
Date: Sun Feb 26 11:51:59 2012 +0100
[Engine] Added GetRange() implementation to MessageBufferBase based on class indexer
src/Engine/MessageBuffers/GitMessageBuffer.cs | 5 -----
src/Engine/MessageBuffers/MessageBufferBase.cs | 17 +++++++++++++++++
2 files changed, 17 insertions(+), 5 deletions(-)
---
diff --git a/src/Engine/MessageBuffers/GitMessageBuffer.cs b/src/Engine/MessageBuffers/GitMessageBuffer.cs
index 75f2aa0..d72364c 100644
--- a/src/Engine/MessageBuffers/GitMessageBuffer.cs
+++ b/src/Engine/MessageBuffers/GitMessageBuffer.cs
@@ -192,11 +192,6 @@ namespace Smuxi.Engine
throw new NotImplementedException ();
}
- public override System.Collections.Generic.IList<MessageModel> GetRange (int offset, int limit)
- {
- throw new NotImplementedException ();
- }
-
public override void Dispose()
{
Flush();
diff --git a/src/Engine/MessageBuffers/MessageBufferBase.cs b/src/Engine/MessageBuffers/MessageBufferBase.cs
index 823ab43..1667f88 100644
--- a/src/Engine/MessageBuffers/MessageBufferBase.cs
+++ b/src/Engine/MessageBuffers/MessageBufferBase.cs
@@ -66,6 +66,23 @@ namespace Smuxi.Engine
ChatID = chatId;
}
+ public virtual IList<MessageModel> GetRange(int offset, int limit)
+ {
+ if (offset < 0) {
+ throw new ArgumentException(
+ "offset must be greater than or equal to 0.", "offset"
+ );
+ }
+
+ var bufferCount = Count;
+ var rangeCount = Math.Min(bufferCount, limit);
+ var range = new List<MessageModel>(rangeCount);
+ for (int i = offset; i < offset + limit && i < bufferCount; i++) {
+ range.Add(this[i]);
+ }
+ return range;
+ }
+
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]