All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.drools.verifier.alwaysTrue.Patterns.drl Maven / Gradle / Ivy

There is a newer version: 9.44.0.Final
Show newest version
/*
 * Copyright 2010 JBoss Inc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

//
// created on: 27.6.2008
//
// Rules in this package look for patterns and rules that are always satisfied.
//
//
package org.drools.verifier.alwaysTrue


import org.drools.verifier.components.Restriction;
import org.drools.verifier.components.Pattern;
import org.drools.verifier.components.SubPattern;
import org.drools.verifier.components.VerifierRule;

import org.drools.verifier.report.components.AlwaysTrue;
import org.drools.verifier.report.components.Opposites;
import org.drools.verifier.report.components.VerifierMessage;
import org.drools.verifier.report.components.Severity;
import org.drools.verifier.report.components.MessageType;

import org.drools.verifier.data.VerifierReport;

import java.util.Map;
import java.util.HashMap;

global VerifierReport result;

rule "Pattern possibility that is always true"
    when
        a :Restriction()
        b :Restriction()
        $pp :SubPattern()

        Opposites(
            (
                left == a && right memberOf $pp.items
            ) && (
                left == b && right memberOf $pp.items
            )
        )
    then
        insert( new AlwaysTrue( $pp , a, b ));
end
/*
//
// Finds pattern possibilities that are always true.
//
// Dependencies: None
//
// Example:
//        Pattern( a > 10 && a <= 10 )
//
rule "Pattern possibility that is always true"
    when
        $p :Pattern()

        $pp :SubPattern(
            patternPath == $p.path
        )

        // For each restriction in pattern possibility
        // there needs to be an opposite.
        forall(
            $r :Restriction(
                this memberOf $pp.items
            )

            Opposites(
                (
                    left == $r
                &&
                    right memberOf $pp.items
                ) || (
                    left memberOf $pp.items
                &&
                    right == $r
                )
            )
        )
    then
        insert( new AlwaysTrue( $pp ));
end
*/


//
// Finds patterns that are always true.
//
// Dependencies:
//    Needs at least one of the following packages or rules to fire:
//         package org.drools.verifier.alwaysTrue;
//            rule "Pattern possibility that is always true"
//
// Example:
//        Pattern( a > 10 && a <= 10 )
//
rule "Pattern that is always true"
    when
        $p :Pattern()

        // Only report the ones that have restrictions.
        exists SubPattern( patternPath == $p.path )

        // For each restriction in each pattern possibility for current pattern,
        // there needs to be an opposite.
        forall(
            $pp :SubPattern(
                patternPath == $p.path
            )

            AlwaysTrue(
                cause == $pp
            )
        )

        $r :VerifierRule( path == $p.rulePath )
    then
        Map impactedRules = new HashMap();
        impactedRules.put( $r.getPath(), $r.getName());

        result.add( new VerifierMessage(
                                impactedRules,
                                Severity.NOTE,
                                MessageType.ALWAYS_TRUE,
                                $p,
                                $p + " in rule " + $r + " is always satisfied." ) );
end




© 2015 - 2025 Weber Informatics LLC | Privacy Policy