[jboss-svn-commits] JBL Code SVN: r12774 - in labs/jbossrules/trunk: drools-compiler/src/test/java/org/drools/integrationtests and 5 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Jun 22 11:03:43 EDT 2007


Author: tirelli
Date: 2007-06-22 11:03:43 -0400 (Fri, 22 Jun 2007)
New Revision: 12774

Added:
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/AccumulateTest.java
   labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_AccumulateAverage.drl
   labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_AccumulateCount.drl
   labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_AccumulateMax.drl
   labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_AccumulateMin.drl
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/AverageAccumulateFunction.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/CountAccumulateFunction.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/MaxAccumulateFunction.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/MinAccumulateFunction.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/SumAccumulateFunction.java
Removed:
   labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_AccumulateExternalFunction.drl
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/AverageAccumulator.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/MaxAccumulator.java
Modified:
   labs/jbossrules/trunk/drools-compiler/src/main/resources/META-INF/drools.default.packagebuilder.conf
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/FirstOrderLogicTest.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/asm/ClassReader.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/asm/MethodVisitor.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/asm/MethodWriter.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/asm/util/CheckMethodAdapter.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/StringUtils.java
Log:
JBRULES-941: Adding default average, sum, count, min and max functions

Modified: labs/jbossrules/trunk/drools-compiler/src/main/resources/META-INF/drools.default.packagebuilder.conf
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/resources/META-INF/drools.default.packagebuilder.conf	2007-06-22 07:41:16 UTC (rev 12773)
+++ labs/jbossrules/trunk/drools-compiler/src/main/resources/META-INF/drools.default.packagebuilder.conf	2007-06-22 15:03:43 UTC (rev 12774)
@@ -2,4 +2,8 @@
 drools.dialect.java = org.drools.rule.builder.dialect.java.JavaDialect
 drools.dialect.mvel = org.drools.rule.builder.dialect.mvel.MVELDialect
 drools.compiler = ECLIPSE
-drools.accumulate.function.average = org.drools.base.accumulators.AverageAccumulator
\ No newline at end of file
+drools.accumulate.function.average = org.drools.base.accumulators.AverageAccumulateFunction
+drools.accumulate.function.max = org.drools.base.accumulators.MaxAccumulateFunction
+drools.accumulate.function.min = org.drools.base.accumulators.MinAccumulateFunction
+drools.accumulate.function.count = org.drools.base.accumulators.CountAccumulateFunction
+drools.accumulate.function.sum = org.drools.base.accumulators.SumAccumulateFunction

