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

org.drools.verifier.rangeChecks.Doubles.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: 7.6.2007
package org.drools.verifier.rangeChecks.doubles;

//list any import classes here.
import org.drools.base.evaluators.Operator;

import org.drools.verifier.components.*;
import org.drools.verifier.report.components.Gap;

import org.drools.verifier.data.VerifierReport;

//declare any global variables here
global VerifierReport result;


// If all ranges are not checked for a field.
//
// Type: Warning
// Dependencies: None
// Example: in "Rule 1" Foo( bar > 42 )
//                        and in Foo( <= 42 || == 42 ) is missing.
//
rule "Range check for doubles, if smaller than or equal is missing"
    @verifying_scopes(["knowledge-package", "decision-table"])
    when
        $f :Field( fieldType == Field.DOUBLE )

        # Foo( bar > 42 )
        $r :NumberRestriction(
            fieldPath == $f.path,
            operator == Operator.GREATER
        )

        # Check if Foo( bar == 42 || <= 42 ) is missing.
        not NumberRestriction(
            fieldPath == $f.path,
            ( operator  == Operator.EQUAL || == Operator.LESS_OR_EQUAL ),
            patternIsNot == $r.patternIsNot,
            value == $r.value
        )
    then
        Gap gap = new Gap( $f, Operator.LESS_OR_EQUAL, $r );

        result.add( gap );
        insert( gap );
end

// If all ranges are not checked for a field.
//
// Type: Warning
// Dependencies: None
// Example: in "Rule 1" Foo( bar < 42 )
//                        and in Foo( >= 42 || == 42 ) is missing.
//
rule "Range check for doubles, if greater than or equal is missing"
    @verifying_scopes(["knowledge-package", "decision-table"])
    when
        $f :Field( fieldType == Field.DOUBLE )

        # Foo( bar > 42 )
        $r :NumberRestriction(
            fieldPath == $f.path,
            operator == Operator.LESS
        )

        # Check if Foo( bar == 42 || <= 42 ) is missing.
        not NumberRestriction(
            fieldPath == $f.path,
            ( operator  == Operator.EQUAL || == Operator.GREATER_OR_EQUAL ),
            patternIsNot == $r.patternIsNot,
            value == $r.value
        )
    then
        Gap gap = new Gap( $f, Operator.GREATER_OR_EQUAL, $r );

        result.add( gap );
        insert( gap );
end

// If all ranges are not checked for a field.
//
// Type: Warning
// Dependencies: None
// Example: in "Rule 1" Foo( bar == 42 || bar <= 42 )
//                     and no Foo( bar > 42 || >= 42 || >= 43 || == 43 )
//                        then Foo( bar > 42 ) is missing.
//
rule "Range check for doubles, equal and greater than"
    @verifying_scopes(["knowledge-package", "decision-table"])
    when
        $f :Field( fieldType == Field.DOUBLE )

        # Foo( bar == 42 )
        $r :NumberRestriction(
            fieldPath == $f.path,
            ( operator == Operator.EQUAL || == Operator.LESS_OR_EQUAL )
        )

        # Check if Foo( bar > 42 || >= 42 ) is missing.
        not NumberRestriction(
            fieldPath == $f.path,
            ( operator == Operator.GREATER || == Operator.GREATER_OR_EQUAL ),
            patternIsNot == $r.patternIsNot,
            value == $r.value
        )
    then
        Gap gap =  new Gap( $f, Operator.GREATER, $r );

        result.add( gap );
        insert( gap );
end

// If all ranges are not checked for a field.
//
// Type: Warning
// Dependencies: None
// Example: in "Rule 1" Foo( bar == 42 || bar >= 42 )
//                     and no Foo( bar < 42 || <= 42 || <= 41 || == 41 )
//                        then Foo( bar < 42 ) is missing.
//
rule "Range check for doubles, equal and smaller than"
    @verifying_scopes(["knowledge-package", "decision-table"])
    when
        $f :Field( fieldType == Field.DOUBLE )

        # Foo( bar == 42 )
        $r :NumberRestriction(
            fieldPath == $f.path,
            ( operator == Operator.EQUAL || == Operator.GREATER_OR_EQUAL )
        )

        # Check if Foo( bar < 42 || <= 42 ) is missing.
        not NumberRestriction(
            fieldPath == $f.path,
            ( operator == Operator.LESS || == Operator.LESS_OR_EQUAL ),
            patternIsNot == $r.patternIsNot,
            value == $r.value
        )
    then
        Gap gap =  new Gap( $f, Operator.LESS, $r );

        result.add( gap );
        insert( gap );
end




© 2015 - 2025 Weber Informatics LLC | Privacy Policy