Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/02/08 14:13:06 (15 years ago)
Author:
gkronber
Message:

Refactored cloning in HL.Core, HL.Data and HL.Constraints

#285 (Cloning could be improved by creating objects at the bottom of the cloning chain with 'new' instead of the top with Activator.CreateInstance())

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/CloningRefactorBranch/HeuristicLab.Constraints/AllSubOperatorsTypeConstraint.cs

    r764 r885  
    4242    }
    4343
    44     public AllSubOperatorsTypeConstraint()
    45       : base() {
     44    /// <summary>
     45    /// Default constructor for an empty AllSubOperatorsTypeConstraint.
     46    /// </summary>
     47    public AllSubOperatorsTypeConstraint() {
    4648      groupConstraint = new SubOperatorTypeConstraint();
     49    }
     50    /// <summary>
     51    /// Copy constructor to create clones (deep).
     52    /// </summary>
     53    /// <param name="original">The original instance to be cloned.</param>
     54    public AllSubOperatorsTypeConstraint(AllSubOperatorsTypeConstraint original)
     55      : this(original, new Dictionary<Guid, object>()) { }
     56    /// <summary>
     57    /// Copy constructor to create clones (deep) reusing already cloned object references.
     58    /// </summary>
     59    /// <param name="original">The instance to be cloned.</param>
     60    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     61    protected AllSubOperatorsTypeConstraint(AllSubOperatorsTypeConstraint original, IDictionary<Guid, object> clonedObjects)
     62      : base(original, clonedObjects) {
     63      this.groupConstraint = (SubOperatorTypeConstraint)Auxiliary.Clone(original.groupConstraint, clonedObjects);
    4764    }
    4865
     
    5976    public override bool Check(IItem data) {
    6077      IOperator op = data as IOperator;
    61       if(data == null) return false;
     78      if (data == null) return false;
    6279
    63       for(int i = 0; i < op.SubOperators.Count; i++) {
     80      for (int i = 0; i < op.SubOperators.Count; i++) {
    6481        groupConstraint.SubOperatorIndex.Data = i;
    65         if(groupConstraint.Check(data) == false) {
     82        if (groupConstraint.Check(data) == false) {
    6683          return false;
    6784        }
     
    7592
    7693    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    77       AllSubOperatorsTypeConstraint clone = new AllSubOperatorsTypeConstraint();
    78       clonedObjects.Add(Guid, clone);
    79       clone.groupConstraint = (SubOperatorTypeConstraint)Auxiliary.Clone(groupConstraint, clonedObjects);
    80       return clone;
     94      return new AllSubOperatorsTypeConstraint(this);
    8195    }
    8296
Note: See TracChangeset for help on using the changeset viewer.