Added: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/AccumulateTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/AccumulateTest.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/AccumulateTest.java	2007-06-22 15:03:43 UTC (rev 12774)
@@ -0,0 +1,689 @@
+package org.drools.integrationtests;
+
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.drools.Cheese;
+import org.drools.Cheesery;
+import org.drools.FactHandle;
+import org.drools.Person;
+import org.drools.PersonInterface;
+import org.drools.RuleBase;
+import org.drools.RuleBaseConfiguration;
+import org.drools.RuleBaseFactory;
+import org.drools.State;
+import org.drools.WorkingMemory;
+import org.drools.compiler.DrlParser;
+import org.drools.compiler.DroolsParserException;
+import org.drools.compiler.PackageBuilder;
+import org.drools.lang.descr.PackageDescr;
+import org.drools.rule.Package;
+import org.drools.rule.Rule;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+public class AccumulateTest extends TestCase {
+    protected RuleBase getRuleBase() throws Exception {
+
+        return RuleBaseFactory.newRuleBase( RuleBase.RETEOO,
+                                            null );
+    }
+
+    protected RuleBase getRuleBase(final RuleBaseConfiguration config) throws Exception {
+
+        return RuleBaseFactory.newRuleBase( RuleBase.RETEOO,
+                                            config );
+    }
+
+    private RuleBase loadRuleBase(final Reader reader) throws IOException,
+                                                      DroolsParserException,
+                                                      Exception {
+        final DrlParser parser = new DrlParser();
+        final PackageDescr packageDescr = parser.parse( reader );
+        if ( parser.hasErrors() ) {
+            System.out.println( parser.getErrors() );
+            Assert.fail( "Error messages in parser, need to sort this our (or else collect error messages)" );
+        }
+        // pre build the package
+        final PackageBuilder builder = new PackageBuilder();
+        builder.addPackage( packageDescr );
+        final Package pkg = builder.getPackage();
+
+        // add the package to a rulebase
+        final RuleBase ruleBase = getRuleBase();
+        ruleBase.addPackage( pkg );
+        // load up the rulebase
+        return ruleBase;
+    }
+
+    public void testAccumulateModify() throws Exception {
+        // read in the source
+        final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_AccumulateModify.drl" ) );
+        final RuleBase ruleBase = loadRuleBase( reader );
+
+        final WorkingMemory wm = ruleBase.newStatefulSession();
+        final List results = new ArrayList();
+
+        wm.setGlobal( "results",
+                      results );
+
+        final Cheese[] cheese = new Cheese[]{new Cheese( "stilton",
+                                                         10 ), new Cheese( "stilton",
+                                                                           2 ), new Cheese( "stilton",
+                                                                                            5 ), new Cheese( "brie",
+                                                                                                             15 ), new Cheese( "brie",
+                                                                                                                               16 ), new Cheese( "provolone",
+                                                                                                                                                 8 )};
+        final Person bob = new Person( "Bob",
+                                       "stilton" );
+
+        final FactHandle[] cheeseHandles = new FactHandle[cheese.length];
+        for ( int i = 0; i < cheese.length; i++ ) {
+            cheeseHandles[i] = wm.insert( cheese[i] );
+        }
+        final FactHandle bobHandle = wm.insert( bob );
+
+        // ---------------- 1st scenario
+        wm.fireAllRules();
+        // no fire, as per rule constraints
+        Assert.assertEquals( 0,
+                             results.size() );
+
+        // ---------------- 2nd scenario
+        final int index = 1;
+        cheese[index].setPrice( 9 );
+        wm.update( cheeseHandles[index],
+                   cheese[index] );
+        wm.fireAllRules();
+
+        // 1 fire
+        Assert.assertEquals( 1,
+                             results.size() );
+        Assert.assertEquals( 24,
+                             ((Cheesery) results.get( results.size() - 1 )).getTotalAmount() );
+
+        // ---------------- 3rd scenario
+        bob.setLikes( "brie" );
+        wm.update( bobHandle,
+                   bob );
+        wm.fireAllRules();
+
+        // 2 fires
+        Assert.assertEquals( 2,
+                             results.size() );
+        Assert.assertEquals( 31,
+                             ((Cheesery) results.get( results.size() - 1 )).getTotalAmount() );
+
+        // ---------------- 4th scenario
+        wm.retract( cheeseHandles[3] );
+        wm.fireAllRules();
+
+        // should not have fired as per constraint
+        Assert.assertEquals( 2,
+                             results.size() );
+
+    }
+
+    public void testAccumulate() throws Exception {
+
+        // read in the source
+        final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_Accumulate.drl" ) );
+        final RuleBase ruleBase = loadRuleBase( reader );
+
+        final WorkingMemory wm = ruleBase.newStatefulSession();
+        final List results = new ArrayList();
+
+        wm.setGlobal( "results",
+                      results );
+
+        wm.insert( new Cheese( "stilton",
+                               10 ) );
+        wm.insert( new Cheese( "brie",
+                               5 ) );
+        wm.insert( new Cheese( "provolone",
+                               150 ) );
+        wm.insert( new Person( "Bob",
+                               "stilton",
+                               20 ) );
+        wm.insert( new Person( "Mark",
+                               "provolone" ) );
+
+        wm.fireAllRules();
+
+        Assert.assertEquals( new Integer( 165 ),
+                             results.get( 0 ) );
+        Assert.assertEquals( new Integer( 10 ),
+                             results.get( 1 ) );
+        Assert.assertEquals( new Integer( 150 ),
+                             results.get( 2 ) );
+        Assert.assertEquals( new Integer( 10 ),
+                             results.get( 3 ) );
+        Assert.assertEquals( new Integer( 210 ),
+                             results.get( 4 ) );
+    }
+
+    public void testMVELAccumulate() throws Exception {
+
+        // read in the source
+        final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_AccumulateMVEL.drl" ) );
+        final RuleBase ruleBase = loadRuleBase( reader );
+
+        final WorkingMemory wm = ruleBase.newStatefulSession();
+        final List results = new ArrayList();
+
+        wm.setGlobal( "results",
+                      results );
+
+        wm.insert( new Cheese( "stilton",
+                               10 ) );
+        wm.insert( new Cheese( "brie",
+                               5 ) );
+        wm.insert( new Cheese( "provolone",
+                               150 ) );
+        wm.insert( new Person( "Bob",
+                               "stilton",
+                               20 ) );
+        wm.insert( new Person( "Mark",
+                               "provolone" ) );
+
+        wm.fireAllRules();
+
+        Assert.assertEquals( new Integer( 165 ),
+                             results.get( 0 ) );
+        Assert.assertEquals( new Integer( 10 ),
+                             results.get( 1 ) );
+        Assert.assertEquals( new Integer( 150 ),
+                             results.get( 2 ) );
+        Assert.assertEquals( new Integer( 10 ),
+                             results.get( 3 ) );
+        Assert.assertEquals( new Integer( 210 ),
+                             results.get( 4 ) );
+    }
+
+    public void testAccumulateModifyMVEL() throws Exception {
+        // read in the source
+        final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_AccumulateModifyMVEL.drl" ) );
+        final RuleBase ruleBase = loadRuleBase( reader );
+
+        final WorkingMemory wm = ruleBase.newStatefulSession();
+        final List results = new ArrayList();
+
+        wm.setGlobal( "results",
+                      results );
+
+        final Cheese[] cheese = new Cheese[]{new Cheese( "stilton",
+                                                         10 ), new Cheese( "stilton",
+                                                                           2 ), new Cheese( "stilton",
+                                                                                            5 ), new Cheese( "brie",
+                                                                                                             15 ), new Cheese( "brie",
+                                                                                                                               16 ), new Cheese( "provolone",
+                                                                                                                                                 8 )};
+        final Person bob = new Person( "Bob",
+                                       "stilton" );
+
+        final FactHandle[] cheeseHandles = new FactHandle[cheese.length];
+        for ( int i = 0; i < cheese.length; i++ ) {
+            cheeseHandles[i] = wm.insert( cheese[i] );
+        }
+        final FactHandle bobHandle = wm.insert( bob );
+
+        // ---------------- 1st scenario
+        wm.fireAllRules();
+        // no fire, as per rule constraints
+        Assert.assertEquals( 0,
+                             results.size() );
+
+        // ---------------- 2nd scenario
+        final int index = 1;
+        cheese[index].setPrice( 9 );
+        wm.update( cheeseHandles[index],
+                   cheese[index] );
+        wm.fireAllRules();
+
+        // 1 fire
+        Assert.assertEquals( 1,
+                             results.size() );
+        Assert.assertEquals( 24,
+                             ((Cheesery) results.get( results.size() - 1 )).getTotalAmount() );
+
+        // ---------------- 3rd scenario
+        bob.setLikes( "brie" );
+        wm.update( bobHandle,
+                   bob );
+        wm.fireAllRules();
+
+        // 2 fires
+        Assert.assertEquals( 2,
+                             results.size() );
+        Assert.assertEquals( 31,
+                             ((Cheesery) results.get( results.size() - 1 )).getTotalAmount() );
+
+        // ---------------- 4th scenario
+        wm.retract( cheeseHandles[3] );
+        wm.fireAllRules();
+
+        // should not have fired as per constraint
+        Assert.assertEquals( 2,
+                             results.size() );
+
+    }
+
+    public void testAccumulateReverseModify() throws Exception {
+        // read in the source
+        final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_AccumulateReverseModify.drl" ) );
+        final RuleBase ruleBase = loadRuleBase( reader );
+
+        final WorkingMemory wm = ruleBase.newStatefulSession();
+        final List results = new ArrayList();
+
+        wm.setGlobal( "results",
+                      results );
+
+        final Cheese[] cheese = new Cheese[]{new Cheese( "stilton",
+                                                         10 ), new Cheese( "stilton",
+                                                                           2 ), new Cheese( "stilton",
+                                                                                            5 ), new Cheese( "brie",
+                                                                                                             15 ), new Cheese( "brie",
+                                                                                                                               16 ), new Cheese( "provolone",
+                                                                                                                                                 8 )};
+        final Person bob = new Person( "Bob",
+                                       "stilton" );
+
+        final FactHandle[] cheeseHandles = new FactHandle[cheese.length];
+        for ( int i = 0; i < cheese.length; i++ ) {
+            cheeseHandles[i] = wm.insert( cheese[i] );
+        }
+        final FactHandle bobHandle = wm.insert( bob );
+
+        // ---------------- 1st scenario
+        wm.fireAllRules();
+        // no fire, as per rule constraints
+        Assert.assertEquals( 0,
+                             results.size() );
+
+        // ---------------- 2nd scenario
+        final int index = 1;
+        cheese[index].setPrice( 9 );
+        wm.update( cheeseHandles[index],
+                   cheese[index] );
+        wm.fireAllRules();
+
+        // 1 fire
+        Assert.assertEquals( 1,
+                             results.size() );
+        Assert.assertEquals( 24,
+                             ((Cheesery) results.get( results.size() - 1 )).getTotalAmount() );
+
+        // ---------------- 3rd scenario
+        bob.setLikes( "brie" );
+        wm.update( bobHandle,
+                   bob );
+        wm.fireAllRules();
+
+        // 2 fires
+        Assert.assertEquals( 2,
+                             results.size() );
+        Assert.assertEquals( 31,
+                             ((Cheesery) results.get( results.size() - 1 )).getTotalAmount() );
+
+        // ---------------- 4th scenario
+        wm.retract( cheeseHandles[3] );
+        wm.fireAllRules();
+
+        // should not have fired as per constraint
+        Assert.assertEquals( 2,
+                             results.size() );
+
+    }
+
+    public void testAccumulateReverseModifyMVEL() throws Exception {
+        // read in the source
+        final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_AccumulateReverseModifyMVEL.drl" ) );
+        final RuleBase ruleBase = loadRuleBase( reader );
+
+        final WorkingMemory wm = ruleBase.newStatefulSession();
+        final List results = new ArrayList();
+
+        wm.setGlobal( "results",
+                      results );
+
+        final Cheese[] cheese = new Cheese[]{new Cheese( "stilton",
+                                                         10 ), new Cheese( "stilton",
+                                                                           2 ), new Cheese( "stilton",
+                                                                                            5 ), new Cheese( "brie",
+                                                                                                             15 ), new Cheese( "brie",
+                                                                                                                               16 ), new Cheese( "provolone",
+                                                                                                                                                 8 )};
+        final Person bob = new Person( "Bob",
+                                       "stilton" );
+
+        final FactHandle[] cheeseHandles = new FactHandle[cheese.length];
+        for ( int i = 0; i < cheese.length; i++ ) {
+            cheeseHandles[i] = wm.insert( cheese[i] );
+        }
+        final FactHandle bobHandle = wm.insert( bob );
+
+        // ---------------- 1st scenario
+        wm.fireAllRules();
+        // no fire, as per rule constraints
+        Assert.assertEquals( 0,
+                             results.size() );
+
+        // ---------------- 2nd scenario
+        final int index = 1;
+        cheese[index].setPrice( 9 );
+        wm.update( cheeseHandles[index],
+                   cheese[index] );
+        wm.fireAllRules();
+
+        // 1 fire
+        Assert.assertEquals( 1,
+                             results.size() );
+        Assert.assertEquals( 24,
+                             ((Cheesery) results.get( results.size() - 1 )).getTotalAmount() );
+
+        // ---------------- 3rd scenario
+        bob.setLikes( "brie" );
+        wm.update( bobHandle,
+                   bob );
+        wm.fireAllRules();
+
+        // 2 fires
+        Assert.assertEquals( 2,
+                             results.size() );
+        Assert.assertEquals( 31,
+                             ((Cheesery) results.get( results.size() - 1 )).getTotalAmount() );
+
+        // ---------------- 4th scenario
+        wm.retract( cheeseHandles[3] );
+        wm.fireAllRules();
+
+        // should not have fired as per constraint
+        Assert.assertEquals( 2,
+                             results.size() );
+
+    }
+
+    public void testAccumulateAverage() throws Exception {
+        // read in the source
+        final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_AccumulateAverage.drl" ) );
+        final RuleBase ruleBase = loadRuleBase( reader );
+
+        final WorkingMemory wm = ruleBase.newStatefulSession();
+        final List results = new ArrayList();
+
+        wm.setGlobal( "results",
+                      results );
+
+        final Cheese[] cheese = new Cheese[]{new Cheese( "stilton",
+                                                         10 ), new Cheese( "stilton",
+                                                                           2 ), new Cheese( "stilton",
+                                                                                            11 ), new Cheese( "brie",
+                                                                                                              15 ), new Cheese( "brie",
+                                                                                                                                17 ), new Cheese( "provolone",
+                                                                                                                                                  8 )};
+        final Person bob = new Person( "Bob",
+                                       "stilton" );
+
+        final FactHandle[] cheeseHandles = new FactHandle[cheese.length];
+        for ( int i = 0; i < cheese.length; i++ ) {
+            cheeseHandles[i] = wm.insert( cheese[i] );
+        }
+        final FactHandle bobHandle = wm.insert( bob );
+
+        // ---------------- 1st scenario
+        wm.fireAllRules();
+        // no fire, as per rule constraints
+        Assert.assertEquals( 0,
+                             results.size() );
+
+        // ---------------- 2nd scenario
+        final int index = 1;
+        cheese[index].setPrice( 9 );
+        wm.update( cheeseHandles[index],
+                   cheese[index] );
+        wm.fireAllRules();
+
+        // 1 fire
+        Assert.assertEquals( 1,
+                             results.size() );
+        Assert.assertEquals( 10,
+                             ((Number) results.get( results.size() - 1 )).intValue() );
+
+        // ---------------- 3rd scenario
+        bob.setLikes( "brie" );
+        wm.update( bobHandle,
+                   bob );
+        wm.fireAllRules();
+
+        // 2 fires
+        Assert.assertEquals( 2,
+                             results.size() );
+        Assert.assertEquals( 16,
+                             ((Number) results.get( results.size() - 1 )).intValue() );
+
+        // ---------------- 4th scenario
+        wm.retract( cheeseHandles[3] );
+        wm.retract( cheeseHandles[4] );
+        wm.fireAllRules();
+
+        // should not have fired as per constraint
+        Assert.assertEquals( 2,
+                             results.size() );
+
+    }
+    
+    public void testAccumulateMax() throws Exception {
+        // read in the source
+        final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_AccumulateMax.drl" ) );
+        final RuleBase ruleBase = loadRuleBase( reader );
+
+        final WorkingMemory wm = ruleBase.newStatefulSession();
+        final List results = new ArrayList();
+
+        wm.setGlobal( "results",
+                      results );
+
+        final Cheese[] cheese = new Cheese[]{new Cheese( "stilton",
+                                                         4 ), new Cheese( "stilton",
+                                                                           2 ), new Cheese( "stilton",
+                                                                                            3 ), new Cheese( "brie",
+                                                                                                              15 ), new Cheese( "brie",
+                                                                                                                                17 ), new Cheese( "provolone",
+                                                                                                                                                  8 )};
+        final Person bob = new Person( "Bob",
+                                       "stilton" );
+
+        final FactHandle[] cheeseHandles = new FactHandle[cheese.length];
+        for ( int i = 0; i < cheese.length; i++ ) {
+            cheeseHandles[i] = wm.insert( cheese[i] );
+        }
+        final FactHandle bobHandle = wm.insert( bob );
+
+        // ---------------- 1st scenario
+        wm.fireAllRules();
+        // no fire, as per rule constraints
+        Assert.assertEquals( 0,
+                             results.size() );
+
+        // ---------------- 2nd scenario
+        final int index = 1;
+        cheese[index].setPrice( 9 );
+        wm.update( cheeseHandles[index],
+                   cheese[index] );
+        wm.fireAllRules();
+
+        // 1 fire
+        Assert.assertEquals( 1,
+                             results.size() );
+        Assert.assertEquals( 9,
+                             ((Number) results.get( results.size() - 1 )).intValue() );
+
+        // ---------------- 3rd scenario
+        bob.setLikes( "brie" );
+        wm.update( bobHandle,
+                   bob );
+        wm.fireAllRules();
+
+        // 2 fires
+        Assert.assertEquals( 2,
+                             results.size() );
+        Assert.assertEquals( 17,
+                             ((Number) results.get( results.size() - 1 )).intValue() );
+
+        // ---------------- 4th scenario
+        wm.retract( cheeseHandles[3] );
+        wm.retract( cheeseHandles[4] );
+        wm.fireAllRules();
+
+        // should not have fired as per constraint
+        Assert.assertEquals( 2,
+                             results.size() );
+
+    }
+    
+    public void testAccumulateMin() throws Exception {
+        // read in the source
+        final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_AccumulateMin.drl" ) );
+        final RuleBase ruleBase = loadRuleBase( reader );
+
+        final WorkingMemory wm = ruleBase.newStatefulSession();
+        final List results = new ArrayList();
+
+        wm.setGlobal( "results",
+                      results );
+
+        final Cheese[] cheese = new Cheese[]{new Cheese( "stilton",
+                                                         8 ), new Cheese( "stilton",
+                                                                           10 ), new Cheese( "stilton",
+                                                                                            9 ), new Cheese( "brie",
+                                                                                                              4 ), new Cheese( "brie",
+                                                                                                                                1 ), new Cheese( "provolone",
+                                                                                                                                                  8 )};
+        final Person bob = new Person( "Bob",
+                                       "stilton" );
+
+        final FactHandle[] cheeseHandles = new FactHandle[cheese.length];
+        for ( int i = 0; i < cheese.length; i++ ) {
+            cheeseHandles[i] = wm.insert( cheese[i] );
+        }
+        final FactHandle bobHandle = wm.insert( bob );
+
+        // ---------------- 1st scenario
+        wm.fireAllRules();
+        // no fire, as per rule constraints
+        Assert.assertEquals( 0,
+                             results.size() );
+
+        // ---------------- 2nd scenario
+        final int index = 1;
+        cheese[index].setPrice( 3 );
+        wm.update( cheeseHandles[index],
+                   cheese[index] );
+        wm.fireAllRules();
+
+        // 1 fire
+        Assert.assertEquals( 1,
+                             results.size() );
+        Assert.assertEquals( 3,
+                             ((Number) results.get( results.size() - 1 )).intValue() );
+
+        // ---------------- 3rd scenario
+        bob.setLikes( "brie" );
+        wm.update( bobHandle,
+                   bob );
+        wm.fireAllRules();
+
+        // 2 fires
+        Assert.assertEquals( 2,
+                             results.size() );
+        Assert.assertEquals( 1,
+                             ((Number) results.get( results.size() - 1 )).intValue() );
+
+        // ---------------- 4th scenario
+        wm.retract( cheeseHandles[3] );
+        wm.retract( cheeseHandles[4] );
+        wm.fireAllRules();
+
+        // should not have fired as per constraint
+        Assert.assertEquals( 2,
+                             results.size() );
+
+    }
+    
+    public void testAccumulateCount() throws Exception {
+        // read in the source
+        final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_AccumulateCount.drl" ) );
+        final RuleBase ruleBase = loadRuleBase( reader );
+
+        final WorkingMemory wm = ruleBase.newStatefulSession();
+        final List results = new ArrayList();
+
+        wm.setGlobal( "results",
+                      results );
+
+        final Cheese[] cheese = new Cheese[]{new Cheese( "stilton",
+                                                         8 ), new Cheese( "stilton",
+                                                                           10 ), new Cheese( "stilton",
+                                                                                            9 ), new Cheese( "brie",
+                                                                                                              4 ), new Cheese( "brie",
+                                                                                                                                1 ), new Cheese( "provolone",
+                                                                                                                                                  8 )};
+        final Person bob = new Person( "Bob",
+                                       "stilton" );
+
+        final FactHandle[] cheeseHandles = new FactHandle[cheese.length];
+        for ( int i = 0; i < cheese.length; i++ ) {
+            cheeseHandles[i] = wm.insert( cheese[i] );
+        }
+        final FactHandle bobHandle = wm.insert( bob );
+
+        // ---------------- 1st scenario
+        wm.fireAllRules();
+        // no fire, as per rule constraints
+        Assert.assertEquals( 1,
+                             results.size() );
+        Assert.assertEquals( 3,
+                             ((Number) results.get( results.size() - 1 )).intValue() );
+
+        // ---------------- 2nd scenario
+        final int index = 1;
+        cheese[index].setPrice( 3 );
+        wm.update( cheeseHandles[index],
+                   cheese[index] );
+        wm.fireAllRules();
+
+        // 1 fire
+        Assert.assertEquals( 2,
+                             results.size() );
+        Assert.assertEquals( 3,
+                             ((Number) results.get( results.size() - 1 )).intValue() );
+
+        // ---------------- 3rd scenario
+        bob.setLikes( "brie" );
+        wm.update( bobHandle,
+                   bob );
+        wm.fireAllRules();
+
+        // 2 fires
+        Assert.assertEquals( 3,
+                             results.size() );
+        Assert.assertEquals( 2,
+                             ((Number) results.get( results.size() - 1 )).intValue() );
+
+        // ---------------- 4th scenario
+        wm.retract( cheeseHandles[3] );
+        wm.fireAllRules();
+
+        // should not have fired as per constraint
+        Assert.assertEquals( 3,
+                             results.size() );
+
+    }
+    
+}

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/FirstOrderLogicTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/FirstOrderLogicTest.java	2007-06-22 07:41:16 UTC (rev 12773)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/FirstOrderLogicTest.java	2007-06-22 15:03:43 UTC (rev 12774)
@@ -40,76 +40,8 @@
                                             config );
     }
 
