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

org.drools.verifier.rangeChecks.Integers.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.integers;

#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.dao.VerifierResult;

global VerifierResult result;

# If all ranges are not checked for a field.
# 
# Type: Warning
# Dependencies: None
# Example: in "Rule 1" Foo( bar > 42 ) 
#						and Foo( <= 42 || == 42 ) is missing.
#
rule "Range check for integers, if smaller than or equal is missing"
	when
		$f :Field( fieldType == Field.FieldType.INT )
		
		# Foo( bar > 42 )
		$r :LiteralRestriction( 
			fieldId == $f.id, 
			operator == Operator.GREATER
		)
		
		# Check if Foo( bar == 42 || <= 42 ) is missing.
		not	LiteralRestriction( 
			fieldId == $f.id, 
			( operator  == Operator.EQUAL || == Operator.LESS_OR_EQUAL ), 
			patternIsNot == $r.patternIsNot, 
			intValue == $r.intValue 
		)
	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 integers, if greater than or equal is missing"
	when
		$f :Field( fieldType == Field.FieldType.INT )
		
		# Foo( bar > 42 )
		$r :LiteralRestriction( 
			fieldId == $f.id, 
			operator == Operator.LESS
		)
		
		# Check if Foo( bar == 42 || <= 42 ) is missing.
		not	LiteralRestriction( 
			fieldId == $f.id, 
			( operator  == Operator.EQUAL || == Operator.GREATER_OR_EQUAL ), 
			patternIsNot == $r.patternIsNot, 
			intValue == $r.intValue 
		)
	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 integers, equal and greater than"
	when
		$f :Field( fieldType == Field.FieldType.INT )

		# Foo( bar == 42 ) 
		$r :LiteralRestriction( 
			fieldId == $f.id, 
			( operator == Operator.EQUAL || == Operator.LESS_OR_EQUAL )
		)

		# Check if Foo( bar > 42 || >= 42 ) is missing.
		not	LiteralRestriction( 
			fieldId == $f.id, 
			( operator == Operator.GREATER || == Operator.GREATER_OR_EQUAL ), 
			patternIsNot == $r.patternIsNot, 
			intValue == $r.intValue 
		)
		
		# Check if Foo( bar == 43 || >= 43 ) is missing.
		not	LiteralRestriction( 
			fieldId == $f.id, 
			( operator == Operator.EQUAL || == Operator.GREATER_OR_EQUAL ), 
			patternIsNot == $r.patternIsNot, 
			eval( intValue == $r.getIntValue() + 1 ) 
		)
	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 integers, equal and smaller than"
	when
		$f :Field( fieldType == Field.FieldType.INT )

		# Foo( bar == 42 ) 
		$r :LiteralRestriction( 
			fieldId == $f.id, 
			( operator == Operator.EQUAL || == Operator.GREATER_OR_EQUAL )
		)

		# Check if Foo( bar < 42 || <= 42 ) is missing.
		not	LiteralRestriction( 
			fieldId == $f.id, 
			( operator == Operator.LESS || == Operator.LESS_OR_EQUAL ), 
			patternIsNot == $r.patternIsNot, 
			intValue == $r.intValue 
		)
		
		# Check if Foo( bar == 41 || <= 41 ) is missing.
		not	LiteralRestriction( 
			fieldId == $f.id, 
			( operator == Operator.EQUAL || == Operator.LESS_OR_EQUAL ), 
			patternIsNot == $r.patternIsNot, 
			eval( intValue == $r.getIntValue() - 1 ) 
		)
	then
		Gap gap =  new Gap( $f, Operator.LESS, $r );
		
		result.add( gap );
		insert( gap );
end




© 2015 - 2025 Weber Informatics LLC | Privacy Policy