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