-    public void xxxtestAccumulateModify() throws Exception {
-        // read in the source
-        final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_AccumulateModify.drl" ) );
-        final RuleBase ruleBase = loadRuleBase( reader );
+    public void testCollect() throws Exception {
 
-        final WorkingMemory wm = ruleBase.newStatefulSession();
-        final List results = new ArrayList();
-
-        wm.setGlobal( "results",
-                      results );
-
-        final Cheese[] cheese = new Cheese[]{new Cheese( "stilton",
-                                                         10 ), new Cheese( "stilton",
-                                                                           2 ), new Cheese( "stilton",
-                                                                                            5 ), new Cheese( "brie",
-                                                                                                             15 ), new Cheese( "brie",
-                                                                                                                               16 ), new Cheese( "provolone",
-                                                                                                                                                 8 )};
-        final Person bob = new Person( "Bob",
-                                       "stilton" );
-
-        final FactHandle[] cheeseHandles = new FactHandle[cheese.length];
-        for ( int i = 0; i < cheese.length; i++ ) {
-            cheeseHandles[i] = wm.insert( cheese[i] );
-        }
-        final FactHandle bobHandle = wm.insert( bob );
-
-        // ---------------- 1st scenario
-        wm.fireAllRules();
-        // no fire, as per rule constraints
-        Assert.assertEquals( 0,
-                             results.size() );
-
-        // ---------------- 2nd scenario
-        final int index = 1;
-        cheese[index].setPrice( 9 );
-        wm.update( cheeseHandles[index],
-                         cheese[index] );
-        wm.fireAllRules();
-
-        // 1 fire
-        Assert.assertEquals( 1,
-                             results.size() );
-        Assert.assertEquals( 24,
-                             ((Cheesery) results.get( results.size() - 1 )).getTotalAmount() );
-
-        // ---------------- 3rd scenario
-        bob.setLikes( "brie" );
-        wm.update( bobHandle,
-                         bob );
-        wm.fireAllRules();
-
-        // 2 fires
-        Assert.assertEquals( 2,
-                             results.size() );
-        Assert.assertEquals( 31,
-                             ((Cheesery) results.get( results.size() - 1 )).getTotalAmount() );
-
-        // ---------------- 4th scenario
-        wm.retract( cheeseHandles[3] );
-        wm.fireAllRules();
-
-        // should not have fired as per constraint
-        Assert.assertEquals( 2,
-                             results.size() );
-
-    }
-
-    public void xxxtestCollect() throws Exception {
-
         // read in the source
         final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_Collect.drl" ) );
         final RuleBase ruleBase = loadRuleBase( reader );
@@ -147,7 +79,7 @@
                              results.get( 0 ).getClass().getName() );
     }
 
