Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/12/13 12:20:25 (12 years ago)
Author:
sforsten
Message:

#2018:

  • added column names to the ValueTypeArray and StringArray
  • added batch update methods to IStringConvertibleArray similar to methods in IStringConvertibleMatrix
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ImprovingStringConvertibleMatrix/HeuristicLab.Data/3.3/DoubleArray.cs

    r7259 r9308  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
     24using System.Linq;
    2225using System.Text;
    2326using HeuristicLab.Common;
     
    2831  [Item("DoubleArray", "Represents an array of double values.")]
    2932  [StorableClass]
    30   public class DoubleArray : ValueTypeArray<double>, IStringConvertibleArray {
     33  public class DoubleArray : ValueTypeArray<double> {
    3134    [StorableConstructor]
    3235    protected DoubleArray(bool deserializing) : base(deserializing) { }
     
    4245    }
    4346
    44     protected virtual bool Validate(string value, out string errorMessage) {
     47    protected override bool Validate(string value, out string errorMessage) {
    4548      double val;
    4649      bool valid = double.TryParse(value, out val);
     
    5558      return valid;
    5659    }
    57     protected virtual string GetValue(int index) {
     60    protected override string GetValue(int index) {
    5861      return this[index].ToString();
    5962    }
    60     protected virtual bool SetValue(string value, int index) {
     63    protected override bool SetValue(string value, int index) {
     64      if (ReadOnly) throw new NotSupportedException("Item cannot be set. ValueTypeArray is read-only.");
    6165      double val;
    6266      if (double.TryParse(value, out val)) {
     
    6872    }
    6973
    70     #region IStringConvertibleArray Members
    71     int IStringConvertibleArray.Length {
    72       get { return Length; }
    73       set { Length = value; }
     74    protected override bool SetValues(IEnumerable<ArrayValue<string>> arrayValues) {
     75      if (ReadOnly) throw new NotSupportedException("Item cannot be set. ValueTypeArray is read-only.");
     76      double parsed;
     77      if (!arrayValues.All(v => double.TryParse(v.Value, out parsed))) return false;
     78      List<int> positions = new List<int>();
     79      foreach (var v in arrayValues) {
     80        parsed = double.Parse(v.Value);
     81        if (array[v.Index] != parsed) {
     82          array[v.Index] = parsed;
     83          positions.Add(v.Index);
     84        }
     85      }
     86      OnItemsChanged(positions);
     87      return true;
    7488    }
    75     bool IStringConvertibleArray.Validate(string value, out string errorMessage) {
    76       return Validate(value, out errorMessage);
    77     }
    78     string IStringConvertibleArray.GetValue(int index) {
    79       return GetValue(index);
    80     }
    81     bool IStringConvertibleArray.SetValue(string value, int index) {
    82       return SetValue(value, index);
    83     }
    84     #endregion
    8589  }
    8690}
Note: See TracChangeset for help on using the changeset viewer.