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

org.drools.verifier.rangeChecks.NumberPatterns.drl Maven / Gradle / Ivy

There is a newer version: 9.44.0.Final
Show newest version
#created on: 7.6.2007
package org.drools.verifier.rangeChecks.patterns;

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

import org.drools.verifier.components.*;
import org.drools.verifier.report.components.MissingNumberPattern;
import org.drools.verifier.report.components.Cause;
import org.drools.verifier.FindMissingNumber;

import org.drools.verifier.dao.VerifierResult;

import java.util.ArrayList;
import java.util.List;

#declare any global variables here
global VerifierResult result;

#
# If all pattern ranges are not checked for a field.
# 
# Type: Warning
# Dependencies: None
# Example: in "Rule 1" Foo( bar == 10 ) and in "Rule 2" Foo( bar == 20 ) and in "Rule 3" Foo( bar == 40 )
# 					then Foo( bar == 30 ) is missing.
rule "Range check for number patterns"
	when
		$f :Field(
			( fieldType == Field.FieldType.INT || == Field.FieldType.DOUBLE )
		)
		(
			# Where pattern is false.
			$list :ArrayList( size > FindMissingNumber.MIN_NUMBER_OF_RESTRICTIONS )
				from collect(
					LiteralRestriction( 
						fieldId == $f.id, 
						patternIsNot == false, 
						operator == Operator.EQUAL
					)
				)
		) or (
			# Where pattern is true.
			$list :ArrayList( size > FindMissingNumber.MIN_NUMBER_OF_RESTRICTIONS )
				from collect(
					LiteralRestriction( 
						fieldId == $f.id, 
						patternIsNot == true, 
						operator == Operator.EQUAL
					)
				)
		)
	then
		Number number = FindMissingNumber.testForPattern( $list );
		if( number != null ){
			MissingNumberPattern mnp = new MissingNumberPattern( $f, Operator.EQUAL, $f.getFieldType(), number.toString() );
			result.add( mnp );
		}
end

#
# If all pattern ranges are not checked for a field.
# 
# Type: Warning
# Dependencies: None
# Example: in "Rule 1" Foo( bar == 10 ) and in "Rule 2" Foo( bar == 20 ) and in "Rule 3" Foo( bar == 40 )
# 					then Foo( bar == 30 ) is missing.
rule "Range check for number patterns, !="
	when
		$f :Field( 
			( fieldType == Field.FieldType.INT || == Field.FieldType.DOUBLE ) 
		)
		(
			# Where pattern is false.
			$list :ArrayList( size > FindMissingNumber.MIN_NUMBER_OF_RESTRICTIONS )
				from collect(
					LiteralRestriction( 
						fieldId == $f.id, 
						patternIsNot == false, 
						operator == Operator.NOT_EQUAL
					)
				)
		) or (
			# Where pattern is false.
			$list :ArrayList( size > FindMissingNumber.MIN_NUMBER_OF_RESTRICTIONS )
				from collect(
					LiteralRestriction( 
						fieldId == $f.id, 
						patternIsNot == true, 
						operator == Operator.NOT_EQUAL
					)
				)
		)
	then
		Number number = FindMissingNumber.testForPattern( $list );
		if( number != null ){
			MissingNumberPattern mnp = new MissingNumberPattern( $f, Operator.NOT_EQUAL, $f.getFieldType(), number.toString() );
			result.add( mnp );
		}
end




© 2015 - 2025 Weber Informatics LLC | Privacy Policy