-    public void xxxtestCollectModify() throws Exception {
+    public void testCollectModify() throws Exception {
         // read in the source
         final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_Collect.drl" ) );
         final RuleBase ruleBase = loadRuleBase( reader );
@@ -216,7 +148,7 @@
                              results.size() );
     }
 
-    public void xxxtestExistsWithBinding() throws Exception {
+    public void testExistsWithBinding() throws Exception {
         final PackageBuilder builder = new PackageBuilder();
         builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_ExistsWithBindings.drl" ) ) );
         final Package pkg = builder.getPackage();
@@ -242,7 +174,7 @@
                       list.size() );
     }
     
-    public void xxxtestNot() throws Exception {
+    public void testNot() throws Exception {
         final PackageBuilder builder = new PackageBuilder();
         builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "not_rule_test.drl" ) ) );
         final Package pkg = builder.getPackage();
@@ -279,7 +211,7 @@
     }
     
     
-    public void xxxtestNotWithBindings() throws Exception {
+    public void testNotWithBindings() throws Exception {
         final PackageBuilder builder = new PackageBuilder();
         builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "not_with_bindings_rule_test.drl" ) ) );
         final Package pkg = builder.getPackage();
@@ -320,7 +252,7 @@
                       list.size() );
     }    
     
-    public void xxxtestExists() throws Exception {
+    public void testExists() throws Exception {
         final PackageBuilder builder = new PackageBuilder();
         builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "exists_rule_test.drl" ) ) );
         final Package pkg = builder.getPackage();
@@ -358,7 +290,7 @@
                       list.size() );
     }
 
