Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 13847 was 9615, checked in by mkommend, 12 years ago

#1734: Updated copyright information in all DataImporter classes.

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