Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/20/16 15:51:04 (8 years ago)
Author:
bburlacu
Message:

#2672: Implement online calculator cloning.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineCovarianceCalculator.cs

    r14185 r14293  
    2222using System;
    2323using System.Collections.Generic;
     24using HeuristicLab.Common;
    2425
    2526namespace HeuristicLab.Problems.DataAnalysis {
    26   public class OnlineCovarianceCalculator : IOnlineCalculator {
     27  public class OnlineCovarianceCalculator : IOnlineCalculator, IDeepCloneable {
    2728
    2829    private double xMean, yMean, Cn;
     
    3637    public OnlineCovarianceCalculator() {
    3738      Reset();
     39    }
     40
     41    // private constructor used internally by the Clone() method
     42    private OnlineCovarianceCalculator(OnlineCovarianceCalculator other) : this() {
     43      Cn = other.Cn;
     44      xMean = other.xMean;
     45      yMean = other.yMean;
     46      n = other.n;
     47      errorState = other.errorState;
    3848    }
    3949
     
    94104      }
    95105    }
     106
     107    // IDeepCloneable interface members
     108    public object Clone() {
     109      return new OnlineCovarianceCalculator(this);
     110    }
     111
     112    public IDeepCloneable Clone(Cloner cloner) {
     113      var clone = cloner.GetClone(this);
     114      if (clone == null) {
     115        clone = (IDeepCloneable)this.Clone();
     116        cloner.RegisterClonedObject(this, clone);
     117      }
     118      return clone;
     119    }
    96120  }
    97121}
Note: See TracChangeset for help on using the changeset viewer.