Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/06/10 01:56:04 (14 years ago)
Author:
swagner
Message:

Merged cloning refactoring branch back into trunk (#922)

Location:
trunk/sources
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources

  • trunk/sources/HeuristicLab.Optimization/3.3/RunCollection.cs

    r4707 r4722  
    3838    [StorableConstructor]
    3939    protected RunCollection(bool deserializing) : base(deserializing) { }
     40
     41    protected RunCollection(RunCollection original, Cloner cloner)
     42      : base(original, cloner) {
     43      resultNames = new List<string>(original.resultNames);
     44      parameterNames = new List<string>(original.parameterNames);
     45      dataTypes = new Dictionary<string, HashSet<Type>>();
     46      foreach (string s in original.dataTypes.Keys)
     47        dataTypes[s] = new HashSet<Type>(original.dataTypes[s]);
     48
     49      constraints = new RunCollectionConstraintCollection(original.constraints.Select(x => cloner.Clone(x)));
     50      foreach (IRunCollectionConstraint constraint in constraints)
     51        constraint.ConstrainedValue = this;
     52      RegisterConstraintsEvents();
     53      RegisterConstraintEvents(constraints);
     54
     55      UpdateFiltering(true);
     56    }
     57    public override IDeepCloneable Clone(Cloner cloner) {
     58      return new RunCollection(this, cloner);
     59    }
    4060    public RunCollection() : base() { Initialize(); }
    4161    public RunCollection(int capacity) : base(capacity) { Initialize(); }
     
    171191
    172192    [StorableHook(HookType.AfterDeserialization)]
    173     private void AfterDeserializationHook() {
     193    private void AfterDeserialization() {
    174194      if (constraints == null) constraints = new RunCollectionConstraintCollection();
    175195      RegisterConstraintsEvents();
    176196      RegisterConstraintEvents(constraints);
    177197      UpdateFiltering(true);
    178     }
    179 
    180     public override IDeepCloneable Clone(Cloner cloner) {
    181       RunCollection clone = (RunCollection)base.Clone(cloner);
    182       clone.resultNames = new List<string>(this.resultNames);
    183       clone.parameterNames = new List<string>(this.parameterNames);
    184       clone.dataTypes = new Dictionary<string, HashSet<Type>>();
    185       foreach (string s in this.dataTypes.Keys)
    186         clone.dataTypes[s] = new HashSet<Type>(this.dataTypes[s]);
    187 
    188       clone.constraints = new RunCollectionConstraintCollection(this.constraints.Select(x => (IRunCollectionConstraint)cloner.Clone(x)));
    189       foreach (IRunCollectionConstraint constraint in clone.constraints)
    190         constraint.ConstrainedValue = clone;
    191       clone.RegisterConstraintsEvents();
    192       clone.RegisterConstraintEvents(clone.constraints);
    193 
    194       clone.UpdateFiltering(true);
    195       return clone;
    196198    }
    197199
     
    253255    public event EventHandler<EventArgs<int, int>> ItemChanged;
    254256    protected virtual void OnItemChanged(int rowIndex, int columnIndex) {
    255       if (ItemChanged != null)
    256         ItemChanged(this, new EventArgs<int, int>(rowIndex, columnIndex));
     257      EventHandler<EventArgs<int, int>> handler = ItemChanged;
     258      if (handler != null) handler(this, new EventArgs<int, int>(rowIndex, columnIndex));
    257259      OnToStringChanged();
    258260    }
    259261    public event EventHandler Reset;
    260262    protected virtual void OnReset() {
    261       if (Reset != null)
    262         Reset(this, EventArgs.Empty);
     263      EventHandler handler = Reset;
     264      if (handler != null) handler(this, EventArgs.Empty);
    263265      OnToStringChanged();
    264266    }
     
    266268    protected virtual void OnColumnNamesChanged() {
    267269      EventHandler handler = ColumnNamesChanged;
    268       if (handler != null)
    269         handler(this, EventArgs.Empty);
     270      if (handler != null) handler(this, EventArgs.Empty);
    270271    }
    271272    public event EventHandler RowNamesChanged;
    272273    protected virtual void OnRowNamesChanged() {
    273274      EventHandler handler = RowNamesChanged;
    274       if (handler != null)
    275         handler(this, EventArgs.Empty);
     275      if (handler != null) handler(this, EventArgs.Empty);
    276276    }
    277277    public event EventHandler SortableViewChanged;
    278278    protected virtual void OnSortableViewChanged() {
    279279      EventHandler handler = SortableViewChanged;
    280       if (handler != null)
    281         handler(this, EventArgs.Empty);
     280      if (handler != null) handler(this, EventArgs.Empty);
    282281    }
    283282
Note: See TracChangeset for help on using the changeset viewer.