[jboss-svn-commits] JBL Code SVN: r13827 - in labs/jbossrules/trunk: drools-compiler/src/test/resources/org/drools/integrationtests and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sun Jul 29 11:35:24 EDT 2007
Author: tirelli
Date: 2007-07-29 11:35:24 -0400 (Sun, 29 Jul 2007)
New Revision: 13827
Added:
labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_NullHashing.drl
Modified:
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeObjectSinkAdapter.java
Log:
JBRULES-1034: fixing alpha hashing for null values. Test case added
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java 2007-07-29 14:16:13 UTC (rev 13826)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java 2007-07-29 15:35:24 UTC (rev 13827)
@@ -3389,4 +3389,27 @@
((List)results.get(1)).size() );
}
+ public void testNullHashing() throws Exception {
+ final PackageBuilder builder = new PackageBuilder();
+ builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_NullHashing.drl" ) ) );
+ final Package pkg = builder.getPackage();
+
+ final RuleBase ruleBase = getRuleBase();
+ ruleBase.addPackage( pkg );
+ final WorkingMemory workingMemory = ruleBase.newStatefulSession();
+
+ final List results = new ArrayList();
+ workingMemory.setGlobal( "results",
+ results );
+
+ workingMemory.insert( new Cheese( "stilton", 15 ) );
+ workingMemory.insert( new Cheese( "", 10 ) );
+ workingMemory.insert( new Cheese( null, 8 ) );
+
+ workingMemory.fireAllRules();
+
+ assertEquals( 3,
+ results.size() );
+ }
+
}
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_NullHashing.drl
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_NullHashing.drl (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_NullHashing.drl 2007-07-29 15:35:24 UTC (rev 13827)
@@ -0,0 +1,26 @@
+package org.drools;
+
+global java.util.List results
+
+rule "Hashing null"
+ salience 10
+ when
+ Cheese( type == null )
+ then
+ results.add( "OK1" );
+end
+
+rule "Hashing empty"
+ salience 5
+ when
+ Cheese( type == "" )
+ then
+ results.add( "OK2" );
+end
+
+rule "Hashing value"
+ when
+ Cheese( type == "stilton" )
+ then
+ results.add( "OK3" );
+end
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeObjectSinkAdapter.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeObjectSinkAdapter.java 2007-07-29 14:16:13 UTC (rev 13826)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeObjectSinkAdapter.java 2007-07-29 15:35:24 UTC (rev 13827)
@@ -515,7 +515,9 @@
case BOOL :
return this.bvalue;
case OBJECT :
- if ( this.ovalue instanceof Boolean ) {
+ if ( this.ovalue == null ) {
+ return false;
+ } else if ( this.ovalue instanceof Boolean ) {
return ((Boolean) this.ovalue).booleanValue();
} else if ( this.ovalue instanceof String ) {
return Boolean.valueOf( (String) this.ovalue ).booleanValue();
@@ -536,7 +538,9 @@
case BOOL :
return this.bvalue ? 1 : 0;
case OBJECT :
- if ( this.ovalue instanceof Number ) {
+ if ( this.ovalue == null ) {
+ return 0;
+ } else if ( this.ovalue instanceof Number ) {
return ((Number) this.ovalue).longValue();
} else if ( this.ovalue instanceof String ) {
return Long.parseLong( (String) this.ovalue );
@@ -557,7 +561,9 @@
case BOOL :
return this.bvalue ? 1 : 0;
case OBJECT :
- if ( this.ovalue instanceof Number ) {
+ if ( this.ovalue == null ) {
+ return 0;
+ } else if ( this.ovalue instanceof Number ) {
return ((Number) this.ovalue).doubleValue();
} else if ( this.ovalue instanceof String ) {
return Double.parseDouble( (String) this.ovalue );
@@ -602,10 +608,10 @@
return (this.index == other.index) && (this.dvalue == other.getDoubleValue());
case OBJECT :
final Object otherValue = other.getObjectValue();
- if ( (this.ovalue instanceof Number) && (otherValue instanceof Number) ) {
+ if ( (this.ovalue != null) && (this.ovalue instanceof Number) && (otherValue instanceof Number) ) {
return (this.index == other.index) && (((Number) this.ovalue).doubleValue() == ((Number) otherValue).doubleValue());
}
- return (this.index == other.index) && (this.ovalue.equals( otherValue ));
+ return (this.index == other.index) && ( this.ovalue == null ? otherValue == null : this.ovalue.equals( otherValue ));
}
return false;
}
More information about the jboss-svn-commits
mailing list