Coverage Report - org.kuali.rice.krms.framework.engine.CollectionOfComparablesTermBasedProposition
 
Classes in this File Line Coverage Branch Coverage Complexity
CollectionOfComparablesTermBasedProposition
77%
14/18
75%
6/8
2.333
 
 1  
 /**
 2  
  * Copyright 2005-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.krms.framework.engine;
 17  
 
 18  
 import java.util.Collection;
 19  
 
 20  
 import org.kuali.rice.krms.api.engine.ExecutionEnvironment;
 21  
 import org.kuali.rice.krms.api.engine.ResultEvent;
 22  
 import org.kuali.rice.krms.api.engine.Term;
 23  
 import org.kuali.rice.krms.api.engine.TermResolutionException;
 24  
 import org.kuali.rice.krms.framework.engine.result.BasicResult;
 25  
 
 26  
 public class CollectionOfComparablesTermBasedProposition<T> extends ComparableTermBasedProposition<T> {
 27  1
         private static final ResultLogger LOG = ResultLogger.getInstance();
 28  
 
 29  
         private CollectionOperator collectionOper;
 30  
         private Term term;
 31  
 
 32  
         public CollectionOfComparablesTermBasedProposition(CollectionOperator collectionOper, ComparisonOperator compareOper, Term term, T expectedValue) {
 33  20
                 super(compareOper, term, expectedValue);
 34  20
                 this.term = term;
 35  20
                 this.collectionOper = collectionOper;
 36  20
         }
 37  
 
 38  
         /**
 39  
          * @see org.kuali.rice.krms.framework.engine.ComparableTermBasedProposition#evaluate(org.kuali.rice.krms.api.engine.ExecutionEnvironment)
 40  
          * @throws TermResolutionException if there is a problem resolving a {@link Term}
 41  
          */
 42  
         @Override
 43  
         public PropositionResult evaluate(ExecutionEnvironment environment) {
 44  20
                 boolean collatedResult = collectionOper.getInitialCollatedResult();
 45  
 
 46  
                 Collection<? extends Comparable<T>> termValue;
 47  
 
 48  20
                 termValue = environment.resolveTerm(term, this);
 49  
 
 50  20
                 if (termValue != null) {
 51  20
                         for (Comparable<T> item : termValue) {
 52  24
                                 collatedResult = collectionOper.reduce(compare(item), collatedResult);
 53  24
                                 if (collectionOper.shortCircuit(collatedResult)) break;
 54  
                         }
 55  
                 }
 56  
 
 57  
                 // TODO: log this appropriately
 58  20
                 if (LOG.isEnabled(environment)) {
 59  20
                         LOG.logResult(new BasicResult(ResultEvent.PropositionEvaluated, this, environment, collatedResult));
 60  
                 }
 61  
 
 62  20
                 return new PropositionResult(collatedResult);
 63  
         }
 64  
 
 65  
         public String toString() {
 66  0
                 StringBuilder sb = new StringBuilder();
 67  0
                 sb.append(collectionOper.toString());
 68  0
                 sb.append(" "+super.toString());
 69  0
                 return sb.toString();
 70  
         }
 71  
 }