commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hen...@apache.org
Subject svn commit: r1667031 - in /commons/proper/jexl/trunk/src: main/java/org/apache/commons/jexl3/ main/java/org/apache/commons/jexl3/internal/ main/java/org/apache/commons/jexl3/internal/introspection/ test/java/org/apache/commons/jexl3/
Date Mon, 16 Mar 2015 15:13:59 GMT
Author: henrib
Date: Mon Mar 16 15:13:58 2015
New Revision: 1667031

URL: http://svn.apache.org/r1667031
Log:
JEXL:
Implementing JEXL-152; ranges can be long or integer and implement contains(...) method

Added:
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/LongRange.java
  (with props)
    commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/RangeTest.java
      - copied, changed from r1665580, commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ArrayLiteralTest.java
Modified:
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/JexlScript.java
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Engine.java
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/IntegerRange.java
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/ArrayListWrapper.java

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java?rev=1667031&r1=1667030&r2=1667031&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java Mon
Mar 16 15:13:58 2015
@@ -285,8 +285,8 @@ public class JexlArithmetic {
     }
 
     /**
-     * Called by the interpreter when evaluating a literal array.
-     * @param size the number of elements in the array
+     * Called by the interpreter when evaluating a literal set.
+     * @param size the number of elements in the set
      * @return the array builder
      */
     public SetBuilder setBuilder(int size) {
@@ -323,16 +323,21 @@ public class JexlArithmetic {
 
     /**
      * Creates a literal range.
-     * <p>The default implementation only accepts integers.</p>
+     * <p>The default implementation only accepts integers and longs.</p>
      * @param from the included lower bound value (null if none)
      * @param to   the included upper bound value (null if none)
      * @return the range as an iterable
      * @throws ArithmeticException as an option if creation fails
      */
     public Iterable<?> createRange(Object from, Object to) throws ArithmeticException
{
-        final int ifrom = toInteger(from);
-        final int ito = toInteger(to);
-        return new org.apache.commons.jexl3.internal.IntegerRange(ifrom, ito);
+        final long lfrom = toLong(from);
+        final long lto = toLong(to);
+        if ((lfrom >= Integer.MIN_VALUE && lfrom <= Integer.MAX_VALUE)
+            && (lto >= Integer.MIN_VALUE && lto <= Integer.MAX_VALUE))
{
+            return new org.apache.commons.jexl3.internal.IntegerRange((int) lfrom, (int)
lto);
+        } else {
+            return new org.apache.commons.jexl3.internal.LongRange(lfrom, lto);
+        }
     }
 
     /**

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/JexlScript.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/JexlScript.java?rev=1667031&r1=1667030&r2=1667031&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/JexlScript.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/JexlScript.java Mon Mar
16 15:13:58 2015
@@ -91,8 +91,8 @@ public interface JexlScript {
     Set<List<String>> getVariables();
 
     /**
-     * Gets this script pragmas
-     * @return the pragmas map
+     * Gets this script pragmas.
+     * @return the (non null, may be empty) pragmas map
      */
     Map<String, Object> getPragmas();
 

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Engine.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Engine.java?rev=1667031&r1=1667030&r2=1667031&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Engine.java
(original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Engine.java
Mon Mar 16 15:13:58 2015
@@ -572,6 +572,7 @@ public class Engine extends JexlEngine {
 
     /**
      * Fills up the list of variables accessed by a node.
+     * @param script the owning script
      * @param node the node
      * @param collector the variable collector
      */

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/IntegerRange.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/IntegerRange.java?rev=1667031&r1=1667030&r2=1667031&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/IntegerRange.java
(original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/IntegerRange.java
Mon Mar 16 15:13:58 2015
@@ -16,12 +16,14 @@
  */
 package org.apache.commons.jexl3.internal;
 
+import java.lang.reflect.Array;
+import java.util.Collection;
 import java.util.Iterator;
 
 /**
  * A range of integers.
  */
-public class IntegerRange implements Iterable<Integer> {
+public class IntegerRange implements Collection<Integer> {
     /** The lower boundary. */
     private final int low;
     /** The upper boundary. */
@@ -33,14 +35,112 @@ public class IntegerRange implements Ite
      * @param to  the higher inclusive boundary
      */
     public IntegerRange(int from, int to) {
-        low = from;
-        high = to;
+        if (from > to) {
+            high = from;
+            low = to;
+        } else {
+            low = from;
+            high = to;
+        }
     }
 
     @Override
     public Iterator<Integer> iterator() {
         return new IntegerIterator(low, high);
     }
+
+    @Override
+    public int size() {
+        return high - low + 1;
+    }
+
+    @Override
+    public boolean isEmpty() {
+        return false;
+    }
+
+    @Override
+    public boolean contains(Object o) {
+        if (o instanceof Number) {
+            long v = ((Number) o).intValue();
+            return low <= v && v <= high;
+        } else {
+            return false;
+        }
+    }
+
+    @Override
+    public Object[] toArray() {
+        final int size = size();
+        Object[] array = new Object[size];
+        for(int a = 0; a < size; ++a) {
+            array[a] = low + a;
+        }
+        return array;
+    }
+
+    @Override
+    @SuppressWarnings("unchecked")
+    public <T> T[] toArray(T[] array) {
+        final Class<?> ct = array.getClass().getComponentType();
+        final int length = size();
+        T[] copy = array;
+        if (ct.isAssignableFrom(Integer.class)) {
+            if (array.length < length) {
+                copy = ct == Object.class
+                       ? (T[]) new Object[length]
+                       : (T[]) Array.newInstance(ct, length);
+            }
+            for (int a = 0; a < length; ++a) {
+                Array.set(copy, a, low + a);
+            }
+            if (length < array.length) {
+                array[length] = null;
+            }
+            return copy;
+        }
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean containsAll(Collection<?> c) {
+        for(Object cc : c) {
+            if (!contains(cc)) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    @Override
+    public boolean add(Integer e) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean remove(Object o) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean addAll(Collection<? extends Integer> c) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean removeAll(Collection<?> c) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean retainAll(Collection<?> c) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void clear() {
+        throw new UnsupportedOperationException();
+    }
 }
 
 /**

Added: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/LongRange.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/LongRange.java?rev=1667031&view=auto
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/LongRange.java
(added)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/LongRange.java
Mon Mar 16 15:13:58 2015
@@ -0,0 +1,189 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.commons.jexl3.internal;
+
+import java.lang.reflect.Array;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+/**
+ * A range of longs.
+ * <p>Behaves as a readonly collection of longs.
+ */
+public class LongRange implements Collection<Long>  {
+    /** The lower boundary. */
+    private final long low;
+    /** The upper boundary. */
+    private final long high;
+
+    /**
+     * Creates a new range.
+     * @param from the lower inclusive boundary
+     * @param to  the higher inclusive boundary
+     */
+    public LongRange(long from, long to) {
+        if (from > to) {
+            high = from;
+            low = to;
+        } else {
+            low = from;
+            high = to;
+        }
+    }
+
+    @Override
+    public Iterator<Long> iterator() {
+        return new LongIterator(low, high);
+    }
+
+    @Override
+    public int size() {
+        return (int)(high - low + 1);
+    }
+
+    @Override
+    public boolean isEmpty() {
+        return false;
+    }
+
+    @Override
+    public boolean contains(Object o) {
+        if (o instanceof Number) {
+            long v = ((Number) o).longValue();
+            return low <= v && v <= high;
+        } else {
+            return false;
+        }
+    }
+
+    @Override
+    public Object[] toArray() {
+        final int size = size();
+        Object[] array = new Object[size];
+        for(int a = 0; a < size; ++a) {
+            array[a] = low + a;
+        }
+        return array;
+    }
+
+    @Override
+    @SuppressWarnings("unchecked")
+    public <T> T[] toArray(T[] array) {
+        final Class<?> ct = array.getClass().getComponentType();
+        final int length = size();
+        T[] copy = array;
+        if (ct.isAssignableFrom(Long.class)) {
+            if (array.length < length) {
+                copy = ct == Object.class
+                       ? (T[]) new Object[length]
+                       : (T[]) Array.newInstance(ct, length);
+            }
+            for (int a = 0; a < length; ++a) {
+                Array.set(copy, a, low + a);
+            }
+            if (length < array.length) {
+                array[length] = null;
+            }
+            return copy;
+        }
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean containsAll(Collection<?> c) {
+        for(Object cc : c) {
+            if (!contains(cc)) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    @Override
+    public boolean add(Long e) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean remove(Object o) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean addAll(Collection<? extends Long> c) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean removeAll(Collection<?> c) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean retainAll(Collection<?> c) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void clear() {
+        throw new UnsupportedOperationException();
+    }
+}
+
+/**
+ * An iterator on a long range.
+ */
+class LongIterator implements Iterator<Long> {
+    /** The lower boundary. */
+    private final long low;
+    /** The upper boundary. */
+    private final long high;
+    /** The current value. */
+    private long cursor;
+    /**
+     * Creates a iterator on the range.
+     * @param l low boundary
+     * @param h high boundary
+     */
+    public LongIterator(long l, long h) {
+        low = l;
+        high = h;
+        cursor = low;
+    }
+
+    @Override
+    public boolean hasNext() {
+        return cursor <= high;
+    }
+
+    @Override
+    public Long next() {
+        if (cursor <= high) {
+            long next = cursor;
+            cursor += 1;
+            return Long.valueOf(next);
+        } else {
+            throw new NoSuchElementException();
+        }
+    }
+
+    @Override
+    public void remove() {
+        throw new UnsupportedOperationException();
+    }
+}

Propchange: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/LongRange.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/ArrayListWrapper.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/ArrayListWrapper.java?rev=1667031&r1=1667030&r2=1667031&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/ArrayListWrapper.java
(original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/ArrayListWrapper.java
Mon Mar 16 15:13:58 2015
@@ -18,10 +18,6 @@ package org.apache.commons.jexl3.interna
 
 import java.lang.reflect.Array;
 import java.util.AbstractList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.ListIterator;
 import java.util.RandomAccess;
 
 /**
@@ -55,7 +51,7 @@ public class ArrayListWrapper extends Ab
     /** {@inheritDoc} */
     @Override
     public Object set(int index, Object element) {
-        Object old = get(index);
+        Object old = Array.get(array, index);
         Array.set(array, index, element);
         return old;
     }
@@ -79,7 +75,7 @@ public class ArrayListWrapper extends Ab
     @Override
     @SuppressWarnings("unchecked")
     public <T> T[] toArray(T[] a) {
-        int size = size();
+        final int size = size();
         if (a.length < size) {
             T[] x = (T[]) Array.newInstance(a.getClass().getComponentType(), size);
             System.arraycopy(a, a.length, x, 0, a.length);
@@ -116,85 +112,4 @@ public class ArrayListWrapper extends Ab
     public boolean contains(Object o) {
         return indexOf(o) != -1;
     }
-
-    @Override
-    public boolean isEmpty() {
-        return super.isEmpty();
-    }
-
-    @Override
-    public Iterator<Object> iterator() {
-        return super.iterator();
-    }
-
-    @Override
-    public boolean containsAll(Collection<?> c) {
-        return super.containsAll(c);
-    }
-
-    @Override
-    public int lastIndexOf(Object o) {
-        return super.lastIndexOf(o);
-    }
-
-    @Override
-    public ListIterator<Object> listIterator() {
-        return super.listIterator();
-    }
-
-    @Override
-    public ListIterator<Object> listIterator(int index) {
-        return super.listIterator(index);
-    }
-
-    @Override
-    public List<Object> subList(int fromIndex, int toIndex) {
-        return super.subList(fromIndex, toIndex);
-    }
-
-    @Override
-    public boolean add(Object o) {
-        throw new UnsupportedOperationException("Not supported.");
-    }
-
-    @Override
-    public boolean remove(Object o) {
-        throw new UnsupportedOperationException("Not supported.");
-    }
-
-    @Override
-    public boolean addAll(Collection<? extends Object> c) {
-        throw new UnsupportedOperationException("Not supported.");
-    }
-
-    @Override
-    public boolean addAll(int index, Collection<? extends Object> c) {
-        throw new UnsupportedOperationException("Not supported.");
-    }
-
-    @Override
-    public boolean removeAll(Collection<?> c) {
-        throw new UnsupportedOperationException("Not supported.");
-    }
-
-    @Override
-    public boolean retainAll(Collection<?> c) {
-        throw new UnsupportedOperationException("Not supported.");
-    }
-
-    @Override
-    public void clear() {
-        throw new UnsupportedOperationException("Not supported.");
-    }
-
-    @Override
-    public void add(int index, Object element) {
-        throw new UnsupportedOperationException("Not supported.");
-    }
-
-    @Override
-    public Object remove(int index) {
-        throw new UnsupportedOperationException("Not supported.");
-    }
-
 }
\ No newline at end of file

Copied: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/RangeTest.java (from
r1665580, commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ArrayLiteralTest.java)
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/RangeTest.java?p2=commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/RangeTest.java&p1=commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ArrayLiteralTest.java&r1=1665580&r2=1667031&rev=1667031&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ArrayLiteralTest.java
(original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/RangeTest.java Mon Mar
16 15:13:58 2015
@@ -14,103 +14,156 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.commons.jexl3;
+package  org.apache.commons.jexl3;
 
-import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import org.junit.Assert;
 
 /**
- * Tests for array literals
- * @since 2.0
+ * Tests for ranges.
+ * @since 3.0
  */
-public class ArrayLiteralTest extends JexlTestCase {
+public class RangeTest extends JexlTestCase {
 
-    public ArrayLiteralTest() {
-        super("ArrayLiteralTest");
+    public RangeTest() {
+        super("RangeTest");
     }
 
-    public void testLiteralWithStrings() throws Exception {
-        JexlExpression e = JEXL.createExpression( "[ 'foo' , 'bar' ]" );
+    public void testIntegerRangeOne() throws Exception {
+        JexlExpression e = JEXL.createExpression("(1..1)");
         JexlContext jc = new MapContext();
 
-        Object o = e.evaluate( jc );
-        Object[] check = { "foo", "bar" };
-        assertTrue( Arrays.equals(check, (Object[])o) );
+        Object o = e.evaluate(jc);
+        Assert.assertTrue(o instanceof Collection<?>);
+        Collection<?> c = (Collection<?>) o;
+        Assert.assertEquals(1, c.size());
+        Object[] a = c.toArray();
+        Assert.assertEquals(1, a.length);
+        Assert.assertEquals(1, ((Number) a[0]).intValue());
     }
 
-    public void testLiteralWithOneEntry() throws Exception {
-        JexlExpression e = JEXL.createExpression( "[ 'foo' ]" );
+    public void testIntegerRange() throws Exception {
+        JexlExpression e = JEXL.createExpression("(1..32)");
         JexlContext jc = new MapContext();
 
-        Object o = e.evaluate( jc );
-        Object[] check = { "foo" };
-        assertTrue( Arrays.equals(check, (Object[])o) );
-    }
+        Object o = e.evaluate(jc);
+        Assert.assertTrue(o instanceof Collection<?>);
+        Collection<?> c = (Collection<?>) o;
+        Assert.assertEquals(32, c.size());
+        int i = 0;
+        Iterator<?> ii = c.iterator();
+        while (ii.hasNext()) {
+            Object v = ii.next();
+            i += 1;
+            Assert.assertEquals(i, ((Number) v).intValue());
+        }
+        Assert.assertEquals(32, i);
 
-    public void testLiteralWithNumbers() throws Exception {
-        JexlExpression e = JEXL.createExpression( "[ 5.0 , 10 ]" );
-        JexlContext jc = new MapContext();
+        Integer[] aa = c.toArray(new Integer[32]);
+        Assert.assertEquals(32, aa.length);
+        for (int l = 0; l < 32; ++l) {
+            Assert.assertTrue(aa[l] == l + 1);
+        }
 
-        Object o = e.evaluate( jc );
-        Object[] check = { new Double(5), new Integer(10) };
-        assertTrue( Arrays.equals(check, (Object[])o) );
-        assertTrue (o.getClass().isArray() && o.getClass().getComponentType().equals(Number.class));
+        aa = c.toArray(new Integer[2]);
+        Assert.assertEquals(32, aa.length);
+        for (int l = 0; l < 32; ++l) {
+            Assert.assertTrue(aa[l] == l + 1);
+        }
+
+        aa = c.toArray(new Integer[34]);
+        Assert.assertEquals(34, aa.length);
+        for (int l = 0; l < 32; ++l) {
+            Assert.assertTrue(aa[l] == l + 1);
+        }
+
+        Object[] oaa = c.toArray();
+        Assert.assertEquals(32, oaa.length);
+        for (int l = 0; l < 32; ++l) {
+            Assert.assertEquals(oaa[l], l + 1);
+        }
     }
 
-    public void testLiteralWithNulls() throws Exception {
-        String []exprs = {
-            "[ null , 10 ]",
-            "[ 10 , null ]",
-            "[ 10 , null , 10]",
-            "[ '10' , null ]",
-            "[ null, '10' , null ]"
-        };
-        Object [][]checks = {
-            {null, new Integer(10)},
-            {new Integer(10), null},
-            {new Integer(10), null, new Integer(10)},
-            { "10", null },
-            { null, "10", null }
-        };
+    public void testLongRange() throws Exception {
+        JexlExpression e = JEXL.createExpression("(6789000001L..6789000032L)");
         JexlContext jc = new MapContext();
-        for(int t = 0; t < exprs.length; ++t) {
-            JexlExpression e = JEXL.createExpression( exprs[t] );
-            Object o = e.evaluate( jc );
-            assertTrue(exprs[t], Arrays.equals(checks[t], (Object[])o) );
+
+        Object o = e.evaluate(jc);
+        Assert.assertTrue(o instanceof Collection<?>);
+        Collection<?> c = (Collection<?>) o;
+        Assert.assertEquals(32, c.size());
+        long i = 6789000000L;
+        Iterator<?> ii = c.iterator();
+        while (ii.hasNext()) {
+            Object v = ii.next();
+            i += 1;
+            Assert.assertEquals(i, ((Number) v).longValue());
+        }
+        Assert.assertEquals(6789000032L, i);
+
+        Long[] aa = c.toArray(new Long[32]);
+        Assert.assertEquals(32, aa.length);
+        for (int l = 0; l < 32; ++l) {
+            Assert.assertTrue(aa[l] == 6789000001L + l);
+        }
+
+        aa = c.toArray(new Long[2]);
+        Assert.assertEquals(32, aa.length);
+        for (int l = 0; l < 32; ++l) {
+            Assert.assertTrue(aa[l] == 6789000001L + l);
         }
 
+        aa = c.toArray(new Long[34]);
+        Assert.assertEquals(34, aa.length);
+        for (int l = 0; l < 32; ++l) {
+            Assert.assertTrue(aa[l] == 6789000001L + l);
+        }
+
+        Object[] oaa = c.toArray();
+        Assert.assertEquals(32, oaa.length);
+        for (int l = 0; l < 32; ++l) {
+            Assert.assertEquals(oaa[l], 6789000001L + l);
+        }
     }
 
-    public void testLiteralWithIntegers() throws Exception {
-        JexlExpression e = JEXL.createExpression( "[ 5 , 10 ]" );
+    public void testIntegerSum() throws Exception {
+        JexlScript e = JEXL.createScript("var s = 0; for(var i : (1..5)) { s = s + i; };
s");
         JexlContext jc = new MapContext();
 
-        Object o = e.evaluate( jc );
-        int[] check = { 5, 10 };
-        assertTrue( Arrays.equals(check, (int[])o) );
+        Object o = e.execute(jc);
+        Assert.assertEquals(15, ((Number) o).intValue());
     }
 
-    public void testSizeOfSimpleArrayLiteral() throws Exception {
-        JexlExpression e = JEXL.createExpression( "size([ 'foo' , 'bar' ])" );
+    public void testIntegerContains() throws Exception {
+        JexlScript e = JEXL.createScript("(x)->{ x =~ (1..10) }");
         JexlContext jc = new MapContext();
 
-        Object o = e.evaluate( jc );
-        assertEquals( new Integer( 2 ), o );
+        Object o = e.execute(jc, 5);
+        Assert.assertEquals(Boolean.TRUE, o);
+        o = e.execute(jc, 0);
+        Assert.assertEquals(Boolean.FALSE, o);
+        o = e.execute(jc, 100);
+        Assert.assertEquals(Boolean.FALSE, o);
     }
 
-    public void notestCallingMethodsOnNewMapLiteral() throws Exception {
-        JexlExpression e = JEXL.createExpression( "size({ 'foo' : 'bar' }.values())" );
+    public void testLongSum() throws Exception {
+        JexlScript e = JEXL.createScript("var s = 0; for(var i : (6789000001L..6789000001L))
{ s = s + i; }; s");
         JexlContext jc = new MapContext();
 
-        Object o = e.evaluate( jc );
-        assertEquals( new Integer( 1 ), o );
+        Object o = e.execute(jc);
+        Assert.assertEquals(6789000001L, ((Number) o).longValue());
     }
 
-    public void testNotEmptySimpleArrayLiteral() throws Exception {
-        JexlExpression e = JEXL.createExpression( "empty([ 'foo' , 'bar' ])" );
+    public void testLongContains() throws Exception {
+        JexlScript e = JEXL.createScript("(x)->{ x =~ (90000000001L..90000000010L) }");
         JexlContext jc = new MapContext();
 
-        Object o = e.evaluate( jc );
-        assertFalse( ( (Boolean) o ).booleanValue() );
+        Object o = e.execute(jc, 90000000005L);
+        Assert.assertEquals(Boolean.TRUE, o);
+        o = e.execute(jc, 0);
+        Assert.assertEquals(Boolean.FALSE, o);
+        o = e.execute(jc, 90000000011L);
+        Assert.assertEquals(Boolean.FALSE, o);
     }
-
 }



Mime
View raw message