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.Collection;
19
20 import org.kuali.rice.krms.api.engine.ExecutionEnvironment;
21 import org.kuali.rice.krms.api.engine.ResultEvent;
22 import org.kuali.rice.krms.api.engine.Term;
23 import org.kuali.rice.krms.api.engine.TermResolutionException;
24 import org.kuali.rice.krms.framework.engine.result.BasicResult;
25
26 public class CollectionOfComparablesTermBasedProposition<T> extends ComparableTermBasedProposition<T> {
27 private static final ResultLogger LOG = ResultLogger.getInstance();
28
29 private CollectionOperator collectionOper;
30 private Term term;
31
32 public CollectionOfComparablesTermBasedProposition(CollectionOperator collectionOper, ComparisonOperator compareOper, Term term, T expectedValue) {
33 super(compareOper, term, expectedValue);
34 this.term = term;
35 this.collectionOper = collectionOper;
36 }
37
38
39
40
41
42 @Override
43 public PropositionResult evaluate(ExecutionEnvironment environment) {
44 boolean collatedResult = collectionOper.getInitialCollatedResult();
45
46 Collection<? extends Comparable<T>> termValue;
47
48 termValue = environment.resolveTerm(term, this);
49
50 if (termValue != null) {
51 for (Comparable<T> item : termValue) {
52 collatedResult = collectionOper.reduce(compare(item), collatedResult);
53 if (collectionOper.shortCircuit(collatedResult)) break;
54 }
55 }
56
57
58 if (LOG.isEnabled(environment)) {
59 LOG.logResult(new BasicResult(ResultEvent.PropositionEvaluated, this, environment, collatedResult));
60 }
61
62 return new PropositionResult(collatedResult);
63 }
64
65 public String toString() {
66 StringBuilder sb = new StringBuilder();
67 sb.append(collectionOper.toString());
68 sb.append(" "+super.toString());
69 return sb.toString();
70 }
71 }