Coverage Report - org.kuali.student.common.ui.client.configurable.mvc.multiplicity.SwapCompositeCondition
 
Classes in this File Line Coverage Branch Coverage Complexity
SwapCompositeCondition
0%
0/49
0%
0/42
2.9
 
 1  
 package org.kuali.student.common.ui.client.configurable.mvc.multiplicity;
 2  
 
 3  
 import java.util.ArrayList;
 4  
 import java.util.List;
 5  
 import java.util.Map;
 6  
 
 7  
 import org.kuali.student.common.ui.client.configurable.mvc.sections.GroupSection;
 8  
 
 9  
 public class SwapCompositeCondition {
 10  
     private String conditionId;
 11  
     private CompositeConditionOperator op;
 12  
     private List<SwapCondition> childrenConditions;
 13  
     private List<SwapCompositeCondition> childrenCompositeConditions;
 14  0
     public SwapCompositeCondition(CompositeConditionOperator op) {
 15  0
         setOp(op);
 16  0
     }
 17  
     public CompositeConditionOperator getOp() {
 18  0
         return op;
 19  
     }
 20  
     public void setOp(CompositeConditionOperator op) {
 21  0
         this.op = op;
 22  0
     }
 23  
     public List<SwapCondition> getChildrenConditions() {
 24  0
         if (childrenConditions == null) {
 25  0
             childrenConditions = new ArrayList<SwapCondition>();
 26  
         }
 27  0
         return childrenConditions;
 28  
     }
 29  
     public void setChildrenConditions(List<SwapCondition> childrenConditions) {
 30  0
         this.childrenConditions = childrenConditions;
 31  0
     }
 32  
     public List<SwapCompositeCondition> getChildrenCompositeConditions() {
 33  0
         return childrenCompositeConditions;
 34  
     }
 35  
     public void setChildrenCompositeConditions(List<SwapCompositeCondition> childrenCompositeConditions) {
 36  0
         this.childrenCompositeConditions = childrenCompositeConditions;
 37  0
     }
 38  
     public boolean evaluate(GroupSection section, Map<String, String> helperFieldKeys) {
 39  0
         boolean result = false;
 40  0
         boolean allSubCompositeConditionsMet = true;
 41  0
         boolean allSubConditionsMet = true;
 42  0
         if (childrenCompositeConditions != null && !childrenCompositeConditions.isEmpty()) {
 43  0
             for (SwapCompositeCondition childCompositeCondition : childrenCompositeConditions) {
 44  0
                 boolean subCompositeConditionMet = childCompositeCondition.evaluate(section, helperFieldKeys);
 45  0
                 if (op == CompositeConditionOperator.OR) {
 46  
                     // as soon as I find one sub condition that meets criteria the entire condition is met for OR
 47  0
                     if (subCompositeConditionMet) {
 48  0
                         allSubCompositeConditionsMet = true;
 49  0
                         break;
 50  
                     }
 51  0
                 } else if (op == CompositeConditionOperator.AND) {
 52  
                     // the entire condition is false once I find at least one sub condition that fails the criteria
 53  0
                     if (!subCompositeConditionMet) {
 54  0
                         allSubCompositeConditionsMet = false;
 55  0
                         break;
 56  
                     }
 57  
                 }
 58  0
             }
 59  
         }
 60  0
         if (childrenConditions != null && !childrenConditions.isEmpty()) {
 61  0
             for (SwapCondition childCondition : childrenConditions) {
 62  0
                 boolean subConditionMet = childCondition.evaluate(section, helperFieldKeys);
 63  0
                 if (op == CompositeConditionOperator.OR) {
 64  
                     // as soon as I find one sub condition that meets criteria the entire condition is met for OR
 65  0
                     if (subConditionMet) {
 66  0
                         allSubConditionsMet = true;
 67  0
                         break;
 68  
                     }
 69  0
                 } else if (op == CompositeConditionOperator.AND) {
 70  
                     // the entire condition is false once I find at least one sub condition that fails the criteria
 71  0
                     if (!subConditionMet) {
 72  0
                         allSubConditionsMet = false;
 73  0
                         break;
 74  
                     }
 75  
                 }
 76  0
             }
 77  
         }
 78  0
         if (op == CompositeConditionOperator.OR) {
 79  0
             result = allSubCompositeConditionsMet || allSubConditionsMet;
 80  0
         } else if (op == CompositeConditionOperator.AND) {
 81  0
             result = allSubCompositeConditionsMet && allSubConditionsMet;
 82  
         }
 83  0
         return result;
 84  
     }
 85  
     public String getConditionId() {
 86  0
         return conditionId;
 87  
     }
 88  
     public void setConditionId(String conditionId) {
 89  0
         this.conditionId = conditionId;
 90  0
     }
 91  
     
 92  
 }