Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.DataImporter/HeuristicLab.DataImporter.Data/DataSetState.cs @ 14781

Last change on this file since 14781 was 9615, checked in by mkommend, 11 years ago

#1734: Updated copyright information in all DataImporter classes.

File size: 3.7 KB
Line 
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
22using System;
23
24namespace HeuristicLab.DataImporter.Data {
25  [Flags]
26  public enum ColumnGroupState {
27    None = 0,
28    Active = 1,
29    ColumnSelected = 2 | Active,
30    DoubleColumnSelected = 4 | ColumnSelected,
31    DateTimeColumnSelected = 8 | ColumnSelected,
32    StringColumnSelected = 16 | ColumnSelected,
33    ProgrammableColumnSelected = 32 | ColumnSelected,
34    AnySelectedColumnContainsNull = 64 | ColumnSelected,
35    Sorted = 128 | Active,
36    AnySelectedColumnNotSorted = 256 | Sorted | ColumnSelected
37  }
38
39  public class DataSetState {
40    public DataSetState(int activeColumnGroups, ColumnGroupState state)
41      : this(activeColumnGroups, -1, state) {
42    }
43
44    public DataSetState(int activeColumnGroups, int selectedColumns, ColumnGroupState state) {
45      this.selectedColumns = selectedColumns;
46      this.activeColumnGroups = activeColumnGroups;
47      this.state = state;
48    }
49
50    private int activeColumnGroups;
51    public int ActiveColumnGroups {
52      get { return this.activeColumnGroups; }
53    }
54
55    private int minActiveColumnGroups = int.MaxValue;
56    public int MinActiveColumnGroups {
57      get { return minActiveColumnGroups; }
58      set { minActiveColumnGroups = value; }
59    }
60
61    //only meaningful if activeColumnGroups == 1
62    private int selectedColumns;
63    public int SelectedColumns {
64      get { return activeColumnGroups == 1 ? this.selectedColumns : -1; } //throw Exception instead of return -1
65      set { this.selectedColumns = value; }
66    }
67
68    private ColumnGroupState state;
69    public ColumnGroupState State {
70      get { return this.state; }
71    }
72
73    public void AddColumnGroupState(ColumnGroupState state) {
74      if (state == ColumnGroupState.None)
75        return;
76      activeColumnGroups++;
77      if (this.state == ColumnGroupState.None)
78        this.state = state;
79      else
80        this.state &= state;
81    }
82
83    public bool Enabled(DataSetState other) {
84      if (this.activeColumnGroups == 0)
85        return true;
86      else if (other.activeColumnGroups != this.activeColumnGroups)
87        if (other.activeColumnGroups >= minActiveColumnGroups) return true;
88        else return false;
89      else if (SelectedColumns != -1 && other.SelectedColumns != SelectedColumns)
90        return false;
91      return (this.state & other.state) == this.state;
92    }
93
94    public override bool Equals(object obj) {
95      if (obj == this)
96        return true;
97      else if(obj is DataSetState) {
98        DataSetState other = (DataSetState)obj;
99        return
100          other.activeColumnGroups == this.activeColumnGroups &&
101          other.state == this.state &&
102          this.selectedColumns == other.selectedColumns;
103      }
104      return false;
105    }
106
107    public override int GetHashCode() {
108      return this.activeColumnGroups.GetHashCode() ^ this.state.GetHashCode() ^ this.selectedColumns.GetHashCode();
109    }
110
111  }
112}
Note: See TracBrowser for help on using the repository browser.