Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/29/18 09:44:07 (6 years ago)
Author:
jkarder
Message:

#2839: merged [16057-16091/trunk] into branch

Location:
branches/2839_HiveProjectManagement
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/2839_HiveProjectManagement

  • branches/2839_HiveProjectManagement/HeuristicLab.Problems.DataAnalysis

  • branches/2839_HiveProjectManagement/HeuristicLab.Problems.DataAnalysis/3.4/ModifiableDataset.cs

    r16057 r16092  
    4747    public ModifiableDataset() { }
    4848
    49     public ModifiableDataset(IEnumerable<string> variableNames, IEnumerable<IList> variableValues) :
    50       base(variableNames, variableValues, cloneValues: false) { }
    51 
     49    public ModifiableDataset(IEnumerable<string> variableNames, IEnumerable<IList> variableValues, bool cloneValues = false) :
     50      base(variableNames, variableValues, cloneValues) { }
     51
     52    public Dataset ToDataset() {
     53      return new Dataset(variableNames, variableNames.Select(v => variableValues[v]));
     54    }
    5255    public void ReplaceRow(int row, IEnumerable<object> values) {
    5356      var list = values.ToList();
     
    9194        variableValues[variableNames[i]].Add(list[i]);
    9295      }
    93       rows++;
     96      Rows++;
    9497      OnRowsChanged();
    9598      OnReset();
     
    98101    // adds a new variable to the dataset
    99102    public void AddVariable(string variableName, IList values) {
     103      InsertVariable(variableName, Columns, values);
     104    }
     105
     106
     107    public void InsertVariable(string variableName, int position, IList values) {
    100108      if (variableValues.ContainsKey(variableName))
    101109        throw new ArgumentException(string.Format("Variable {0} is already present in the dataset.", variableName));
    102110
    103       if (values == null || values.Count == 0)
    104         throw new ArgumentException("Cannot add variable with no values.");
     111      if (position < 0 || position > Columns)
     112        throw new ArgumentException(string.Format("Incorrect position {0} specified. The position must be between 0 and {1}.", position, Columns));
     113
     114      if (values == null)
     115        throw new ArgumentNullException("values", "Values must not be null. At least an empty list of values has to be provided.");
     116
     117      if (values.Count != Rows)
     118        throw new ArgumentException(string.Format("{0} values are provided, but {1} rows are present in the dataset.", values.Count, Rows));
    105119
    106120      if (!IsAllowedType(values))
    107121        throw new ArgumentException(string.Format("Unsupported type {0} for variable {1}.", GetElementType(values), variableName));
    108122
     123      variableNames.Insert(position, variableName);
    109124      variableValues[variableName] = values;
    110       variableNames.Add(variableName);
    111125
    112126      OnColumnsChanged();
     
    129143      foreach (var list in variableValues.Values)
    130144        list.RemoveAt(row);
    131       rows--;
     145      Rows--;
    132146      OnRowsChanged();
    133147      OnReset();
Note: See TracChangeset for help on using the changeset viewer.