[jboss-svn-commits] JBL Code SVN: r24146 - in labs/jbossrules/trunk/drools-core/src: test/java/org/drools/base and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Nov 28 19:12:54 EST 2008


Author: tirelli
Date: 2008-11-28 19:12:54 -0500 (Fri, 28 Nov 2008)
New Revision: 24146

Modified:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/AfterEvaluatorDefinition.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/BeforeEvaluatorDefinition.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/CoincidesEvaluatorDefinition.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/DuringEvaluatorDefinition.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/FinishesEvaluatorDefinition.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/IncludesEvaluatorDefinition.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/TemporalEvaluatorFactoryTest.java
Log:
JBRULES-1873: fixing and documenting operators

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/AfterEvaluatorDefinition.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/AfterEvaluatorDefinition.java	2008-11-28 23:28:41 UTC (rev 24145)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/AfterEvaluatorDefinition.java	2008-11-29 00:12:54 UTC (rev 24146)
@@ -198,7 +198,7 @@
         public AfterEvaluator(final ValueType type,
                               final boolean isNegated,
                               final Long[] parameters,
-                              final String paramText ) {
+                              final String paramText) {
             super( type,
                    isNegated ? NOT_AFTER : AFTER );
             this.paramText = paramText;
@@ -210,12 +210,14 @@
             super.readExternal( in );
             initRange = in.readLong();
             finalRange = in.readLong();
+            paramText = (String) in.readObject();
         }
 
         public void writeExternal(ObjectOutput out) throws IOException {
             super.writeExternal( out );
             out.writeLong( initRange );
             out.writeLong( finalRange );
+            out.writeObject( paramText );
         }
 
         @Override
@@ -326,14 +328,13 @@
          *
          * @param parameters
          */
