#region License Information /* HeuristicLab * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; namespace HeuristicLab.DataImporter.Data { [Flags] public enum ColumnGroupState { None = 0, Active = 1, ColumnSelected = 2 | Active, DoubleColumnSelected = 4 | ColumnSelected, DateTimeColumnSelected = 8 | ColumnSelected, StringColumnSelected = 16 | ColumnSelected, ProgrammableColumnSelected = 32 | ColumnSelected, AnySelectedColumnContainsNull = 64 | ColumnSelected, Sorted = 128 | Active, AnySelectedColumnNotSorted = 256 | Sorted | ColumnSelected } public class DataSetState { public DataSetState(int activeColumnGroups, ColumnGroupState state) : this(activeColumnGroups, -1, state) { } public DataSetState(int activeColumnGroups, int selectedColumns, ColumnGroupState state) { this.selectedColumns = selectedColumns; this.activeColumnGroups = activeColumnGroups; this.state = state; } private int activeColumnGroups; public int ActiveColumnGroups { get { return this.activeColumnGroups; } } private int minActiveColumnGroups = int.MaxValue; public int MinActiveColumnGroups { get { return minActiveColumnGroups; } set { minActiveColumnGroups = value; } } //only meaningful if activeColumnGroups == 1 private int selectedColumns; public int SelectedColumns { get { return activeColumnGroups == 1 ? this.selectedColumns : -1; } //throw Exception instead of return -1 set { this.selectedColumns = value; } } private ColumnGroupState state; public ColumnGroupState State { get { return this.state; } } public void AddColumnGroupState(ColumnGroupState state) { if (state == ColumnGroupState.None) return; activeColumnGroups++; if (this.state == ColumnGroupState.None) this.state = state; else this.state &= state; } public bool Enabled(DataSetState other) { if (this.activeColumnGroups == 0) return true; else if (other.activeColumnGroups != this.activeColumnGroups) if (other.activeColumnGroups >= minActiveColumnGroups) return true; else return false; else if (SelectedColumns != -1 && other.SelectedColumns != SelectedColumns) return false; return (this.state & other.state) == this.state; } public override bool Equals(object obj) { if (obj == this) return true; else if(obj is DataSetState) { DataSetState other = (DataSetState)obj; return other.activeColumnGroups == this.activeColumnGroups && other.state == this.state && this.selectedColumns == other.selectedColumns; } return false; } public override int GetHashCode() { return this.activeColumnGroups.GetHashCode() ^ this.state.GetHashCode() ^ this.selectedColumns.GetHashCode(); } } }