[jboss-svn-commits] JBL Code SVN: r17223 - labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Dec 13 09:53:49 EST 2007


Author: mgroch
Date: 2007-12-13 09:53:48 -0500 (Thu, 13 Dec 2007)
New Revision: 17223

Added:
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/FinishedByEvaluatorDefinition.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/FinishesEvaluatorDefinition.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/StartedByEvaluatorDefinition.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/StartsEvaluatorDefinition.java
Modified:
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/BeforeEvaluatorDefinition.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/CoincidesEvaluatorDefinition.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/DuringEvaluatorDefinition.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/IncludesEvaluatorDefinition.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/MeetsEvaluatorDefinition.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/MetByEvaluatorDefinition.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/OverlappedByEvaluatorDefinition.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/OverlapsEvaluatorDefinition.java
Log:
JBRULES-1374
added support for remaining evaluators, i.e. starts, startedby, finishes & finishedby
recalculating the UIDs for all evaluators (useful for serialization)

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/BeforeEvaluatorDefinition.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/BeforeEvaluatorDefinition.java	2007-12-13 14:53:35 UTC (rev 17222)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/BeforeEvaluatorDefinition.java	2007-12-13 14:53:48 UTC (rev 17223)
@@ -130,10 +130,9 @@
      * Implements the 'before' evaluator itself
      */
     public static class BeforeEvaluator extends BaseEvaluator {
-
-    	private static final long serialVersionUID = -4778826341073034320L;
+		private static final long serialVersionUID = -4778826341073034320L;
 		
-    	private long                  initRange;
+		private long                  initRange;
         private long                  finalRange;
 
         public BeforeEvaluator(final ValueType type,

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/CoincidesEvaluatorDefinition.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/CoincidesEvaluatorDefinition.java	2007-12-13 14:53:35 UTC (rev 17222)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/CoincidesEvaluatorDefinition.java	2007-12-13 14:53:48 UTC (rev 17223)
@@ -129,8 +129,8 @@
     /**
      * Implements the 'coincides' evaluator itself
      */
-    public static class CoincidesEvaluator extends BaseEvaluator {
-		private static final long serialVersionUID = 542620783453908232L;
+    public static class CoincidesEvaluator extends BaseEvaluator {		
+		private static final long serialVersionUID = 6031520837249122183L;
 		
 		private long                  startDev;
         private long                  endDev;

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/DuringEvaluatorDefinition.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/DuringEvaluatorDefinition.java	2007-12-13 14:53:35 UTC (rev 17222)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/DuringEvaluatorDefinition.java	2007-12-13 14:53:48 UTC (rev 17223)
@@ -130,7 +130,7 @@
      * Implements the 'during' evaluator itself
      */
     public static class DuringEvaluator extends BaseEvaluator {
-		private static final long serialVersionUID = -6458186473527866405L;
+		private static final long serialVersionUID = -5856043346192967722L;
 		
 		private long                  startMinDev, startMaxDev;
         private long                  endMinDev, endMaxDev;

Added: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/FinishedByEvaluatorDefinition.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/FinishedByEvaluatorDefinition.java	                        (rev 0)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/FinishedByEvaluatorDefinition.java	2007-12-13 14:53:48 UTC (rev 17223)
@@ -0,0 +1,274 @@
+/*
+ * 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 Dec 6, 2007
+ */
+package org.drools.base.evaluators;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.drools.RuntimeDroolsException;
+import org.drools.base.BaseEvaluator;
+import org.drools.base.ValueType;
+import org.drools.common.EventFactHandle;
+import org.drools.common.InternalFactHandle;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.rule.VariableRestriction.ObjectVariableContextEntry;
+import org.drools.rule.VariableRestriction.VariableContextEntry;
+import org.drools.spi.Evaluator;
+import org.drools.spi.Extractor;
+import org.drools.spi.FieldValue;
+
+/**
+ * The implementation of the 'finishedby' evaluator definition
+ * 
+ * @author mgroch
+ */
+public class FinishedByEvaluatorDefinition
+    implements
+    EvaluatorDefinition {
+
+    public static final Operator  FINISHED_BY       = Operator.addOperatorToRegistry( "finishedby",
+                                                                                  false );
+    public static final Operator  NOT_FINISHED_BY   = Operator.addOperatorToRegistry( "finishedby",
+                                                                                  true );
+    
+    private static final String[] SUPPORTED_IDS = { FINISHED_BY.getOperatorString() };
+    
+    private Map<String, FinishedByEvaluator> cache        = Collections.emptyMap();
+
+    /**
+     * @inheridDoc
+     */
+    public Evaluator getEvaluator(ValueType type,
+                                  Operator operator) {
+        return this.getEvaluator( type,
+                                  operator.getOperatorString(),
+                                  operator.isNegated(),
+                                  null );
+    }
+
+    /**
+     * @inheridDoc
+     */
+    public Evaluator getEvaluator(ValueType type,
+                                  Operator operator,
+                                  String parameterText) {
+        return this.getEvaluator( type,
+                                  operator.getOperatorString(),
+                                  operator.isNegated(),
+                                  parameterText );
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public Evaluator getEvaluator(final ValueType type,
+                                  final String operatorId,
+                                  final boolean isNegated,
+                                  final String parameterText) {
+        if ( this.cache == Collections.EMPTY_MAP ) {
+            this.cache = new HashMap<String, FinishedByEvaluator>();
+        }
+        String key = isNegated + ":" + parameterText;
+        FinishedByEvaluator eval = this.cache.get( key );
+        if ( eval == null ) {
+            eval = new FinishedByEvaluator( type,
+                                       isNegated,
+                                       parameterText );
+            this.cache.put( key,
+                            eval );
+        }
+        return eval;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public String[] getEvaluatorIds() {
+        return SUPPORTED_IDS;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public boolean isNegatable() {
+        return true;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public boolean operatesOnFactHandles() {
+        return true;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public boolean supportsType(ValueType type) {
+        // supports all types, since it operates over fact handles
+        // Note: should we change this interface to allow checking of event classes only?
+        return true;
+    }
+
+    /**
+     * Implements the 'finishedby' evaluator itself
+     */
+    public static class FinishedByEvaluator extends BaseEvaluator {
+		private static final long serialVersionUID = -5156972073099070733L;
+		
+		private long                  startMinDev, startMaxDev;
+        private long                  endDev;
+
+        public FinishedByEvaluator(final ValueType type,
+                              final boolean isNegated,
+                              final String parameters) {
+            super( type,
+                   isNegated ? NOT_FINISHED_BY : FINISHED_BY );
+            this.parseParameters( parameters );
+        }
+        
+        @Override
+        public Object prepareObject(InternalFactHandle handle) {
+            return handle;
+        }
+        
+        public boolean evaluate(InternalWorkingMemory workingMemory,
+                                final Extractor extractor,
+                                final Object object1,
+                                final FieldValue object2) {
+            throw new RuntimeDroolsException( "The 'finishedby' operator can only be used to compare one event to another, and never to compare to literal constraints." );
+        }
+
+        public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+                final VariableContextEntry context,
+                final Object left) {
+			
+        	if ( context.rightNull ) {
+        		return false;
+				}
+			long distStart = ((EventFactHandle) left ).getStartTimestamp() - ((EventFactHandle)((ObjectVariableContextEntry) context).right).getStartTimestamp();
+			long distEnd = Math.abs(((EventFactHandle) left ).getEndTimestamp() - ((EventFactHandle)((ObjectVariableContextEntry) context).right).getEndTimestamp());
+			return this.getOperator().isNegated() ^ ( distStart >= this.startMinDev && distStart <= this.startMaxDev 
+					&& distEnd <= this.endDev );
+		}
+			
+		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 = Math.abs(((EventFactHandle) ((ObjectVariableContextEntry) context).left).getEndTimestamp() - ((EventFactHandle) right ).getEndTimestamp());
+			return this.getOperator().isNegated() ^ ( distStart >= this.startMinDev && distStart <= this.startMaxDev 
+					&& distEnd <= this.endDev );
+		}
+			
+		public boolean evaluate(InternalWorkingMemory workingMemory,
+			     final Extractor extractor1,
+			     final Object object1,
+			     final Extractor extractor2,
+			     final Object object2) {
+			if ( extractor1.isNullValue( workingMemory,
+			              object1 ) ) {
+			return false;
+			}
+			long distStart = ((EventFactHandle) object2 ).getStartTimestamp() - ((EventFactHandle) object1 ).getStartTimestamp();
+			long distEnd = Math.abs(((EventFactHandle) object2 ).getEndTimestamp() - ((EventFactHandle) object1 ).getEndTimestamp());
+			return this.getOperator().isNegated() ^ ( distStart >= this.startMinDev && distStart <= this.startMaxDev 
+					&& distEnd <= this.endDev );
+		}
+
+        public String toString() {
+            return "finishedby[" + startMinDev + ", " + startMaxDev + ", " + endDev + "]";
+        }
+
+        /* (non-Javadoc)
+         * @see java.lang.Object#hashCode()
+         */
+        @Override
+        public int hashCode() {
+            final int PRIME = 31;
+            int result = super.hashCode();
+            result = PRIME * result + (int) (endDev ^ (endDev >>> 32));
+            result = PRIME * result + (int) (startMaxDev ^ (startMaxDev >>> 32));
+            result = PRIME * result + (int) (startMinDev ^ (startMinDev >>> 32));
+            return result;
+        }
+
+        /* (non-Javadoc)
+         * @see java.lang.Object#equals(java.lang.Object)
+         */
+        @Override
+        public boolean equals(Object obj) {
+            if ( this == obj ) return true;
+            if ( !super.equals( obj ) ) return false;
+            if ( getClass() != obj.getClass() ) return false;
+            final FinishedByEvaluator other = (FinishedByEvaluator) obj;
+            return endDev == other.endDev && startMaxDev == other.startMaxDev && startMinDev == other.startMinDev;
+        }
+
+        /**
+         * This methods tries to parse the string of parameters to customize 
+         * the evaluator.
+         * 
+         * @param parameters
+         */
+        private void parseParameters(String parameters) {
+        	if ( parameters == null || parameters.trim().length() == 0 ) {
+                // exact matching at the end of the intervals, open bounded range for the starts
+                this.startMinDev = 1;
+                this.startMaxDev = Long.MAX_VALUE;
+                this.endDev = 0;
+                return;
+            }
+
+            try {
+                String[] ranges = parameters.split( "," );
+                if ( ranges.length == 1 ) {
+                    // exact matching at the end of the intervals
+                	// deterministic point in time for deviations of the starts of the intervals
+                	this.startMinDev = Long.parseLong( ranges[0] );
+                    this.startMaxDev = this.startMinDev;
+                    this.endDev = 0;
+                } else if ( ranges.length == 2 ) {
+                    // exact matching at the end of the intervals
+                	// range for deviations of the starts of the intervals 
+                    this.startMinDev = Long.parseLong( ranges[0] );
+                    this.startMaxDev = Long.parseLong( ranges[1] );
+                    this.endDev = 0;
+                } else if ( ranges.length == 3 ) {
+                	// max. deviation at the ends of the intervals
+                	// range for deviations of the starts of the intervals 
+                    this.startMinDev = Long.parseLong( ranges[0] );
+                    this.startMaxDev = Long.parseLong( ranges[1] );
+                    this.endDev = Long.parseLong( ranges[2] );
+                } else {
+                    throw new RuntimeDroolsException( "[FinishedBy Evaluator]: Not possible to parse parameters: '" + parameters + "'" );
+                }
+            } catch ( NumberFormatException e ) {
+                throw new RuntimeDroolsException( "[FinishedBy Evaluator]: Not possible to parse parameters: '" + parameters + "'",
+                                                  e );
+            }
+        }
+
+    }
+
+}

Added: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/FinishesEvaluatorDefinition.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/FinishesEvaluatorDefinition.java	                        (rev 0)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/FinishesEvaluatorDefinition.java	2007-12-13 14:53:48 UTC (rev 17223)
@@ -0,0 +1,274 @@
+/*
+ * 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 Dec 6, 2007
+ */
+package org.drools.base.evaluators;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.drools.RuntimeDroolsException;
+import org.drools.base.BaseEvaluator;
+import org.drools.base.ValueType;
+import org.drools.common.EventFactHandle;
+import org.drools.common.InternalFactHandle;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.rule.VariableRestriction.ObjectVariableContextEntry;
+import org.drools.rule.VariableRestriction.VariableContextEntry;
+import org.drools.spi.Evaluator;
+import org.drools.spi.Extractor;
+import org.drools.spi.FieldValue;
+
+/**
+ * The implementation of the 'finishes' evaluator definition
+ * 
+ * @author mgroch
+ */
+public class FinishesEvaluatorDefinition
+    implements
+    EvaluatorDefinition {
+
+    public static final Operator  FINISHES       = Operator.addOperatorToRegistry( "finishes",
+                                                                                  false );
+    public static final Operator  FINISHES_NOT   = Operator.addOperatorToRegistry( "finishes",
+                                                                                  true );
+    
+    private static final String[] SUPPORTED_IDS = { FINISHES.getOperatorString() };
+    
+    private Map<String, FinishesEvaluator> cache        = Collections.emptyMap();
+
+    /**
+     * @inheridDoc
+     */
+    public Evaluator getEvaluator(ValueType type,
+                                  Operator operator) {
+        return this.getEvaluator( type,
+                                  operator.getOperatorString(),
+                                  operator.isNegated(),
+                                  null );
+    }
+
+    /**
+     * @inheridDoc
+     */
+    public Evaluator getEvaluator(ValueType type,
+                                  Operator operator,
+                                  String parameterText) {
+        return this.getEvaluator( type,
+                                  operator.getOperatorString(),
+                                  operator.isNegated(),
+                                  parameterText );
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public Evaluator getEvaluator(final ValueType type,
+                                  final String operatorId,
+                                  final boolean isNegated,
+                                  final String parameterText) {
+        if ( this.cache == Collections.EMPTY_MAP ) {
+            this.cache = new HashMap<String, FinishesEvaluator>();
+        }
+        String key = isNegated + ":" + parameterText;
+        FinishesEvaluator eval = this.cache.get( key );
+        if ( eval == null ) {
+            eval = new FinishesEvaluator( type,
+                                       isNegated,
+                                       parameterText );
+            this.cache.put( key,
+                            eval );
+        }
+        return eval;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public String[] getEvaluatorIds() {
+        return SUPPORTED_IDS;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public boolean isNegatable() {
+        return true;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public boolean operatesOnFactHandles() {
+        return true;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public boolean supportsType(ValueType type) {
+        // supports all types, since it operates over fact handles
+        // Note: should we change this interface to allow checking of event classes only?
+        return true;
+    }
+
+    /**
+     * Implements the 'finishes' evaluator itself
+     */
+    public static class FinishesEvaluator extends BaseEvaluator {
+		private static final long serialVersionUID = 6232789044144077522L;
+		
+		private long                  startMinDev, startMaxDev;
+        private long                  endDev;
+
+        public FinishesEvaluator(final ValueType type,
+                              final boolean isNegated,
+                              final String parameters) {
+            super( type,
+                   isNegated ? FINISHES_NOT : FINISHES );
+            this.parseParameters( parameters );
+        }
+        
+        @Override
+        public Object prepareObject(InternalFactHandle handle) {
+            return handle;
+        }
+        
+        public boolean evaluate(InternalWorkingMemory workingMemory,
+                                final Extractor extractor,
+                                final Object object1,
+                                final FieldValue object2) {
+            throw new RuntimeDroolsException( "The 'finishes' operator can only be used to compare one event to another, and never to compare to literal constraints." );
+        }
+
+        public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+                final VariableContextEntry context,
+                final Object left) {
+			
+        	if ( context.rightNull ) {
+        		return false;
+				}
+			long distStart = ((EventFactHandle)((ObjectVariableContextEntry) context).right).getStartTimestamp() - ((EventFactHandle) left ).getStartTimestamp();
+			long distEnd = Math.abs(((EventFactHandle) left ).getEndTimestamp() - ((EventFactHandle)((ObjectVariableContextEntry) context).right).getEndTimestamp());
+			return this.getOperator().isNegated() ^ ( distStart >= this.startMinDev && distStart <= this.startMaxDev 
+					&& distEnd <= this.endDev );
+		}
+			
+		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 = Math.abs(((EventFactHandle) ((ObjectVariableContextEntry) context).left).getEndTimestamp() - ((EventFactHandle) right ).getEndTimestamp());
+			return this.getOperator().isNegated() ^ ( distStart >= this.startMinDev && distStart <= this.startMaxDev 
+					&& distEnd <= this.endDev );
+		}
+			
+		public boolean evaluate(InternalWorkingMemory workingMemory,
+			     final Extractor extractor1,
+			     final Object object1,
+			     final Extractor extractor2,
+			     final Object object2) {
+			if ( extractor1.isNullValue( workingMemory,
+			              object1 ) ) {
+			return false;
+			}
+			long distStart = ((EventFactHandle) object1 ).getStartTimestamp() - ((EventFactHandle) object2 ).getStartTimestamp();
+			long distEnd = Math.abs(((EventFactHandle) object2 ).getEndTimestamp() - ((EventFactHandle) object1 ).getEndTimestamp());
+			return this.getOperator().isNegated() ^ ( distStart >= this.startMinDev && distStart <= this.startMaxDev 
+					&& distEnd <= this.endDev );
+		}
+
+        public String toString() {
+            return "finishes[" + startMinDev + ", " + startMaxDev + ", " + endDev + "]";
+        }
+
+        /* (non-Javadoc)
+         * @see java.lang.Object#hashCode()
+         */
+        @Override
+        public int hashCode() {
+            final int PRIME = 31;
+            int result = super.hashCode();
+            result = PRIME * result + (int) (endDev ^ (endDev >>> 32));
+            result = PRIME * result + (int) (startMaxDev ^ (startMaxDev >>> 32));
+            result = PRIME * result + (int) (startMinDev ^ (startMinDev >>> 32));
+            return result;
+        }
+
+        /* (non-Javadoc)
+         * @see java.lang.Object#equals(java.lang.Object)
+         */
+        @Override
+        public boolean equals(Object obj) {
+            if ( this == obj ) return true;
+            if ( !super.equals( obj ) ) return false;
+            if ( getClass() != obj.getClass() ) return false;
+            final FinishesEvaluator other = (FinishesEvaluator) obj;
+            return endDev == other.endDev && startMaxDev == other.startMaxDev && startMinDev == other.startMinDev;
+        }
+
+        /**
+         * This methods tries to parse the string of parameters to customize 
+         * the evaluator.
+         * 
+         * @param parameters
+         */
+        private void parseParameters(String parameters) {
+        	if ( parameters == null || parameters.trim().length() == 0 ) {
+                // exact matching at the end of the intervals, open bounded range for the starts
+                this.startMinDev = 1;
+                this.startMaxDev = Long.MAX_VALUE;
+                this.endDev = 0;
+                return;
+            }
+
+            try {
+                String[] ranges = parameters.split( "," );
+                if ( ranges.length == 1 ) {
+                    // exact matching at the end of the intervals
+                	// deterministic point in time for deviations of the starts of the intervals
+                	this.startMinDev = Long.parseLong( ranges[0] );
+                    this.startMaxDev = this.startMinDev;
+                    this.endDev = 0;
+                } else if ( ranges.length == 2 ) {
+                    // exact matching at the end of the intervals
+                	// range for deviations of the starts of the intervals 
+                    this.startMinDev = Long.parseLong( ranges[0] );
+                    this.startMaxDev = Long.parseLong( ranges[1] );
+                    this.endDev = 0;
+                } else if ( ranges.length == 3 ) {
+                	// max. deviation at the ends of the intervals
+                	// range for deviations of the starts of the intervals 
+                    this.startMinDev = Long.parseLong( ranges[0] );
+                    this.startMaxDev = Long.parseLong( ranges[1] );
+                    this.endDev = Long.parseLong( ranges[2] );
+                } else {
+                    throw new RuntimeDroolsException( "[Finishes Evaluator]: Not possible to parse parameters: '" + parameters + "'" );
+                }
+            } catch ( NumberFormatException e ) {
+                throw new RuntimeDroolsException( "[Finishes Evaluator]: Not possible to parse parameters: '" + parameters + "'",
+                                                  e );
+            }
+        }
+
+    }
+
+}

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/IncludesEvaluatorDefinition.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/IncludesEvaluatorDefinition.java	2007-12-13 14:53:35 UTC (rev 17222)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/IncludesEvaluatorDefinition.java	2007-12-13 14:53:48 UTC (rev 17223)
@@ -130,7 +130,7 @@
      * Implements the 'includes' evaluator itself
      */
     public static class IncludesEvaluator extends BaseEvaluator {
-		private static final long serialVersionUID = -6458186473527866405L;
+		private static final long serialVersionUID = -5947397607962049251L;
 		
 		private long                  startMinDev, startMaxDev;
         private long                  endMinDev, endMaxDev;

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/MeetsEvaluatorDefinition.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/MeetsEvaluatorDefinition.java	2007-12-13 14:53:35 UTC (rev 17222)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/MeetsEvaluatorDefinition.java	2007-12-13 14:53:48 UTC (rev 17223)
@@ -130,9 +130,9 @@
      * Implements the 'meets' evaluator itself
      */
     public static class MeetsEvaluator extends BaseEvaluator {
-        private static final long serialVersionUID = 1018648684053005286L;
+		private static final long serialVersionUID = 9091548399308812447L;
 		
-        private long                  finalRange;
+		private long                  finalRange;
 
         public MeetsEvaluator(final ValueType type,
                               final boolean isNegated,

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/MetByEvaluatorDefinition.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/MetByEvaluatorDefinition.java	2007-12-13 14:53:35 UTC (rev 17222)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/MetByEvaluatorDefinition.java	2007-12-13 14:53:48 UTC (rev 17223)
@@ -130,9 +130,9 @@
      * Implements the 'metby' evaluator itself
      */
     public static class MetByEvaluator extends BaseEvaluator {
-        private static final long serialVersionUID = 4628787624924047853L;
+		private static final long serialVersionUID = 7907908401657594347L;
 		
-        private long                  finalRange;
+		private long                  finalRange;
 
         public MetByEvaluator(final ValueType type,
                               final boolean isNegated,

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/OverlappedByEvaluatorDefinition.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/OverlappedByEvaluatorDefinition.java	2007-12-13 14:53:35 UTC (rev 17222)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/OverlappedByEvaluatorDefinition.java	2007-12-13 14:53:48 UTC (rev 17223)
@@ -130,7 +130,7 @@
      * Implements the 'overlappedby' evaluator itself
      */
     public static class OverlappedByEvaluator extends BaseEvaluator {
-		private static final long serialVersionUID = -6458186473527866405L;
+		private static final long serialVersionUID = -2768899194494247889L;
 		
 		private long                  startMinDev, startMaxDev;
         private long                  endMinDev, endMaxDev;

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/OverlapsEvaluatorDefinition.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/OverlapsEvaluatorDefinition.java	2007-12-13 14:53:35 UTC (rev 17222)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/OverlapsEvaluatorDefinition.java	2007-12-13 14:53:48 UTC (rev 17223)
@@ -130,7 +130,7 @@
      * Implements the 'overlaps' evaluator itself
      */
     public static class OverlapsEvaluator extends BaseEvaluator {
-		private static final long serialVersionUID = -6458186473527866405L;
+		private static final long serialVersionUID = -5108524288774833244L;
 		
 		private long                  startMinDev, startMaxDev;
         private long                  endMinDev, endMaxDev;

Added: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/StartedByEvaluatorDefinition.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/StartedByEvaluatorDefinition.java	                        (rev 0)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/StartedByEvaluatorDefinition.java	2007-12-13 14:53:48 UTC (rev 17223)
@@ -0,0 +1,274 @@
+/*
+ * 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 Dec 6, 2007
+ */
+package org.drools.base.evaluators;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.drools.RuntimeDroolsException;
+import org.drools.base.BaseEvaluator;
+import org.drools.base.ValueType;
+import org.drools.common.EventFactHandle;
+import org.drools.common.InternalFactHandle;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.rule.VariableRestriction.ObjectVariableContextEntry;
+import org.drools.rule.VariableRestriction.VariableContextEntry;
+import org.drools.spi.Evaluator;
+import org.drools.spi.Extractor;
+import org.drools.spi.FieldValue;
+
+/**
+ * The implementation of the 'startedby' evaluator definition
+ * 
+ * @author mgroch
+ */
+public class StartedByEvaluatorDefinition
+    implements
+    EvaluatorDefinition {
+
+    public static final Operator  STARTED_BY       = Operator.addOperatorToRegistry( "startedby",
+                                                                                  false );
+    public static final Operator  NOT_STARTED_BY   = Operator.addOperatorToRegistry( "startedby",
+                                                                                  true );
+    
+    private static final String[] SUPPORTED_IDS = { STARTED_BY.getOperatorString() };
+    
+    private Map<String, StartedByEvaluator> cache        = Collections.emptyMap();
+
+    /**
+     * @inheridDoc
+     */
+    public Evaluator getEvaluator(ValueType type,
+                                  Operator operator) {
+        return this.getEvaluator( type,
+                                  operator.getOperatorString(),
+                                  operator.isNegated(),
+                                  null );
+    }
+
+    /**
+     * @inheridDoc
+     */
+    public Evaluator getEvaluator(ValueType type,
+                                  Operator operator,
+                                  String parameterText) {
+        return this.getEvaluator( type,
+                                  operator.getOperatorString(),
+                                  operator.isNegated(),
+                                  parameterText );
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public Evaluator getEvaluator(final ValueType type,
+                                  final String operatorId,
+                                  final boolean isNegated,
+                                  final String parameterText) {
+        if ( this.cache == Collections.EMPTY_MAP ) {
+            this.cache = new HashMap<String, StartedByEvaluator>();
+        }
+        String key = isNegated + ":" + parameterText;
+        StartedByEvaluator eval = this.cache.get( key );
+        if ( eval == null ) {
+            eval = new StartedByEvaluator( type,
+                                       isNegated,
+                                       parameterText );
+            this.cache.put( key,
+                            eval );
+        }
+        return eval;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public String[] getEvaluatorIds() {
+        return SUPPORTED_IDS;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public boolean isNegatable() {
+        return true;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public boolean operatesOnFactHandles() {
+        return true;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public boolean supportsType(ValueType type) {
+        // supports all types, since it operates over fact handles
+        // Note: should we change this interface to allow checking of event classes only?
+        return true;
+    }
+
+    /**
+     * Implements the 'startedby' evaluator itself
+     */
+    public static class StartedByEvaluator extends BaseEvaluator {
+		private static final long serialVersionUID = -2655549435451501420L;
+		
+		private long                  startDev;
+        private long                  endMinDev, endMaxDev;
+
+        public StartedByEvaluator(final ValueType type,
+                              final boolean isNegated,
+                              final String parameters) {
+            super( type,
+                   isNegated ? NOT_STARTED_BY : STARTED_BY );
+            this.parseParameters( parameters );
+        }
+        
+        @Override
+        public Object prepareObject(InternalFactHandle handle) {
+            return handle;
+        }
+        
+        public boolean evaluate(InternalWorkingMemory workingMemory,
+                                final Extractor extractor,
+                                final Object object1,
+                                final FieldValue object2) {
+            throw new RuntimeDroolsException( "The 'startedby' operator can only be used to compare one event to another, and never to compare to literal constraints." );
+        }
+
+        public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+                final VariableContextEntry context,
+                final Object left) {
+			
+        	if ( context.rightNull ) {
+        		return false;
+				}
+			long distStart = Math.abs(((EventFactHandle)((ObjectVariableContextEntry) context).right).getStartTimestamp() - ((EventFactHandle) left ).getStartTimestamp());
+			long distEnd = ((EventFactHandle)((ObjectVariableContextEntry) context).right).getEndTimestamp() - ((EventFactHandle) left ).getEndTimestamp();
+			return this.getOperator().isNegated() ^ ( distStart <= this.startDev 
+					&& 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 = Math.abs(((EventFactHandle) right ).getStartTimestamp() - ((EventFactHandle) ((ObjectVariableContextEntry) context).left).getStartTimestamp());
+			long distEnd = ((EventFactHandle) right ).getEndTimestamp() - ((EventFactHandle) ((ObjectVariableContextEntry) context).left).getEndTimestamp();
+			return this.getOperator().isNegated() ^ ( distStart <= this.startDev 
+					&& distEnd >= this.endMinDev && distEnd <= this.endMaxDev );
+		}
+			
+		public boolean evaluate(InternalWorkingMemory workingMemory,
+			     final Extractor extractor1,
+			     final Object object1,
+			     final Extractor extractor2,
+			     final Object object2) {
+			if ( extractor1.isNullValue( workingMemory,
+			              object1 ) ) {
+			return false;
+			}
+			long distStart = Math.abs(((EventFactHandle) object1 ).getStartTimestamp() - ((EventFactHandle) object2 ).getStartTimestamp());
+			long distEnd = ((EventFactHandle) object1 ).getEndTimestamp() - ((EventFactHandle) object2 ).getEndTimestamp();
+			return this.getOperator().isNegated() ^ ( distStart  <= this.startDev 
+					&& distEnd >= this.endMinDev && distEnd <= this.endMaxDev );
+		}
+
+        public String toString() {
+            return "startedby[" + startDev + ", " + endMinDev + ", " + endMaxDev + "]";
+        }
+
+        /* (non-Javadoc)
+         * @see java.lang.Object#hashCode()
+         */
+        @Override
+        public int hashCode() {
+            final int PRIME = 31;
+            int result = super.hashCode();
+            result = PRIME * result + (int) (endMaxDev ^ (endMaxDev >>> 32));
+            result = PRIME * result + (int) (endMinDev ^ (endMinDev >>> 32));
+            result = PRIME * result + (int) (startDev ^ (startDev >>> 32));
+            return result;
+        }
+
+        /* (non-Javadoc)
+         * @see java.lang.Object#equals(java.lang.Object)
+         */
+        @Override
+        public boolean equals(Object obj) {
+            if ( this == obj ) return true;
+            if ( !super.equals( obj ) ) return false;
+            if ( getClass() != obj.getClass() ) return false;
+            final StartedByEvaluator other = (StartedByEvaluator) obj;
+            return endMaxDev == other.endMaxDev && endMinDev == other.endMinDev && startDev == other.startDev;
+        }
+
+        /**
+         * This methods tries to parse the string of parameters to customize 
+         * the evaluator.
+         * 
+         * @param parameters
+         */
+        private void parseParameters(String parameters) {
+            if ( parameters == null || parameters.trim().length() == 0 ) {
+                // exact matching at the beginning of the intervals, open bounded ranges for the ends
+                this.startDev = 0;
+                this.endMinDev = 1;
+                this.endMaxDev = Long.MAX_VALUE;
+                return;
+            }
+
+            try {
+                String[] ranges = parameters.split( "," );
+                if ( ranges.length == 1 ) {
+                    // exact matching at the beginning of the intervals
+                	// deterministic point in time for deviations of the ends of the intervals
+                	this.startDev = 0;
+                	this.endMinDev = Long.parseLong( ranges[0] );
+                    this.endMaxDev = this.endMinDev;
+                } else if ( ranges.length == 2 ) {
+                    // exact matching at the beginning of the intervals
+                	// range for deviations of the ends of the intervals 
+                	this.startDev = 0;
+                    this.endMinDev = Long.parseLong( ranges[0] );
+                    this.endMaxDev = Long.parseLong( ranges[1] );
+                } else if ( ranges.length == 3 ) {
+                	// max. deviation at the starts of the intervals
+                	// range for deviations of the ends of the intervals 
+                	this.startDev = Long.parseLong( ranges[0] );;
+                    this.endMinDev = Long.parseLong( ranges[1] );
+                    this.endMaxDev = Long.parseLong( ranges[2] );
+                } else {
+                    throw new RuntimeDroolsException( "[StartedBy Evaluator]: Not possible to parse parameters: '" + parameters + "'" );
+                }
+            } catch ( NumberFormatException e ) {
+                throw new RuntimeDroolsException( "[StartedBy Evaluator]: Not possible to parse parameters: '" + parameters + "'",
+                                                  e );
+            }
+        }
+
+    }
+
+}

Added: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/StartsEvaluatorDefinition.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/StartsEvaluatorDefinition.java	                        (rev 0)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/StartsEvaluatorDefinition.java	2007-12-13 14:53:48 UTC (rev 17223)
@@ -0,0 +1,274 @@
+/*
+ * 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 Dec 6, 2007
+ */
+package org.drools.base.evaluators;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.drools.RuntimeDroolsException;
+import org.drools.base.BaseEvaluator;
+import org.drools.base.ValueType;
+import org.drools.common.EventFactHandle;
+import org.drools.common.InternalFactHandle;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.rule.VariableRestriction.ObjectVariableContextEntry;
+import org.drools.rule.VariableRestriction.VariableContextEntry;
+import org.drools.spi.Evaluator;
+import org.drools.spi.Extractor;
+import org.drools.spi.FieldValue;
+
+/**
+ * The implementation of the 'starts' evaluator definition
+ * 
+ * @author mgroch
+ */
+public class StartsEvaluatorDefinition
+    implements
+    EvaluatorDefinition {
+
+    public static final Operator  STARTS       = Operator.addOperatorToRegistry( "starts",
+                                                                                  false );
+    public static final Operator  STARTS_NOT   = Operator.addOperatorToRegistry( "starts",
+                                                                                  true );
+    
+    private static final String[] SUPPORTED_IDS = { STARTS.getOperatorString() };
+    
+    private Map<String, StartsEvaluator> cache        = Collections.emptyMap();
+
+    /**
+     * @inheridDoc
+     */
+    public Evaluator getEvaluator(ValueType type,
+                                  Operator operator) {
+        return this.getEvaluator( type,
+                                  operator.getOperatorString(),
+                                  operator.isNegated(),
+                                  null );
+    }
+
+    /**
+     * @inheridDoc
+     */
+    public Evaluator getEvaluator(ValueType type,
+                                  Operator operator,
+                                  String parameterText) {
+        return this.getEvaluator( type,
+                                  operator.getOperatorString(),
+                                  operator.isNegated(),
+                                  parameterText );
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public Evaluator getEvaluator(final ValueType type,
+                                  final String operatorId,
+                                  final boolean isNegated,
+                                  final String parameterText) {
+        if ( this.cache == Collections.EMPTY_MAP ) {
+            this.cache = new HashMap<String, StartsEvaluator>();
+        }
+        String key = isNegated + ":" + parameterText;
+        StartsEvaluator eval = this.cache.get( key );
+        if ( eval == null ) {
+            eval = new StartsEvaluator( type,
+                                       isNegated,
+                                       parameterText );
+            this.cache.put( key,
+                            eval );
+        }
+        return eval;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public String[] getEvaluatorIds() {
+        return SUPPORTED_IDS;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public boolean isNegatable() {
+        return true;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public boolean operatesOnFactHandles() {
+        return true;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public boolean supportsType(ValueType type) {
+        // supports all types, since it operates over fact handles
+        // Note: should we change this interface to allow checking of event classes only?
+        return true;
+    }
+
+    /**
+     * Implements the 'starts' evaluator itself
+     */
+    public static class StartsEvaluator extends BaseEvaluator {
+		private static final long serialVersionUID = 5622952247746290865L;
+		
+		private long                  startDev;
+        private long                  endMinDev, endMaxDev;
+
+        public StartsEvaluator(final ValueType type,
+                              final boolean isNegated,
+                              final String parameters) {
+            super( type,
+                   isNegated ? STARTS_NOT : STARTS );
+            this.parseParameters( parameters );
+        }
+        
+        @Override
+        public Object prepareObject(InternalFactHandle handle) {
+            return handle;
+        }
+        
+        public boolean evaluate(InternalWorkingMemory workingMemory,
+                                final Extractor extractor,
+                                final Object object1,
+                                final FieldValue object2) {
+            throw new RuntimeDroolsException( "The 'starts' operator can only be used to compare one event to another, and never to compare to literal constraints." );
+        }
+
+        public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+                final VariableContextEntry context,
+                final Object left) {
+			
+        	if ( context.rightNull ) {
+        		return false;
+				}
+			long distStart = Math.abs(((EventFactHandle)((ObjectVariableContextEntry) context).right).getStartTimestamp() - ((EventFactHandle) left ).getStartTimestamp());
+			long distEnd = ((EventFactHandle) left ).getEndTimestamp() - ((EventFactHandle)((ObjectVariableContextEntry) context).right).getEndTimestamp();
+			return this.getOperator().isNegated() ^ ( distStart <= this.startDev 
+					&& 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 = Math.abs(((EventFactHandle) right ).getStartTimestamp() - ((EventFactHandle) ((ObjectVariableContextEntry) context).left).getStartTimestamp());
+			long distEnd = ((EventFactHandle) ((ObjectVariableContextEntry) context).left).getEndTimestamp() - ((EventFactHandle) right ).getEndTimestamp();
+			return this.getOperator().isNegated() ^ ( distStart <= this.startDev 
+					&& distEnd >= this.endMinDev && distEnd <= this.endMaxDev );
+		}
+			
+		public boolean evaluate(InternalWorkingMemory workingMemory,
+			     final Extractor extractor1,
+			     final Object object1,
+			     final Extractor extractor2,
+			     final Object object2) {
+			if ( extractor1.isNullValue( workingMemory,
+			              object1 ) ) {
+			return false;
+			}
+			long distStart = Math.abs(((EventFactHandle) object1 ).getStartTimestamp() - ((EventFactHandle) object2 ).getStartTimestamp());
+			long distEnd = ((EventFactHandle) object2 ).getEndTimestamp() - ((EventFactHandle) object1 ).getEndTimestamp();
+			return this.getOperator().isNegated() ^ ( distStart  <= this.startDev 
+					&& distEnd >= this.endMinDev && distEnd <= this.endMaxDev );
+		}
+
+        public String toString() {
+            return "starts[" + startDev + ", " + endMinDev + ", " + endMaxDev + "]";
+        }
+
+        /* (non-Javadoc)
+         * @see java.lang.Object#hashCode()
+         */
+        @Override
+        public int hashCode() {
+            final int PRIME = 31;
+            int result = super.hashCode();
+            result = PRIME * result + (int) (endMaxDev ^ (endMaxDev >>> 32));
+            result = PRIME * result + (int) (endMinDev ^ (endMinDev >>> 32));
+            result = PRIME * result + (int) (startDev ^ (startDev >>> 32));
+            return result;
+        }
+
+        /* (non-Javadoc)
+         * @see java.lang.Object#equals(java.lang.Object)
+         */
+        @Override
+        public boolean equals(Object obj) {
+            if ( this == obj ) return true;
+            if ( !super.equals( obj ) ) return false;
+            if ( getClass() != obj.getClass() ) return false;
+            final StartsEvaluator other = (StartsEvaluator) obj;
+            return endMaxDev == other.endMaxDev && endMinDev == other.endMinDev && startDev == other.startDev;
+        }
+
+        /**
+         * This methods tries to parse the string of parameters to customize 
+         * the evaluator.
+         * 
+         * @param parameters
+         */
+        private void parseParameters(String parameters) {
+            if ( parameters == null || parameters.trim().length() == 0 ) {
+                // exact matching at the beginning of the intervals, open bounded ranges for the ends
+                this.startDev = 0;
+                this.endMinDev = 1;
+                this.endMaxDev = Long.MAX_VALUE;
+                return;
+            }
+
+            try {
+                String[] ranges = parameters.split( "," );
+                if ( ranges.length == 1 ) {
+                    // exact matching at the beginning of the intervals
+                	// deterministic point in time for deviations of the ends of the intervals
+                	this.startDev = 0;
+                	this.endMinDev = Long.parseLong( ranges[0] );
+                    this.endMaxDev = this.endMinDev;
+                } else if ( ranges.length == 2 ) {
+                    // exact matching at the beginning of the intervals
+                	// range for deviations of the ends of the intervals 
+                	this.startDev = 0;
+                    this.endMinDev = Long.parseLong( ranges[0] );
+                    this.endMaxDev = Long.parseLong( ranges[1] );
+                } else if ( ranges.length == 3 ) {
+                	// max. deviation at the starts of the intervals
+                	// range for deviations of the ends of the intervals 
+                	this.startDev = Long.parseLong( ranges[0] );;
+                    this.endMinDev = Long.parseLong( ranges[1] );
+                    this.endMaxDev = Long.parseLong( ranges[2] );
+                } else {
+                    throw new RuntimeDroolsException( "[Starts Evaluator]: Not possible to parse parameters: '" + parameters + "'" );
+                }
+            } catch ( NumberFormatException e ) {
+                throw new RuntimeDroolsException( "[Starts Evaluator]: Not possible to parse parameters: '" + parameters + "'",
+                                                  e );
+            }
+        }
+
+    }
+
+}




More information about the jboss-svn-commits mailing list