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.expression.ComparisonOperator;
26 import org.kuali.rice.krms.framework.engine.result.BasicResult;
27
28
29
30
31
32
33
34 public class ComparableTermBasedProposition<T> implements Proposition {
35 private static final ResultLogger LOG = ResultLogger.getInstance();
36
37 private final ComparisonOperator operator;
38 private final Term term;
39 private final T expectedValue;
40
41
42
43
44
45
46
47 public ComparableTermBasedProposition(ComparisonOperator operator, Term term, T expectedValue) {
48 this.operator = operator;
49 this.term = term;
50 this.expectedValue = expectedValue;
51 }
52
53
54
55
56
57 @Override
58 public PropositionResult evaluate(ExecutionEnvironment environment) {
59 Comparable<T> termValue;
60
61 termValue = environment.resolveTerm(term, this);
62
63 boolean result = compare(termValue);
64
65 if (LOG.isEnabled(environment)){
66 LOG.logResult(new BasicResult(ResultEvent.PropositionEvaluated, this, environment, result));
67 }
68 return new PropositionResult(result);
69 }
70
71
72
73
74
75
76
77 protected boolean compare(Comparable<T> termValue) {
78 boolean result = Boolean.valueOf(operator.compare(termValue, getExpectedValue()));
79 return result;
80 }
81
82
83 @Override
84 public List<Proposition> getChildren() {
85 return Collections.emptyList();
86 }
87
88 @Override
89 public boolean isCompound() {
90 return false;
91 }
92
93
94
95
96 protected T getExpectedValue() {
97 return this.expectedValue;
98 }
99
100 @Override
101 public String toString(){
102 StringBuilder sb = new StringBuilder();
103 sb.append(term.toString());
104 sb.append(" "+operator.toString());
105 sb.append(" "+expectedValue.toString());
106 return sb.toString();
107 }
108 }