Changeset 10991
- Timestamp:
- 06/11/14 14:48:26 (10 years ago)
- Location:
- branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations
- Files:
-
- 2 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)); -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/TransactionalPreprocessingData.cs
r10978 r10991 89 89 #region Overridden IPreprocessingData Members 90 90 91 public override T GetCell<T>(int columnIndex, int rowIndex) 92 { 93 return (T)variableValues[columnIndex][rowIndex]; 94 } 95 91 96 public override void SetCell<T>(int columnIndex, int rowIndex, T value) { 92 97 SaveSnapshot(DataPreprocessingChangedEventType.ChangeItem, columnIndex, rowIndex); 93 base.SetCell<T>(columnIndex, rowIndex, value);98 variableValues[columnIndex][rowIndex] = value; 94 99 if (!IsInTransaction) 95 100 OnChanged(DataPreprocessingChangedEventType.ChangeItem, columnIndex, rowIndex); 101 } 102 103 public override string GetCellAsString(int columnIndex, int rowIndex) 104 { 105 return variableValues[columnIndex][rowIndex].ToString(); 106 } 107 108 public override string GetVariableName(int columnIndex) 109 { 110 return variableNames[columnIndex]; 111 } 112 113 public override int GetColumnIndex(string variableName) 114 { 115 return variableNames.IndexOf(variableName); 116 } 117 118 public override bool IsType<T>(int columnIndex) 119 { 120 return variableValues[columnIndex] is List<T>; 121 } 122 123 [Obsolete("use the index based variant, is faster")] 124 public override IList<T> GetValues<T>(string variableName, bool considerSelection) 125 { 126 return GetValues<T>(GetColumnIndex(variableName), considerSelection); 127 } 128 129 public override IList<T> GetValues<T>(int columnIndex, bool considerSelection) 130 { 131 if (considerSelection) 132 { 133 var list = new List<T>(); 134 foreach (var rowIdx in selection[columnIndex]) 135 { 136 list.Add((T)variableValues[columnIndex][rowIdx]); 137 } 138 return list; 139 } 140 else 141 { 142 return (IList<T>)variableValues[columnIndex]; 143 } 96 144 } 97 145 98 146 public override void SetValues<T>(int columnIndex, IList<T> values) { 99 147 SaveSnapshot(DataPreprocessingChangedEventType.ChangeColumn, columnIndex, -1); 100 base.SetValues<T>(columnIndex, values); 148 if (IsType<T>(columnIndex)) 149 { 150 variableValues[columnIndex] = (IList)values; 151 } 152 else 153 { 154 throw new ArgumentException("The datatype of column " + columnIndex + " must be of type " + variableValues[columnIndex].GetType().Name + " but was " + typeof(T).Name); 155 } 101 156 if (!IsInTransaction) 102 157 OnChanged(DataPreprocessingChangedEventType.ChangeColumn, columnIndex, -1); … … 105 160 public override void InsertRow(int rowIndex) { 106 161 SaveSnapshot(DataPreprocessingChangedEventType.DeleteRow, -1, rowIndex); 107 base.InsertRow(rowIndex); 162 foreach (IList column in variableValues) 163 { 164 Type type = column.GetType().GetGenericArguments()[0]; 165 column.Insert(rowIndex, type.IsValueType ? Activator.CreateInstance(type) : null); 166 } 108 167 if (!IsInTransaction) 109 168 OnChanged(DataPreprocessingChangedEventType.AddRow, -1, rowIndex); … … 112 171 public override void DeleteRow(int rowIndex) { 113 172 SaveSnapshot(DataPreprocessingChangedEventType.AddRow, -1, rowIndex); 114 base.DeleteRow(rowIndex); 173 foreach (IList column in variableValues) 174 { 175 column.RemoveAt(rowIndex); 176 } 115 177 if (!IsInTransaction) 116 178 OnChanged(DataPreprocessingChangedEventType.DeleteRow, -1, rowIndex); … … 119 181 public override void InsertColumn<T>(string variableName, int columnIndex) { 120 182 SaveSnapshot(DataPreprocessingChangedEventType.DeleteColumn, columnIndex, -1); 121 base.InsertColumn<T>(variableName, columnIndex); 183 variableValues.Insert(columnIndex, new List<T>(Rows)); 184 variableNames.Insert(columnIndex, variableName); 122 185 if (!IsInTransaction) 123 186 OnChanged(DataPreprocessingChangedEventType.AddColumn, columnIndex, -1); … … 126 189 public override void DeleteColumn(int columnIndex) { 127 190 SaveSnapshot(DataPreprocessingChangedEventType.AddColumn, columnIndex, -1); 128 base.DeleteColumn(columnIndex); 191 variableValues.RemoveAt(columnIndex); 192 variableNames.RemoveAt(columnIndex); 129 193 if (!IsInTransaction) 130 194 OnChanged(DataPreprocessingChangedEventType.DeleteColumn, columnIndex, -1); 131 195 } 196 197 public override Dataset ExportToDataset() 198 { 199 IList<IList> values = new List<IList>(); 200 201 for (int i = 0; i < Columns; ++i) 202 { 203 values.Add(variableValues[i]); 204 } 205 206 var dataset = new Dataset(variableNames, values); 207 return dataset; 208 } 209 210 public override void ClearSelection() 211 { 212 Selection = new Dictionary<int, IList<int>>(); 213 } 214 215 public override event EventHandler SelectionChanged; 216 217 protected override void OnSelectionChanged() 218 { 219 var listeners = SelectionChanged; 220 if (listeners != null) listeners(this, EventArgs.Empty); 221 } 222 132 223 133 224 #endregion
Note: See TracChangeset
for help on using the changeset viewer.