-
Notifications
You must be signed in to change notification settings - Fork 0
/
VirtList.cs
210 lines (193 loc) · 8.01 KB
/
VirtList.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
////using System;
////using System.Collections.Generic;
////using System.Linq;
////using System.Text;
////using System.Threading.Tasks;
////namespace gsmagic {
//// class VirtList {
//// }
////}
//using System;
//using System.Collections;
//using System.Collections.Generic;
//namespace VirtualListWithPagingTechnique {
// namespace VirtualLists {
// public interface IObjectGenerator<T> {
// /// <summary>
// /// Returns the number of items in the collection.
// /// </summary>
// int Count { get; }
// /// <summary>
// /// Generate the item that is located on the specified index.
// /// </summary>
// /// <remarks>
// /// This method is only be called once per index.
// /// </remarks>
// /// <param name="index">Index of the items that must be generated.</param>
// /// <returns>Fresh new instance.</returns>
// T CreateObject(int index);
// }
// /// <summary>
// /// Virtual lists are lists from which the content is loaded on demand.
// /// </summary>
// /// <remarks>
// /// Use visual lists if it is expensive to populate the list and only
// /// a subset of the list's elements are used. The virtual list uses an
// /// object generator to populate the list on demand.
// /// </remarks>
// /// <typeparam name="T">Objects that are stored inside the list.</typeparam>
// public class VirtualList<T> : IList<T>, IList where T : class {
// #region Internal attributes
// /// <summary>
// /// Object that is used to generate the requested objects.
// /// </summary>
// /// <remarks>
// /// This object can also hold a IMultipleObjectGenerator reference.
// /// </remarks>
// private readonly IObjectGenerator<T> _generator;
// /// <summary>
// /// Internal array that holds the cached items.
// /// </summary>
// private readonly T[] _cachedItems;
// #endregion
// #region Constructor
// /// <summary>
// /// Create the virtual list.
// /// </summary>
// /// <param name="generator"></param>
// public VirtualList(IObjectGenerator<T> generator) {
// int maxItems = generator.Count; // Determine the number of items
// _generator = generator; // Save generator and items
// _cachedItems = new T[maxItems];
// }
// #endregion
// #region IList<T> Members
// public int IndexOf(T item) {
// return IndexOf(item);
// }
// public void Insert(int index, T item) {
// throw new NotSupportedException("VirtualList is a read-only collection.");
// }
// public void RemoveAt(int index) {
// throw new NotSupportedException("VirtualList is a read-only collection.");
// }
// public T this[int index] {
// get {
// if (!IsItemCached(index)) // Cache item if it isn't cached already
// CacheItem(index);
// return _cachedItems[index]; // Return the cached object
// }
// set { throw new NotSupportedException("VirtualList is a read-only collection."); }
// }
// #endregion
// #region ICollection<T> Members
// public void Add(T item) {
// throw new NotSupportedException("VirtualList is a read-only collection.");
// }
// public void Clear() {
// throw new NotSupportedException("VirtualList is a read-only collection.");
// }
// public bool Contains(T item) {
// return (IndexOf(item) != -1);
// }
// public void CopyTo(T[] array, int arrayIndex) {
// _cachedItems.CopyTo(array, arrayIndex);
// }
// public int Count {
// get { return _cachedItems.Length; }
// }
// public bool IsReadOnly {
// get { return true; }
// }
// public bool Remove(T item) {
// throw new NotSupportedException("VirtualList is a read-only collection.");
// }
// #endregion
// #region IEnumerable<T> Members
// public IEnumerator<T> GetEnumerator() {
// return new VirtualEnumerator(this);
// }
// #endregion
// #region IList Members
// public int Add(object value) {
// throw new NotSupportedException("VirtualList is a read-only collection.");
// }
// public bool Contains(object value) {
// throw new NotImplementedException();
// }
// public int IndexOf(object value) {
// int items = _cachedItems.Length;
// for (int index = 0; index < items; ++index) {
// if (_cachedItems[index].Equals(value)) // Check if item is found
// return index;
// }
// return -1; // Item not found
// }
// public void Insert(int index, object value) {
// throw new NotSupportedException("VirtualList is a read-only collection.");
// }
// public bool IsFixedSize {
// get { return true; }
// }
// public void Remove(object value) {
// throw new NotSupportedException("VirtualList is a read-only collection.");
// }
// object IList.this[int index] {
// get { return this[index]; }
// set { throw new NotSupportedException("VirtualList is a read-only collection."); }
// }
// #endregion
// #region ICollection Members
// public void CopyTo(Array array, int index) {
// _cachedItems.CopyTo(array, index);
// }
// public bool IsSynchronized {
// get { return false; }
// }
// public object SyncRoot {
// get { return this; }
// }
// #endregion
// #region IEnumerable Members
// IEnumerator IEnumerable.GetEnumerator() {
// return new VirtualEnumerator(this);
// }
// #endregion
// #region Internal helper methods required for caching
// private bool IsItemCached(int index) {
// return (_cachedItems[index] != null); // If the object is NULL, then it is empty
// }
// #endregion
// public void CacheItem(int index) {
// _cachedItems[index] = _generator.CreateObject(index); // Obtain only a single object
// }
// #region Internal IEnumerator implementation
// private class VirtualEnumerator : IEnumerator<T> {
// private readonly VirtualList<T> _collection;
// private int _cursor;
// public VirtualEnumerator(VirtualList<T> collection) {
// _collection = collection;
// _cursor = 0;
// }
// public T Current {
// get { return _collection[_cursor]; }
// }
// object IEnumerator.Current {
// get { return Current; }
// }
// public bool MoveNext() {
// if (_cursor == _collection.Count) // Check if we are behind
// return false;
// ++_cursor; // Increment cursor
// return true;
// }
// public void Reset() {
// _cursor = 0; // Reset cursor
// }
// public void Dispose() { // NOP
// }
// }
// #endregion
// }
// }
//}