Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 6451 was 6134, checked in by gkronber, 14 years ago

#1471: added plugin for DbExplorer interfaces, deleted .resx files, set svn:ignore properties, and added license header

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