Free cookie consent management tool by TermsFeed Policy Generator

Changeset 9432


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

#2042: Changed ToString of ValueTypeMatrix and -Array to display only the first N elements until a string length of 100 is reached.

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

Legend:

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

    r8587 r9432  
    3434  [StorableClass]
    3535  public abstract class ValueTypeArray<T> : Item, IEnumerable<T> where T : struct {
     36    private const int maximumToStringLength = 100;
     37
    3638    public static new Image StaticItemImage {
    3739      get { return HeuristicLab.Common.Resources.VSImageLibrary.Class; }
     
    99101
    100102    public override string ToString() {
     103      if (array.Length == 0) return "[]";
     104
    101105      StringBuilder sb = new StringBuilder();
    102106      sb.Append("[");
    103       if (array.Length > 0) {
    104         sb.Append(array[0].ToString());
    105         for (int i = 1; i < array.Length; i++)
    106           sb.Append(";").Append(array[i].ToString());
     107      sb.Append(array[0].ToString());
     108      for (int i = 1; i < array.Length; i++) {
     109        sb.Append(";").Append(array[i].ToString());
     110        if (sb.Length > maximumToStringLength) {
     111          sb.Append("...");
     112          break;
     113        }
    107114      }
    108115      sb.Append("]");
     
    122129      if (ItemChanged != null)
    123130        ItemChanged(this, new EventArgs<int>(index));
    124       OnToStringChanged();
     131      if (index < maximumToStringLength)
     132        OnToStringChanged();
    125133    }
    126134    public event EventHandler Reset;
  • trunk/sources/HeuristicLab.Data/3.3/ValueTypeMatrix.cs

    r7259 r9432  
    3434  [StorableClass]
    3535  public abstract class ValueTypeMatrix<T> : Item, IEnumerable<T> where T : struct {
     36    private const int maximumToStringLength = 100;
     37
    3638    public static new Image StaticItemImage {
    3739      get { return HeuristicLab.Common.Resources.VSImageLibrary.Class; }
     
    194196
    195197    public override string ToString() {
     198      if (matrix.Length == 0) return "[]";
     199
    196200      StringBuilder sb = new StringBuilder();
    197201      sb.Append("[");
    198       if (matrix.Length > 0) {
    199         for (int i = 0; i < Rows; i++) {
    200           sb.Append("[").Append(matrix[i, 0].ToString());
    201           for (int j = 1; j < Columns; j++)
    202             sb.Append(";").Append(matrix[i, j].ToString());
    203           sb.Append("]");
     202      for (int i = 0; i < Rows; i++) {
     203        sb.Append("[").Append(matrix[i, 0].ToString());
     204        for (int j = 1; j < Columns; j++)
     205          sb.Append(";").Append(matrix[i, j].ToString());
     206        sb.Append("]");
     207
     208        if (sb.Length > maximumToStringLength) {
     209          sb.Append("[...]");
     210          break;
    204211        }
    205212      }
    206213      sb.Append("]");
     214
    207215      return sb.ToString();
    208216    }
     
    251259      if (ItemChanged != null)
    252260        ItemChanged(this, new EventArgs<int, int>(rowIndex, columnIndex));
    253       OnToStringChanged();
     261
     262      //approximation to avoid firing of unnecessary ToStringChangedEvents
     263      //columnIndex is not used, because always full rows are returned in the ToString method
     264      if (rowIndex * Columns < maximumToStringLength)
     265        OnToStringChanged();
    254266    }
    255267    public event EventHandler Reset;
Note: See TracChangeset for help on using the changeset viewer.