Free cookie consent management tool by TermsFeed Policy Generator

Changeset 9433


Ignore:
Timestamp:
05/03/13 11:37:56 (12 years ago)
Author:
mkommend
Message:

#2042: Updated ToString of StringConvertibleMatrix /-Array.

Location:
trunk/sources/HeuristicLab.Data/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Data/3.3/StringArray.cs

    r7259 r9433  
    3434  [StorableClass]
    3535  public class StringArray : Item, IEnumerable<string>, IStringConvertibleArray {
     36    private const int maximumToStringLength = 100;
     37
    3638    public static new Image StaticItemImage {
    3739      get { return HeuristicLab.Common.Resources.VSImageLibrary.Class; }
     
    106108
    107109    public override string ToString() {
     110      if (array.Length == 0) return "[]";
     111
    108112      StringBuilder sb = new StringBuilder();
    109113      sb.Append("[");
    110       if (array.Length > 0) {
    111         sb.Append(array[0]);
    112         for (int i = 1; i < array.Length; i++)
    113           sb.Append(";").Append(array[i]);
     114      sb.Append(array[0]);
     115      for (int i = 1; i < array.Length; i++) {
     116        sb.Append(";").Append(array[i]);
     117        if (sb.Length > maximumToStringLength) {
     118          sb.Append("...");
     119          break;
     120        }
    114121      }
    115122      sb.Append("]");
     
    150157      if (ItemChanged != null)
    151158        ItemChanged(this, new EventArgs<int>(index));
    152       OnToStringChanged();
     159      if (index < maximumToStringLength)
     160        OnToStringChanged();
    153161    }
    154162    public event EventHandler Reset;
  • trunk/sources/HeuristicLab.Data/3.3/StringMatrix.cs

    r7259 r9433  
    3434  [StorableClass]
    3535  public class StringMatrix : Item, IEnumerable<string>, IStringConvertibleMatrix {
     36    private const int maximumToStringLength = 100;
     37
    3638    public static new Image StaticItemImage {
    3739      get { return HeuristicLab.Common.Resources.VSImageLibrary.Class; }
     
    208210
    209211    public override string ToString() {
     212      if (matrix.Length == 0) return "[]";
     213
    210214      StringBuilder sb = new StringBuilder();
    211215      sb.Append("[");
    212       if (matrix.Length > 0) {
    213         for (int i = 0; i < Rows; i++) {
    214           sb.Append("[").Append(matrix[i, 0]);
    215           for (int j = 1; j < Columns; j++)
    216             sb.Append(";").Append(matrix[i, j]);
    217           sb.Append("]");
     216      for (int i = 0; i < Rows; i++) {
     217        sb.Append("[").Append(matrix[i, 0]);
     218        for (int j = 1; j < Columns; j++)
     219          sb.Append(";").Append(matrix[i, j]);
     220        sb.Append("]");
     221
     222        if (sb.Length > maximumToStringLength) {
     223          sb.Append("[...]");
     224          break;
    218225        }
    219226      }
    220227      sb.Append("]");
     228
    221229      return sb.ToString();
    222230    }
     
    286294      if (ItemChanged != null)
    287295        ItemChanged(this, new EventArgs<int, int>(rowIndex, columnIndex));
    288       OnToStringChanged();
     296
     297      //approximation to avoid firing of unnecessary ToStringChangedEvents
     298      //columnIndex is not used, because always full rows are returned in the ToString method
     299      if (rowIndex * Columns < maximumToStringLength)
     300        OnToStringChanged();
    289301    }
    290302    public event EventHandler Reset;
Note: See TracChangeset for help on using the changeset viewer.