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/IntArray.cs

    r7259 r9308  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
     24using System.Linq;
    2225using System.Text;
    2326using HeuristicLab.Common;
     
    2831  [Item("IntArray", "Represents an array of integer values.")]
    2932  [StorableClass]
    30   public class IntArray : ValueTypeArray<int>, IStringConvertibleArray {
     33  public class IntArray : ValueTypeArray<int> {
    3134    [StorableConstructor]
    3235    protected IntArray(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      int val;
    4649      bool valid = int.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      int val;
    6266      if (int.TryParse(value, out val)) {
     
    6771      }
    6872    }
    69 
    70     #region IStringConvertibleArray Members
    71     int IStringConvertibleArray.Length {
    72       get { return Length; }
    73       set { Length = value; }
     73    protected override bool SetValues(IEnumerable<ArrayValue<string>> arrayValues) {
     74      if (ReadOnly) throw new NotSupportedException("Item cannot be set. ValueTypeArray is read-only.");
     75      int parsed;
     76      if (!arrayValues.All(v => int.TryParse(v.Value, out parsed))) return false;
     77      List<int> positions = new List<int>();
     78      foreach (var v in arrayValues) {
     79        parsed = int.Parse(v.Value);
     80        if (array[v.Index] != parsed) {
     81          array[v.Index] = parsed;
     82          positions.Add(v.Index);
     83        }
     84      }
     85      OnItemsChanged(positions);
     86      return true;
    7487    }
    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
    8588  }
    8689}
Note: See TracChangeset for help on using the changeset viewer.