01: package org.drools.conflict;
02:
03: import org.drools.spi.Activation;
04: import org.drools.spi.ConflictResolver;
05:
06: public class DepthConflictResolver implements ConflictResolver {
07: /**
08: *
09: */
10: private static final long serialVersionUID = 400L;
11: public static final DepthConflictResolver INSTANCE = new DepthConflictResolver();
12:
13: public static ConflictResolver getInstance() {
14: return DepthConflictResolver.INSTANCE;
15: }
16:
17: /**
18: * @see ConflictResolver
19: */
20: public final int compare(final Object existing, final Object adding) {
21: return compare((Activation) existing, (Activation) adding);
22: }
23:
24: public int compare(final Activation lhs, final Activation rhs) {
25: final int s1 = lhs.getSalience();
26: final int s2 = rhs.getSalience();
27:
28: if (s1 > s2) {
29: return -1;
30: } else if (s1 < s2) {
31: return 1;
32: }
33:
34: final long p1 = lhs.getPropagationContext()
35: .getPropagationNumber();
36: final long p2 = rhs.getPropagationContext()
37: .getPropagationNumber();
38: if (p1 != p2) {
39: return (int) (p2 - p1);
40: }
41:
42: final long r1 = lhs.getTuple().getRecency();
43: final long r2 = rhs.getTuple().getRecency();
44:
45: if (r1 != r2) {
46: return (int) (r2 - r1);
47: }
48:
49: final long l1 = lhs.getRule().getLoadOrder();
50: final long l2 = rhs.getRule().getLoadOrder();
51:
52: return (int) (l2 - l1);
53: }
54:
55: }
|