-        private void setParameters( Long[] parameters ) {
+        private void setParameters(Long[] parameters) {
             if ( parameters == null || parameters.length == 0 ) {
                 // open bounded range
                 this.initRange = 1;
                 this.finalRange = Long.MAX_VALUE;
-                return;
-            } else if( parameters.length == 1 ) {
-                if( parameters[0].longValue() >= 0 ) {
+            } else if ( parameters.length == 1 ) {
+                if ( parameters[0].longValue() >= 0 ) {
                     // up to that value
                     this.initRange = 1;
                     this.finalRange = parameters[0].longValue();
@@ -342,8 +343,8 @@
                     this.initRange = parameters[0].longValue();
                     this.finalRange = -1;
                 }
-            } else if( parameters.length == 2 ) {
-                if( parameters[0].longValue() <= parameters[1].longValue() ) {
+            } else if ( parameters.length == 2 ) {
+                if ( parameters[0].longValue() <= parameters[1].longValue() ) {
                     this.initRange = parameters[0].longValue();
                     this.finalRange = parameters[1].longValue();
                 } else {

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/BeforeEvaluatorDefinition.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/BeforeEvaluatorDefinition.java	2008-11-28 23:28:41 UTC (rev 24145)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/BeforeEvaluatorDefinition.java	2008-11-29 00:12:54 UTC (rev 24146)
@@ -210,12 +210,14 @@
             super.readExternal( in );
             initRange = in.readLong();
             finalRange = in.readLong();
+            paramText = (String) in.readObject();
         }
 
         public void writeExternal(ObjectOutput out) throws IOException {
             super.writeExternal( out );
             out.writeLong( initRange );
             out.writeLong( finalRange );
+            out.writeObject( paramText );
         }
 
         @Override

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/CoincidesEvaluatorDefinition.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/CoincidesEvaluatorDefinition.java	2008-11-28 23:28:41 UTC (rev 24145)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/CoincidesEvaluatorDefinition.java	2008-11-29 00:12:54 UTC (rev 24146)
@@ -42,7 +42,7 @@
  * 
  * <p>The <b><code>coincides</code></b> evaluator correlates two events and matches when both
  * happen at the same time. Optionally, the evaluator accept thresholds for the distance between
- * events start and finish timestamps.</p> 
+ * events' start and finish timestamps.</p> 
  * 
  * <p>Lets look at an example:</p>
  * 
@@ -55,36 +55,21 @@
  * <p>Optionally, this operator accepts one or two parameters. These parameters are the thresholds
  * for the distance between matching timestamps. If only one paratemer is given, it is used for 
  * both start and end timestamps. If two parameters are given, then the first is used as a threshold
- * for the start timestamp and the second one is used as a parameter for the end timestamp.</p>
+ * for the start timestamp and the second one is used as a threshold for the end timestamp. In other
+ * words:</p>
  * 
- * ---------------------- NEED TO FINISH WRITING THE JAVADOC -----------------------------
+ * <pre> $eventA : EventA( this coincides[15s, 10s] $eventB ) </pre> 
  * 
- * <pre> 3m30s <= $eventA.startTimestamp - $eventB.endTimeStamp <= 4m </pre>
+ * Above pattern will match if and only if:
  * 
- * <p>The temporal distance interval for the <b><code>after</code></b> operator is optional:</p>
- * 
- * <ul><li>If two values are defined (like in the example bellow), the interval starts on the
- * first value and finishes on the second.</li>
- * <li>If only one value is defined, we have two cases. If the value is negative, then the interval
- * starts on the value and finishes on -1ms. If the value is positive, then the interval starts on 
- * +1ms and finishes on the value.</li>
- * <li>If no value is defined, it is assumed that the initial value is 1ms and the final value
- * is the positive infinity.</li></ul>
- * 
- * <p><b>NOTE:</b> it is allowed to define negative distances for this operator. Example:</p>
- * 
- * <pre>$eventA : EventA( this after[ -3m30s, -2m ] $eventB )</pre>
- *
- * <p><b>NOTE:</b> if the initial value is greater than the finish value, the engine automatically
- * reverse them, as there is no reason to have the initial value greater than the finish value. Example: 
- * the following two patterns are considered to have the same semantics:</p>
- * 
  * <pre>
- * $eventA : EventA( this after[ -3m30s, -2m ] $eventB )
- * $eventA : EventA( this after[ -2m, -3m30s ] $eventB )
+ * abs( $eventA.startTimestamp - $eventB.startTimestamp ) <= 15s &&
+ * abs( $eventA.endTimestamp - $eventB.endTimestamp ) <= 10s 
  * </pre>
  * 
- *
+ * <p><b>NOTE:</b> it makes no sense to use negative interval values for the parameters and the 
+ * engine will raise an error if that happens.</p>
+ * 
  * @author etirelli
  * @author mgroch
  */
@@ -217,12 +202,14 @@
             super.readExternal( in );
             startDev = in.readLong();
             endDev = in.readLong();
+            paramText = (String) in.readObject();
         }
 
         public void writeExternal(ObjectOutput out) throws IOException {
             super.writeExternal( out );
             out.writeLong( startDev );
             out.writeLong( endDev );
+            out.writeObject( paramText );
         }
 
         @Override
@@ -328,16 +315,23 @@
                 this.startDev = 0;
                 this.endDev = 0;
                 return;
-            } else if ( parameters.length == 1 ) {
-                // same deviation for both
-                this.startDev = parameters[0].longValue();
-                this.endDev = parameters[0].longValue();
-            } else if ( parameters.length == 2 ) {
-                // different deviation 
-                this.startDev = parameters[0].longValue();
-                this.endDev = parameters[1].longValue();
             } else {
-                throw new RuntimeDroolsException( "[Coincides Evaluator]: Not possible to have more than 2 parameters: '" + paramText + "'" );
+                for( Long param : parameters ) {
+                    if( param.longValue() < 0 ) {
+                        throw new RuntimeDroolsException( "[Coincides Evaluator]: negative values not allowed for temporal distance thresholds: '" + paramText + "'" );
+                    }
+                }
+                if ( parameters.length == 1 ) {
+                    // same deviation for both
+                    this.startDev = parameters[0].longValue();
+                    this.endDev = parameters[0].longValue();
+                } else if ( parameters.length == 2 ) {
+                    // different deviation 
+                    this.startDev = parameters[0].longValue();
+                    this.endDev = parameters[1].longValue();
+                } else {
+                    throw new RuntimeDroolsException( "[Coincides Evaluator]: Not possible to have more than 2 parameters: '" + paramText + "'" );
+                }
             }
         }
 

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/DuringEvaluatorDefinition.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/DuringEvaluatorDefinition.java	2008-11-28 23:28:41 UTC (rev 24145)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/DuringEvaluatorDefinition.java	2008-11-29 00:12:54 UTC (rev 24146)
@@ -38,29 +38,85 @@
 import org.drools.time.Interval;
 
 /**
- * The implementation of the 'during' evaluator definition
+ * <p>The implementation of the <code>during</code> evaluator definition.</p>
+ * 
+ * <p>The <b><code>during</code></b> evaluator correlates two events and matches when the current event 
+ * happens during the occurrence of the event being correlated.</p> 
+ * 
+ * <p>Lets look at an example:</p>
+ * 
+ * <pre>$eventA : EventA( this during $eventB )</pre>
  *
+ * <p>The previous pattern will match if and only if the $eventA starts after $eventB starts and finishes
+ * before $eventB finishes. In other words:</p>
+ * 
+ * <pre> $eventB.startTimestamp < $eventA.startTimestamp <= $eventA.endTimestamp < $eventB.endTimestamp </pre>
+ * 
+ * <p>The <b><code>during</code></b> operator accepts 1, 2 or 4 optional parameters as follow:</p>
+ * 
+ * <ul><li>If one value is defined, this will be the maximum distance between the start timestamp of both
+ * event and the maximum distance between the end timestamp of both events in order to operator match. Example:</li></lu>
+ * 
+ * <pre>$eventA : EventA( this during[ 5s ] $eventB )</pre>
+ * 
+ * Will match if and only if:
+ * 
+ * <pre> 
+ * 0 < $eventA.startTimestamp - $eventB.startTimestamp <= 5s &&
+ * 0 < $eventB.endTimestamp - $eventA.endTimestamp <= 5s
+ * </pre>
+ * 
+ * <ul><li>If two values are defined, the first value will be the minimum distance between the timestamps
+ * of both events, while the second value will be the maximum distance between the timestamps of both events. 
+ * Example:</li></lu>
+ * 
+ * <pre>$eventA : EventA( this during[ 5s, 10s ] $eventB )</pre>
+ * 
+ * Will match if and only if:
+ * 
+ * <pre> 
+ * 5s <= $eventA.startTimestamp - $eventB.startTimestamp <= 10s &&
+ * 5s <= $eventB.endTimestamp - $eventA.endTimestamp <= 10s
+ * </pre>
+ * 
+ * <ul><li>If four values are defined, the first two values will be the minimum and maximum distances between the 
+ * start timestamp of both events, while the last two values will be the minimum and maximum distances between the 
+ * end timestamp of both events. Example:</li></lu>
+ * 
+ * <pre>$eventA : EventA( this during[ 2s, 6s, 4s, 10s ] $eventB )</pre>
+ * 
+ * Will match if and only if:
+ * 
+ * <pre> 
+ * 2s <= $eventA.startTimestamp - $eventB.startTimestamp <= 6s &&
+ * 4s <= $eventB.endTimestamp - $eventA.endTimestamp <= 10s
+ * </pre>
+ * 
+ * @author etirelli
  * @author mgroch
  */
 public class DuringEvaluatorDefinition
     implements
     EvaluatorDefinition {
 
-    public static final Operator  DURING       = Operator.addOperatorToRegistry( "during",
-                                                                                  false );
-    public static final Operator  NOT_DURING   = Operator.addOperatorToRegistry( "during",
-                                                                                  true );
+    public static final Operator         DURING        = Operator.addOperatorToRegistry( "during",
+                                                                                         false );
+    public static final Operator         NOT_DURING    = Operator.addOperatorToRegistry( "during",
+                                                                                         true );
 
-    private static final String[] SUPPORTED_IDS = { DURING.getOperatorString() };
+    private static final String[]        SUPPORTED_IDS = {DURING.getOperatorString()};
 
-    private Map<String, DuringEvaluator> cache        = Collections.emptyMap();
+    private Map<String, DuringEvaluator> cache         = Collections.emptyMap();
+    private volatile TimeIntervalParser  parser        = new TimeIntervalParser();
 
-    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        cache  = (Map<String, DuringEvaluator>)in.readObject();
+    @SuppressWarnings("unchecked")
+    public void readExternal(ObjectInput in) throws IOException,
+                                            ClassNotFoundException {
+        cache = (Map<String, DuringEvaluator>) in.readObject();
     }
 
     public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeObject(cache);
+        out.writeObject( cache );
     }
 
     /**
@@ -99,9 +155,11 @@
         String key = isNegated + ":" + parameterText;
         DuringEvaluator eval = this.cache.get( key );
         if ( eval == null ) {
+            Long[] params = parser.parse( parameterText );
             eval = new DuringEvaluator( type,
-                                       isNegated,
-                                       parameterText );
+                                        isNegated,
+                                        params,
+                                        parameterText );
             this.cache.put( key,
                             eval );
         }
@@ -142,36 +200,42 @@
      * Implements the 'during' evaluator itself
      */
     public static class DuringEvaluator extends BaseEvaluator {
-		private static final long serialVersionUID = -5856043346192967722L;
+        private static final long serialVersionUID = -5856043346192967722L;
 
-		private long                  startMinDev, startMaxDev;
-        private long                  endMinDev, endMaxDev;
+        private long              startMinDev, startMaxDev;
+        private long              endMinDev, endMaxDev;
+        private String            paramText;
 
         public DuringEvaluator() {
         }
 
         public DuringEvaluator(final ValueType type,
-                              final boolean isNegated,
-                              final String parameters) {
+                               final boolean isNegated,
+                               final Long[] parameters,
+                               final String paramText) {
             super( type,
                    isNegated ? NOT_DURING : DURING );
-            this.parseParameters( parameters );
+            this.paramText = paramText;
+            this.setParameters( parameters );
         }
 
-        public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-            super.readExternal(in);
+        public void readExternal(ObjectInput in) throws IOException,
+                                                ClassNotFoundException {
+            super.readExternal( in );
             startMinDev = in.readLong();
             startMaxDev = in.readLong();
-            endMinDev   = in.readLong();
-            endMaxDev   = in.readLong();
+            endMinDev = in.readLong();
+            endMaxDev = in.readLong();
+            paramText = (String) in.readObject();
         }
 
         public void writeExternal(ObjectOutput out) throws IOException {
-            super.writeExternal(out);
-            out.writeLong(startMinDev);
-            out.writeLong(startMaxDev);
-            out.writeLong(endMinDev);
-            out.writeLong(endMaxDev);
+            super.writeExternal( out );
+            out.writeLong( startMinDev );
+            out.writeLong( startMaxDev );
+            out.writeLong( endMinDev );
+            out.writeLong( endMaxDev );
+            out.writeObject( paramText );
         }
 
         @Override
@@ -183,15 +247,17 @@
         public boolean isTemporal() {
             return true;
         }
-        
+
         @Override
         public Interval getInterval() {
-            if( this.getOperator().isNegated() ) {
-                return new Interval( Interval.MIN, Interval.MAX );
+            if ( this.getOperator().isNegated() ) {
+                return new Interval( Interval.MIN,
+                                     Interval.MAX );
             }
-            return new Interval( 0, Interval.MAX );
+            return new Interval( 1,
+                                 Interval.MAX );
         }
-        
+
         public boolean evaluate(InternalWorkingMemory workingMemory,
                                 final InternalReadAccessor extractor,
                                 final Object object1,
@@ -200,48 +266,45 @@
         }
 
         public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
-                final VariableContextEntry context,
-                final Object left) {
+                                           final VariableContextEntry context,
+                                           final Object left) {
 
-        	if ( context.rightNull ) {
-        		return false;
-				}
-			long distStart = ((EventFactHandle)((ObjectVariableContextEntry) context).right).getStartTimestamp() - ((EventFactHandle) left ).getStartTimestamp();
-			long distEnd = ((EventFactHandle) left ).getEndTimestamp() - ((EventFactHandle)((ObjectVariableContextEntry) context).right).getEndTimestamp();
-			return this.getOperator().isNegated() ^ ( distStart >= this.startMinDev && distStart <= this.startMaxDev
-					&& distEnd >= this.endMinDev && distEnd <= this.endMaxDev );
-		}
+            if ( context.rightNull ) {
+                return false;
+            }
+            long distStart = ((EventFactHandle) ((ObjectVariableContextEntry) context).right).getStartTimestamp() - ((EventFactHandle) left).getStartTimestamp();
+            long distEnd = ((EventFactHandle) left).getEndTimestamp() - ((EventFactHandle) ((ObjectVariableContextEntry) context).right).getEndTimestamp();
+            return this.getOperator().isNegated() ^ (distStart >= this.startMinDev && distStart <= this.startMaxDev && distEnd >= this.endMinDev && distEnd <= this.endMaxDev);
+        }
 
-		public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
-			               final VariableContextEntry context,
-			               final Object right) {
-			if ( context.extractor.isNullValue( workingMemory,
-			                     right ) ) {
-			return false;
-			}
-			long distStart = ((EventFactHandle) right ).getStartTimestamp() - ((EventFactHandle) ((ObjectVariableContextEntry) context).left).getStartTimestamp();
-			long distEnd = ((EventFactHandle) ((ObjectVariableContextEntry) context).left).getEndTimestamp() - ((EventFactHandle) right ).getEndTimestamp();
-			return this.getOperator().isNegated() ^ ( distStart >= this.startMinDev && distStart <= this.startMaxDev
-					&& distEnd >= this.endMinDev && distEnd <= this.endMaxDev );
-		}
+        public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+                                          final VariableContextEntry context,
+                                          final Object right) {
+            if ( context.extractor.isNullValue( workingMemory,
+                                                right ) ) {
+                return false;
+            }
+            long distStart = ((EventFactHandle) right).getStartTimestamp() - ((EventFactHandle) ((ObjectVariableContextEntry) context).left).getStartTimestamp();
+            long distEnd = ((EventFactHandle) ((ObjectVariableContextEntry) context).left).getEndTimestamp() - ((EventFactHandle) right).getEndTimestamp();
+            return this.getOperator().isNegated() ^ (distStart >= this.startMinDev && distStart <= this.startMaxDev && distEnd >= this.endMinDev && distEnd <= this.endMaxDev);
+        }
 
