1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Collections.Specialized;
|
---|
6 | using System.Collections;
|
---|
7 |
|
---|
8 | namespace Microsoft.Research.DynamicDataDisplay.Filters
|
---|
9 | {
|
---|
10 | /// <summary>
|
---|
11 | /// Represents a utility class which wraps each value in a sequence with a wrapper, which
|
---|
12 | /// contains an position of wrapped element in a sequence.
|
---|
13 | /// </summary>
|
---|
14 | public static class IndexWrapper
|
---|
15 | {
|
---|
16 | public const int Empty = -1;
|
---|
17 |
|
---|
18 | /// <summary>
|
---|
19 | /// Generates the index-wrapped series for specified series.
|
---|
20 | /// </summary>
|
---|
21 | /// <typeparam name="T"></typeparam>
|
---|
22 | /// <param name="series">The series.</param>
|
---|
23 | /// <returns></returns>
|
---|
24 | public static IEnumerable<IndexWrapper<T>> Generate<T>(IEnumerable<T> series, int startingWith = 0)
|
---|
25 | {
|
---|
26 | IndexWrapper<T> indexWrapper = new IndexWrapper<T>();
|
---|
27 |
|
---|
28 | int index = startingWith;
|
---|
29 | foreach (var item in series)
|
---|
30 | {
|
---|
31 | indexWrapper.Data = item;
|
---|
32 | indexWrapper.Index = index;
|
---|
33 |
|
---|
34 | yield return indexWrapper;
|
---|
35 |
|
---|
36 | index++;
|
---|
37 | }
|
---|
38 | }
|
---|
39 |
|
---|
40 | /// <summary>
|
---|
41 | /// Generates the index-wrapped sequence for a given sequence of items.
|
---|
42 | /// </summary>
|
---|
43 | /// <param name="items">The items.</param>
|
---|
44 | /// <param name="startingIndex">Index of the starting.</param>
|
---|
45 | /// <returns></returns>
|
---|
46 | public static IEnumerable<IndexWrapper<object>> Generate(IList items, int startingIndex)
|
---|
47 | {
|
---|
48 | IndexWrapper<object> indexWrapper = new IndexWrapper<object>();
|
---|
49 |
|
---|
50 | for (int i = 0; i < items.Count; i++)
|
---|
51 | {
|
---|
52 | indexWrapper.Data = items[i];
|
---|
53 | indexWrapper.Index = startingIndex + i;
|
---|
54 |
|
---|
55 | yield return indexWrapper;
|
---|
56 | }
|
---|
57 | }
|
---|
58 | }
|
---|
59 | }
|
---|