Changeset 10991 for branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/PreprocessingData.cs
- Timestamp:
- 06/11/14 14:48:26 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/PreprocessingData.cs
r10978 r10991 126 126 #region IPreprocessingData Members 127 127 128 public T GetCell<T>(int columnIndex, int rowIndex) { 129 return (T)variableValues[columnIndex][rowIndex]; 130 } 128 public abstract T GetCell<T>(int columnIndex, int rowIndex); 131 129 132 public virtual void SetCell<T>(int columnIndex, int rowIndex, T value) { 133 variableValues[columnIndex][rowIndex] = value; 134 } 130 public abstract void SetCell<T>(int columnIndex, int rowIndex, T value); 135 131 136 public string GetCellAsString(int columnIndex, int rowIndex) { 137 return variableValues[columnIndex][rowIndex].ToString(); 138 } 132 public abstract string GetCellAsString(int columnIndex, int rowIndex); 139 133 140 public string GetVariableName(int columnIndex) { 141 return variableNames[columnIndex]; 142 } 134 public abstract string GetVariableName(int columnIndex); 143 135 144 public int GetColumnIndex(string variableName) { 145 return variableNames.IndexOf(variableName); 146 } 136 public abstract int GetColumnIndex(string variableName); 147 137 148 public bool IsType<T>(int columnIndex) { 149 return variableValues[columnIndex] is List<T>; 150 } 138 public abstract bool IsType<T>(int columnIndex); 151 139 152 140 [Obsolete("use the index based variant, is faster")] 153 public IList<T> GetValues<T>(string variableName, bool considerSelection) { 154 return GetValues<T>(GetColumnIndex(variableName), considerSelection); 155 } 141 public abstract IList<T> GetValues<T>(string variableName, bool considerSelection); 156 142 157 public IList<T> GetValues<T>(int columnIndex, bool considerSelection) { 158 if (considerSelection) { 159 var list = new List<T>(); 160 foreach (var rowIdx in selection[columnIndex]) { 161 list.Add((T)variableValues[columnIndex][rowIdx]); 162 } 163 return list; 164 } else { 165 return (IList<T>)variableValues[columnIndex]; 166 } 167 } 143 public abstract IList<T> GetValues<T>(int columnIndex, bool considerSelection); 168 144 169 public virtual void SetValues<T>(int columnIndex, IList<T> values) { 170 if (IsType<T>(columnIndex)) { 171 variableValues[columnIndex] = (IList)values; 172 } else { 173 throw new ArgumentException("The datatype of column " + columnIndex + " must be of type " + variableValues[columnIndex].GetType().Name + " but was " + typeof(T).Name); 174 } 175 } 145 public abstract void SetValues<T>(int columnIndex, IList<T> values); 176 146 177 public virtual void InsertRow(int rowIndex) { 178 foreach (IList column in variableValues) { 179 Type type = column.GetType().GetGenericArguments()[0]; 180 column.Insert(rowIndex, type.IsValueType ? Activator.CreateInstance(type) : null); 181 } 182 } 147 public abstract void InsertRow(int rowIndex); 183 148 184 public virtual void DeleteRow(int rowIndex) { 185 foreach (IList column in variableValues) { 186 column.RemoveAt(rowIndex); 187 } 188 } 149 public abstract void DeleteRow(int rowIndex); 189 150 190 public virtual void InsertColumn<T>(string variableName, int columnIndex) { 191 variableValues.Insert(columnIndex, new List<T>(Rows)); 192 variableNames.Insert(columnIndex, variableName); 193 } 151 public abstract void InsertColumn<T>(string variableName, int columnIndex); 194 152 195 public virtual void DeleteColumn(int columnIndex) { 196 variableValues.RemoveAt(columnIndex); 197 variableNames.RemoveAt(columnIndex); 198 } 153 public abstract void DeleteColumn(int columnIndex); 199 154 200 public Dataset ExportToDataset() { 201 IList<IList> values = new List<IList>(); 155 public abstract Dataset ExportToDataset(); 202 156 203 for (int i = 0; i < Columns; ++i) { 204 values.Add(variableValues[i]); 205 } 157 public abstract void ClearSelection(); 206 158 207 var dataset = new Dataset(variableNames, values); 208 return dataset; 209 } 210 211 public void ClearSelection() { 212 Selection = new Dictionary<int, IList<int>>(); 213 } 214 215 public event EventHandler SelectionChanged; 216 protected virtual void OnSelectionChanged() { 217 var listeners = SelectionChanged; 218 if (listeners != null) listeners(this, EventArgs.Empty); 219 } 159 public abstract event EventHandler SelectionChanged; 160 protected abstract void OnSelectionChanged(); 220 161 221 162 public event DataPreprocessingChangedEventHandler Changed; 222 protected virtual void OnChanged(DataPreprocessingChangedEventType type, int column, int row) { 163 protected virtual void OnChanged(DataPreprocessingChangedEventType type, int column, int row) 164 { 223 165 var listeners = Changed; 224 166 if (listeners != null) listeners(this, new DataPreprocessingChangedEventArgs(type, column, row));
Note: See TracChangeset
for help on using the changeset viewer.