[jboss-svn-commits] JBL Code SVN: r24114 - in labs/jbossrules/trunk: drools-core and 3 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Nov 26 23:16:01 EST 2008


Author: tirelli
Date: 2008-11-26 23:16:01 -0500 (Wed, 26 Nov 2008)
New Revision: 24114

Added:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/EvaluatorParametersParser.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/TimeIntervalParser.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/evaluators/
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/evaluators/TimeIntervalParserTest.java
Modified:
   labs/jbossrules/trunk/drools-core/pom.xml
   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/EvaluatorDefinition.java
   labs/jbossrules/trunk/pom.xml
Log:
JBRULES-1873: Adding support for time unit parsing. Fixing 'after' evaluator. Adding javadocs to 'after' evaluator

Modified: labs/jbossrules/trunk/drools-core/pom.xml
===================================================================
--- labs/jbossrules/trunk/drools-core/pom.xml	2008-11-27 04:03:09 UTC (rev 24113)
+++ labs/jbossrules/trunk/drools-core/pom.xml	2008-11-27 04:16:01 UTC (rev 24114)
@@ -30,6 +30,10 @@
       <artifactId>drools-api</artifactId>
     </dependency>         
     
+    <dependency>
+      <groupId>joda-time</groupId>
+      <artifactId>joda-time</artifactId>
+    </dependency>         
   </dependencies>
   
   <build>

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-27 04:03:09 UTC (rev 24113)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/AfterEvaluatorDefinition.java	2008-11-27 04:16:01 UTC (rev 24114)
@@ -20,7 +20,6 @@
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
-import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
@@ -39,29 +38,61 @@
 import org.drools.time.Interval;
 
 /**
- * The implementation of the 'after' evaluator definition
+ * <p>The implementation of the 'after' evaluator definition.</p>
+ * 
+ * <p>The <b><code>after</code></b> evaluator correlates two events and matches when the distance from the 
+ * current event to the event being correlated belongs to the distance range declared 
+ * for the operator.</p> 
+ * 
+ * <p>Lets look at an example:</p>
+ * 
+ * <pre>$eventA : EventA( this after[ 3m30s, 4m ] $eventB )</pre>
  *
+ * <p>The previous pattern will match if and only if the temporal distance between the 
+ * time when $eventB finished and the time when $eventA started is between ( 3 minutes 
+ * and 30 seconds ) and ( 4 minutes ). In other words:</p>
+ * 
+ * <pre> 3m30s <= $eventA.startTimestamp - $eventB.endTimeStamp <= 4m </pre>
+ * 
+ * <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, it is assumed that it is the finish value and the default
+ * initial value is 1ms.</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. The only 
+ * requirement is that the initial distance in the interval must always be lower than the 
+ * final distance. Example:</p>
+ * 
+ * <pre>$eventA : EventA( this after[ -3m30s, -2m ] $eventB )</pre>
+ *
  * @author etirelli
  */
 public class AfterEvaluatorDefinition
     implements
     EvaluatorDefinition {
-    
-    public static final Operator   AFTER         = Operator.addOperatorToRegistry( "after",
-                                                                                   false );
-    public static final Operator   NOT_AFTER     = Operator.addOperatorToRegistry( "after",
-                                                                                   true );
 
-    private static final String[]  SUPPORTED_IDS = {AFTER.getOperatorString()};
+    public static final Operator        AFTER         = Operator.addOperatorToRegistry( "after",
+                                                                                        false );
+    public static final Operator        NOT_AFTER     = Operator.addOperatorToRegistry( "after",
+                                                                                        true );
 
-    private Map<String, Evaluator> cache         = Collections.emptyMap();
+    private static final String[]       SUPPORTED_IDS = {AFTER.getOperatorString()};
 
-    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        cache  = (Map<String, Evaluator>)in.readObject();
+    private Map<String, Evaluator>      cache         = Collections.emptyMap();
+    private volatile TimeIntervalParser parser        = new TimeIntervalParser();
+
+    @SuppressWarnings("unchecked")
+    public void readExternal(ObjectInput in) throws IOException,
+                                            ClassNotFoundException {
+        cache = (Map<String, Evaluator>) in.readObject();
     }
 
     public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeObject(cache);
+        out.writeObject( cache );
     }
 
     /**
@@ -100,8 +131,10 @@
         String key = isNegated + ":" + parameterText;
         Evaluator eval = this.cache.get( key );
         if ( eval == null ) {
+            Long[] params = parser.parse( parameterText );
             eval = new AfterEvaluator( type,
                                        isNegated,
+                                       params,
                                        parameterText );
             this.cache.put( key,
                             eval );
@@ -147,28 +180,32 @@
 
         private long              initRange;
         private long              finalRange;
+        private String            paramText;
 
         public AfterEvaluator() {
         }
 
         public AfterEvaluator(final ValueType type,
                               final boolean isNegated,
-                              final String parameters) {
+                              final Long[] parameters,
+                              final String paramText ) {
             super( type,
                    isNegated ? NOT_AFTER : AFTER );
-            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 );
             initRange = in.readLong();
             finalRange = in.readLong();
         }
 
         public void writeExternal(ObjectOutput out) throws IOException {
-            super.writeExternal(out);
-            out.writeLong(initRange);
-            out.writeLong(finalRange);
+            super.writeExternal( out );
+            out.writeLong( initRange );
+            out.writeLong( finalRange );
         }
 
         @Override
@@ -180,19 +217,19 @@
         public boolean isTemporal() {
             return true;
         }
-        
+
         @Override
         public Interval getInterval() {
             long init = this.initRange;
             long end = this.finalRange;
-            if( this.getOperator().isNegated() ) {
-                if( init == Interval.MIN && end != Interval.MAX ) {
-                    init = finalRange+1;
+            if ( this.getOperator().isNegated() ) {
+                if ( init == Interval.MIN && end != Interval.MAX ) {
+                    init = finalRange + 1;
                     end = Interval.MAX;
-                } else if( init != Interval.MIN && end == Interval.MAX ) {
+                } else if ( init != Interval.MIN && end == Interval.MAX ) {
                     init = Interval.MIN;
-                    end = initRange-1;
-                } else if( init == Interval.MIN && end == Interval.MAX ) {
+                    end = initRange - 1;
+                } else if ( init == Interval.MIN && end == Interval.MAX ) {
                     init = 0;
                     end = -1;
                 } else {
@@ -200,9 +237,10 @@
                     end = Interval.MAX;
                 }
             }
-            return new Interval( init, end );
+            return new Interval( init,
+                                 end );
         }
-        
+
         public boolean evaluate(InternalWorkingMemory workingMemory,
                                 final InternalReadAccessor extractor,
                                 final Object object1,
@@ -217,7 +255,7 @@
                 return false;
             }
             long dist = ((EventFactHandle) ((ObjectVariableContextEntry) context).right).getStartTimestamp() - ((EventFactHandle) left).getEndTimestamp();
-            return this.getOperator().isNegated() ^ ( dist >= this.initRange && dist <= this.finalRange );
+            return this.getOperator().isNegated() ^ (dist >= this.initRange && dist <= this.finalRange);
         }
 
         public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
@@ -229,7 +267,7 @@
             }
             long dist = ((EventFactHandle) right).getStartTimestamp() - ((EventFactHandle) ((ObjectVariableContextEntry) context).left).getEndTimestamp();
 
-            return this.getOperator().isNegated() ^ ( dist >= this.initRange && dist <= this.finalRange );
+            return this.getOperator().isNegated() ^ (dist >= this.initRange && dist <= this.finalRange);
         }
 
         public boolean evaluate(InternalWorkingMemory workingMemory,
@@ -242,11 +280,11 @@
                 return false;
             }
             long dist = ((EventFactHandle) object1).getStartTimestamp() - ((EventFactHandle) object2).getEndTimestamp();
-            return this.getOperator().isNegated() ^ ( dist >= this.initRange && dist <= this.finalRange );
+            return this.getOperator().isNegated() ^ (dist >= this.initRange && dist <= this.finalRange);
         }
 
         public String toString() {
-            return this.getOperator().toString()+ "[" + initRange + ", " + finalRange + "]";
+            return this.getOperator().toString() + "[" + paramText + "]";
         }
 
         /* (non-Javadoc)
@@ -274,36 +312,26 @@
         }
 
         /**
-         * 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 ) {
+        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 ) {
+                // up to that value
+                this.initRange = 1;
+                this.finalRange = parameters[0].longValue();
+            } else if( parameters.length == 2 ) {
+                this.initRange = parameters[0].longValue();
+                this.finalRange = parameters[1].longValue();
+            } else {
+                throw new RuntimeDroolsException( "[After Evaluator]: Not possible to have more than 2 parameters: '" + paramText + "'" );
             }
-
-            try {
-                String[] ranges = parameters.split( "," );
-                if ( ranges.length == 1 ) {
-                    // deterministic point in time
-                    this.initRange = Long.parseLong( ranges[0] );
-                    this.finalRange = this.initRange;
-                } else if ( ranges.length == 2 ) {
-                    // regular range
-                    this.initRange = Long.parseLong( ranges[0] );
-                    this.finalRange = Long.parseLong( ranges[1] );
-                } else {
-                    throw new RuntimeDroolsException( "[After Evaluator]: Not possible to parse parameters: '" + parameters + "'" );
-                }
-            } catch ( NumberFormatException e ) {
-                throw new RuntimeDroolsException( "[After Evaluator]: Not possible to parse parameters: '" + parameters + "'",
-                                                  e );
-            }
         }
 
     }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/EvaluatorDefinition.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/EvaluatorDefinition.java	2008-11-27 04:03:09 UTC (rev 24113)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/EvaluatorDefinition.java	2008-11-27 04:16:01 UTC (rev 24114)
@@ -42,7 +42,7 @@
     public String[] getEvaluatorIds();
 
     /**
-     * My appologies to english speakers if the word "negatable" does not
+     * My apologies to English speakers if the word "negatable" does not
      * exists. :)
      *
      * This method returns true if this evaluator supports negation. Example:
@@ -59,7 +59,7 @@
      *
      * @param type the type of the attributes this evaluator will
      *             operate on. This is important because the evaluator
-     *             may do optimizations and type coercion based on the
+     *             may do optimisations and type coercion based on the
      *             types it is evaluating. It is also possible that
      *             this evaluator does not support a given type.
      *
@@ -87,7 +87,7 @@
      *
      * @param type the type of the attributes this evaluator will
      *             operate on. This is important because the evaluator
-     *             may do optimizations and type coercion based on the
+     *             may do optimisations and type coercion based on the
      *             types it is evaluating. It is also possible that
      *             this evaluator does not support a given type.
      *
@@ -111,7 +111,7 @@
      *
      * @param type the type of the attributes this evaluator will
      *             operate on. This is important because the evaluator
-     *             may do optimizations and type coercion based on the
+     *             may do optimisations and type coercion based on the
      *             types it is evaluating. It is also possible that
      *             this evaluator does not support a given type.
      *

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/EvaluatorParametersParser.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/EvaluatorParametersParser.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/EvaluatorParametersParser.java	2008-11-27 04:16:01 UTC (rev 24114)
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2008 Red Hat
+ * 
+ * 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.
+ *
+ */
+package org.drools.base.evaluators;
+
+/**
+ * An interface for Evaluator Parameters Parser.
+ * 
+ * Evaluators may optionally have parameters. This parameters are passed into the
+ * EvaluatorDefinition as a String that needs to eventually be parsed. This interface
+ * defines the operations a parser implementation must expose. 
+ * 
+ * @author etirelli
+ */
+public interface EvaluatorParametersParser {
+    
+    /**
+     * Parses the given paramText and return an array
+     * of objects where each position in the array corresponds
+     * to the appropriate parameter in the parameter string.
+     * 
+     * @param paramText the string of parameters
+     * 
+     * @return the array of objects corresponding to each parameter
+     */
+    public Object[] parse( final String paramText );
+
+}

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/TimeIntervalParser.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/TimeIntervalParser.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/TimeIntervalParser.java	2008-11-27 04:16:01 UTC (rev 24114)
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2008 Red Hat
+ * 
+ * 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.
+ *
+ */
+package org.drools.base.evaluators;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.drools.RuntimeDroolsException;
+
+/**
+ * A parameters parser that uses JodaTime for time units parsing.
+ *  
+ * @author etirelli
+ */
+public class TimeIntervalParser
+    implements
+    EvaluatorParametersParser {
+
+    // Simple syntax
+    private static final Pattern SIMPLE  = Pattern.compile( "([+-])?((\\d+)[Dd])?\\s*((\\d+)[Hh])?\\s*((\\d+)[Mm])?\\s*((\\d+)[Ss])?\\s*((\\d+)([Mm][Ss])?)?" );
+    private static final int     SIM_SGN = 1;
+    private static final int     SIM_DAY = 3;
+    private static final int     SIM_HOU = 5;
+    private static final int     SIM_MIN = 7;
+    private static final int     SIM_SEC = 9;
+    private static final int     SIM_MS  = 11;
+
+    // ISO 8601 compliant
+    //    private static final Pattern ISO8601   = Pattern.compile( "(P((\\d+)[Yy])?((\\d+)[Mm])?((\\d+)[Dd])?)?(T((\\d+)[Hh])?((\\d+)[Mm])?((\\d+)[Ss])?((\\d+)([Mm][Ss])?)?)?" );
+
+    private static final long    SEC_MS  = 1000;
+    private static final long    MIN_MS  = 60 * SEC_MS;
+    private static final long    HOU_MS  = 60 * MIN_MS;
+    private static final long    DAY_MS  = 24 * HOU_MS;
+
+    //    private static final long    MON_MS = 30 * DAY_MS;
+    //    private static final long    YEA_MS = 365 * DAY_MS;
+
+    /**
+     * @inheritDoc
+     * 
+     * @see org.drools.base.evaluators.EvaluatorParametersParser#parse(java.lang.String)
+     */
+    public Long[] parse(String paramText) {
+        if ( paramText == null || paramText.trim().length() == 0 ) {
+            return new Long[0];
+        }
+        String[] params = paramText.split( "," );
+        Long[] result = new Long[params.length];
+        int index = 0;
+        for ( String param : params ) {
+            String trimmed = param.trim();
+            if ( trimmed.length() > 0 ) {
+                Matcher mat = SIMPLE.matcher( trimmed );
+                if ( mat.matches() ) {
+                    int days = (mat.group( SIM_DAY ) != null) ? Integer.parseInt( mat.group( SIM_DAY ) ) : 0;
+                    int hours = (mat.group( SIM_HOU ) != null) ? Integer.parseInt( mat.group( SIM_HOU ) ) : 0;
+                    int min = (mat.group( SIM_MIN ) != null) ? Integer.parseInt( mat.group( SIM_MIN ) ) : 0;
+                    int sec = (mat.group( SIM_SEC ) != null) ? Integer.parseInt( mat.group( SIM_SEC ) ) : 0;
+                    int ms = (mat.group( SIM_MS ) != null) ? Integer.parseInt( mat.group( SIM_MS ) ) : 0;
+                    long r = days * DAY_MS + hours * HOU_MS + min * MIN_MS + sec * SEC_MS + ms;
+                    if( mat.group(SIM_SGN) != null && mat.group( SIM_SGN ).equals( "-" ) ) {
+                        r = -r;
+                    }
+                    result[index] = new Long( r );
+                } else {
+                    throw new RuntimeDroolsException( "Error parsing interval value: " + param );
+                }
+            } else {
+                throw new RuntimeDroolsException( "Empty parameters not allowed in: [" + paramText + "]" );
+            }
+            index++;
+        }
+        return result;
+    }
+
+}

