Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.DataImporter/HeuristicLab.DataImporter.Data/Model/DataSet.cs @ 7968

Last change on this file since 7968 was 7267, checked in by gkronber, 13 years ago

#1734 updated copyright year in all files of the DataImporter branch

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