-		public boolean evaluate(InternalWorkingMemory workingMemory,
-			     final InternalReadAccessor extractor1,
-			     final Object object1,
-			     final InternalReadAccessor extractor2,
-			     final Object object2) {
-			if ( extractor1.isNullValue( workingMemory,
-			              object1 ) ) {
-			return false;
-			}
-			long distStart = ((EventFactHandle) object1 ).getStartTimestamp() - ((EventFactHandle) object2 ).getStartTimestamp();
-			long distEnd = ((EventFactHandle) object2 ).getEndTimestamp() - ((EventFactHandle) object1 ).getEndTimestamp();
-			return this.getOperator().isNegated() ^ ( distStart >= this.startMinDev && distStart <= this.startMaxDev
-					&& distEnd >= this.endMinDev && distEnd <= this.endMaxDev );
-		}
+        public boolean evaluate(InternalWorkingMemory workingMemory,
+                                final InternalReadAccessor extractor1,
+                                final Object object1,
+                                final InternalReadAccessor extractor2,
+                                final Object object2) {
+            if ( extractor1.isNullValue( workingMemory,
+                                         object1 ) ) {
+                return false;
+            }
+            long distStart = ((EventFactHandle) object1).getStartTimestamp() - ((EventFactHandle) object2).getStartTimestamp();
+            long distEnd = ((EventFactHandle) object2).getEndTimestamp() - ((EventFactHandle) object1).getEndTimestamp();
+            return this.getOperator().isNegated() ^ (distStart >= this.startMinDev && distStart <= this.startMaxDev && distEnd >= this.endMinDev && distEnd <= this.endMaxDev);
+        }
 
         public String toString() {
-            return "during[" + startMinDev + ", " + startMaxDev + ", " + endMinDev + ", " + endMaxDev + "]";
+            return "during[" + paramText + "]";
         }
 
         /* (non-Javadoc)
@@ -267,53 +330,42 @@
             if ( !super.equals( obj ) ) return false;
             if ( getClass() != obj.getClass() ) return false;
             final DuringEvaluator other = (DuringEvaluator) obj;
-            return endMaxDev == other.endMaxDev && endMinDev == other.endMinDev
-            	&& startMaxDev == other.startMaxDev && startMinDev == other.startMinDev;
+            return endMaxDev == other.endMaxDev && endMinDev == other.endMinDev && startMaxDev == other.startMaxDev && startMinDev == other.startMinDev;
         }
 
         /**
-         * This methods tries to parse the string of parameters to customize
-         * the evaluator.
+         * This methods sets the parameters appropriately.
          *
          * @param parameters
          */
