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