Search in sources :

Example 1 with InstanceNotEqualsConstraint

use of org.drools.core.common.InstanceNotEqualsConstraint in project drools by kiegroup.

the class PatternBuilder method checkRemoveIdentities.

/**
 * @param context
 * @param pattern
 * @param betaConstraints
 */
private void checkRemoveIdentities(final BuildContext context, final Pattern pattern, final List<BetaNodeFieldConstraint> betaConstraints) {
    if (context.getKnowledgeBase().getConfiguration().isRemoveIdentities() && pattern.getObjectType().getClass() == ClassObjectType.class) {
        // Check if this object type exists before
        // If it does we need stop instance equals cross product
        final Class<?> thisClass = ((ClassObjectType) pattern.getObjectType()).getClassType();
        for (final Pattern previousPattern : context.getObjectType()) {
            final Class<?> previousClass = ((ClassObjectType) previousPattern.getObjectType()).getClassType();
            if (thisClass.isAssignableFrom(previousClass)) {
                betaConstraints.add(new InstanceNotEqualsConstraint(previousPattern));
            }
        }
        // Must be added after the checking, otherwise it matches against itself
        context.getObjectType().add(pattern);
    }
}
Also used : Pattern(org.drools.core.rule.Pattern) ClassObjectType(org.drools.core.base.ClassObjectType) InstanceNotEqualsConstraint(org.drools.core.common.InstanceNotEqualsConstraint)

Aggregations

ClassObjectType (org.drools.core.base.ClassObjectType)1 InstanceNotEqualsConstraint (org.drools.core.common.InstanceNotEqualsConstraint)1 Pattern (org.drools.core.rule.Pattern)1