Added: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/evaluators/TimeIntervalParserTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/evaluators/TimeIntervalParserTest.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/evaluators/TimeIntervalParserTest.java	2008-11-27 04:16:01 UTC (rev 24114)
@@ -0,0 +1,142 @@
+/*
+ * Copyright 2008 Red Hat
+ * 
+ * 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.
+ *
+ */
+package org.drools.base.evaluators;
+
+import junit.framework.TestCase;
+
+/**
+ * @author admin
+ *
+ */
+public class TimeIntervalParserTest extends TestCase {
+
+    /* (non-Javadoc)
+     * @see junit.framework.TestCase#setUp()
+     */
+    protected void setUp() throws Exception {
+        super.setUp();
+    }
+
+    /**
+     * Test method for {@link org.drools.base.evaluators.TimeIntervalParser#parse(java.lang.String)}.
+     */
+    public void testParse() {
+        String input = "2d10h49m10s789ms";
+        long expected = 211750789;
+        Long[] result = new TimeIntervalParser().parse( input );
+        assertEquals( 1, result.length );
+        assertEquals( expected, result[0].longValue() );
+    }
+
+    /**
+     * Test method for {@link org.drools.base.evaluators.TimeIntervalParser#parse(java.lang.String)}.
+     */
+    public void testParse2() {
+        String input = "10h49m789ms";
+        long expected = 10 * 3600000 + 49 * 60000 + 789;
+        Long[] result = new TimeIntervalParser().parse( input );
+        assertEquals( 1, result.length );
+        assertEquals( expected, result[0].longValue() );
+    }
+
+    /**
+     * Test method for {@link org.drools.base.evaluators.TimeIntervalParser#parse(java.lang.String)}.
+     */
+    public void testParse3() {
+        // ms are optional
+        String input = " 10h49m789 , 12h ";
+        long expected1 = 10 * 3600000 + 49 * 60000 + 789;
+        long expected2 = 12 * 3600000;
+        Long[] result = new TimeIntervalParser().parse( input );
+        assertEquals( 2, result.length );
+        assertEquals( expected1, result[0].longValue() );
+        assertEquals( expected2, result[1].longValue() );
+    }
+
+    /**
+     * Test method for {@link org.drools.base.evaluators.TimeIntervalParser#parse(java.lang.String)}.
+     */
+    public void testParse4() {
+        // raw ms without the unit declared
+        String input = " 15957, 3500000 ";
+        long expected1 = 15957;
+        long expected2 = 3500000;
+        Long[] result = new TimeIntervalParser().parse( input );
+        assertEquals( 2, result.length );
+        assertEquals( expected1, result[0].longValue() );
+        assertEquals( expected2, result[1].longValue() );
+    }
+
+    /**
+     * Test method for {@link org.drools.base.evaluators.TimeIntervalParser#parse(java.lang.String)}.
+     */
+    public void testParse5() {
+        // empty input
+        String input = "";
+        Long[] result = new TimeIntervalParser().parse( input );
+        assertEquals( 0, result.length );
+    }
+    
+    /**
+     * Test method for {@link org.drools.base.evaluators.TimeIntervalParser#parse(java.lang.String)}.
+     */
+    public void testParse6() {
+        // null input
+        String input = null;
+        Long[] result = new TimeIntervalParser().parse( input );
+        assertEquals( 0, result.length );
+    }
+    
+    /**
+     * Test method for {@link org.drools.base.evaluators.TimeIntervalParser#parse(java.lang.String)}.
+     */
+    public void testParse7() {
+        // empty input
+        String input = "  ";
+        Long[] result = new TimeIntervalParser().parse( input );
+        assertEquals( 0, result.length );
+    }
+    
+    /**
+     * Test method for {@link org.drools.base.evaluators.TimeIntervalParser#parse(java.lang.String)}.
+     */
+    public void testParse8() {
+        // raw ms without the unit declared
+        String input = " -15957, 3500000 ";
+        long expected1 = -15957;
+        long expected2 = 3500000;
+        Long[] result = new TimeIntervalParser().parse( input );
+        assertEquals( 2, result.length );
+        assertEquals( expected1, result[0].longValue() );
+        assertEquals( expected2, result[1].longValue() );
+    }
+
+    /**
+     * Test method for {@link org.drools.base.evaluators.TimeIntervalParser#parse(java.lang.String)}.
+     */
+    public void testParse9() {
+        // ms are optional
+        String input = " -10h49m789 , -8h ";
+        long expected1 = -( 10 * 3600000 + 49 * 60000 + 789 );
+        long expected2 = -( 8 * 3600000 );
+        Long[] result = new TimeIntervalParser().parse( input );
+        assertEquals( 2, result.length );
+        assertEquals( expected1, result[0].longValue() );
+        assertEquals( expected2, result[1].longValue() );
+    }
+
+}

Modified: labs/jbossrules/trunk/pom.xml
===================================================================
--- labs/jbossrules/trunk/pom.xml	2008-11-27 04:03:09 UTC (rev 24113)
+++ labs/jbossrules/trunk/pom.xml	2008-11-27 04:16:01 UTC (rev 24114)
@@ -920,6 +920,11 @@
                 <artifactId>mvel2</artifactId>
                 <version>${mvel.dep.version}</version>
             </dependency>
+            <dependency>
+                <groupId>joda-time</groupId>
+                <artifactId>joda-time</artifactId>
+                <version>1.5.2</version>
+            </dependency>
 
             <!-- drools-compiler -->
             <dependency>




More information about the jboss-svn-commits mailing list