-    public void xxxtestExists2() throws Exception {
+    public void testExists2() throws Exception {
         final PackageBuilder builder = new PackageBuilder();
         builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_exists.drl" ) ) );
         final Package pkg = builder.getPackage();
@@ -402,7 +334,7 @@
     }
     
 
-    public void xxxtestForall() throws Exception {
+    public void testForall() throws Exception {
         final PackageBuilder builder = new PackageBuilder();
         builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_Forall.drl" ) ) );
         final Package pkg = builder.getPackage();
@@ -436,46 +368,7 @@
                       list.size() );
     }
     
-    public void xxxtestAccumulate() throws Exception {
-
-        // read in the source
-        final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_Accumulate.drl" ) );
-        final RuleBase ruleBase = loadRuleBase( reader );
-
-        final WorkingMemory wm = ruleBase.newStatefulSession();
-        final List results = new ArrayList();
-
-        wm.setGlobal( "results",
-                      results );
-
-        wm.insert( new Cheese( "stilton",
-                                     10 ) );
-        wm.insert( new Cheese( "brie",
-                                     5 ) );
-        wm.insert( new Cheese( "provolone",
-                                     150 ) );
-        wm.insert( new Person( "Bob",
-                                     "stilton",
-                                     20 ) );
-        wm.insert( new Person( "Mark",
-                                     "provolone" ) );
-
-        wm.fireAllRules();
-
-        Assert.assertEquals( new Integer( 165 ),
-                             results.get( 0 ) );
-        Assert.assertEquals( new Integer( 10 ),
-                             results.get( 1 ) );
-        Assert.assertEquals( new Integer( 150 ),
-                             results.get( 2 ) );
-        Assert.assertEquals( new Integer( 10 ),
-                             results.get( 3 ) );
-        Assert.assertEquals( new Integer( 210 ),
-                             results.get( 4 ) );
-    }
-    
-
-    public void xxxtestRemoveIdentitiesSubNetwork() throws Exception {
+    public void testRemoveIdentitiesSubNetwork() throws Exception {
         final PackageBuilder builder = new PackageBuilder();
         builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_removeIdentitiesSubNetwork.drl" ) ) );
         final Package pkg = builder.getPackage();
@@ -543,314 +436,4 @@
         return ruleBase;
     }
     
-    public void xxxtestMVELAccumulate() throws Exception {
-
-        // read in the source
-        final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_AccumulateMVEL.drl" ) );
-        final RuleBase ruleBase = loadRuleBase( reader );
-
-        final WorkingMemory wm = ruleBase.newStatefulSession();
-        final List results = new ArrayList();
-
-        wm.setGlobal( "results",
-                      results );
-
-        wm.insert( new Cheese( "stilton",
-                                     10 ) );
-        wm.insert( new Cheese( "brie",
-                                     5 ) );
-        wm.insert( new Cheese( "provolone",
-                                     150 ) );
-        wm.insert( new Person( "Bob",
-                                     "stilton",
-                                     20 ) );
-        wm.insert( new Person( "Mark",
-                                     "provolone" ) );
-
-        wm.fireAllRules();
-
-        Assert.assertEquals( new Integer( 165 ),
-                             results.get( 0 ) );
-        Assert.assertEquals( new Integer( 10 ),
-                             results.get( 1 ) );
-        Assert.assertEquals( new Integer( 150 ),
-                             results.get( 2 ) );
-        Assert.assertEquals( new Integer( 10 ),
-                             results.get( 3 ) );
-        Assert.assertEquals( new Integer( 210 ),
-                             results.get( 4 ) );
-    }
-    
-    public void xxxtestAccumulateModifyMVEL() throws Exception {
-        // read in the source
-        final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_AccumulateModifyMVEL.drl" ) );
-        final RuleBase ruleBase = loadRuleBase( reader );
-
-        final WorkingMemory wm = ruleBase.newStatefulSession();
-        final List results = new ArrayList();
-
-        wm.setGlobal( "results",
-                      results );
-
-        final Cheese[] cheese = new Cheese[]{new Cheese( "stilton",
-                                                         10 ), new Cheese( "stilton",
-                                                                           2 ), new Cheese( "stilton",
-                                                                                            5 ), new Cheese( "brie",
-                                                                                                             15 ), new Cheese( "brie",
-                                                                                                                               16 ), new Cheese( "provolone",
-                                                                                                                                                 8 )};
-        final Person bob = new Person( "Bob",
-                                       "stilton" );
-
-        final FactHandle[] cheeseHandles = new FactHandle[cheese.length];
-        for ( int i = 0; i < cheese.length; i++ ) {
-            cheeseHandles[i] = wm.insert( cheese[i] );
-        }
-        final FactHandle bobHandle = wm.insert( bob );
-
-        // ---------------- 1st scenario
-        wm.fireAllRules();
-        // no fire, as per rule constraints
-        Assert.assertEquals( 0,
-                             results.size() );
-
-        // ---------------- 2nd scenario
-        final int index = 1;
-        cheese[index].setPrice( 9 );
-        wm.update( cheeseHandles[index],
-                         cheese[index] );
-        wm.fireAllRules();
-
-        // 1 fire
-        Assert.assertEquals( 1,
-                             results.size() );
-        Assert.assertEquals( 24,
-                             ((Cheesery) results.get( results.size() - 1 )).getTotalAmount() );
-
-        // ---------------- 3rd scenario
-        bob.setLikes( "brie" );
-        wm.update( bobHandle,
-                         bob );
-        wm.fireAllRules();
-
-        // 2 fires
-        Assert.assertEquals( 2,
-                             results.size() );
-        Assert.assertEquals( 31,
-                             ((Cheesery) results.get( results.size() - 1 )).getTotalAmount() );
-
-        // ---------------- 4th scenario
-        wm.retract( cheeseHandles[3] );
-        wm.fireAllRules();
-
-        // should not have fired as per constraint
-        Assert.assertEquals( 2,
-                             results.size() );
-
-    }
-
-    public void xxxtestAccumulateReverseModify() throws Exception {
-        // read in the source
-        final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_AccumulateReverseModify.drl" ) );
-        final RuleBase ruleBase = loadRuleBase( reader );
-
-        final WorkingMemory wm = ruleBase.newStatefulSession();
-        final List results = new ArrayList();
-
-        wm.setGlobal( "results",
-                      results );
-
-        final Cheese[] cheese = new Cheese[]{new Cheese( "stilton",
-                                                         10 ), new Cheese( "stilton",
-                                                                           2 ), new Cheese( "stilton",
-                                                                                            5 ), new Cheese( "brie",
-                                                                                                             15 ), new Cheese( "brie",
-                                                                                                                               16 ), new Cheese( "provolone",
-                                                                                                                                                 8 )};
-        final Person bob = new Person( "Bob",
-                                       "stilton" );
-
-        final FactHandle[] cheeseHandles = new FactHandle[cheese.length];
-        for ( int i = 0; i < cheese.length; i++ ) {
-            cheeseHandles[i] = wm.insert( cheese[i] );
-        }
-        final FactHandle bobHandle = wm.insert( bob );
-
-        // ---------------- 1st scenario
-        wm.fireAllRules();
-        // no fire, as per rule constraints
-        Assert.assertEquals( 0,
-                             results.size() );
-
-        // ---------------- 2nd scenario
-        final int index = 1;
-        cheese[index].setPrice( 9 );
-        wm.update( cheeseHandles[index],
-                         cheese[index] );
-        wm.fireAllRules();
-
-        // 1 fire
-        Assert.assertEquals( 1,
-                             results.size() );
-        Assert.assertEquals( 24,
-                             ((Cheesery) results.get( results.size() - 1 )).getTotalAmount() );
-
-        // ---------------- 3rd scenario
-        bob.setLikes( "brie" );
-        wm.update( bobHandle,
-                         bob );
-        wm.fireAllRules();
-
-        // 2 fires
-        Assert.assertEquals( 2,
-                             results.size() );
-        Assert.assertEquals( 31,
-                             ((Cheesery) results.get( results.size() - 1 )).getTotalAmount() );
-
-        // ---------------- 4th scenario
-        wm.retract( cheeseHandles[3] );
-        wm.fireAllRules();
-
-        // should not have fired as per constraint
-        Assert.assertEquals( 2,
-                             results.size() );
-
-    }
-
-    public void xxxtestAccumulateReverseModifyMVEL() throws Exception {
-        // read in the source
-        final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_AccumulateReverseModifyMVEL.drl" ) );
-        final RuleBase ruleBase = loadRuleBase( reader );
-
-        final WorkingMemory wm = ruleBase.newStatefulSession();
-        final List results = new ArrayList();
-
-        wm.setGlobal( "results",
-                      results );
-
-        final Cheese[] cheese = new Cheese[]{new Cheese( "stilton",
-                                                         10 ), new Cheese( "stilton",
-                                                                           2 ), new Cheese( "stilton",
-                                                                                            5 ), new Cheese( "brie",
-                                                                                                             15 ), new Cheese( "brie",
-                                                                                                                               16 ), new Cheese( "provolone",
-                                                                                                                                                 8 )};
-        final Person bob = new Person( "Bob",
-                                       "stilton" );
-
-        final FactHandle[] cheeseHandles = new FactHandle[cheese.length];
-        for ( int i = 0; i < cheese.length; i++ ) {
-            cheeseHandles[i] = wm.insert( cheese[i] );
-        }
-        final FactHandle bobHandle = wm.insert( bob );
-
-        // ---------------- 1st scenario
-        wm.fireAllRules();
-        // no fire, as per rule constraints
-        Assert.assertEquals( 0,
-                             results.size() );
-
-        // ---------------- 2nd scenario
-        final int index = 1;
-        cheese[index].setPrice( 9 );
-        wm.update( cheeseHandles[index],
-                         cheese[index] );
-        wm.fireAllRules();
-
-        // 1 fire
-        Assert.assertEquals( 1,
-                             results.size() );
-        Assert.assertEquals( 24,
-                             ((Cheesery) results.get( results.size() - 1 )).getTotalAmount() );
-
-        // ---------------- 3rd scenario
-        bob.setLikes( "brie" );
-        wm.update( bobHandle,
-                         bob );
-        wm.fireAllRules();
-
-        // 2 fires
-        Assert.assertEquals( 2,
-                             results.size() );
-        Assert.assertEquals( 31,
-                             ((Cheesery) results.get( results.size() - 1 )).getTotalAmount() );
-
-        // ---------------- 4th scenario
-        wm.retract( cheeseHandles[3] );
-        wm.fireAllRules();
-
-        // should not have fired as per constraint
-        Assert.assertEquals( 2,
-                             results.size() );
-
-    }
-
-    public void testAccumulateExternalFunction() throws Exception {
-        // read in the source
-        final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_AccumulateExternalFunction.drl" ) );
-        final RuleBase ruleBase = loadRuleBase( reader );
-
-        final WorkingMemory wm = ruleBase.newStatefulSession();
-        final List results = new ArrayList();
-
-        wm.setGlobal( "results",
-                      results );
-
-        final Cheese[] cheese = new Cheese[]{new Cheese( "stilton",
-                                                         10 ), new Cheese( "stilton",
-                                                                           2 ), new Cheese( "stilton",
-                                                                                            11 ), new Cheese( "brie",
-                                                                                                             15 ), new Cheese( "brie",
-                                                                                                                               17 ), new Cheese( "provolone",
-                                                                                                                                                 8 )};
-        final Person bob = new Person( "Bob",
-                                       "stilton" );
-
-        final FactHandle[] cheeseHandles = new FactHandle[cheese.length];
-        for ( int i = 0; i < cheese.length; i++ ) {
-            cheeseHandles[i] = wm.insert( cheese[i] );
-        }
-        final FactHandle bobHandle = wm.insert( bob );
-
-        // ---------------- 1st scenario
-        wm.fireAllRules();
-        // no fire, as per rule constraints
-        Assert.assertEquals( 0,
-                             results.size() );
-
-        // ---------------- 2nd scenario
-        final int index = 1;
-        cheese[index].setPrice( 9 );
-        wm.update( cheeseHandles[index],
-                         cheese[index] );
-        wm.fireAllRules();
-
-        // 1 fire
-        Assert.assertEquals( 1,
-                             results.size() );
-        Assert.assertEquals( 10,
-                             ((Number) results.get( results.size() - 1 )).intValue() );
-
-        // ---------------- 3rd scenario
-        bob.setLikes( "brie" );
-        wm.update( bobHandle,
-                         bob );
-        wm.fireAllRules();
-
-        // 2 fires
-        Assert.assertEquals( 2,
-                             results.size() );
-        Assert.assertEquals( 16,
-                             ((Number) results.get( results.size() - 1 )).intValue() );
-
-        // ---------------- 4th scenario
-        wm.retract( cheeseHandles[3] );
-        wm.retract( cheeseHandles[4] );
-        wm.fireAllRules();
-
-        // should not have fired as per constraint
-        Assert.assertEquals( 2,
-                             results.size() );
-
-    }
 }

Copied: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_AccumulateAverage.drl (from rev 12773, labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_AccumulateExternalFunction.drl)
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_AccumulateAverage.drl	                        (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_AccumulateAverage.drl	2007-06-22 15:03:43 UTC (rev 12774)
@@ -0,0 +1,16 @@
+package org.drools.test;
+
+import org.drools.Cheese;
+import org.drools.Person;
+
+global java.util.List results;
+
+rule "External Function" salience 80
+    when
+        $person : Person( $likes : likes )
+    	$avg    : Number( intValue >= 10 ) 
+    	                       from accumulate( $cheese : Cheese( type == $likes, $price : price ),
+                                                average( $price ) );
+    then
+        results.add( $avg );
+end  

Added: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_AccumulateCount.drl
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_AccumulateCount.drl	                        (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_AccumulateCount.drl	2007-06-22 15:03:43 UTC (rev 12774)
@@ -0,0 +1,16 @@
+package org.drools.test;
+
+import org.drools.Cheese;
+import org.drools.Person;
+
+global java.util.List results;
+
+rule "External Function" salience 80
+    when
+        $person : Person( $likes : likes )
+    	$count  : Number( intValue >= 2 ) 
+    	                       from accumulate( $cheese : Cheese( type == $likes  ),
+                                                count( $cheese ) );
+    then
+        results.add( $count );
+end  


Property changes on: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_AccumulateCount.drl
___________________________________________________________________
Name: svn:executable
   + *

Deleted: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_AccumulateExternalFunction.drl
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_AccumulateExternalFunction.drl	2007-06-22 07:41:16 UTC (rev 12773)
+++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_AccumulateExternalFunction.drl	2007-06-22 15:03:43 UTC (rev 12774)
@@ -1,16 +0,0 @@
-package org.drools.test;
-
-import org.drools.Cheese;
-import org.drools.Person;
-
-global java.util.List results;
-
-rule "External Function" salience 80
-    when
-        $person : Person( $likes : likes )
-    	$avg    : Number( intValue >= 10 ) 
-    	                       from accumulate( $cheese : Cheese( type == $likes, $price : price ),
-                                                average( $price ) );
-    then
-        results.add( $avg );
-end  

Added: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_AccumulateMax.drl
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_AccumulateMax.drl	                        (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_AccumulateMax.drl	2007-06-22 15:03:43 UTC (rev 12774)
@@ -0,0 +1,16 @@
+package org.drools.test;
+
+import org.drools.Cheese;
+import org.drools.Person;
+
+global java.util.List results;
+
+rule "External Function" salience 80
+    when
+        $person : Person( $likes : likes )
+    	$max    : Number( intValue >= 5 ) 
+    	                       from accumulate( $cheese : Cheese( type == $likes, $price : price ),
+                                                max( $price ) );
+    then
+        results.add( $max );
+end  


Property changes on: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_AccumulateMax.drl
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_AccumulateMin.drl
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_AccumulateMin.drl	                        (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_AccumulateMin.drl	2007-06-22 15:03:43 UTC (rev 12774)
@@ -0,0 +1,16 @@
+package org.drools.test;
+
+import org.drools.Cheese;
+import org.drools.Person;
+
+global java.util.List results;
+
+rule "External Function" salience 80
+    when
+        $person : Person( $likes : likes )
+    	$min    : Number( intValue <= 5 ) 
+    	                       from accumulate( $cheese : Cheese( type == $likes, $price : price ),
+                                                min( $price ) );
+    then
+        results.add( $min );
+end  


Property changes on: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_AccumulateMin.drl
___________________________________________________________________
Name: svn:executable
   + *

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/asm/ClassReader.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/asm/ClassReader.java	2007-06-22 07:41:16 UTC (rev 12773)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/asm/ClassReader.java	2007-06-22 15:03:43 UTC (rev 12774)
@@ -1217,7 +1217,7 @@
                     mv.visitAttribute( cattrs );
                     cattrs = attr;
                 }
-                // visits the max stack and max locals values
+                // visits the min stack and min locals values
                 mv.visitMaxs( maxStack,
                               maxLocals );
             }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/asm/MethodVisitor.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/asm/MethodVisitor.java	2007-06-22 07:41:16 UTC (rev 12773)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/asm/MethodVisitor.java	2007-06-22 15:03:43 UTC (rev 12774)
@@ -248,7 +248,7 @@
      * Visits a TABLESWITCH instruction.
      * 
      * @param min the minimum key value.
-     * @param max the maximum key value.
+     * @param min the maximum key value.
      * @param dflt beginning of the default handler block.
      * @param labels beginnings of the handler blocks. <tt>labels[i]</tt> is
      *        the beginning of the handler block for the <tt>min + i</tt> key.
@@ -281,7 +281,7 @@
 
     // -------------------------------------------------------------------------
     // Exceptions table entries, debug information,
-    // max stack size and max locals
+    // min stack size and min locals
     // -------------------------------------------------------------------------
 
     /**

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/asm/MethodWriter.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/asm/MethodWriter.java	2007-06-22 07:41:16 UTC (rev 12773)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/asm/MethodWriter.java	2007-06-22 15:03:43 UTC (rev 12774)
@@ -625,7 +625,7 @@
 
     public void visitInsn(final int opcode) {
         if ( this.computeMaxs ) {
-            // updates current and max stack sizes
+            // updates current and min stack sizes
             final int size = this.stackSize + MethodWriter.SIZE[opcode];
             if ( size > this.maxStackSize ) {
                 this.maxStackSize = size;
@@ -646,7 +646,7 @@
     public void visitIntInsn(final int opcode,
                              final int operand) {
         if ( this.computeMaxs && opcode != Opcodes.NEWARRAY ) {
-            // updates current and max stack sizes only if opcode == NEWARRAY
+            // updates current and min stack sizes only if opcode == NEWARRAY
             // (stack size variation = 0 for BIPUSH or SIPUSH)
             final int size = this.stackSize + 1;
             if ( size > this.maxStackSize ) {
@@ -667,7 +667,7 @@
     public void visitVarInsn(final int opcode,
                              final int var) {
         if ( this.computeMaxs ) {
-            // updates current and max stack sizes
+            // updates current and min stack sizes
             if ( opcode == Opcodes.RET ) {
                 // no stack change, but end of current block (no successor)
                 if ( this.currentBlock != null ) {
@@ -681,7 +681,7 @@
                 }
                 this.stackSize = size;
             }
-            // updates max locals
+            // updates min locals
             int n;
             if ( opcode == Opcodes.LLOAD || opcode == Opcodes.DLOAD || opcode == Opcodes.LSTORE || opcode == Opcodes.DSTORE ) {
                 n = var + 2;
@@ -715,7 +715,7 @@
     public void visitTypeInsn(final int opcode,
                               final String desc) {
         if ( this.computeMaxs && opcode == Opcodes.NEW ) {
-            // updates current and max stack sizes only if opcode == NEW
+            // updates current and min stack sizes only if opcode == NEW
             // (stack size variation = 0 for ANEWARRAY, CHECKCAST, INSTANCEOF)
             final int size = this.stackSize + 1;
             if ( size > this.maxStackSize ) {
@@ -751,7 +751,7 @@
                     size = this.stackSize + (c == 'D' || c == 'J' ? -3 : -2);
                     break;
             }
-            // updates current and max stack sizes
+            // updates current and min stack sizes
             if ( size > this.maxStackSize ) {
                 this.maxStackSize = size;
             }
@@ -796,7 +796,7 @@
             } else {
                 size = this.stackSize - (argSize >> 2) + (argSize & 0x03);
             }
-            // updates current and max stack sizes
+            // updates current and min stack sizes
             if ( size > this.maxStackSize ) {
                 this.maxStackSize = size;
             }
@@ -837,7 +837,7 @@
                                   label );
                 }
             } else {
-                // updates current stack size (max stack size unchanged because
+                // updates current stack size (min stack size unchanged because
                 // stack size variation always negative in this case)
                 this.stackSize += MethodWriter.SIZE[opcode];
                 if ( this.currentBlock != null ) {
@@ -892,7 +892,7 @@
                               label );
             }
             // begins a new current block,
-            // resets the relative current and max stack sizes
+            // resets the relative current and min stack sizes
             this.currentBlock = label;
             this.stackSize = 0;
             this.maxStackSize = 0;
@@ -913,7 +913,7 @@
             } else {
                 size = this.stackSize + 1;
             }
-            // updates current and max stack sizes
+            // updates current and min stack sizes
             if ( size > this.maxStackSize ) {
                 this.maxStackSize = size;
             }
@@ -936,7 +936,7 @@
     public void visitIincInsn(final int var,
                               final int increment) {
         if ( this.computeMaxs ) {
-            // updates max locals only (no stack change)
+            // updates min locals only (no stack change)
             final int n = var + 1;
             if ( n > this.maxLocals ) {
                 this.maxLocals = n;
@@ -957,7 +957,7 @@
                                      final Label dflt,
                                      final Label labels[]) {
         if ( this.computeMaxs ) {
-            // updates current stack size (max stack size unchanged)
+            // updates current stack size (min stack size unchanged)
             --this.stackSize;
             // ends current block (with many new successors)
             if ( this.currentBlock != null ) {
@@ -994,7 +994,7 @@
                                       final int keys[],
                                       final Label labels[]) {
         if ( this.computeMaxs ) {
-            // updates current stack size (max stack size unchanged)
+            // updates current stack size (min stack size unchanged)
             --this.stackSize;
             // ends current block (with many new successors)
             if ( this.currentBlock != null ) {
@@ -1031,7 +1031,7 @@
     public void visitMultiANewArrayInsn(final String desc,
                                         final int dims) {
         if ( this.computeMaxs ) {
-            // updates current stack size (max stack size unchanged because
+            // updates current stack size (min stack size unchanged because
             // stack size variation always negative or null)
             this.stackSize += 1 - dims;
         }
@@ -1101,11 +1101,11 @@
     public void visitMaxs(final int maxStack,
                           final int maxLocals) {
         if ( this.computeMaxs ) {
-            // true (non relative) max stack size
+            // true (non relative) min stack size
             int max = 0;
             /*
              * control flow analysis algorithm: while the block stack is not
-             * empty, pop a block from this stack, update the max stack size,
+             * empty, pop a block from this stack, update the min stack size,
              * compute the true (non relative) begin stack size of the
              * successors of this block, and push these successors onto the
              * stack (unless they have already been pushed onto the stack).
@@ -1118,10 +1118,10 @@
                 // pops a block from the stack
                 Label l = stack;
                 stack = stack.next;
-                // computes the true (non relative) max stack size of this block
+                // computes the true (non relative) min stack size of this block
                 final int start = l.beginStackSize;
                 final int blockMax = start + l.maxStackSize;
-                // updates the global max stack size
+                // updates the global min stack size
                 if ( blockMax > max ) {
                     max = blockMax;
                 }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/asm/util/CheckMethodAdapter.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/asm/util/CheckMethodAdapter.java	2007-06-22 07:41:16 UTC (rev 12773)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/asm/util/CheckMethodAdapter.java	2007-06-22 15:03:43 UTC (rev 12774)
@@ -517,7 +517,7 @@
                     false,
                     "default label" );
         if ( labels == null || labels.length != max - min + 1 ) {
-            throw new IllegalArgumentException( "There must be max - min + 1 labels" );
+            throw new IllegalArgumentException( "There must be min - min + 1 labels" );
         }
         for ( int i = 0; i < labels.length; ++i ) {
             checkLabel( labels[i],
@@ -638,9 +638,9 @@
         checkEndCode();
         this.endCode = true;
         checkUnsignedShort( maxStack,
-                            "Invalid max stack" );
+                            "Invalid min stack" );
         checkUnsignedShort( maxLocals,
-                            "Invalid max locals" );
+                            "Invalid min locals" );
         this.mv.visitMaxs( maxStack,
                            maxLocals );
     }

Copied: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/AverageAccumulateFunction.java (from rev 12773, labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/AverageAccumulator.java)
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/AverageAccumulateFunction.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/AverageAccumulateFunction.java	2007-06-22 15:03:43 UTC (rev 12774)
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2007 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 Jun 21, 2007
+ */
+package org.drools.base.accumulators;
+
+
+/**
+ * An implementation of an accumulator capable of calculating average values
+ * 
+ * @author etirelli
+ *
+ */
+public class AverageAccumulateFunction implements AccumulateFunction {
+
+    protected static class AverageData {
+        public int    count = 0;
+        public double total = 0;
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.base.accumulators.AccumulateFunction#createContext()
+     */
+    public Object createContext() {
+        return new AverageData();
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.base.accumulators.AccumulateFunction#init(java.lang.Object)
+     */
+    public void init(Object context) throws Exception {
+        AverageData data = (AverageData) context;
+        data.count = 0;
+        data.total = 0;
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.base.accumulators.AccumulateFunction#accumulate(java.lang.Object, java.lang.Object)
+     */
+    public void accumulate(Object context,
+                           Object value) {
+        AverageData data = (AverageData) context;
+        data.count++;
+        data.total += ((Number) value).doubleValue();
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.base.accumulators.AccumulateFunction#reverse(java.lang.Object, java.lang.Object)
+     */
+    public void reverse(Object context,
+                        Object value) throws Exception {
+        AverageData data = (AverageData) context;
+        data.count--;
+        data.total -= ((Number) value).doubleValue();
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.base.accumulators.AccumulateFunction#getResult(java.lang.Object)
+     */
+    public Object getResult(Object context) throws Exception {
+        AverageData data = (AverageData) context;
+        return new Double( data.count == 0 ? 0 : data.total / data.count );
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.base.accumulators.AccumulateFunction#supportsReverse()
+     */
+    public boolean supportsReverse() {
+        return true;
+    }
+
+}

Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/AverageAccumulator.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/AverageAccumulator.java	2007-06-22 07:41:16 UTC (rev 12773)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/AverageAccumulator.java	2007-06-22 15:03:43 UTC (rev 12774)
@@ -1,85 +0,0 @@
-/*
- * Copyright 2007 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 Jun 21, 2007
- */
-package org.drools.base.accumulators;
-
-
-/**
- * An implementation of an accumulator capable of calculating average values
- * 
- * @author etirelli
- *
- */
-public class AverageAccumulator implements AccumulateFunction {
-
-    protected static class AverageData {
-        public int    count = 0;
-        public double total = 0;
-    }
-
-    /* (non-Javadoc)
-     * @see org.drools.base.accumulators.AccumulateFunction#createContext()
-     */
-    public Object createContext() {
-        return new AverageData();
-    }
-
-    /* (non-Javadoc)
-     * @see org.drools.base.accumulators.AccumulateFunction#init(java.lang.Object)
-     */
-    public void init(Object context) throws Exception {
-        AverageData data = (AverageData) context;
-        data.count = 0;
-        data.total = 0;
-    }
-
-    /* (non-Javadoc)
-     * @see org.drools.base.accumulators.AccumulateFunction#accumulate(java.lang.Object, java.lang.Object)
-     */
-    public void accumulate(Object context,
-                           Object value) {
-        AverageData data = (AverageData) context;
-        data.count++;
-        data.total += ((Number) value).doubleValue();
-    }
-
-    /* (non-Javadoc)
-     * @see org.drools.base.accumulators.AccumulateFunction#reverse(java.lang.Object, java.lang.Object)
-     */
-    public void reverse(Object context,
-                        Object value) throws Exception {
-        AverageData data = (AverageData) context;
-        data.count--;
-        data.total -= ((Number) value).doubleValue();
-    }
-
-    /* (non-Javadoc)
-     * @see org.drools.base.accumulators.AccumulateFunction#getResult(java.lang.Object)
-     */
-    public Object getResult(Object context) throws Exception {
-        AverageData data = (AverageData) context;
-        return new Double( data.count == 0 ? 0 : data.total / data.count );
-    }
-
-    /* (non-Javadoc)
-     * @see org.drools.base.accumulators.AccumulateFunction#supportsReverse()
-     */
-    public boolean supportsReverse() {
-        return true;
-    }
-
-}

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/CountAccumulateFunction.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/CountAccumulateFunction.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/CountAccumulateFunction.java	2007-06-22 15:03:43 UTC (rev 12774)
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2007 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 Jun 21, 2007
+ */
+package org.drools.base.accumulators;
+
+
+/**
+ * An implementation of an accumulator capable of counting occurences
+ * 
+ * @author etirelli
+ *
+ */
+public class CountAccumulateFunction implements AccumulateFunction {
+
+    protected static class CountData {
+        public long   count = 0;
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.base.accumulators.AccumulateFunction#createContext()
+     */
+    public Object createContext() {
+        return new CountData();
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.base.accumulators.AccumulateFunction#init(java.lang.Object)
+     */
+    public void init(Object context) throws Exception {
+        CountData data = (CountData) context;
+        data.count = 0;
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.base.accumulators.AccumulateFunction#accumulate(java.lang.Object, java.lang.Object)
+     */
+    public void accumulate(Object context,
+                           Object value) {
+        CountData data = (CountData) context;
+        data.count++;
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.base.accumulators.AccumulateFunction#reverse(java.lang.Object, java.lang.Object)
+     */
+    public void reverse(Object context,
+                        Object value) throws Exception {
+        CountData data = (CountData) context;
+        data.count--;
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.base.accumulators.AccumulateFunction#getResult(java.lang.Object)
+     */
+    public Object getResult(Object context) throws Exception {
+        CountData data = (CountData) context;
+        return new Long( data.count );
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.base.accumulators.AccumulateFunction#supportsReverse()
+     */
+    public boolean supportsReverse() {
+        return true;
+    }
+
+}

Copied: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/MaxAccumulateFunction.java (from rev 12773, labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/MaxAccumulator.java)
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/MaxAccumulateFunction.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/MaxAccumulateFunction.java	2007-06-22 15:03:43 UTC (rev 12774)
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2007 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 Jun 21, 2007
+ */
+package org.drools.base.accumulators;
+
+
+/**
+ * An implementation of an accumulator capable of calculating maximum values
+ * 
+ * @author etirelli
+ *
+ */
+public class MaxAccumulateFunction implements AccumulateFunction {
+
+    protected static class MaxData {
+        public double max = Double.MIN_VALUE;
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.base.accumulators.AccumulateFunction#createContext()
+     */
+    public Object createContext() {
+        return new MaxData();
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.base.accumulators.AccumulateFunction#init(java.lang.Object)
+     */
+    public void init(Object context) throws Exception {
+        MaxData data = (MaxData) context;
+        data.max = Double.MIN_VALUE;
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.base.accumulators.AccumulateFunction#accumulate(java.lang.Object, java.lang.Object)
+     */
+    public void accumulate(Object context,
+                           Object value) {
+        MaxData data = (MaxData) context;
+        data.max = Math.max( data.max, ((Number)value).doubleValue() );
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.base.accumulators.AccumulateFunction#reverse(java.lang.Object, java.lang.Object)
+     */
+    public void reverse(Object context,
+                        Object value) throws Exception {
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.base.accumulators.AccumulateFunction#getResult(java.lang.Object)
+     */
+    public Object getResult(Object context) throws Exception {
+        MaxData data = (MaxData) context;
+        return new Double( data.max );
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.base.accumulators.AccumulateFunction#supportsReverse()
+     */
+    public boolean supportsReverse() {
+        return false;
+    }
+
+}

Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/MaxAccumulator.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/MaxAccumulator.java	2007-06-22 07:41:16 UTC (rev 12773)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/MaxAccumulator.java	2007-06-22 15:03:43 UTC (rev 12774)
@@ -1,79 +0,0 @@
-/*
- * Copyright 2007 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 Jun 21, 2007
- */
-package org.drools.base.accumulators;
-
-
-/**
- * An implementation of an accumulator capable of calculating average values
- * 
- * @author etirelli
- *
- */
-public class MaxAccumulator implements AccumulateFunction {
-
-    protected static class MaxData {
-        public double max = Double.MIN_VALUE;
-    }
-
-    /* (non-Javadoc)
-     * @see org.drools.base.accumulators.AccumulateFunction#createContext()
-     */
-    public Object createContext() {
-        return new MaxData();
-    }
-
-    /* (non-Javadoc)
-     * @see org.drools.base.accumulators.AccumulateFunction#init(java.lang.Object)
-     */
-    public void init(Object context) throws Exception {
-        MaxData data = (MaxData) context;
-        data.max = 0;
-    }
-
-    /* (non-Javadoc)
-     * @see org.drools.base.accumulators.AccumulateFunction#accumulate(java.lang.Object, java.lang.Object)
-     */
-    public void accumulate(Object context,
-                           Object value) {
-        MaxData data = (MaxData) context;
-        data.max = Math.max( data.max, ((Number)value).doubleValue() );
-    }
-
-    /* (non-Javadoc)
-     * @see org.drools.base.accumulators.AccumulateFunction#reverse(java.lang.Object, java.lang.Object)
-     */
-    public void reverse(Object context,
-                        Object value) throws Exception {
-    }
-
-    /* (non-Javadoc)
-     * @see org.drools.base.accumulators.AccumulateFunction#getResult(java.lang.Object)
-     */
-    public Object getResult(Object context) throws Exception {
-        MaxData data = (MaxData) context;
-        return new Double( data.max );
-    }
-
-    /* (non-Javadoc)
-     * @see org.drools.base.accumulators.AccumulateFunction#supportsReverse()
-     */
-    public boolean supportsReverse() {
-        return false;
-    }
-
-}

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/MinAccumulateFunction.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/MinAccumulateFunction.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/MinAccumulateFunction.java	2007-06-22 15:03:43 UTC (rev 12774)
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2007 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 Jun 21, 2007
+ */
+package org.drools.base.accumulators;
+
+
+/**
+ * An implementation of an accumulator capable of calculating minimun values
+ * 
+ * @author etirelli
+ *
+ */
+public class MinAccumulateFunction implements AccumulateFunction {
+
+    protected static class MaxData {
+        public double min = Double.MAX_VALUE;
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.base.accumulators.AccumulateFunction#createContext()
+     */
+    public Object createContext() {
+        return new MaxData();
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.base.accumulators.AccumulateFunction#init(java.lang.Object)
+     */
+    public void init(Object context) throws Exception {
+        MaxData data = (MaxData) context;
+        data.min = Double.MAX_VALUE;
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.base.accumulators.AccumulateFunction#accumulate(java.lang.Object, java.lang.Object)
+     */
+    public void accumulate(Object context,
+                           Object value) {
+        MaxData data = (MaxData) context;
+        data.min = Math.min( data.min, ((Number)value).doubleValue() );
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.base.accumulators.AccumulateFunction#reverse(java.lang.Object, java.lang.Object)
+     */
+    public void reverse(Object context,
+                        Object value) throws Exception {
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.base.accumulators.AccumulateFunction#getResult(java.lang.Object)
+     */
+    public Object getResult(Object context) throws Exception {
+        MaxData data = (MaxData) context;
+        return new Double( data.min );
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.base.accumulators.AccumulateFunction#supportsReverse()
+     */
+    public boolean supportsReverse() {
+        return false;
+    }
+
+}

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/SumAccumulateFunction.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/SumAccumulateFunction.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/SumAccumulateFunction.java	2007-06-22 15:03:43 UTC (rev 12774)
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2007 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 Jun 21, 2007
+ */
+package org.drools.base.accumulators;
+
+
+/**
+ * An implementation of an accumulator capable of calculating sum of values
+ * 
+ * @author etirelli
+ *
+ */
+public class SumAccumulateFunction implements AccumulateFunction {
+
+    protected static class SumData {
+        public double total = 0;
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.base.accumulators.AccumulateFunction#createContext()
+     */
+    public Object createContext() {
+        return new SumData();
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.base.accumulators.AccumulateFunction#init(java.lang.Object)
+     */
+    public void init(Object context) throws Exception {
+        SumData data = (SumData) context;
+        data.total = 0;
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.base.accumulators.AccumulateFunction#accumulate(java.lang.Object, java.lang.Object)
+     */
+    public void accumulate(Object context,
+                           Object value) {
+        SumData data = (SumData) context;
+        data.total += ((Number) value).doubleValue();
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.base.accumulators.AccumulateFunction#reverse(java.lang.Object, java.lang.Object)
+     */
+    public void reverse(Object context,
+                        Object value) throws Exception {
+        SumData data = (SumData) context;
+        data.total -= ((Number) value).doubleValue();
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.base.accumulators.AccumulateFunction#getResult(java.lang.Object)
+     */
+    public Object getResult(Object context) throws Exception {
+        SumData data = (SumData) context;
+        return new Double( data.total );
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.base.accumulators.AccumulateFunction#supportsReverse()
+     */
+    public boolean supportsReverse() {
+        return true;
+    }
+
+}

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/StringUtils.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/StringUtils.java	2007-06-22 07:41:16 UTC (rev 12773)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/StringUtils.java	2007-06-22 15:03:43 UTC (rev 12774)
@@ -372,8 +372,8 @@
      * <p>A <code>null</code> input String returns <code>null</code>.
      * A <code>null</code> separatorChars splits on whitespace.</p>
      *
-     * <p>If more than <code>max</code> delimited substrings are found, the last
-     * returned string includes all characters after the first <code>max - 1</code>
+     * <p>If more than <code>min</code> delimited substrings are found, the last
+     * returned string includes all characters after the first <code>min - 1</code>
      * returned strings (including separator characters).</p>
      *
      * <pre>
@@ -388,7 +388,7 @@
      * @param str  the String to parse, may be null
      * @param separatorChars  the characters used as the delimiters,
      *  <code>null</code> splits on whitespace
-     * @param max  the maximum number of elements to include in the
+     * @param min  the maximum number of elements to include in the
      *  array. A zero or negative value implies no limit
      * @return an array of parsed Strings, <code>null</code> if null String input
      */
@@ -576,8 +576,8 @@
      * <p>A <code>null</code> input String returns <code>null</code>.
      * A <code>null</code> separatorChars splits on whitespace.</p>
      *
-     * <p>If more than <code>max</code> delimited substrings are found, the last
-     * returned string includes all characters after the first <code>max - 1</code>
+     * <p>If more than <code>min</code> delimited substrings are found, the last
+     * returned string includes all characters after the first <code>min - 1</code>
      * returned strings (including separator characters).</p>
      *
      * <pre>
@@ -595,7 +595,7 @@
      * @param str  the String to parse, may be <code>null</code>
      * @param separatorChars  the characters used as the delimiters,
      *  <code>null</code> splits on whitespace
-     * @param max  the maximum number of elements to include in the
+     * @param min  the maximum number of elements to include in the
      *  array. A zero or negative value implies no limit
      * @return an array of parsed Strings, <code>null</code> if null String input
      * @since 2.1
@@ -616,7 +616,7 @@
      *
      * @param str  the String to parse, may be <code>null</code>
      * @param separatorChars the separate character
-     * @param max  the maximum number of elements to include in the
+     * @param min  the maximum number of elements to include in the
      *  array. A zero or negative value implies no limit.
      * @param preserveAllTokens if <code>true</code>, adjacent separators are
      * treated as empty token separators; if <code>false</code>, adjacent




More information about the jboss-svn-commits mailing list