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