Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/05/20 05:46:07 (4 years ago)
Author:
abeham
Message:

#2521: completed port of VRP (needs testing though)

Location:
branches/2521_ProblemRefactoring/HeuristicLab.Collections/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Collections/3.3/ObservableCollection.cs

    r17461 r17718  
    103103        if (list.Capacity != capacity)
    104104          OnPropertyChanged("Capacity");
    105         OnPropertyChanged("Item[]");
    106         OnPropertyChanged("Count");
    107       }
     105        OnPropertyChanged("Count");
     106      }
     107    }
     108
     109    /// <summary>
     110    /// Performs a Clear and an AddRange, but does not fire separate events for those operations
     111    /// </summary>
     112    /// <param name="collection"></param>
     113    public void Replace(IEnumerable<T> collection) {
     114      List<T> oldItems = null;
     115      if (list.Any()) oldItems = new List<T>(list);
     116      else oldItems = new List<T>();
     117
     118      int oldCapacity = list.Capacity;
     119      list.Clear();
     120      list.AddRange(collection);
     121
     122      List<T> items = null;
     123      if (list.Any()) items = new List<T>(list);
     124      else items = new List<T>();
     125
     126      OnCollectionReset(items, oldItems);
     127      if (oldCapacity != list.Capacity) OnPropertyChanged("Capacity");
     128      if (oldItems.Count != items.Count) OnPropertyChanged("Count");
    108129    }
    109130
  • branches/2521_ProblemRefactoring/HeuristicLab.Collections/3.3/ObservableSet.cs

    r17226 r17718  
    128128        OnItemsRemoved(items);
    129129      }
     130    }
     131
     132    /// <summary>
     133    /// Performs a Clear and an Add, but does not fire separate events for those operations
     134    /// </summary>
     135    /// <param name="other"></param>
     136    public void Replace(IEnumerable<T> other) {
     137      List<T> oldItems = null;
     138      if (set.Any()) oldItems = new List<T>(set);
     139      else oldItems = new List<T>();
     140
     141      set.Clear();
     142      set.UnionWith(other);
     143
     144      List<T> items = null;
     145      if (set.Any()) items = new List<T>(set);
     146      else items = new List<T>();
     147
     148      OnCollectionReset(items, oldItems);
     149      if (oldItems.Count != items.Count) OnPropertyChanged("Count");
    130150    }
    131151
Note: See TracChangeset for help on using the changeset viewer.