01: package org.drools.conflict;
02:
03: /*
04: * Copyright 2005 JBoss Inc
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: import org.drools.spi.Activation;
20: import org.drools.spi.ConflictResolver;
21:
22: /**
23: * <code>ConflictResolver</code> that uses the salience of rules to resolve
24: * conflict.
25: *
26: * @see #getInstance
27: * @see org.drools.rule.Rule#getSalience
28: *
29: * @author <a href="mailto:bob@werken.com">bob mcwhirter </a>
30: * @author <a href="mailto:simon@redhillconsulting.com.au">Simon Harris </a>
31: *
32: * @version $Id: SalienceConflictResolver.java,v 1.3 2004/06/25 02:46:39
33: * mproctor Exp $
34: */
35: public class SalienceConflictResolver extends AbstractConflictResolver {
36: // ----------------------------------------------------------------------
37: // Class members
38: // ----------------------------------------------------------------------
39:
40: /**
41: *
42: */
43: private static final long serialVersionUID = 400L;
44: /** Singleton instance. */
45: private static final SalienceConflictResolver INSTANCE = new SalienceConflictResolver();
46:
47: // ----------------------------------------------------------------------
48: // Class methods
49: // ----------------------------------------------------------------------
50:
51: /**
52: * Retrieve the singleton instance.
53: *
54: * @return The singleton instance.
55: */
56: public static ConflictResolver getInstance() {
57: return SalienceConflictResolver.INSTANCE;
58: }
59:
60: // ----------------------------------------------------------------------
61: // Constructors
62: // ----------------------------------------------------------------------
63:
64: /**
65: * Construct.
66: */
67: public SalienceConflictResolver() {
68: // intentionally left blank
69: }
70:
71: // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
72:
73: /**
74: * @see ConflictResolver
75: */
76: public int compare(final Activation lhs, final Activation rhs) {
77: final int s1 = lhs.getSalience();
78: final int s2 = rhs.getSalience();
79:
80: if (s1 > s2) {
81: return -1;
82: } else if (s1 < s2) {
83: return 1;
84: } else {
85: return 0;
86: }
87: }
88: }
|