Coverage Report - org.kuali.rice.krms.framework.engine.CollectionOfComparablesTermBasedProposition
 
Classes in this File Line Coverage Branch Coverage Complexity
CollectionOfComparablesTermBasedProposition
100%
18/18
75%
6/8
2.333
 
 1  
 package org.kuali.rice.krms.framework.engine;
 2  
 
 3  
 import java.util.Collection;
 4  
 
 5  
 import org.kuali.rice.krms.api.engine.ExecutionEnvironment;
 6  
 import org.kuali.rice.krms.api.engine.ResultEvent;
 7  
 import org.kuali.rice.krms.api.engine.Term;
 8  
 import org.kuali.rice.krms.api.engine.TermResolutionException;
 9  
 import org.kuali.rice.krms.framework.engine.result.BasicResult;
 10  
 
 11  
 public class CollectionOfComparablesTermBasedProposition<T> extends ComparableTermBasedProposition<T> {
 12  1
         private static final ResultLogger LOG = ResultLogger.getInstance();
 13  
 
 14  
         private CollectionOperator collectionOper;
 15  
         private Term term;
 16  
 
 17  
         public CollectionOfComparablesTermBasedProposition(CollectionOperator collectionOper, ComparisonOperator compareOper, Term term, T expectedValue) {
 18  20
                 super(compareOper, term, expectedValue);
 19  20
                 this.term = term;
 20  20
                 this.collectionOper = collectionOper;
 21  20
         }
 22  
 
 23  
         /**
 24  
          * @see org.kuali.rice.krms.framework.engine.ComparableTermBasedProposition#evaluate(org.kuali.rice.krms.api.engine.ExecutionEnvironment)
 25  
          * @throws TermResolutionException if there is a problem resolving a {@link Term}
 26  
          */
 27  
         @Override
 28  
         public boolean evaluate(ExecutionEnvironment environment) {
 29  20
                 boolean collatedResult = collectionOper.getInitialCollatedResult();
 30  
 
 31  
                 Collection<? extends Comparable<T>> termValue;
 32  
 
 33  20
                 termValue = environment.resolveTerm(term);
 34  
 
 35  20
                 if (termValue != null) {
 36  20
                         for (Comparable<T> item : termValue) {
 37  24
                                 collatedResult = collectionOper.reduce(compare(item), collatedResult);
 38  24
                                 if (collectionOper.shortCircuit(collatedResult)) break;
 39  
                         }
 40  
                 }
 41  
 
 42  
                 // TODO: log this appropriately
 43  20
                 if (LOG.isEnabled(environment)) {
 44  20
                         LOG.logResult(new BasicResult(ResultEvent.PropositionEvaluated, this, environment, collatedResult));
 45  
                 }
 46  
 
 47  20
                 return collatedResult;
 48  
         }
 49  
 
 50  
         public String toString() {
 51  390
                 StringBuilder sb = new StringBuilder();
 52  390
                 sb.append(collectionOper.toString());
 53  390
                 sb.append(" "+super.toString());
 54  390
                 return sb.toString();
 55  
         }
 56  
 }