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 | 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 | |
|
43 | |
|
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 | |
|
61 | |
|
62 | |
|
63 | |
|
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 | |
|
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 | |
} |