Free cookie consent management tool by TermsFeed Policy Generator

Changeset 435


Ignore:
Timestamp:
08/04/08 00:35:55 (16 years ago)
Author:
gkronber
Message:
  • code could be improved after removing the 'TypeId' variable and directly comparing instances of IOperator
  • added firing change events in the SubOperatorTypeConstraints (ticket #163)
Location:
trunk/sources/HeuristicLab.Constraints
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Constraints/AllSubOperatorsTypeConstraint.cs

    r2 r435  
    4949    public void AddOperator(IOperator op) {
    5050      groupConstraint.AddOperator(op);
     51      FireChanged();
    5152    }
    5253
    5354    public void RemoveOperator(IOperator op) {
    5455      groupConstraint.RemoveOperator(op);
     56      FireChanged();
    5557    }
    5658
    5759    public override bool Check(IItem data) {
    5860      IOperator op = data as IOperator;
    59       if (data == null) return false;
     61      if(data == null) return false;
    6062
    61       for (int i = 0; i < op.SubOperators.Count; i++ ) {
     63      for(int i = 0; i < op.SubOperators.Count; i++) {
    6264        groupConstraint.SubOperatorIndex.Data = i;
    63         if(groupConstraint.Check(data)==false) {
     65        if(groupConstraint.Check(data) == false) {
    6466          return false;
    6567        }
     
    8486
    8587    #region persistence
    86     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
     88    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
    8789      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    8890      XmlNode subOperatorsNode = PersistenceManager.Persist("SubOperatorsGroupConstraint", groupConstraint, document, persistedObjects);
     
    9294    }
    9395
    94     public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
     96    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
    9597      base.Populate(node, restoredObjects);
    9698      groupConstraint = (SubOperatorTypeConstraint)PersistenceManager.Restore(node.SelectSingleNode("SubOperatorsGroupConstraint"), restoredObjects);
  • trunk/sources/HeuristicLab.Constraints/SubOperatorsTypeConstraint.cs

    r430 r435  
    5252    }
    5353
     54    public SubOperatorTypeConstraint(int index) : base() {
     55      subOperatorIndex = new IntData(index);
     56      subOperators = new List<IOperator>();
     57    }
     58
    5459    public void AddOperator(IOperator op) {
    55       // check if already in the list of allowed functions
    56       foreach(IOperator existingOp in subOperators) {
    57         if(existingOp == op) {
    58           return;
    59         }
     60      if(!subOperators.Contains(op)) {
     61        subOperators.Add(op);
     62        FireChanged();
    6063      }
    61 
    62       subOperators.Add(op);
    6364    }
    6465
    6566    public void RemoveOperator(IOperator op) {
    66       IOperator matchingOperator = null;
    67       foreach(IOperator existingOp in subOperators) {
    68         if(existingOp == op) {
    69           matchingOperator = existingOp;
    70           break;
    71         }
    72       }
    73 
    74       if(matchingOperator != null) {
    75         subOperators.Remove(matchingOperator);
     67      if(subOperators.Contains(op)) {
     68        subOperators.Remove(op);
     69        FireChanged();
    7670      }
    7771    }
     
    8478        return false;
    8579      }
    86 
    87       return subOperators.Exists(delegate(IOperator curOp) { return curOp == op.SubOperators[subOperatorIndex.Data]; });
     80      return subOperators.Contains(op.SubOperators[subOperatorIndex.Data]);
    8881    }
    8982
Note: See TracChangeset for help on using the changeset viewer.