01: package org.drools.rule;
02:
03: import org.drools.common.InternalWorkingMemory;
04: import org.drools.reteoo.ReteTuple;
05: import org.drools.spi.AlphaNodeFieldConstraint;
06: import org.drools.spi.BetaNodeFieldConstraint;
07: import org.drools.spi.FieldExtractor;
08: import org.drools.spi.Restriction;
09:
10: public class MultiRestrictionFieldConstraint implements
11: AlphaNodeFieldConstraint, BetaNodeFieldConstraint {
12:
13: /**
14: *
15: */
16: private static final long serialVersionUID = 400L;
17:
18: private final FieldExtractor extractor;
19:
20: private final Restriction restrictions;
21:
22: public MultiRestrictionFieldConstraint(
23: final FieldExtractor extractor,
24: final Restriction restrictions) {
25: this .extractor = extractor;
26: this .restrictions = restrictions;
27: }
28:
29: public FieldExtractor getFieldExtractor() {
30: return this .extractor;
31: }
32:
33: public Declaration[] getRequiredDeclarations() {
34: return this .restrictions.getRequiredDeclarations();
35: }
36:
37: public String toString() {
38: return "[MultiRestrictionConstraint fieldExtractor="
39: + this .extractor + " restrictions ="
40: + this .restrictions + "]";
41: }
42:
43: public int hashCode() {
44: final int PRIME = 31;
45: int result = 1;
46: result = PRIME * this .extractor.hashCode();
47: result = PRIME * this .restrictions.hashCode();
48: return result;
49: }
50:
51: public boolean equals(final Object object) {
52: if (this == object) {
53: return true;
54: }
55: if (object == null
56: || object.getClass() != MultiRestrictionFieldConstraint.class) {
57: return false;
58: }
59: final MultiRestrictionFieldConstraint other = (MultiRestrictionFieldConstraint) object;
60:
61: return this .extractor.equals(other.extractor)
62: && this .restrictions.equals(other.restrictions);
63: }
64:
65: public boolean isAllowed(final Object object,
66: final InternalWorkingMemory workingMemory) {
67: return this .restrictions.isAllowed(this .extractor, object,
68: workingMemory);
69: }
70:
71: public ContextEntry getContextEntry() {
72: return this .restrictions.getContextEntry();
73: }
74:
75: public boolean isAllowedCachedLeft(final ContextEntry context,
76: final Object object) {
77: return this .restrictions.isAllowedCachedLeft(context, object);
78: }
79:
80: public boolean isAllowedCachedRight(final ReteTuple tuple,
81: final ContextEntry context) {
82: return this.restrictions.isAllowedCachedRight(tuple, context);
83: }
84:
85: }
|