Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.DataImporter/HeuristicLab.DataImporter.Data/Model/ColumnBase.cs @ 9015

Last change on this file since 9015 was 8387, checked in by mkommend, 12 years ago

#1908: Updated SplitDictionaryStyleDataCommand to allow splitting multiple columns. Additionally made minor code improvements in the DataImporter.

File size: 4.7 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;
24using System.Windows.Forms;
25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
26
27namespace HeuristicLab.DataImporter.Data.Model {
28  [StorableClass]
29  public abstract class ColumnBase {
30    private ColumnBase() {
31    }
32
33    protected ColumnBase(string name)
34      : this() {
35      this.sortOrder = SortOrder.None;
36      this.name = name;
37    }
38
39    private Type dataType;
40    public Type DataType {
41      get { return dataType; }
42      protected set { this.dataType = value; }
43    }
44
45    [Storable]
46    private string name;
47    public string Name {
48      get { return name; }
49      set { this.name = value; }
50    }
51
52    private bool selected;
53    public bool Selected {
54      get { return this.selected; }
55      set { this.selected = value; }
56    }
57
58    [Storable]
59    private SortOrder sortOrder;
60    public SortOrder SortOrder {
61      get { return sortOrder; }
62      set { this.sortOrder = value; }
63    }
64
65    public override string ToString() {
66      return this.name;
67    }
68
69    protected abstract IList Values { get; }
70    public IEnumerable ValuesEnumerable {
71      get { return this.Values; }
72    }
73
74    public IComparable Minimum {
75      get {
76        IComparable min = null;
77        foreach (IComparable val in Values)
78          if (val != null && (min == null || val.CompareTo(min) <= 0))
79            min = val;
80        return min;
81      }
82    }
83
84    public IComparable Maximum {
85      get {
86        IComparable max = null;
87        foreach (IComparable val in Values)
88          if (val != null && (max == null || val.CompareTo(max) >= 0))
89            max = val;
90        return max;
91      }
92    }
93
94    public int TotalValuesCount {
95      get { return this.Values.Count; }
96    }
97
98    public int NonNullValuesCount {
99      get { return TotalValuesCount - NullValuesCount; }
100    }
101
102    public int NullValuesCount {
103      get {
104        int i = 0;
105        foreach (IComparable value in Values)
106          if (value == null)
107            i++;
108        return i;
109      }
110    }
111
112    public IComparable GetValue(int index) {
113      if (index >= this.TotalValuesCount || index < 0)
114        return null;
115      return (IComparable)this.Values[index];
116    }
117
118    public bool ContainsNullValues {
119      get {
120        for (int i = 0; i < this.Values.Count; i++) {
121          if (this.Values[i] == null)
122            return true;
123        }
124        return false;
125      }
126    }
127
128    public bool ContainsNotNullValues {
129      get {
130        for (int i = 0; i < this.Values.Count; i++) {
131          if (this.Values[i] != null)
132            return true;
133        }
134        return false;
135      }
136    }
137
138    public void Resize(int size) {
139      int oldCnt = this.TotalValuesCount;
140      if (size > oldCnt) {
141        for (int i = 0; i < size - oldCnt; i++)
142          this.AddValue(null);
143      } else {
144        for (int i = 0; i < oldCnt - size; i++)
145          this.Values.RemoveAt(this.TotalValuesCount - 1);
146      }
147    }
148
149    public abstract void AddValue(IComparable value);
150    public abstract void AddValueOrNull(IComparable value);
151    public abstract void InsertValue(int position, IComparable value);
152    public abstract void ChangeValue(int position, IComparable value);
153    public abstract void ChangeValueOrNull(int position, IComparable value);
154    public abstract void ChangeValueOrLeaveOldValue(int position, IComparable value);
155
156    public void RemoveValue(int position) {
157      this.Values.RemoveAt(position);
158    }
159
160    public abstract ColumnBase CreateCopyOfColumnWithoutValues();
161    public abstract ColumnBase CreateCopyOfColumnWithoutValues(int capacity);
162
163    public event EventHandler Changed;
164    protected virtual void OnChanged() {
165      if (this.Changed != null)
166        this.Changed(this, EventArgs.Empty);
167    }
168    public void FireChanged() {
169      this.OnChanged();
170    }
171  }
172}
Note: See TracBrowser for help on using the repository browser.