Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12032 for branches


Ignore:
Timestamp:
02/18/15 11:02:11 (9 years ago)
Author:
bburlacu
Message:

#2276: Extended functionality of ModifiableDataset with three new methods: AddVariable, RemoveVariable and ChangeVariableValue.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Problems.DataAnalysis/3.4/ModifiableDataset.cs

    r11589 r12032  
    22
    33/* HeuristicLab
    4  * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    55 *
    66 * This file is part of HeuristicLab.
     
    7474    }
    7575
     76    // adds a new variable to the dataset
     77    public void AddVariable<T>(string variableName, IEnumerable<T> values) {
     78      if (variableValues.ContainsKey(variableName))
     79        throw new ArgumentException("Variable " + variableName + " is already present in the dataset.");
     80      int count = values.Count();
     81      if (count != rows)
     82        throw new ArgumentException("The number of values must exactly match the number of rows in the dataset.");
     83      variableValues[variableName] = new List<T>(values);
     84      variableNames.Add(variableName);
     85    }
     86
     87    public void RemoveVariable(string variableName) {
     88      if (!variableValues.ContainsKey(variableName))
     89        throw new ArgumentException("The variable " + variableName + " does not exist in the dataset.");
     90      variableValues.Remove(variableName);
     91      variableNames.Remove(variableName);
     92    }
     93
    7694    // slow, avoid to use this
    7795    public void RemoveRow(int row) {
     
    7997        list.RemoveAt(row);
    8098      rows--;
     99    }
     100
     101    public void ChangeVariableValue(object value, string variableName, int row) {
     102      IList list;
     103      variableValues.TryGetValue(variableName, out list);
     104      if (list == null)
     105        throw new ArgumentException("The variable " + variableName + " does not exist in the dataset.");
     106      if (row < 0 || list.Count < row)
     107        throw new ArgumentOutOfRangeException("Invalid row value");
     108      list[row] = value;
    81109    }
    82110
Note: See TracChangeset for help on using the changeset viewer.