#region License Information /* HeuristicLab * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Collections; using System.Windows.Forms; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.DataImporter.Data.Model { [StorableClass] public abstract class ColumnBase { private ColumnBase() { } protected ColumnBase(string name) : this() { this.sortOrder = SortOrder.None; this.name = name; } private Type dataType; public Type DataType { get { return dataType; } protected set { this.dataType = value; } } [Storable] private string name; public string Name { get { return name; } set { this.name = value; } } private bool selected; public bool Selected { get { return this.selected; } set { this.selected = value; } } [Storable] private SortOrder sortOrder; public SortOrder SortOrder { get { return sortOrder; } set { this.sortOrder = value; } } public override string ToString() { return this.name; } protected abstract IList Values { get; } public IEnumerable ValuesEnumerable { get { return this.Values; } } public IComparable Minimum { get { IComparable min = null; foreach (IComparable val in Values) if (val != null && (min == null || val.CompareTo(min) <= 0)) min = val; return min; } } public IComparable Maximum { get { IComparable max = null; foreach (IComparable val in Values) if (val != null && (max == null || val.CompareTo(max) >= 0)) max = val; return max; } } public int TotalValuesCount { get { return this.Values.Count; } } public int NonNullValuesCount { get { return TotalValuesCount - NullValuesCount; } } public int NullValuesCount { get { int i = 0; foreach (IComparable value in Values) if (value == null) i++; return i; } } public IComparable GetValue(int index) { if (index >= this.TotalValuesCount || index < 0) return null; return (IComparable)this.Values[index]; } public bool ContainsNullValues { get { for (int i = 0; i < this.Values.Count; i++) { if (this.Values[i] == null) return true; } return false; } } public bool ContainsNotNullValues { get { for (int i = 0; i < this.Values.Count; i++) { if (this.Values[i] != null) return true; } return false; } } public void Resize(int size) { int oldCnt = this.TotalValuesCount; if (size > oldCnt) { for (int i = 0; i < size - oldCnt; i++) this.AddValue(null); } else { for (int i = 0; i < oldCnt - size; i++) this.Values.RemoveAt(this.TotalValuesCount - 1); } } public abstract void AddValue(IComparable value); public abstract void AddValueOrNull(IComparable value); public abstract void InsertValue(int position, IComparable value); public abstract void ChangeValue(int position, IComparable value); public abstract void ChangeValueOrNull(int position, IComparable value); public abstract void ChangeValueOrLeaveOldValue(int position, IComparable value); public void RemoveValue(int position) { this.Values.RemoveAt(position); } public abstract ColumnBase CreateCopyOfColumnWithoutValues(); public abstract ColumnBase CreateCopyOfColumnWithoutValues(int capacity); public event EventHandler Changed; protected virtual void OnChanged() { if (this.Changed != null) this.Changed(this, EventArgs.Empty); } public void FireChanged() { this.OnChanged(); } } }