-        private void parseParameters(String parameters) {
-            if ( parameters == null || parameters.trim().length() == 0 ) {
-                // open bounded ranges
+        private void setParameters(Long[] parameters) {
+            if ( parameters == null || parameters.length == 0 ) {
+                // open bounded range
                 this.startMinDev = 1;
                 this.startMaxDev = Long.MAX_VALUE;
                 this.endMinDev = 1;
                 this.endMaxDev = Long.MAX_VALUE;
-                return;
+            } else if ( parameters.length == 1 ) {
+                // open bounded ranges
+                this.startMinDev = 1;
+                this.startMaxDev = parameters[0].longValue();
+                this.endMinDev = 1;
+                this.endMaxDev = parameters[0].longValue();
+            } else if ( parameters.length == 2 ) {
+                // open bounded ranges
+                this.startMinDev = parameters[0].longValue();
+                this.startMaxDev = parameters[1].longValue();
+                this.endMinDev = parameters[0].longValue();
+                this.endMaxDev = parameters[1].longValue();
+            } else if ( parameters.length == 4 ) {
+                // open bounded ranges
+                this.startMinDev = parameters[0].longValue();
+                this.startMaxDev = parameters[1].longValue();
+                this.endMinDev = parameters[2].longValue();
+                this.endMaxDev = parameters[3].longValue();
+            } else {
+                throw new RuntimeDroolsException( "[During Evaluator]: Not possible to use " + parameters.length + " parameters: '" + paramText + "'" );
             }
-
-            try {
-                String[] ranges = parameters.split( "," );
-                if ( ranges.length == 1 ) {
-                    // deterministic point in time for deviation of the starts of the intervals
-                    this.startMinDev = Long.parseLong( ranges[0] );
-                    this.startMaxDev = this.startMinDev;
-                    this.endMinDev = this.startMinDev;
-                    this.endMaxDev = this.startMinDev;
-                } else if ( ranges.length == 2 ) {
-                    // deterministic points in time for deviations of the starts and the ends of the intervals
-                    this.startMinDev = Long.parseLong( ranges[0] );
-                    this.startMaxDev = this.startMinDev;
-                    this.endMinDev = Long.parseLong( ranges[1] );
-                    this.endMaxDev = this.endMinDev;
-                } else if ( ranges.length == 4 ) {
-                    // ranges for deviations of the starts and the ends of the intervals
-                	this.startMinDev = Long.parseLong( ranges[0] );
-                    this.startMaxDev = Long.parseLong( ranges[1] );
-                    this.endMinDev = Long.parseLong( ranges[2] );
-                    this.endMaxDev = Long.parseLong( ranges[3] );
-                } else {
-                    throw new RuntimeDroolsException( "[During Evaluator]: Not possible to parse parameters: '" + parameters + "'" );
-                }
-            } catch ( NumberFormatException e ) {
-                throw new RuntimeDroolsException( "[During Evaluator]: Not possible to parse parameters: '" + parameters + "'",
-                                                  e );
-            }
         }
 
     }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/FinishesEvaluatorDefinition.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/FinishesEvaluatorDefinition.java	2008-11-28 23:28:41 UTC (rev 24145)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/FinishesEvaluatorDefinition.java	2008-11-29 00:12:54 UTC (rev 24146)
@@ -38,8 +38,61 @@
 import org.drools.time.Interval;
 
 /**
- * The implementation of the 'finishes' evaluator definition
+ * <p>The implementation of the <code>during</code> evaluator definition.</p>
+ * 
+ * <p>The <b><code>during</code></b> evaluator correlates two events and matches when the current event 
+ * happens during the occurrence of the event being correlated.</p> 
+ * 
+ * <p>Lets look at an example:</p>
+ * 
+ * <pre>$eventA : EventA( this during $eventB )</pre>
  *
+ * <p>The previous pattern will match if and only if the $eventA starts after $eventB starts and finishes
+ * before $eventB finishes. In other words:</p>
+ * 
+ * <pre> $eventB.startTimestamp < $eventA.startTimestamp <= $eventA.endTimestamp < $eventB.endTimestamp </pre>
+ * 
+ * <p>The <b><code>during</code></b> operator accepts 1, 2 or 4 optional parameters as follow:</p>
+ * 
+ * <ul><li>If one value is defined, this will be the maximum distance between the start timestamp of both
+ * event and the maximum distance between the end timestamp of both events in order to operator match. Example:</li></lu>
+ * 
+ * <pre>$eventA : EventA( this during[ 5s ] $eventB )</pre>
+ * 
+ * Will match if and only if:
+ * 
+ * <pre> 
+ * 0 < $eventA.startTimestamp - $eventB.startTimestamp <= 5s &&
+ * 0 < $eventB.endTimestamp - $eventA.endTimestamp <= 5s
+ * </pre>
+ * 
+ * <ul><li>If two values are defined, the first value will be the minimum distance between the timestamps
+ * of both events, while the second value will be the maximum distance between the timestamps of both events. 
+ * Example:</li></lu>
+ * 
+ * <pre>$eventA : EventA( this during[ 5s, 10s ] $eventB )</pre>
+ * 
+ * Will match if and only if:
+ * 
+ * <pre> 
+ * 5s <= $eventA.startTimestamp - $eventB.startTimestamp <= 10s &&
+ * 5s <= $eventB.endTimestamp - $eventA.endTimestamp <= 10s
+ * </pre>
+ * 
+ * <ul><li>If four values are defined, the first two values will be the minimum and maximum distances between the 
+ * start timestamp of both events, while the last two values will be the minimum and maximum distances between the 
+ * end timestamp of both events. Example:</li></lu>
+ * 
+ * <pre>$eventA : EventA( this during[ 2s, 6s, 4s, 10s ] $eventB )</pre>
+ * 
+ * Will match if and only if:
+ * 
+ * <pre> 
+ * 2s <= $eventA.startTimestamp - $eventB.startTimestamp <= 6s &&
+ * 4s <= $eventB.endTimestamp - $eventA.endTimestamp <= 10s
+ * </pre>
+ * 
+ * @author etirelli
  * @author mgroch
  */
 public class FinishesEvaluatorDefinition
@@ -55,6 +108,7 @@
 
     private Map<String, FinishesEvaluator> cache        = Collections.emptyMap();
 
+    @SuppressWarnings("unchecked")
     public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
         cache  = (Map<String, FinishesEvaluator>)in.readObject();
     }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/IncludesEvaluatorDefinition.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/IncludesEvaluatorDefinition.java	2008-11-28 23:28:41 UTC (rev 24145)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/IncludesEvaluatorDefinition.java	2008-11-29 00:12:54 UTC (rev 24146)
