Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.DataImporter/HeuristicLab.DataImporter.Data/Model/DataSet.cs @ 17717

Last change on this file since 17717 was 16994, checked in by gkronber, 6 years ago

#2520 Update plugin dependencies and references for HL.DataImporter for new persistence

File size: 3.5 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;
23using System.Collections.Generic;
24using System.Linq;
25using HEAL.Attic;
26
27namespace HeuristicLab.DataImporter.Data.Model {
28  [StorableType("92C9DDC3-8C5D-4496-9C72-E7F9E8624D5B")]
29  public class DataSet {
30
31    [Storable]
32    private List<ColumnGroup> columnGroups;
33    public IEnumerable<ColumnGroup> ColumnGroups {
34      get { return this.columnGroups; }
35    }
36    [StorableConstructor]
37    protected DataSet(StorableConstructorFlag _) { }
38    public DataSet() {
39      this.columnGroups = new List<ColumnGroup>();
40    }
41
42    public event EventHandler Changed;
43    protected virtual void OnChanged() {
44      if (this.Changed != null)
45        this.Changed(this, EventArgs.Empty);
46    }
47    public void FireChanged() {
48      this.OnChanged();
49    }
50
51    public void AddColumnGroup(ColumnGroup columnGroup) {
52      this.CheckColumnGroupName(columnGroup);
53      this.columnGroups.Add(columnGroup);
54    }
55
56    public void AddColumnGroups(IEnumerable<ColumnGroup> columnGroups) {
57      foreach (ColumnGroup columnGroup in columnGroups) {
58        this.CheckColumnGroupName(columnGroup);
59      }
60      this.columnGroups.AddRange(columnGroups);
61    }
62
63    private void CheckColumnGroupName(ColumnGroup columnGroup) {
64      int i = 0;
65      string columnGroupName = columnGroup.Name;
66      while (this.ColumnGroups.Any(cg => cg.Name == columnGroupName && cg != columnGroup)) {
67        i++;
68        columnGroupName = columnGroup.Name + " " + i;
69      }
70      columnGroup.Name = columnGroupName;
71    }
72
73    public void InsertColumnGroup(int position, ColumnGroup columnGroup) {
74      this.CheckColumnGroupName(columnGroup);
75      this.columnGroups.Insert(position, columnGroup);
76    }
77
78    public void ReplaceColumnGroup(int position, ColumnGroup columnGroup) {
79      this.columnGroups[position] = columnGroup;
80      this.CheckColumnGroupName(columnGroup);
81    }
82
83    public void RemoveColumnGroup(ColumnGroup columnGroup) {
84      this.columnGroups.Remove(columnGroup);
85    }
86
87    public int IndexOfColumnGroup(ColumnGroup columnGroup) {
88      return this.columnGroups.IndexOf(columnGroup);
89    }
90
91    public ColumnGroup GetColumnGroup(string columnGroupName) {
92      IEnumerable<ColumnGroup> groups = this.columnGroups.Where(g => g.Name == columnGroupName);
93      if (groups.Count() != 1)
94        throw new InvalidOperationException("Found 0 or more than 1 column group with the name \"" + columnGroupName + "\".");
95      return groups.First();
96
97    }
98
99    public IEnumerable<ColumnGroup> ActiveColumnGroups {
100      get {
101        return this.columnGroups.Where(cg => cg.Active);
102      }
103    }
104  }
105}
Note: See TracBrowser for help on using the repository browser.