Coverage Report - org.kuali.rice.krms.framework.engine.ComparableTermBasedProposition
 
Classes in this File Line Coverage Branch Coverage Complexity
ComparableTermBasedProposition
90%
19/21
50%
1/2
1.143
 
 1  
 package org.kuali.rice.krms.framework.engine;
 2  
 
 3  
 import java.util.Collections;
 4  
 import java.util.List;
 5  
 
 6  
 import org.kuali.rice.krms.api.engine.ExecutionEnvironment;
 7  
 import org.kuali.rice.krms.api.engine.ResultEvent;
 8  
 import org.kuali.rice.krms.api.engine.Term;
 9  
 import org.kuali.rice.krms.api.engine.TermResolutionException;
 10  
 import org.kuali.rice.krms.framework.engine.result.BasicResult;
 11  
 
 12  
 public class ComparableTermBasedProposition<T> implements Proposition {
 13  1
         private static final ResultLogger LOG = ResultLogger.getInstance();
 14  
 
 15  
         private final ComparisonOperator operator;
 16  
         private final Term term;
 17  
         private final T expectedValue;
 18  
 
 19  
 
 20  33
         public ComparableTermBasedProposition(ComparisonOperator operator, Term term, T expectedValue) {
 21  33
                 this.operator = operator;
 22  33
                 this.term = term;
 23  33
                 this.expectedValue = expectedValue;
 24  33
         }
 25  
 
 26  
         /**
 27  
          * @see org.kuali.rice.krms.framework.engine.Proposition#evaluate(org.kuali.rice.krms.api.engine.ExecutionEnvironment)
 28  
          * @throws TermResolutionException if there is a problem resolving the {@link Term}
 29  
          */
 30  
         @Override
 31  
         public boolean evaluate(ExecutionEnvironment environment) {
 32  
                 Comparable<T> termValue;
 33  
 
 34  16
                 termValue = environment.resolveTerm(term);
 35  
 
 36  16
                 boolean result = compare(termValue);
 37  
 
 38  16
                 if (LOG.isEnabled(environment)){
 39  16
                         LOG.logResult(new BasicResult(ResultEvent.PropositionEvaluated, this, environment, result));
 40  
                 }
 41  16
                 return result;
 42  
         }
 43  
 
 44  
         /**
 45  
          * This method does the actual comparison of the term value w/ the expected value
 46  
          *
 47  
          * @param termValue
 48  
          * @return the boolean result of the comparison
 49  
          */
 50  
         protected boolean compare(Comparable<T> termValue) {
 51  40
                 boolean result = Boolean.valueOf(operator.compare(termValue, getExpectedValue()));
 52  40
                 return result;
 53  
         }
 54  
         
 55  
 
 56  
         @Override
 57  
         public List<Proposition> getChildren() {
 58  0
             return Collections.emptyList();
 59  
         }
 60  
         
 61  
         @Override
 62  
         public boolean isCompound() {
 63  0
             return false;
 64  
         }
 65  
 
 66  
         /**
 67  
          * @return the expectedValue
 68  
          */
 69  
         protected T getExpectedValue() {
 70  40
                 return this.expectedValue;
 71  
         }
 72  
 
 73  
         public String toString(){
 74  472
                 StringBuilder sb = new StringBuilder();
 75  472
                 sb.append(term.toString());
 76  472
                 sb.append(" "+operator.toString());
 77  472
                 sb.append(" "+expectedValue.toString());
 78  472
                 return sb.toString();
 79  
         }
 80  
 }