@@ -38,29 +38,86 @@
 import org.drools.time.Interval;
 
 /**
- * The implementation of the 'includes' evaluator definition
+ * <p>The implementation of the <code>includes</code> evaluator definition.</p>
+ * 
+ * <p>The <b><code>includes</code></b> evaluator correlates two events and matches when the event 
+ * being correlated happens during the current event. It is the symmetrical opposite of <code>during</code>
+ * evaluator.</p> 
+ * 
+ * <p>Lets look at an example:</p>
+ * 
+ * <pre>$eventA : EventA( this includes $eventB )</pre>
  *
+ * <p>The previous pattern will match if and only if the $eventB starts after $eventA starts and finishes
+ * before $eventA finishes. In other words:</p>
+ * 
+ * <pre> $eventA.startTimestamp < $eventB.startTimestamp <= $eventB.endTimestamp < $eventA.endTimestamp </pre>
+ * 
+ * <p>The <b><code>includes</code></b> operator accepts 1, 2 or 4 optional parameters as follow:</p>
+ * 
+ * <ul><li>If one value is defined, this will be the maximum distance between the start timestamp of both
+ * event and the maximum distance between the end timestamp of both events in order to operator match. Example:</li></lu>
+ * 
+ * <pre>$eventA : EventA( this includes[ 5s ] $eventB )</pre>
+ * 
+ * Will match if and only if:
+ * 
+ * <pre> 
+ * 0 < $eventB.startTimestamp - $eventA.startTimestamp <= 5s &&
+ * 0 < $eventA.endTimestamp - $eventB.endTimestamp <= 5s
+ * </pre>
+ * 
+ * <ul><li>If two values are defined, the first value will be the minimum distance between the timestamps
+ * of both events, while the second value will be the maximum distance between the timestamps of both events. 
+ * Example:</li></lu>
+ * 
+ * <pre>$eventA : EventA( this includes[ 5s, 10s ] $eventB )</pre>
+ * 
+ * Will match if and only if:
+ * 
+ * <pre> 
+ * 5s <= $eventB.startTimestamp - $eventA.startTimestamp <= 10s &&
+ * 5s <= $eventA.endTimestamp - $eventB.endTimestamp <= 10s
+ * </pre>
+ * 
+ * <ul><li>If four values are defined, the first two values will be the minimum and maximum distances between the 
+ * start timestamp of both events, while the last two values will be the minimum and maximum distances between the 
+ * end timestamp of both events. Example:</li></lu>
+ * 
+ * <pre>$eventA : EventA( this includes[ 2s, 6s, 4s, 10s ] $eventB )</pre>
+ * 
+ * Will match if and only if:
+ * 
+ * <pre> 
+ * 2s <= $eventB.startTimestamp - $eventA.startTimestamp <= 6s &&
+ * 4s <= $eventA.endTimestamp - $eventB.endTimestamp <= 10s
+ * </pre>
+ * 
+ * @author etirelli
  * @author mgroch
  */
 public class IncludesEvaluatorDefinition
     implements
     EvaluatorDefinition {
 
-    public static final Operator  INCLUDES       = Operator.addOperatorToRegistry( "includes",
-                                                                                  false );
-    public static final Operator  INCLUDES_NOT   = Operator.addOperatorToRegistry( "includes",
-                                                                                  true );
+    public static final Operator           INCLUDES      = Operator.addOperatorToRegistry( "includes",
+                                                                                           false );
+    public static final Operator           INCLUDES_NOT  = Operator.addOperatorToRegistry( "includes",
+                                                                                           true );
 
-    private static final String[] SUPPORTED_IDS = { INCLUDES.getOperatorString() };
+    private static final String[]          SUPPORTED_IDS = {INCLUDES.getOperatorString()};
 
-    private Map<String, IncludesEvaluator> cache        = Collections.emptyMap();
+    private Map<String, IncludesEvaluator> cache         = Collections.emptyMap();
+    private volatile TimeIntervalParser    parser        = new TimeIntervalParser();
 
-    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        cache  = (Map<String, IncludesEvaluator>)in.readObject();
+    @SuppressWarnings("unchecked")
+    public void readExternal(ObjectInput in) throws IOException,
+                                            ClassNotFoundException {
+        cache = (Map<String, IncludesEvaluator>) in.readObject();
     }
 
     public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeObject(cache);
+        out.writeObject( cache );
     }
 
     /**
@@ -99,9 +156,11 @@
         String key = isNegated + ":" + parameterText;
         IncludesEvaluator eval = this.cache.get( key );
         if ( eval == null ) {
+            Long[] params = parser.parse( parameterText );
             eval = new IncludesEvaluator( type,
-                                       isNegated,
-                                       parameterText );
+                                          isNegated,
+                                          params,
+                                          parameterText );
             this.cache.put( key,
                             eval );
         }
@@ -142,36 +201,40 @@
      * Implements the 'includes' evaluator itself
      */
     public static class IncludesEvaluator extends BaseEvaluator {
-		private static final long serialVersionUID = -5947397607962049251L;
+        private static final long serialVersionUID = -5947397607962049251L;
 
-		private long                  startMinDev, startMaxDev;
-        private long                  endMinDev, endMaxDev;
+        private long              startMinDev, startMaxDev;
+        private long              endMinDev, endMaxDev;
+        private String            paramText;
 
         public IncludesEvaluator() {
         }
 
         public IncludesEvaluator(final ValueType type,
-                              final boolean isNegated,
-                              final String parameters) {
+                                 final boolean isNegated,
+                                 final Long[] parameters,
+                                 final String paramText) {
             super( type,
                    isNegated ? INCLUDES_NOT : INCLUDES );
-            this.parseParameters( parameters );
+            this.paramText = paramText;
+            this.setParameters( parameters );
         }
 
-        public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-            super.readExternal(in);
+        public void readExternal(ObjectInput in) throws IOException,
+                                                ClassNotFoundException {
+            super.readExternal( in );
             startMinDev = in.readLong();
             startMaxDev = in.readLong();
-            endMinDev   = in.readLong();
-            endMaxDev   = in.readLong();
+            endMinDev = in.readLong();
+            endMaxDev = in.readLong();
         }
 
         public void writeExternal(ObjectOutput out) throws IOException {
-            super.writeExternal(out);
-            out.writeLong(startMinDev);
-            out.writeLong(startMaxDev);
-            out.writeLong(endMinDev);
-            out.writeLong(endMaxDev);
+            super.writeExternal( out );
+            out.writeLong( startMinDev );
+            out.writeLong( startMaxDev );
+            out.writeLong( endMinDev );
+            out.writeLong( endMaxDev );
         }
 
         @Override
@@ -183,15 +246,17 @@
         public boolean isTemporal() {
             return true;
         }
-        
+
         @Override
         public Interval getInterval() {
-            if( this.getOperator().isNegated() ) {
-                return new Interval( Interval.MIN, Interval.MAX );
+            if ( this.getOperator().isNegated() ) {
+                return new Interval( Interval.MIN,
+                                     Interval.MAX );
             }
-            return new Interval( Interval.MIN, 0 );
+            return new Interval( Interval.MIN,
+                                 0 );
         }
-        
+
         public boolean evaluate(InternalWorkingMemory workingMemory,
                                 final InternalReadAccessor extractor,
                                 final Object object1,
@@ -200,45 +265,42 @@
         }
 
         public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
-                final VariableContextEntry context,
-                final Object left) {
+                                           final VariableContextEntry context,
+                                           final Object left) {
 
-        	if ( context.rightNull ) {
-        		return false;
-				}
-			long distStart = ((EventFactHandle) left ).getStartTimestamp() - ((EventFactHandle)((ObjectVariableContextEntry) context).right).getStartTimestamp();
-			long distEnd = ((EventFactHandle)((ObjectVariableContextEntry) context).right).getEndTimestamp() - ((EventFactHandle) left ).getEndTimestamp();
-			return this.getOperator().isNegated() ^ ( distStart >= this.startMinDev && distStart <= this.startMaxDev
-					&& distEnd >= this.endMinDev && distEnd <= this.endMaxDev );
-		}
+            if ( context.rightNull ) {
+                return false;
+            }
+            long distStart = ((EventFactHandle) left).getStartTimestamp() - ((EventFactHandle) ((ObjectVariableContextEntry) context).right).getStartTimestamp();
+            long distEnd = ((EventFactHandle) ((ObjectVariableContextEntry) context).right).getEndTimestamp() - ((EventFactHandle) left).getEndTimestamp();
+            return this.getOperator().isNegated() ^ (distStart >= this.startMinDev && distStart <= this.startMaxDev && distEnd >= this.endMinDev && distEnd <= this.endMaxDev);
+        }
 
