1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Linq;
|
---|
25 | using System.Text;
|
---|
26 |
|
---|
27 | namespace HeuristicLab.DataPreprocessing.Views {
|
---|
28 | class FindPreprocessingItemsIterator : IFindPreprocessingItemsIterator {
|
---|
29 | private IDictionary<int, IList<int>> items;
|
---|
30 | private Tuple<int, int> currentCell;
|
---|
31 |
|
---|
32 | public FindPreprocessingItemsIterator(IDictionary<int, IList<int>> items) {
|
---|
33 | this.items = items;
|
---|
34 | Reset();
|
---|
35 | }
|
---|
36 |
|
---|
37 | public bool MoveNext() {
|
---|
38 | bool result = false;
|
---|
39 | if (items != null) {
|
---|
40 | do {
|
---|
41 | if (currentCell.Item2 < items[currentCell.Item1].Count - 1) {
|
---|
42 | currentCell = new Tuple<int, int>(currentCell.Item1, currentCell.Item2 + 1);
|
---|
43 | } else if (currentCell.Item1 < items.Count - 1) {
|
---|
44 | currentCell = new Tuple<int, int>(currentCell.Item1 + 1, 0);
|
---|
45 | }
|
---|
46 | } while (!EndReached() && !CurrentCellExists());
|
---|
47 | result = EndReached();
|
---|
48 | }
|
---|
49 | return result;
|
---|
50 | }
|
---|
51 |
|
---|
52 | public Tuple<int, int> GetCurrent() {
|
---|
53 | Tuple<int, int> resultCells = null;
|
---|
54 | if (items != null && CurrentCellExists()) {
|
---|
55 | int cellRow = items[currentCell.Item1].ElementAt(currentCell.Item2);
|
---|
56 | resultCells = new Tuple<int, int>(currentCell.Item1, cellRow);
|
---|
57 | }
|
---|
58 | return resultCells;
|
---|
59 | }
|
---|
60 |
|
---|
61 | public void Reset() {
|
---|
62 | currentCell = new Tuple<int, int>(0, 0);
|
---|
63 | }
|
---|
64 |
|
---|
65 | private bool CurrentCellExists() {
|
---|
66 | bool result = false;
|
---|
67 | if (items != null) {
|
---|
68 | result = items.ContainsKey(currentCell.Item1) && currentCell.Item2 < items[currentCell.Item1].Count;
|
---|
69 | }
|
---|
70 | return result;
|
---|
71 | }
|
---|
72 |
|
---|
73 | private bool EndReached() {
|
---|
74 | bool result = true;
|
---|
75 | if (items != null && CurrentCellExists()) {
|
---|
76 | result = currentCell.Item1 >= items.Count - 1 && currentCell.Item2 >= items[currentCell.Item1].Count - 1;
|
---|
77 | }
|
---|
78 | return result;
|
---|
79 | }
|
---|
80 | }
|
---|
81 | }
|
---|