Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/DynamicDataDisplay/Charts/Filters/IndexWrapper.cs @ 12503

Last change on this file since 12503 was 12503, checked in by aballeit, 9 years ago

#2283 added GUI and charts; fixed MCTS

File size: 1.6 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Collections.Specialized;
6using System.Collections;
7
8namespace 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}
Note: See TracBrowser for help on using the repository browser.