[jboss-svn-commits] JBL Code SVN: r8412 - in labs/jbossrules/trunk: drools-compiler/src/test/java/org/drools/integrationtests drools-compiler/src/test/resources/org/drools/integrationtests drools-core/src/main/java/org/drools/reteoo
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Dec 19 12:08:30 EST 2006
Author: tirelli
Date: 2006-12-19 12:08:20 -0500 (Tue, 19 Dec 2006)
New Revision: 8412
Modified:
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java
labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/insurance_pricing_example.drl
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeObjectSinkAdapter.java
Log:
JBRULES-591: Fixing problem with type conversion in alpha node hashing
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java 2006-12-19 17:07:39 UTC (rev 8411)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java 2006-12-19 17:08:20 UTC (rev 8412)
@@ -3116,9 +3116,6 @@
wm.fireAllRules();
- System.out.println("BASE PRICE IS: " + policy.getBasePrice());
- System.out.println("DISCOUNT IS: " + policy.getDiscountPercent());
-
assertEquals(120, policy.getBasePrice());
}
Modified: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/insurance_pricing_example.drl
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/insurance_pricing_example.drl 2006-12-19 17:07:39 UTC (rev 8411)
+++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/insurance_pricing_example.drl 2006-12-19 17:08:20 UTC (rev 8412)
@@ -18,7 +18,7 @@
policy: Policy(type == "FIRE_THEFT")
then
policy.setBasePrice(200);
- System.out.println("Priors not relevant");
+ // System.out.println("Priors not relevant");
end
#From row number: 12
@@ -49,7 +49,7 @@
policy: Policy(type == "COMPREHENSIVE")
then
policy.setBasePrice(150);
- System.out.println("Safe driver discount");
+ // System.out.println("Safe driver discount");
end
#From row number: 15
@@ -70,7 +70,7 @@
policy: Policy(type == "COMPREHENSIVE")
then
policy.setBasePrice(700);
- System.out.println("Location risk");
+ // System.out.println("Location risk");
end
#From row number: 17
@@ -81,7 +81,7 @@
policy: Policy(type == "FIRE_THEFT")
then
policy.setBasePrice(550);
- System.out.println("Location risk");
+ // System.out.println("Location risk");
end
#From row number: 18
@@ -92,7 +92,7 @@
policy: Policy(type == "COMPREHENSIVE")
then
policy.setBasePrice(120);
- System.out.println("Cheapest possible");
+ // System.out.println("Cheapest possible");
end
#From row number: 19
@@ -123,7 +123,7 @@
policy: Policy(type == "THIRD_PARTY")
then
policy.setBasePrice(800);
- System.out.println("High risk");
+ // System.out.println("High risk");
end
#From row number: 30
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 2006-12-19 17:07:39 UTC (rev 8411)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeObjectSinkAdapter.java 2006-12-19 17:08:20 UTC (rev 8412)
@@ -498,6 +498,82 @@
this.hashCode = result;
}
+ public boolean getBooleanValue() {
+ switch( this.type ) {
+ case BOOL:
+ return this.bvalue;
+ case OBJECT:
+ if( this.ovalue instanceof Boolean ) {
+ return ((Boolean) this.ovalue).booleanValue();
+ } else if( this.ovalue instanceof String ){
+ return Boolean.valueOf( (String) this.ovalue ).booleanValue();
+ } else {
+ throw new ClassCastException( "Can't convert "+this.ovalue.getClass()+" to a boolean value.");
+ }
+ case LONG:
+ throw new ClassCastException( "Can't convert long to a boolean value.");
+ case DOUBLE:
+ throw new ClassCastException( "Can't convert double to a boolean value.");
+
+ }
+ return false;
+ }
+
+ public long getLongValue() {
+ switch( this.type ) {
+ case BOOL:
+ return this.bvalue ? 1 : 0;
+ case OBJECT:
+ if( this.ovalue instanceof Number ) {
+ return ((Number) this.ovalue).longValue();
+ } else if( this.ovalue instanceof String ){
+ return Long.parseLong( (String) this.ovalue );
+ } else {
+ throw new ClassCastException( "Can't convert "+this.ovalue.getClass()+" to a long value.");
+ }
+ case LONG:
+ return this.lvalue;
+ case DOUBLE:
+ return (long) this.dvalue;
+
+ }
+ return 0;
+ }
+
+ public double getDoubleValue() {
+ switch( this.type ) {
+ case BOOL:
+ return this.bvalue ? 1 : 0;
+ case OBJECT:
+ if( this.ovalue instanceof Number ) {
+ return ((Number) this.ovalue).doubleValue();
+ } else if( this.ovalue instanceof String ){
+ return Double.parseDouble( (String) this.ovalue );
+ } else {
+ throw new ClassCastException( "Can't convert "+this.ovalue.getClass()+" to a double value.");
+ }
+ case LONG:
+ return this.lvalue;
+ case DOUBLE:
+ return this.dvalue;
+ }
+ return 0;
+ }
+
+ public Object getObjectValue() {
+ switch( this.type ) {
+ case BOOL:
+ return this.bvalue ? Boolean.TRUE : Boolean.FALSE;
+ case OBJECT:
+ return this.ovalue;
+ case LONG:
+ return new Long( this.lvalue );
+ case DOUBLE:
+ return new Double( this.dvalue );
+ }
+ return null;
+ }
+
public int hashCode() {
return this.hashCode;
}
@@ -505,12 +581,21 @@
public boolean equals(final Object object) {
final HashKey other = (HashKey) object;
- return this.index == other.index &&
- this.type == other.type &&
- ( ((this.type == BOOL) && (this.bvalue == other.bvalue)) ||
- ((this.type == LONG) && (this.lvalue == other.lvalue)) ||
- ((this.type == DOUBLE) && (this.dvalue == other.dvalue)) ||
- ((this.type == OBJECT) && (this.ovalue.equals( other.ovalue ))) );
+ switch( this.type ) {
+ case BOOL:
+ return ( this.index == other.index ) && ( this.bvalue == other.getBooleanValue() );
+ case LONG:
+ return ( this.index == other.index ) && ( this.lvalue == other.getLongValue() );
+ case DOUBLE:
+ return ( this.index == other.index ) && ( this.dvalue == other.getDoubleValue() );
+ case OBJECT:
+ Object otherValue = other.getObjectValue();
+ if( ( 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 false;
}
}
More information about the jboss-svn-commits
mailing list