-		public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
-			               final VariableContextEntry context,
-			               final Object right) {
-			if ( context.extractor.isNullValue( workingMemory,
-			                     right ) ) {
-			return false;
-			}
-			long distStart = ((EventFactHandle) ((ObjectVariableContextEntry) context).left).getStartTimestamp() - ((EventFactHandle) right ).getStartTimestamp();
-			long distEnd = ((EventFactHandle) right ).getEndTimestamp() - ((EventFactHandle) ((ObjectVariableContextEntry) context).left).getEndTimestamp();
-			return this.getOperator().isNegated() ^ ( distStart >= this.startMinDev && distStart <= this.startMaxDev
-					&& distEnd >= this.endMinDev && distEnd <= this.endMaxDev );
-		}
+        public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+                                          final VariableContextEntry context,
+                                          final Object right) {
+            if ( context.extractor.isNullValue( workingMemory,
+                                                right ) ) {
+                return false;
+            }
+            long distStart = ((EventFactHandle) ((ObjectVariableContextEntry) context).left).getStartTimestamp() - ((EventFactHandle) right).getStartTimestamp();
+            long distEnd = ((EventFactHandle) right).getEndTimestamp() - ((EventFactHandle) ((ObjectVariableContextEntry) context).left).getEndTimestamp();
+            return this.getOperator().isNegated() ^ (distStart >= this.startMinDev && distStart <= this.startMaxDev && distEnd >= this.endMinDev && distEnd <= this.endMaxDev);
+        }
 
-		public boolean evaluate(InternalWorkingMemory workingMemory,
-			     final InternalReadAccessor extractor1,
-			     final Object object1,
-			     final InternalReadAccessor extractor2,
-			     final Object object2) {
-			if ( extractor1.isNullValue( workingMemory,
-			              object1 ) ) {
-			return false;
-			}
-			long distStart = ((EventFactHandle) object2 ).getStartTimestamp() - ((EventFactHandle) object1 ).getStartTimestamp();
-			long distEnd = ((EventFactHandle) object1 ).getEndTimestamp() - ((EventFactHandle) object2 ).getEndTimestamp();
-			return this.getOperator().isNegated() ^ ( distStart >= this.startMinDev && distStart <= this.startMaxDev
-					&& distEnd >= this.endMinDev && distEnd <= this.endMaxDev );
-		}
+        public boolean evaluate(InternalWorkingMemory workingMemory,
+                                final InternalReadAccessor extractor1,
+                                final Object object1,
+                                final InternalReadAccessor extractor2,
+                                final Object object2) {
+            if ( extractor1.isNullValue( workingMemory,
+                                         object1 ) ) {
+                return false;
+            }
+            long distStart = ((EventFactHandle) object2).getStartTimestamp() - ((EventFactHandle) object1).getStartTimestamp();
+            long distEnd = ((EventFactHandle) object1).getEndTimestamp() - ((EventFactHandle) object2).getEndTimestamp();
+            return this.getOperator().isNegated() ^ (distStart >= this.startMinDev && distStart <= this.startMaxDev && distEnd >= this.endMinDev && distEnd <= this.endMaxDev);
+        }
 
         public String toString() {
             return "includes[" + startMinDev + ", " + startMaxDev + ", " + endMinDev + ", " + endMaxDev + "]";
@@ -267,53 +329,42 @@
             if ( !super.equals( obj ) ) return false;
             if ( getClass() != obj.getClass() ) return false;
             final IncludesEvaluator other = (IncludesEvaluator) obj;
-            return endMaxDev == other.endMaxDev && endMinDev == other.endMinDev
-            	&& startMaxDev == other.startMaxDev && startMinDev == other.startMinDev;
+            return endMaxDev == other.endMaxDev && endMinDev == other.endMinDev && startMaxDev == other.startMaxDev && startMinDev == other.startMinDev;
         }
 
         /**
-         * This methods tries to parse the string of parameters to customize
-         * the evaluator.
+         * This methods sets the parameters appropriately.
          *
          * @param parameters
          */
