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.PROPOSITION_EVALUATED, 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
84
85
86
87
88
89 @Override
90 public List<Proposition> getChildren() {
91 return Collections.emptyList();
92 }
93
94 @Override
95 public boolean isCompound() {
96 return false;
97 }
98
99
100
101
102
103 protected T getExpectedValue() {
104 return this.expectedValue;
105 }
106
107 @Override
108 public String toString(){
109 StringBuilder sb = new StringBuilder();
110 sb.append(term.toString());
111 sb.append(" "+operator.toString());
112 sb.append(" "+expectedValue.toString());
113 return sb.toString();
114 }
115 }