1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 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 public ComparableTermBasedProposition(ComparisonOperator operator, Term term, T expectedValue) {
36 this.operator = operator;
37 this.term = term;
38 this.expectedValue = expectedValue;
39 }
40
41
42
43
44
45 @Override
46 public PropositionResult evaluate(ExecutionEnvironment environment) {
47 Comparable<T> termValue;
48
49 termValue = environment.resolveTerm(term, this);
50
51 boolean result = compare(termValue);
52
53 if (LOG.isEnabled(environment)){
54 LOG.logResult(new BasicResult(ResultEvent.PropositionEvaluated, this, environment, result));
55 }
56 return new PropositionResult(result);
57 }
58
59
60
61
62
63
64
65 protected boolean compare(Comparable<T> termValue) {
66 boolean result = Boolean.valueOf(operator.compare(termValue, getExpectedValue()));
67 return result;
68 }
69
70
71 @Override
72 public List<Proposition> getChildren() {
73 return Collections.emptyList();
74 }
75
76 @Override
77 public boolean isCompound() {
78 return false;
79 }
80
81
82
83
84 protected T getExpectedValue() {
85 return this.expectedValue;
86 }
87
88 public String toString(){
89 StringBuilder sb = new StringBuilder();
90 sb.append(term.toString());
91 sb.append(" "+operator.toString());
92 sb.append(" "+expectedValue.toString());
93 return sb.toString();
94 }
95 }