Coverage Report - org.kuali.rice.krms.framework.engine.CompoundProposition
 
Classes in this File Line Coverage Branch Coverage Complexity
CompoundProposition
0%
0/21
0%
0/18
9
 
 1  
 package org.kuali.rice.krms.framework.engine;
 2  
 
 3  
 import java.util.List;
 4  
 
 5  
 import org.kuali.rice.krms.api.ExecutionEnvironment;
 6  
 import org.kuali.rice.krms.api.LogicalOperator;
 7  
 import org.kuali.rice.krms.api.Proposition;
 8  
 
 9  
 public class CompoundProposition implements Proposition {
 10  
 
 11  
         private final LogicalOperator logicalOperator;
 12  
         private final List<Proposition> propositions;
 13  
         
 14  0
         public CompoundProposition(LogicalOperator logicalOperator, List<Proposition> propositions) {
 15  0
                 if (propositions == null || propositions.isEmpty()) {
 16  0
                         throw new IllegalArgumentException("Propositions must be non-null and non-empty.");
 17  
                 }
 18  0
                 if (logicalOperator == null) {
 19  0
                         throw new IllegalArgumentException("Logical operator must be non-null.");
 20  
                 }
 21  0
                 this.logicalOperator = logicalOperator;
 22  0
                 this.propositions = propositions;
 23  0
         }
 24  
         
 25  
         @Override
 26  
         public boolean evaluate(ExecutionEnvironment environment) {
 27  0
                 if (logicalOperator == LogicalOperator.AND) {
 28  0
                         for (Proposition proposition : propositions) {
 29  0
                                 boolean result = proposition.evaluate(environment);
 30  0
                                 if (!result) {
 31  0
                                         return false;
 32  
                                 }
 33  0
                         }
 34  0
                         return true;
 35  0
                 } else if (logicalOperator == LogicalOperator.OR) {
 36  0
                         for (Proposition proposition : propositions) {
 37  0
                                 if (proposition.evaluate(environment)) {
 38  0
                                         return true;
 39  
                                 }
 40  
                         }
 41  0
                         return false;
 42  
                 }
 43  0
                 throw new IllegalStateException("Invalid logical operator: " + logicalOperator);
 44  
         }
 45  
 
 46  
 }