Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.DataImporter/HeuristicLab.DataImporter.Data/Model/ColumnBase.cs @ 16567

Last change on this file since 16567 was 16567, checked in by gkronber, 5 years ago

#2520: changed StorableConstructors and added StorableType attributes in HeuristicLab.DataImporter addon

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