-        private void parseParameters(String parameters) {
-            if ( parameters == null || parameters.trim().length() == 0 ) {
-                // open bounded ranges
+        private void setParameters(Long[] parameters) {
+            if ( parameters == null || parameters.length == 0 ) {
+                // open bounded range
                 this.startMinDev = 1;
                 this.startMaxDev = Long.MAX_VALUE;
                 this.endMinDev = 1;
                 this.endMaxDev = Long.MAX_VALUE;
-                return;
+            } else if ( parameters.length == 1 ) {
+                // open bounded ranges
+                this.startMinDev = 1;
+                this.startMaxDev = parameters[0].longValue();
+                this.endMinDev = 1;
+                this.endMaxDev = parameters[0].longValue();
+            } else if ( parameters.length == 2 ) {
+                // open bounded ranges
+                this.startMinDev = parameters[0].longValue();
+                this.startMaxDev = parameters[1].longValue();
+                this.endMinDev = parameters[0].longValue();
+                this.endMaxDev = parameters[1].longValue();
+            } else if ( parameters.length == 4 ) {
+                // open bounded ranges
+                this.startMinDev = parameters[0].longValue();
+                this.startMaxDev = parameters[1].longValue();
+                this.endMinDev = parameters[2].longValue();
+                this.endMaxDev = parameters[3].longValue();
+            } else {
+                throw new RuntimeDroolsException( "[During Evaluator]: Not possible to use " + parameters.length + " parameters: '" + paramText + "'" );
             }
-
-            try {
-                String[] ranges = parameters.split( "," );
-                if ( ranges.length == 1 ) {
-                    // deterministic point in time for deviation of the starts of the intervals
-                    this.startMinDev = Long.parseLong( ranges[0] );
-                    this.startMaxDev = this.startMinDev;
-                    this.endMinDev = this.startMinDev;
-                    this.endMaxDev = this.startMinDev;
-                } else if ( ranges.length == 2 ) {
-                    // deterministic points in time for deviations of the starts and the ends of the intervals
-                    this.startMinDev = Long.parseLong( ranges[0] );
-                    this.startMaxDev = this.startMinDev;
-                    this.endMinDev = Long.parseLong( ranges[1] );
-                    this.endMaxDev = this.endMinDev;
-                } else if ( ranges.length == 4 ) {
-                    // ranges for deviations of the starts and the ends of the intervals
-                	this.startMinDev = Long.parseLong( ranges[0] );
-                    this.startMaxDev = Long.parseLong( ranges[1] );
-                    this.endMinDev = Long.parseLong( ranges[2] );
-                    this.endMaxDev = Long.parseLong( ranges[3] );
-                } else {
-                    throw new RuntimeDroolsException( "[Includes Evaluator]: Not possible to parse parameters: '" + parameters + "'" );
-                }
-            } catch ( NumberFormatException e ) {
-                throw new RuntimeDroolsException( "[Includes Evaluator]: Not possible to parse parameters: '" + parameters + "'",
-                                                  e );
-            }
         }
 
     }

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/TemporalEvaluatorFactoryTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/TemporalEvaluatorFactoryTest.java	2008-11-28 23:28:41 UTC (rev 24145)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/TemporalEvaluatorFactoryTest.java	2008-11-29 00:12:54 UTC (rev 24146)
@@ -24,6 +24,10 @@
 import junit.framework.TestCase;
 
 import org.drools.RuntimeDroolsException;
+import org.drools.base.evaluators.AfterEvaluatorDefinition;
+import org.drools.base.evaluators.BeforeEvaluatorDefinition;
+import org.drools.base.evaluators.CoincidesEvaluatorDefinition;
+import org.drools.base.evaluators.DuringEvaluatorDefinition;
 import org.drools.base.evaluators.EvaluatorDefinition;
 import org.drools.base.evaluators.EvaluatorRegistry;
 import org.drools.common.EventFactHandle;
@@ -49,7 +53,7 @@
     private EvaluatorRegistry registry = new EvaluatorRegistry();
 
     public void testAfter() {
-        registry.addEvaluatorDefinition( "org.drools.base.evaluators.AfterEvaluatorDefinition" );
+        registry.addEvaluatorDefinition( AfterEvaluatorDefinition.class.getName() );
 
         EventFactHandle foo = new EventFactHandle( 1,
                                                    "foo",
@@ -134,7 +138,7 @@
     }
 
     public void testBefore() {
-        registry.addEvaluatorDefinition( "org.drools.base.evaluators.BeforeEvaluatorDefinition" );
+        registry.addEvaluatorDefinition( BeforeEvaluatorDefinition.class.getName() );
 
         EventFactHandle foo = new EventFactHandle( 1,
                                                    "foo",
@@ -219,7 +223,7 @@
     }
 
     public void testCoincides() {
-        registry.addEvaluatorDefinition( "org.drools.base.evaluators.CoincidesEvaluatorDefinition" );
+        registry.addEvaluatorDefinition( CoincidesEvaluatorDefinition.class.getName() );
 
         EventFactHandle foo = new EventFactHandle( 1,
                                                    "foo",
@@ -280,6 +284,136 @@
                           ValueType.OBJECT_TYPE );
     }
 
+    public void testDuring() {
+        registry.addEvaluatorDefinition( DuringEvaluatorDefinition.class.getName() );
+
+        EventFactHandle foo = new EventFactHandle( 1,
+                                                   "foo",
+                                                   1,
+                                                   2,
+                                                   10 );
+        EventFactHandle bar = new EventFactHandle( 2,
+                                                   "bar",
+                                                   1,
+                                                   4,
+                                                   7 );
+        EventFactHandle drool = new EventFactHandle( 1,
+                                                     "drool",
+                                                     1,
+                                                     1,
+                                                     5 );
+        EventFactHandle mole = new EventFactHandle( 1,
+                                                    "mole",
+                                                    1,
+                                                    7,
+                                                    6 );
+
+        final Object[][] data = {
+                 {foo, "during", bar, Boolean.FALSE}, 
+                 {foo, "during", drool, Boolean.FALSE}, 
+                 {foo, "during", mole, Boolean.FALSE}, 
+                 {bar, "during", foo, Boolean.TRUE}, 
+                 {bar, "during", drool, Boolean.FALSE}, 
+                 {bar, "during", mole, Boolean.FALSE}, 
+                 {foo, "not during", bar, Boolean.TRUE}, 
+                 {foo, "not during", drool, Boolean.TRUE}, 
+                 {foo, "not during", mole, Boolean.TRUE}, 
+                 {bar, "not during", foo, Boolean.FALSE}, 
+                 {bar, "not during", drool, Boolean.TRUE}, 
+                 {bar, "not during", mole, Boolean.TRUE}, 
+
+                 {bar, "during[2]", foo, Boolean.TRUE}, 
+                 {bar, "during[3]", foo, Boolean.TRUE}, 
+                 {bar, "during[1]", foo, Boolean.FALSE},
+                 {bar, "not during[2]", foo, Boolean.FALSE}, 
+                 {bar, "not during[3]", foo, Boolean.FALSE}, 
+                 {bar, "not during[1]", foo, Boolean.TRUE},
+                 
+                 {bar, "during[1, 2]", foo, Boolean.TRUE}, 
+                 {bar, "during[2, 3]", foo, Boolean.FALSE}, 
+                 {bar, "during[3, 3]", foo, Boolean.FALSE},
+                 {bar, "not during[1, 2]", foo, Boolean.FALSE}, 
+                 {bar, "not during[2, 3]", foo, Boolean.TRUE}, 
+                 {bar, "not during[3, 3]", foo, Boolean.TRUE},
+                 
+                 {bar, "during[2, 2, 1, 1]", foo, Boolean.TRUE}, 
+                 {bar, "during[1, 5, 1, 3]", foo, Boolean.TRUE}, 
+                 {bar, "during[0, 1, 0, 3]", foo, Boolean.FALSE},
+                 {bar, "not during[2, 2, 1, 1]", foo, Boolean.FALSE}, 
+                 {bar, "not during[1, 5, 1, 3]", foo, Boolean.FALSE}, 
+                 {bar, "not during[0, 1, 0, 3]", foo, Boolean.TRUE}
+                 
+                };
+
+        runEvaluatorTest( data,
+                          ValueType.OBJECT_TYPE );
+    }
+
+    public void testIncludes() {
+        registry.addEvaluatorDefinition( DuringEvaluatorDefinition.class.getName() );
+
+        EventFactHandle foo = new EventFactHandle( 1,
+                                                   "foo",
+                                                   1,
+                                                   2,
+                                                   10 );
+        EventFactHandle bar = new EventFactHandle( 2,
+                                                   "bar",
+                                                   1,
+                                                   4,
+                                                   7 );
+        EventFactHandle drool = new EventFactHandle( 1,
+                                                     "drool",
+                                                     1,
+                                                     1,
+                                                     5 );
+        EventFactHandle mole = new EventFactHandle( 1,
+                                                    "mole",
+                                                    1,
+                                                    7,
+                                                    6 );
+
+        final Object[][] data = {
+                 {bar, "includes", foo, Boolean.FALSE}, 
+                 {drool, "includes", foo, Boolean.FALSE}, 
+                 {mole, "includes", foo, Boolean.FALSE}, 
+                 {foo, "includes", bar, Boolean.TRUE}, 
+                 {drool, "includes", bar, Boolean.FALSE}, 
+                 {mole, "includes", bar, Boolean.FALSE}, 
+                 {bar, "not includes", foo, Boolean.TRUE}, 
+                 {drool, "not includes", foo, Boolean.TRUE}, 
+                 {mole, "not includes", foo, Boolean.TRUE}, 
+                 {foo, "not includes", bar, Boolean.FALSE}, 
+                 {drool, "not includes", bar, Boolean.TRUE}, 
+                 {mole, "not includes", bar, Boolean.TRUE}, 
+
+                 {foo, "includes[2]", bar, Boolean.TRUE}, 
+                 {foo, "includes[3]", bar, Boolean.TRUE}, 
+                 {foo, "includes[1]", bar, Boolean.FALSE},
+                 {foo, "not includes[2]", bar, Boolean.FALSE}, 
+                 {foo, "not includes[3]", bar, Boolean.FALSE}, 
+                 {foo, "not includes[1]", bar, Boolean.TRUE},
+                 
+                 {foo, "includes[1, 2]", bar, Boolean.TRUE}, 
+                 {foo, "includes[2, 3]", bar, Boolean.FALSE}, 
+                 {foo, "includes[3, 3]", bar, Boolean.FALSE},
+                 {foo, "not includes[1, 2]", bar, Boolean.FALSE}, 
+                 {foo, "not includes[2, 3]", bar, Boolean.TRUE}, 
+                 {foo, "not includes[3, 3]", bar, Boolean.TRUE},
+                 
+                 {foo, "includes[2, 2, 1, 1]", bar, Boolean.TRUE}, 
+                 {foo, "includes[1, 5, 1, 3]", bar, Boolean.TRUE}, 
+                 {foo, "includes[0, 1, 0, 3]", bar, Boolean.FALSE},
+                 {foo, "not includes[2, 2, 1, 1]", bar, Boolean.FALSE}, 
+                 {foo, "not includes[1, 5, 1, 3]", bar, Boolean.FALSE}, 
+                 {foo, "not includes[0, 1, 0, 3]", bar, Boolean.TRUE}
+                 
+                };
+
+        runEvaluatorTest( data,
+                          ValueType.OBJECT_TYPE );
+    }
+
     private void runEvaluatorTest(final Object[][] data,
                                   final ValueType valueType) {
         final InternalReadAccessor extractor = new MockExtractor();
@@ -297,7 +431,6 @@
             }
             EvaluatorDefinition evalDef = registry.getEvaluatorDefinition( evaluatorStr );
             assertNotNull( evalDef );
-            @SuppressWarnings("unused")
             final Evaluator evaluator = evalDef.getEvaluator( valueType,
                                                               evaluatorStr,
                                                               isNegated,
@@ -398,10 +531,10 @@
         final FieldValue value = FieldFactory.getFieldValue( row[2] );
         RuntimeDroolsException exc = null;
         try {
-            final boolean result = evaluator.evaluate( null,
-                                                       extractor,
-                                                       row[0],
-                                                       value );
+            evaluator.evaluate( null,
+                                extractor,
+                                row[0],
+                                value );
         } catch ( RuntimeDroolsException e ) {
             exc = e;
         }
@@ -536,7 +669,7 @@
             return object != null ? ((Number) object).doubleValue() : 0.0;
         }
 
-        public Class getExtractToClass() {
+        public Class<?> getExtractToClass() {
             return null;
         }
 




More information about the jboss-svn-commits mailing list